def update_http_port(self, port, new_domains=None): if new_domains and new_domains != self.domains: him.remove_container_routes(self, new_domains) self.domains = new_domains self.http_port = port self.save() him.route_container_ports(self)
def start_container(self): bindings = self.container.ports for internal, external in self.container.ports.iteritems(): if not external: bindings[internal] = random.randint(1025, 65535) success = False error = None while not success and not error: try: c.docker.start(self.container.docker_id, port_bindings=bindings) logger.debug("Container started: "+self.container.id) self.container.ports = bindings self.container.save() him.route_container_ports(self.container) success = True except docker.client.APIError as e: if e.is_client_error(): self.push_error(e) error = True if e.is_server_error(): if "port" in e: # This still has a chance to fail msg = e.explanation.rsplit(":", 1) bad_port = int(msg) for port in bindings: if bindings[port] == bad_port: bindings[port] = random.randint(1025, 65535) else: self.push_error(e) error = True