예제 #1
0
 def exec_command_and_get_output(self, cmd, timeout=2):
     exec_id = cli.exec_create(self.get_name(), cmd,
                               stdout=True, stderr=False,
                               tty=False)
     output_stream = cli.exec_start(exec_id, detach=False,
                                    stream=True)
     status = self.check_exit_status(exec_id, None, timeout)
     if conf.containers_file() is None:
         return (status, ''.join(output_stream))
     else:
         return (status, ''.join(output_stream.readline()))
예제 #2
0
 def exec_command_and_get_output(self, cmd, timeout=2):
     exec_id = cli.exec_create(self.get_name(),
                               cmd,
                               stdout=True,
                               stderr=False,
                               tty=False)
     output_stream = cli.exec_start(exec_id, detach=False, stream=True)
     status = self.check_exit_status(exec_id, None, timeout)
     if conf.containers_file() is None:
         return (status, ''.join(output_stream))
     else:
         return (status, ''.join(output_stream.readline()))
예제 #3
0
    def __init__(self, containers_file, extra_ssh_config_file):

        with open(conf.containers_file()) as infile:
            containers = yaml.load(infile)

        self._containers = []
        self._container_default_config = {}

        self._ssh_config = SSHConfig()
        if extra_ssh_config_file is not None:
            with open(extra_ssh_config_file) as ssh_config_file:
                self._ssh_config.parse(ssh_config_file)

        self._missing_host_key_policy = AutoAddPolicy()

        for container_config in containers:
            if container_config['Host'] == '*':
                self._container_default_config = container_config
                break

        for container_config in containers:
            if container_config['Host'] == '*':
                continue

            container_host = container_config['Host']
            ssh_host_config = self._ssh_config.lookup(container_host)

            ip_address = self._get_hostname_option(container_config)

            container = {
                'Hostname': container_host,
                'Id': container_host,
                'Name': container_host,
                'Labels': {
                    'interface': container_config['Interface'],
                    'type': container_config['Type']
                },
                'State': {
                   'Running': 'running'
                },
                'NetworkSettings': {
                    'IPAddress': ip_address,
                    'MacAddress': None,
                    'Ports': None
                },
                'Config': container_config
            }
            self._containers.append(container)

        self.next_exec_id = 0
        self.ssh_connections = {}
        self.execs = {}
예제 #4
0
import logging
import os.path
import time
import yaml

from mdts.lib.mdtsdocker import DockerClient
from mdts.lib.ssh import SshClient

from mdts.services.interface import Interface
from mdts.tests.utils import conf

LOG = logging.getLogger(__name__)

cli = None

if conf.containers_file() is None:
    print("containers_file not configured -> using Docker API")
    cli = DockerClient(base_url='unix://var/run/docker.sock',
                       timeout=conf.docker_http_timeout(),
                       sandbox_prefix=conf.sandbox_prefix(),
                       sandbox_name=conf.sandbox_name())
else:
    print("containers_file configured as '%s' -> using SSH" %
          conf.containers_file())
    cli = SshClient(conf.containers_file(), conf.extra_ssh_config_file())


class Service(object):
    def __init__(self, container_id):
        self.container_id = container_id
        self.info = cli.inspect_container(container_id)
예제 #5
0
파일: service.py 프로젝트: itsuugo/midonet
import logging
import os.path
import time
import yaml

from mdts.lib.mdtsdocker import DockerClient
from mdts.lib.ssh import SshClient

from mdts.services.interface import Interface
from mdts.tests.utils import conf

LOG = logging.getLogger(__name__)

cli = None

if conf.containers_file() is None:
    print("containers_file not configured -> using Docker API")
    cli = DockerClient(base_url='unix://var/run/docker.sock',
                       timeout=conf.docker_http_timeout(),
                       sandbox_prefix=conf.sandbox_prefix(),
                       sandbox_name=conf.sandbox_name())
else:
    print("containers_file configured as '%s' -> using SSH" %
          conf.containers_file())
    cli = SshClient(conf.containers_file(), conf.extra_ssh_config_file())

class Service(object):

    def __init__(self, container_id):
        self.container_id = container_id
        self.info = cli.inspect_container(container_id)