def __init__(self, identifier, image='topology/ryu:latest', **kwargs):

        # Determine shared directory
        shared_dir = '/tmp/topology_{}_{}'.format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = ['{}:/tmp'.format(shared_dir)]

        super(RyuControllerNode, self).__init__(identifier,
                                                image=image,
                                                binds=binds,
                                                **kwargs)

        # Supervisor daemon
        self._supervisord = None

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Copy the ryu app into the container
        self.app_name = self.metadata.get('app', None)
        if self.app_name is not None:
            copy(self.app_name, self.shared_dir)

        # Add bash shell
        self._shells['bash'] = DockerShell(self.container_id,
                                           'sh -c "TERM=dumb bash"',
                                           'root@.*:.*# ')
    def __init__(
            self, identifier,
            image='topology/ryu:latest',
            **kwargs):

        # Determine shared directory
        shared_dir = '/tmp/topology_{}_{}'.format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = ['{}:/tmp'.format(shared_dir)]

        super(RyuControllerNode, self).__init__(
            identifier, image=image, binds=binds, **kwargs
        )

        # Supervisor daemon
        self._supervisord = None

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Copy the ryu app into the container
        self.app_name = self.metadata.get('app', None)
        if self.app_name is not None:
            copy(self.app_name, self.shared_dir)

        # Add bash shell
        self._shells['bash'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# '
        )
Example #3
0
    def __init__(
            self, identifier,
            image='ubuntu:latest', registry=None, command='bash',
            binds=None, network_mode='none', hostname=None, **kwargs):

        super(DockerNode, self).__init__(identifier, **kwargs)

        self._pid = None
        self._image = image
        self._registry = registry
        self._command = command
        self._hostname = hostname
        self._client = Client(version='auto')

        # Autopull docker image if necessary
        self._autopull()

        # Create shared directory
        self.shared_dir = '/tmp/topology/{}_{}'.format(
            identifier, str(id(self))
        )
        ensure_dir(self.shared_dir)

        # Add binded directories
        container_binds = [
            '{}:/tmp'.format(self.shared_dir)
        ]
        if binds is not None:
            container_binds.extend(binds.split(';'))

        if (self.metadata.get('type', 'host') == 'host' or
           self.metadata.get('type', 'host') == 'oobmhost'):
            # Create host config
            self._host_config = self._client.create_host_config(
                # Container is given access to all devices
                cap_add=['ALL'],
                # Avoid connecting to host bridge, usually docker0
                network_mode=network_mode,
                binds=container_binds
            )
        else:
            # Create host config
            self._host_config = self._client.create_host_config(
                # Container is given access to all devices
                privileged=True,
                # Avoid connecting to host bridge, usually docker0
                network_mode=network_mode,
                binds=container_binds
            )

        # Create container
        self.container_id = self._client.create_container(
            image=self._image,
            command=self._command,
            name='{}_{}'.format(identifier, str(id(self))),
            detach=True,
            tty=True,
            hostname=self._hostname,
            host_config=self._host_config
        )['Id']
Example #4
0
    def __init__(self, identifier, image='topology/p4switch:latest', **kwargs):

        # Determine shared directory
        shared_dir = '/tmp/topology_{}_{}'.format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = ['{}:/tmp'.format(shared_dir)]

        super(P4SwitchNode, self).__init__(identifier,
                                           image=image,
                                           binds=binds,
                                           **kwargs)

        # Behavioral model daemon process
        self._bm_daemon = None

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Add bash shell
        self._shells['bash'] = DockerShell(self.container_id,
                                           'sh -c "TERM=dumb bash"',
                                           'root@.*:.*# ')

        # Add SAI shell (https://github.com/p4lang/switchsai)
        self._shells['sai'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/switch_sai_rpc-remote '
            '-h localhost:9092 ')

        # Add switchapi shell (https://github.com/p4lang/switchapi)
        self._shells['api'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/switch_api_rpc-remote '
            '-h localhost:9091 ')

        # Add PD shells
        self._shells['pd_conn_mgr'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/conn_mgr-remote '
            '-h localhost:9090 ')
        self._shells['pd_mc'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/mc-remote '
            '-h localhost:9090 ')
        self._shells['pd_p4'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/dc-remote '
            '-h localhost:9090 ')
