def post(req, resp): del resp['data']['instance']['+data']['dockerInspect'] docker_container = resp['data']['instance']['+data']['dockerContainer'] fields = resp['data']['instance']['+data']['+fields'] id = docker_container['Id'] del docker_container['Created'] del docker_container['Id'] del docker_container['Status'] docker_container = _sort_ports(docker_container) del docker_container['Ports'][0]['PublicPort'] del docker_container['Ports'][1]['PublicPort'] del fields['dockerIp'] assert fields['dockerPorts']['8080/tcp'] is not None assert fields['dockerPorts']['12201/udp'] is not None fields['dockerPorts']['8080/tcp'] = '1234' fields['dockerPorts']['12201/udp'] = '5678' inspect = Client().inspect_container(id) port = Config.api_proxy_listen_port() assert 'CATTLE_CONFIG_URL={0}'.format(Config.config_url()) in \ inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_SCHEME=https' not in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PATH=/a/path' not in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PORT={0}'.format(port) not in \ inspect['Config']['Env'] assert 'ENV1=value1' in inspect['Config']['Env']
def post(req, resp): del resp['data']['instance']['+data']['dockerInspect'] docker_container = resp['data']['instance']['+data']['dockerContainer'] fields = resp['data']['instance']['+data']['+fields'] id = docker_container['Id'] del docker_container['Created'] del docker_container['Id'] del docker_container['Status'] docker_container = _sort_ports(docker_container) del docker_container['Ports'][0]['PublicPort'] del docker_container['Ports'][1]['PublicPort'] del fields['dockerIp'] assert fields['dockerPorts']['8080/tcp'] is not None assert fields['dockerPorts']['12201/udp'] is not None fields['dockerPorts']['8080/tcp'] = '1234' fields['dockerPorts']['12201/udp'] = '5678' inspect = Client().inspect_container(id) port = Config.api_proxy_listen_port() assert 'CATTLE_CONFIG_URL={0}'.format(Config.config_url()) in \ inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_SCHEME=https' not in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PATH=/a/path' not in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PORT={0}'.format(port) not in \ inspect['Config']['Env'] assert 'ENV1=value1' in inspect['Config']['Env']
def setup_cattle_config_url(instance, create_config): if instance.get('agentId') is None: return if 'labels' not in create_config: create_config['labels'] = {} create_config['labels']['io.rancher.container.agent_id'] = \ str(instance.get('agentId')) url = Config.config_url() if url is not None: parsed = urlparse(url) if 'localhost' == parsed.hostname: port = Config.api_proxy_listen_port() add_to_env(create_config, CATTLE_AGENT_INSTANCE='true', CATTLE_CONFIG_URL_SCHEME=parsed.scheme, CATTLE_CONFIG_URL_PATH=parsed.path, CATTLE_CONFIG_URL_PORT=port) else: add_to_env(create_config, CATTLE_CONFIG_URL=url) add_to_env(create_config, CATTLE_URL=url)
def post(req, resp): id = resp['data']['instanceHostMap']['instance'] id = id['+data']['dockerContainer']['Id'] inspect = docker_client().inspect_container(id) instance_activate_common_validation(resp) port = Config.api_proxy_listen_port() assert 'CATTLE_CONFIG_URL_SCHEME=https' in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PATH=/a/path' in inspect['Config']['Env'] assert 'CATTLE_CONFIG_URL_PORT={0}'.format(port) in \ inspect['Config']['Env']
def before_start(self, instance, host, config, start_config): if instance.get('agentId') is None: return url = Config.config_url() if url is not None: parsed = urlparse(url) if 'localhost' == parsed.hostname: port = Config.api_proxy_listen_port() add_to_env(config, CATTLE_AGENT_INSTANCE='true', CATTLE_CONFIG_URL_SCHEME=parsed.scheme, CATTLE_CONFIG_URL_PATH=parsed.path, CATTLE_CONFIG_URL_PORT=port) else: add_to_env(config, CATTLE_CONFIG_URL=url)
def before_start(self, instance, host, config, start_config): if instance.get('agentId') is None: return url = Config.config_url() if url is not None: parsed = urlparse(url) if 'localhost' == parsed.hostname: port = Config.api_proxy_listen_port() add_to_env(config, CATTLE_AGENT_INSTANCE='true', CATTLE_CONFIG_URL_SCHEME=parsed.scheme, CATTLE_CONFIG_URL_PATH=parsed.path, CATTLE_CONFIG_URL_PORT=port) else: add_to_env(config, CATTLE_CONFIG_URL=url)
def on_startup(self): url = Config.config_url() if "localhost" not in url: return parsed = urlparse.urlparse(url) from_host = Config.api_proxy_listen_host() from_port = Config.api_proxy_listen_port() to_host_ip = socket.gethostbyname(parsed.hostname) to_port = get_url_port(url) log.info("Proxying %s:%s -> %s:%s", from_host, from_port, to_host_ip, to_port) listen = "TCP4-LISTEN:{0},fork,bind={1},reuseaddr".format(from_port, from_host) to = "TCP:{0}:{1}".format(to_host_ip, to_port) background(["socat", listen, to])
def on_startup(self): url = Config.config_url() if 'localhost' not in url: return parsed = urlparse.urlparse(url) from_host = Config.api_proxy_listen_host() from_port = Config.api_proxy_listen_port() to_host_ip = socket.gethostbyname(parsed.hostname) to_port = get_url_port(url) log.info('Proxying %s:%s -> %s:%s', from_host, from_port, to_host_ip, to_port) listen = 'TCP4-LISTEN:{0},fork,bind={1},reuseaddr'.format(from_port, from_host) to = 'TCP:{0}:{1}'.format(to_host_ip, to_port) background(['socat', listen, to])