def manage_docker_opts(opts, remove=False): """ Add or remove docker daemon options. Options here will be merged with configured docker-opts when layer-docker processes a daemon restart. :param opts: Dictionary keys/values; use None value if the key is a flag :param remove: Boolean True to remove the options; False to add them :return: None """ try: docker_opts = DockerOpts() except Exception as e: hookenv.log(e) return for k, v in opts.items(): # Always remove existing option if docker_opts.exists(k): docker_opts.pop(k) if not remove: docker_opts.add(k, v) hookenv.log('DockerOpts daemon options changed. Requesting a restart.') # State will be removed by layer-docker after restart set_state('docker.restart')
def scrub_sdn_config(): ''' If this scenario of states is true, we have likely broken a relationship to our once configured SDN provider. This necessitates a cleanup of the Docker Options for BIP and MTU of the presumed dead SDN interface. ''' opts = DockerOpts() try: opts.pop('bip') except KeyError: hookenv.log('Unable to locate bip in Docker config.') hookenv.log('Assuming no action required.') try: opts.pop('mtu') except KeyError: hookenv.log('Unable to locate mtu in Docker config.') hookenv.log('Assuming no action required.') # This method does everything we need to ensure the bridge configuration # has been removed. restarting the daemon restores docker with its default # networking mode. _remove_docker_network_bridge() recycle_daemon() remove_state('docker.sdn.configured')
def scrub_sdn_config(): """ If this scenario of states is true, we have likely broken a relationship to our once configured SDN provider. This necessitates a cleanup of the Docker Options for BIP and MTU of the presumed dead SDN interface. :return: None """ opts = DockerOpts() try: opts.pop('bip') except KeyError: hookenv.log('Unable to locate bip in Docker config.') hookenv.log('Assuming no action required.') try: opts.pop('mtu') except KeyError: hookenv.log('Unable to locate mtu in Docker config.') hookenv.log('Assuming no action required.') # This method does everything we need to ensure the bridge configuration # has been removed. restarting the daemon restores docker with its default # networking mode. _remove_docker_network_bridge() recycle_daemon() remove_state('docker.sdn.configured')
def container_sdn_setup(sdn): ''' Receive the information from the SDN plugin, and render the docker engine options. ''' sdn_config = sdn.get_sdn_config() bind_ip = sdn_config['subnet'] mtu = sdn_config['mtu'] if data_changed('bip', bind_ip) or data_changed('mtu', mtu): status_set('maintenance', 'Configuring container runtime with SDN.') opts = DockerOpts() # This is a great way to misconfigure a docker daemon. Remove the # existing bind ip and mtu values of the SDN if opts.exists('bip'): opts.pop('bip') if opts.exists('mtu'): opts.pop('mtu') opts.add('bip', bind_ip) opts.add('mtu', mtu) _remove_docker_network_bridge() set_state('docker.sdn.configured')
def manage_docker_opts(opts, remove=False): '''Add or remove docker daemon options. Options here will be merged with configured docker-opts when layer-docker processes a daemon restart. :param: dict opts: option keys/values; use None value if the key is a flag :param: bool remove: True to remove the options; False to add them ''' docker_opts = DockerOpts() for k, v in opts.items(): # Always remove existing option if docker_opts.exists(k): docker_opts.pop(k) if not remove: docker_opts.add(k, v) hookenv.log('DockerOpts daemon options changed. Requesting a restart.') # State will be removed by layer-docker after restart set_state('docker.restart')
def container_sdn_setup(sdn): """ Receive the information from the SDN plugin, and render the docker engine options. :param sdn: SDNPluginProvider :return: None """ sdn_config = sdn.get_sdn_config() bind_ip = sdn_config["subnet"] mtu = sdn_config["mtu"] if data_changed("bip", bind_ip) or data_changed("mtu", mtu): status.maintenance("Configuring container runtime with SDN.") opts = DockerOpts() # This is a great way to misconfigure a docker daemon. Remove the # existing bind ip and mtu values of the SDN if opts.exists("bip"): opts.pop("bip") if opts.exists("mtu"): opts.pop("mtu") opts.add("bip", bind_ip) opts.add("mtu", mtu) _remove_docker_network_bridge() set_state("docker.sdn.configured")