Example #5
0
    def __init__(
            self, identifier,
            image='ubuntu:latest', registry=None, command='bash',
            binds=None, network_mode='none', hostname=None, **kwargs):

        super(DockerNode, self).__init__(identifier, **kwargs)

        self._pid = None
        self._image = image
        self._registry = registry
        self._command = command
        self._hostname = hostname
        self._client = Client(version='auto')

        # Autopull docker image if necessary
        self._autopull()

        # Create shared directory
        self.shared_dir = '/tmp/topology/{}_{}'.format(
            identifier, str(id(self))
        )
        ensure_dir(self.shared_dir)

        # Add binded directories
        container_binds = [
            '{}:/tmp'.format(self.shared_dir)
        ]
        if binds is not None:
            container_binds.extend(binds.split(';'))

        # Create host config
        self._host_config = self._client.create_host_config(
            # Container is given access to all devices
            privileged=True,
            # Avoid connecting to host bridge, usually docker0
            network_mode=network_mode,
            binds=container_binds
        )

        # Create container
        self.container_id = self._client.create_container(
            image=self._image,
            command=self._command,
            name='{}_{}'.format(identifier, str(id(self))),
            detach=True,
            tty=True,
            hostname=self._hostname,
            host_config=self._host_config
        )['Id']
Example #6
0
    def __init__(self, identifier, image="topology/ops:latest", **kwargs):

        # Determine shared directory
        shared_dir = "/tmp/topology_{}_{}".format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = ["{}:/tmp".format(shared_dir), "/dev/log:/dev/log", "/sys/fs/cgroup:/sys/fs/cgroup:ro"]

        super(OpenSwitchNode, self).__init__(identifier, image=image, command="/sbin/init", binds=binds, **kwargs)

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Add vtysh (default) and bash shell
        self._shells["vtysh"] = DockerShell(self.container_id, "vtysh", "(^|\n)switch(\([\-a-zA-Z0-9]*\))?#")
        self._shells["bash"] = DockerShell(self.container_id, 'sh -c "TERM=dumb bash"', "bash-.*#")
        self._shells["bash_swns"] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb ip netns exec swns bash"', "bash-.*#"
        )
        self._shells["vsctl"] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', "bash-.*#", prefix="ovs-vsctl ", timeout=60
        )
Example #7
0
    def __init__(self, identifier, image='topology/ops:latest', **kwargs):

        # Determine shared directory
        shared_dir = '/tmp/topology_{}_{}'.format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = [
            '{}:/tmp'.format(shared_dir), '/dev/log:/dev/log',
            '/sys/fs/cgroup:/sys/fs/cgroup:ro'
        ]

        super(OpenSwitchNode, self).__init__(identifier,
                                             image=image,
                                             command='/sbin/init',
                                             binds=binds,
                                             hostname='switch',
                                             **kwargs)

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Add vtysh (default) and bash shell
        self._shells['vtysh'] = DockerShell(
            self.container_id, 'vtysh', '(^|\n)switch(\([\-a-zA-Z0-9]*\))?#')
        self._shells['bash'] = DockerShell(self.container_id,
                                           'sh -c "TERM=dumb bash"',
                                           'bash-.*#')
        self._shells['bash_swns'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb ip netns exec swns bash"',
            'bash-.*#')
        self._shells['vsctl'] = DockerShell(self.container_id,
                                            'sh -c "TERM=dumb bash"',
                                            'bash-.*#',
                                            prefix='ovs-vsctl ',
                                            timeout=60)
