def setup_links(instance, create_config, start_config): """ Sets up a container's config for rancher-managed links by removing the docker native link configuration and emulating links through environment variables. Note that a non-rancher container (one created and started outside the rancher API) container will not have its link configuration manipulated. This is because on a container restart, we would not be able to properly rebuild the link configuration because it depends on manipulating the create_config. """ if not _has_service(instance, 'linkService') or is_nonrancher_container( instance): return if 'links' in start_config: del start_config['links'] result = {} for link in instance.instanceLinks: name = link.linkName try: for link_port in link.data.fields.ports: proto = link_port.protocol ip = link_port.ipAddress dst = link_port.publicPort port = link_port.privatePort full_port = '{0}://{1}:{2}'.format(proto, ip, dst) data = { 'NAME': '/cattle/{0}'.format(name), 'PORT': full_port, 'PORT_{0}_{1}'.format(port, proto): full_port, 'PORT_{0}_{1}_ADDR'.format(port, proto): ip, 'PORT_{0}_{1}_PORT'.format(port, proto): dst, 'PORT_{0}_{1}_PROTO'.format(port, proto): proto, } for k, v in data.items(): result['{0}_{1}'.format(name, k).upper()] = v except AttributeError: pass if len(result) > 0: add_to_env(create_config, **result)
def setup_ports(instance, create_config, start_config): """ Sets up a container's config for rancher-managed ports by removing the native docker port configuration. We do this because rancher emulates ports outside of Docker's direct purview to allow for multi-host networking. Note that a non-rancher container (one created and started outside the rancher API) will not have its port configuration manipulated. This is because on a container restart, we would not be able to properly rebuild the port config because it depends on manipulating the create_config. """ if not _has_service(instance, 'portService') or is_nonrancher_container( instance): return if 'ports' in create_config: del create_config['ports'] start_config['publish_all_ports'] = False
def setup_ports(instance, create_config, start_config): """ Sets up a container's config for rancher-managed ports by removing the native docker port configuration. We do this because rancher emulates ports outside of Docker's direct purview to allow for multi-host networking. Note that a non-rancher container (one created and started outside the rancher API) will not have its port configuration manipulated. This is because on a container restart, we would not be able to properly rebuild the port config because it depends on manipulating the create_config. """ if not _has_service(instance, 'portService') or is_nonrancher_container(instance): return if 'ports' in create_config: del create_config['ports'] start_config['publish_all_ports'] = False
def setup_links(instance, create_config, start_config): """ Sets up a container's config for rancher-managed links by removing the docker native link configuration and emulating links through environment variables. Note that a non-rancher container (one created and started outside the rancher API) container will not have its link configuration manipulated. This is because on a container restart, we would not be able to properly rebuild the link configuration because it depends on manipulating the create_config. """ if not _has_service(instance, 'linkService') or is_nonrancher_container( instance): return if 'links' in start_config: del start_config['links'] result = {} for link in instance.instanceLinks: link_name = link.linkName _add_link_env(link_name, link, result) _copy_link_env(link_name, link, result) try: for name in link.data.fields.instanceNames: _add_link_env(name, link, result, in_ip=link_name) _copy_link_env(name, link, result) # This does assume the format {env}_{name} parts = name.split('_', 1) if len(parts) == 1: continue _add_link_env(parts[1], link, result, in_ip=link_name) _copy_link_env(parts[1], link, result) except AttributeError: pass if len(result) > 0: add_to_env(create_config, **result)
def setup_links(instance, create_config, start_config): """ Sets up a container's config for rancher-managed links by removing the docker native link configuration and emulating links through environment variables. Note that a non-rancher container (one created and started outside the rancher API) container will not have its link configuration manipulated. This is because on a container restart, we would not be able to properly rebuild the link configuration because it depends on manipulating the create_config. """ if not _has_service(instance, 'linkService') or is_nonrancher_container(instance): return if 'links' in start_config: del start_config['links'] result = {} for link in instance.instanceLinks: link_name = link.linkName _add_link_env(link_name, link, result) _copy_link_env(link_name, link, result) try: for name in link.data.fields.instanceNames: _add_link_env(name, link, result, in_ip=link_name) _copy_link_env(name, link, result) # This does assume the format {env}_{name} parts = name.split('_', 1) if len(parts) == 1: continue _add_link_env(parts[1], link, result, in_ip=link_name) _copy_link_env(parts[1], link, result) except AttributeError: pass if len(result) > 0: add_to_env(create_config, **result)