예제 #1
0
def run_flannel(etcd):
    ''' Render the docker-compose template, and run the flannel daemon '''

    status_set('maintenance', 'Starting flannel network container.')
    context = {}
    if is_state('etcd.tls.available'):
        cert_path = '/etc/ssl/flannel'
    else:
        cert_path = None

    context.update(config())
    context.update({'charm_dir': os.getenv('CHARM_DIR'),
                    'connection_string': etcd.get_connection_string(),
                    'cert_path': cert_path})
    render('flannel-compose.yml', 'files/flannel/docker-compose.yml', context)

    compose = Compose('files/flannel',
                      socket='unix:///var/run/bootstrap-docker.sock')
    compose.up()
    # Give the flannel daemon a moment to actually generate the interface
    # configuration seed. Otherwise we enter a time/wait scenario which
    # may cuase this to be called out of order and break the expectation
    # of the deployment.
    time.sleep(3)
    ingest_network_config()
def start_application():
    compose = Compose('files/voting-app')
    # Launch the workload
    compose.up()
    # Declare ports to Juju - this requires a manual step of juju expose
    # otherwise the public facing ports never actually get exposed for traffic.
    open_port(config('vote_port'))
    open_port(config('result_port'))
예제 #3
0
 def test_context_manager(self, cwdmock):
     cwdmock.return_value = '/tmp'
     with patch('os.chdir') as chmock:
         compose = Compose('files/workspace', strict=False)
         with patch('charms.docker.runner.check_output'):
             compose.up('nginx')
             # We can only test the return called with in this manner.
             # So check that we at least reset context
             chmock.assert_called_with('/tmp')
예제 #4
0
def swarm_relation_broken():
    """
    Destroy the swarm agent, and optionally the manager.
    This state should only be entered if the Docker host relation with ETCD has
    been broken, thus leaving the cluster without a discovery service
    """
    c = Compose("files/swarm")
    c.kill()
    c.rm()
    remove_state("swarm.available")
    status_set("waiting", "Reconfiguring swarm")
예제 #5
0
def reconfigure_flannel_network():
    ''' When the user changes the cidr, we need to reconfigure the
    backing etcd_store, and re-launch the flannel docker container.'''
    # Stop any running flannel containers
    compose = Compose('files/flannel')
    compose.kill()
    compose.rm()

    remove_state('flannel.subnet.configured')
    remove_state('flannel.bridge.configured')
    remove_state('sdn.available')
예제 #6
0
def start_swarm(cluster_string, cert_path=None):
    ''' Render the compose configuration and start the swarm scheduler '''
    opts = {}
    opts['addr'] = unit_private_ip()
    opts['port'] = 2376
    opts['leader'] = is_leader()
    opts['connection_string'] = cluster_string
    if cert_path:
        opts['discovery_tls_path'] = cert_path
    render('docker-compose.yml', 'files/swarm/docker-compose.yml', opts)
    c = Compose('files/swarm')
    c.up()
    set_state('swarm.available')
예제 #7
0
def start_swarm(cluster_string, cert_path=None):
    """ Render the compose configuration and start the swarm scheduler """
    opts = {}
    opts["addr"] = unit_private_ip()
    opts["port"] = 2376
    opts["leader"] = is_leader()
    opts["connection_string"] = cluster_string
    if cert_path:
        opts["discovery_tls_path"] = cert_path
    render("docker-compose.yml", "files/swarm/docker-compose.yml", opts)
    c = Compose("files/swarm")
    c.up()
    set_state("swarm.available")
예제 #8
0
def run_flannel(etcd):
    ''' Render the docker-compose template, and run the flannel daemon '''

    status_set('maintenance', 'Starting flannel network container.')
    context = {}
    if is_state('etcd.tls.available'):
        cert_path = '/etc/ssl/flannel'
    else:
        cert_path = None
    # Put all the configuration values in the context dictionary.
    context.update(config())
    iface = config('iface')
    # When iface is None or empty string.
    if not iface:
        # Attempt to detect the default interface.
        iface = get_default_interface()
        # When detection not successful, print message and return.
        if not iface:
            status_set('blocked', "Interface detection failed. "
                       "Set charm's iface config option.")
            return
    # Add additional key/values to the context dictionary.
    context.update({'charm_dir': os.getenv('CHARM_DIR'),
                    'connection_string': etcd.get_connection_string(),
                    'cert_path': cert_path})
    # Render the flannel-compose.yml file using the current context.
    render('flannel-compose.yml', 'files/flannel/docker-compose.yml', context)

    compose = Compose('files/flannel',
                      socket='unix:///var/run/bootstrap-docker.sock')
    compose.up()
    # Give the flannel daemon a moment to actually generate the interface
    # configuration seed. Otherwise we enter a time/wait scenario which
    # may cause this to be called out of order and break the expectation
    # of the deployment.
    time.sleep(3)
    ingest_network_config()
예제 #9
0
def compose():
    '''compose brings up the athens service.'''
    status_set('maintenance', 'docker-compose up athens')
    os.environ['athens_image'] = config()['athens-image']
    os.environ['ATHENS_DISK_STORAGE_ROOT'] = '/srv/athens/cache'
    os.environ['ATHENS_STORAGE_TYPE'] = 'disk'
    os.environ['ATHENS_NETRC_PATH'] = '/srv/athens/netrc'
    os.environ['http_proxy'] = config()['http_proxy']
    os.environ['https_proxy'] = config()['https_proxy']
    os.environ['no_proxy'] = config()['no_proxy']
    Compose(charm_dir()).up()
    clear_flag('athens.restart')
    set_flag('athens.up')
    application_version_set(
        requests.get('http://localhost:3000/version').json()['version'])
    status_set('active', 'athens running')
예제 #10
0
def swarm_relation_broken():
    """
    Destroy the swarm agent, and optionally the manager.
    This state should only be entered if the Docker host relation with ETCD has
    been broken, thus leaving the cluster without a discovery service
    """
    c = Compose('files/swarm')
    c.kill()
    c.rm()
    remove_state('swarm.available')
    status_set('waiting', 'Reconfiguring swarm')
def stop():
    compose = Compose('files/docker-registry')
    compose.down()
    close_port(config().previous('registry_port'))
    status_set('maintenance', 'Docker registry stopped.')
def start():
    compose = Compose('files/docker-registry')
    compose.up()
    open_port(config('registry_port'))
    status_set('active', 'Docker registry ready.')
예제 #13
0
 def test_run(self, ccmock, chmock):
     compose = Compose('files/workspace', strict=False)
     compose.up('nginx')
     chmock.assert_called_with('files/workspace')
     ccmock.assert_called_with(['docker-compose', 'up', '-d', 'nginx'])
예제 #14
0
 def compose(self):
     return Compose('files/test', strict=False)
예제 #15
0
 def test_init_strict(self):
     with patch('charms.docker.compose.Workspace.validate') as f:
         Compose('test', strict=True)
         # Is this the beast? is mock() doing the right thing here?
         f.assert_called_with()
예제 #16
0
 def _compose(self):
     return Compose(os.path.dirname(str(self.compose_config)))
예제 #17
0
 def test_socket_run_has_host_output(self, ccmock, chmock):
     compose = Compose('files/workspace', strict=False, socket='test')
     compose.up()
     chmock.assert_called_with('files/workspace')
     ccmock.assert_called_with(['docker-compose', 'up', '-d'])
     assert (os.getenv('DOCKER_HOST') == 'test')