Exemplo n.º 1
0
 def env(self):
     command = CommandBuilder('docker-machine', 'env')
     if self.local:
         command.append('-u')
     else:
         command.append(self.name)
     return command.run()
Exemplo n.º 2
0
    def create(self, driver, **config):
        command = CommandBuilder('docker-machine', 'create')
        command.append('--driver', driver)
        if config.get('swarm_token') is not None:
            command.append('--swarm')
            command.append('--swarm-discovery',
                           'token://{token}'.format(config.get('swarm_token')))
        if config.get('swarm_master') is not None:
            command.append('--swarm-master')
        if config.get('registry_mirror') is not None:
            ip = DockerMachine(config.get('registry_mirror')).ip()
            if not ip:
                printe('IP for the registry machine could not be determined. '
                       'Does that machine have an IP?', terminate=True)
            command.append('--engine-registry-mirror', 'http://%s:5000' % ip)
        if config.get('experimental') is not None:
            command.append('--engine-install-url',
                           'https://experimental.docker.com')
        if config.get('neighbor_machine') is not None \
                and not config.get('multihost_networking') is not None:
            printe('Neighbor machine was provided but multihost networking '
                   'was not enabled explicitly. Multihost networking must be '
                   'enabled if neighboring machine is to be used.',
                   terminate=2)
        if config.get('multihost_networking') is not None:
            command.append('--engine-opt', 'default-network=overlay:multihost')
            command.append('--engine-label',
                           'com.docker.network.driver.overlay.'
                           'bind_interface=eth0')
            if config.get('neighbor_machine') is not None:
                command.append('--engine-label',
                               'com.docker.network.driver.overlay.'
                               'neighbor_ip={ip}'.format(
                                   DockerMachine(
                                       config.get('neighbor_machine')).ip()))
        if config.get('consul') is not None:
            if isinstance(config.get('consul'), str):
                consul_name = config.get('consul')
            else:
                consul_name = 'consul'
            command.append('--engine-opt', 'kv-store=consul:{ip}:8500'.format(
                DockerMachine(consul_name).ip()))

        command.append(self.name)
        return command.run()