Example #8
0
    def __init__(self,
                 identifier,
                 image='ubuntu:latest',
                 registry=None,
                 command='bash',
                 binds=None,
                 network_mode='none',
                 hostname=None,
                 shared_dir_base='/tmp/topology/docker/',
                 shared_dir_mount='/var/topology',
                 environment=None,
                 tty=True,
                 devices=None,
                 **kwargs):

        super(DockerNode, self).__init__(identifier, **kwargs)

        self._pid = None
        self._image = image
        self._registry = registry
        self._command = command
        self._hostname = hostname
        self._environment = environment
        self._client = Client(version='auto')

        self._container_name = '{identifier}_{pid}_{timestamp}'.format(
            identifier=identifier,
            pid=getpid(),
            timestamp=datetime.now().isoformat().replace(':', '-'))
        self._shared_dir_base = shared_dir_base
        self._shared_dir_mount = shared_dir_mount
        self._shared_dir = join(shared_dir_base, self._container_name)

        # Autopull docker image if necessary
        self._autopull()

        # Create shared directory
        ensure_dir(self._shared_dir)

        # Add binded directories
        container_binds = [
            '{}:{}'.format(self._shared_dir, self._shared_dir_mount)
        ]
        if binds is not None:
            container_binds.extend(binds.split(';'))

        # Create host config
        self._host_config = self._client.create_host_config(
            # Container is given access to all devices
            privileged=True,
            devices=devices,
            # Avoid connecting to host bridge, usually docker0
            network_mode=network_mode,
            binds=container_binds)

        # Create container
        self._container_id = self._client.create_container(
            image=self._image,
            command=self._command,
            name=self._container_name,
            detach=True,
            tty=tty,
            hostname=self._hostname,
            host_config=self._host_config,
            environment=self._environment)['Id']
    def __init__(
            self, identifier,
            image='topology/p4switch:latest',
            **kwargs):

        # Determine shared directory
        shared_dir = '/tmp/topology_{}_{}'.format(identifier, str(id(self)))
        ensure_dir(shared_dir)

        # Add binded directories
        binds = ['{}:/tmp'.format(shared_dir)]

        super(P4SwitchNode, self).__init__(
            identifier, image=image, binds=binds, **kwargs
        )

        # Behavioral model daemon process
        self._bm_daemon = None

        # Save location of the shared dir in host
        self.shared_dir = shared_dir

        # Add bash shell
        self._shells['bash'] = DockerShell(
            self.container_id, 'sh -c "TERM=dumb bash"', 'root@.*:.*# '
        )

        # Add SAI shell (https://github.com/p4lang/switchsai)
        self._shells['sai'] = DockerShell(
            self.container_id,
            'sh -c "TERM=dumb bash"',
            'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/switch_sai_rpc-remote '
            '-h localhost:9092 '
        )

        # Add switchapi shell (https://github.com/p4lang/switchapi)
        self._shells['api'] = DockerShell(
            self.container_id,
            'sh -c "TERM=dumb bash"',
            'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/switch_api_rpc-remote '
            '-h localhost:9091 '
        )

        # Add PD shells
        self._shells['pd_conn_mgr'] = DockerShell(
            self.container_id,
            'sh -c "TERM=dumb bash"',
            'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/conn_mgr-remote '
            '-h localhost:9090 '
        )
        self._shells['pd_mc'] = DockerShell(
            self.container_id,
            'sh -c "TERM=dumb bash"',
            'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/mc-remote '
            '-h localhost:9090 '
        )
        self._shells['pd_p4'] = DockerShell(
            self.container_id,
            'sh -c "TERM=dumb bash"',
            'root@.*:.*# ',
            '/p4factory/targets/switch/tests/pd_thrift/dc-remote '
            '-h localhost:9090 '
        )
Example #10
0
    def __init__(self,
                 identifier,
                 image='ubuntu:latest',
                 registry=None,
                 command='bash',
                 binds=None,
                 network_mode='none',
                 hostname=None,
                 environment=None,
                 privileged=True,
                 tty=True,
                 shared_dir_base='/tmp/topology/docker/',
                 shared_dir_mount='/var/topology',
                 create_host_config_kwargs=None,
                 create_container_kwargs=None,
                 **kwargs):

        super(DockerNode, self).__init__(identifier, **kwargs)

        self._pid = None
        self._image = image
        self._registry = registry
        self._command = command
        self._hostname = hostname
        self._environment = environment
        self._client = APIClient(version='auto')

        self._container_name = '{identifier}_{pid}_{timestamp}'.format(
            identifier=identifier,
            pid=getpid(),
            timestamp=datetime.now().isoformat().replace(':', '-'))
        self._shared_dir_base = shared_dir_base
        self._shared_dir_mount = shared_dir_mount
        self._shared_dir = join(shared_dir_base, self._container_name)

        self._create_host_config_kwargs = create_host_config_kwargs or {}
        self._create_container_kwargs = create_container_kwargs or {}

        # Autopull docker image if necessary
        self._autopull()

        # Create shared directory
        ensure_dir(self._shared_dir)

        # Add binded directories
        container_binds = [
            '{}:{}'.format(self._shared_dir, self._shared_dir_mount)
        ]
        if binds is not None:
            container_binds.extend(binds.split(';'))

        # Create host config
        create_host_config_call = {
            'privileged': privileged,
            'network_mode': network_mode,
            'binds': container_binds,
            'init': True
        }
        create_host_config_call.update(self._create_host_config_kwargs)

        self._host_config = self._client.create_host_config(
            **create_host_config_call)

        # Create container
        create_container_call = {
            'image': self._image,
            'command': self._command,
            'name': self._container_name,
            'detach': True,
            'tty': tty,
            'hostname': self._hostname,
            'host_config': self._host_config,
            'environment': self._environment,
        }
        create_container_call.update(self._create_container_kwargs)

        self._container_id = self._client.create_container(
            **create_container_call)['Id']