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 kmeans_gen(self, l=10):
        for _ in range(l):
            builder = CommandBuilder(self)
            cmd = builder.kmeans_random_command()
            assert cmd is not None
            # print(cmd)

            self.take_command(cmd)
Exemplo n.º 3
0
 def __init__(self, name=False, url=False):
     if not name and url:
         name = CommandBuilder('bash', '-c',
                               'docker-machine ls | tail -n +2 | grep "%s" '
                               '| sed "s/\s.*//"' % url).run()
     self.local = not name
     if self.local:
         name = '127.0.0.1'
     self.name = name
Exemplo n.º 4
0
 def __init__(self, drawer, exception_handler):
     super().__init__(drawer)
     self.regex_pattern = r'(^[a-zA-Z]\b)\s+?(-?\b\d+\.?\d?\b)?\s*?([#|//].*)?$'
     self.__output_log = []
     self.exception_handler = exception_handler
     try:
         self.command_builder = CommandBuilder()
     except Exception as e:
         self.exception_handler.display_and_exit(e)
Exemplo n.º 5
0
 def __init__(self):
     self.started = False
     self.matlab = None
     self.quarc = True
     self.external = True
     self.build = True
     self.external = self.quarc & self.external
     self.build = self.quarc & self.build
     self.commandBuilder = CommandBuilder()
Exemplo n.º 6
0
    def rand_gen(self, l=10):
        for _ in range(l):
            # self.tree_.dump_tree()

            builder = CommandBuilder(self)
            cmd = builder.random_command()
            assert cmd is not None
            # print(cmd)

            self.take_command(cmd)
Exemplo n.º 7
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()
Exemplo n.º 8
0
 def logs(self, tail=100):
     if self.name:
         return self.base_command().append(
             'logs', '--follow', '--tail', str(int(tail)),
             self.name).run(replaceForeground=True)
     else:
         return CommandBuilder(
             'bash', '-c', """
    set -m
    trap 'kill $(jobs -p)' 2
    count=0
    for c in $(docker ps --format "{{.Names}}"); do
        color="$(echo "$c" | md5 | cut -c1-4)"
        color=$((31 + ((16#${color}) % 7) ))
        docker logs -f $c | sed "s/^/\033[1;${color}m$c | \033[0;00m/" &
        count+=1
    done
    wait
         """).run(replaceForeground=True)
Exemplo n.º 9
0
 def base_command(self):
     return CommandBuilder('docker')
Exemplo n.º 10
0
 def ip(self):
     return CommandBuilder('docker-machine', 'ip', self.name).run()
Exemplo n.º 11
0
 def list():
     return CommandBuilder('docker-machine',
                           'ls').run(replaceForeground=True)
Exemplo n.º 12
0
 def stop(self):
     if self.local:
         printe("Machine name not provided: Won't try to stop local.")
     return CommandBuilder('docker-machine', 'stop', self.name).run()
Exemplo n.º 13
0
 def ssh(self):
     if self.local:
         printe("Machine name not provided: Won't try to ssh to local.")
     return CommandBuilder('docker-machine', 'ssh',
                           self.name).run(replaceForeground=True)
Exemplo n.º 14
0
 def remove(self):
     if self.local:
         printe("Machine name not provided: Cannot remove a local Docker "
                "instance.")
     return CommandBuilder('docker-machine', 'rm', self.name).run()
Exemplo n.º 15
0
 def config(self):
     if self.local:
         return False
     return CommandBuilder('docker-machine', 'config',
                           self.name).run().split()