示例#1
0
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker("info")
        self.node_info = {}
        for node, nodeip in [
            (entry[0], entry[1].split(":")[0]) for entry in info["DriverStatus"] if SIMPLE_IP_PORT.match(entry[1])
        ]:
            self.node_info[node] = nodeip
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # specify extra host configuration
        if extra_host_config is None:
            extra_host_config = {}
        if "mem_limit" not in extra_host_config:
            extra_host_config["mem_limit"] = "1g"

        # specify extra creation options
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if "working_dir" not in extra_create_kwargs:
            extra_create_kwargs["working_dir"] = self.homedir

        # start the container
        yield DockerSpawner.start(
            self, image=image, extra_create_kwargs=extra_create_kwargs, extra_host_config=extra_host_config
        )

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info(
            "{} was started on {} ({}:{})".format(self.container_name, name, self.user.server.ip, self.user.server.port)
        )

        self.log.info(self.env)
示例#2
0
    def start(self, image=None):
        self.parse_config(self._repo_dir)
        start_command = None
        extra_create_kwargs = {
            'ports': [self.container_port]
        }
        if not self.everware_config.get('everware_based', True):
            start_command = make_git_command(self.repo_url_with_token, self.commit_sha)
            if 'start_command' in self.everware_config:
                nginx_config = self._get_nginx_config(
                    8888,
                    self.custom_service_token(),
                    self.user.name
                )
                start_command.extend(make_nginx_start_command(nginx_config))
                start_command.extend(make_custom_start_command(self.everware_config['start_command']))
            else:
                start_command.extend(make_default_start_command(self.get_env()))
            extra_create_kwargs.update({
                'command': start_command.get_single_command()
            })

        extra_host_config = {
            'port_bindings': {
                self.container_port: (self.container_ip,)
            }
        }
        ip, port = yield DockerSpawner.start(self, image,
                            extra_create_kwargs=extra_create_kwargs,
                            extra_host_config=extra_host_config)
        return ip, port
    def start(self, image=None, extra_create_kwargs=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        num_nodes = int(info['DriverStatus'][2][1])
        node_info = info['DriverStatus'][3::5]
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            self.node_info[node] = ip_port.split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # start the container
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if 'mem_limit' not in extra_create_kwargs:
            extra_create_kwargs['mem_limit'] = '1g'
        if 'working_dir' not in extra_create_kwargs:
            extra_create_kwargs['working_dir'] = self.homedir
        yield DockerSpawner.start(
            self, image=image, extra_create_kwargs=extra_create_kwargs)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info("{} was started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip, self.user.server.port))

        self.log.info(self.env)
示例#4
0
    def start(self, image=None, extra_create_kwargs=None,
            extra_start_kwargs=None, extra_host_config=None):
        # container_prefix is used to construct container_name
        if 'container_prefix' in self.user_options: 
            self.container_prefix = self.user_options['container_prefix']
        if 'cmd' in self.user_options:
            self.cmd='/bin/bash -c "{}"'.format(self.user_options['cmd'])

        
        if 'data_sources' in self.user_options:
            sources=self.user_options['data_sources']
            for source in sources:
                print(source)
                if source['control'] == 'ro':
                    print(source['source'])
                    self.read_only_volumes[source['source']]= source['target']
        
        if 'workspace' in self.user_options:
            workspace = self.user_options['workspace']
            #FIXME: DON'T USE HARDCODED PATH. 
            self.volumes[workspace] = "/home/wode-user/work/"
            
        
        
        # start the container
        ip_port = yield DockerSpawner.start(
            self, image=self.user_options['docker_image'],
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)
        return ip_port
    def start(self,
              image=None,
              extra_create_kwargs=None,
              extra_start_kwargs=None,
              extra_host_config=None):
        # container_prefix is used to construct container_name
        self.container_prefix = self.user_options['container_prefix']

        # start the container
        yield DockerSpawner.start(self,
                                  image=self.user_options['container_image'],
                                  extra_create_kwargs=extra_create_kwargs,
                                  extra_host_config=extra_host_config)
示例#6
0
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        num_nodes = int(info['DriverStatus'][3][1])
        node_info = info['DriverStatus'][4::6]
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            self.node_info[node] = ip_port.split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # specify extra creation options
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if 'working_dir' not in extra_create_kwargs:
            extra_create_kwargs['working_dir'] = "/home/{}".format(self.singleuser)

        # specify extra host configuration
        if extra_host_config is None:
            extra_host_config = {}

        if self.user_options['env'] == 'singleuser':
            image = 'singleuser'
            if 'mem_limit' not in extra_host_config:
                extra_host_config['mem_limit'] = '1g'
        elif self.user_options['env'] == 'hadoop':
            image = 'hadoop'
            if 'mem_limit' not in extra_host_config:
                extra_host_config['mem_limit'] = '3g'
        elif self.user_options['env'] == 'spark':
            image = 'spark'
            if 'mem_limit' not in extra_host_config:
                extra_host_config['mem_limit'] = '2g'
        else:
            image = 'singleuser'
            if 'mem_limit' not in extra_host_config:
                extra_host_config['mem_limit'] = '1g'

        # start the container
        yield DockerSpawner.start(
            self, image=image,
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info("{} was started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip, self.user.server.port))

        self.log.info(self.env)
示例#7
0
    def start(self, image=None, extra_create_kwargs=None,
            extra_start_kwargs=None, extra_host_config=None):
        # container_prefix is used to construct container_name
        self.container_prefix = '{}-{}'.format(
            super().container_prefix,
            self.user_options['container_image'].replace('/', '-')
        )

        # start the container
        ip, port = yield DockerSpawner.start(
            self, image=self.user_options['container_image'],
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)
        return ip, port
示例#8
0
    def start(self,
              image=None,
              extra_create_kwargs=None,
              extra_start_kwargs=None,
              extra_host_config=None):
        # container_prefix is used to construct container_name
        self.container_prefix = self.user_options['container_prefix']

        # start the container
        ret = yield DockerSpawner.start(
            self,
            image=self.user_options['container_image'],
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)
        self.log.info('Started service at %s:%d' % ret)
        return ret
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        num_nodes = int(info['SystemStatus'][3][1])
        node_info = info['SystemStatus'][4::9]
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            self.node_info[node.strip()] = ip_port.strip().split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # specify extra host configuration
        if extra_host_config is None:
            extra_host_config = {}
#        if 'mem_limit' not in extra_host_config:
#            extra_host_config['mem_limit'] = '8g'

        # specify extra creation options
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if 'working_dir' not in extra_create_kwargs:
            extra_create_kwargs['working_dir'] = "/home/{}".format(self.singleuser)

        # create and set permissions of home dir if it doesn't exist
        user_dir = os.path.join(self.root_dir, self.user.name)
        if not os.path.exists(user_dir):
            os.makedirs(user_dir)
        os.chown(user_dir, 1000, 100)
        
        # start the container
        yield DockerSpawner.start(
            self, image=image,
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info("{} was started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip, self.user.server.port))

        self.log.info(self.env)
示例#10
0
    def start(self,
              image=None,
              extra_create_kwargs=None,
              extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        self.log.info('SystemStatus: ' + str(info['SystemStatus']))
        num_nodes = int(info['SystemStatus'][3][1])
        self.log.info('num_nodes: ' + str(num_nodes))
        node_info = info['SystemStatus'][4::
                                         9]  # swarm 1.2.4; docker-py v1.7-1.8
        self.log.info('node_info: ' + str(node_info))
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            if node == '':
                self.log.info('name for ip_port %s is empty.' % ip_port)
            self.node_info[node.strip()] = ip_port.split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # start the container
        self.log.info("starting container: image:{}".format(image))
        yield DockerSpawner.start(self,
                                  image=image,
                                  extra_create_kwargs=extra_create_kwargs,
                                  extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info(self.env)
        self.log.info("api: {} started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip,
            self.user.server.port))

        # Future method of determining ip
        inspection = self.client.inspect_container(self.container_id)
        ip = inspection['Node']['IP']
        node = inspection['Node']['Name']
        container_name = inspection['Name'][1:]  # omit leading "/"
        self.log.info("inspector: {} started on {} ({})".format(
            container_name, node, ip))
    def start(self, *args, **kwargs):
        data_container = yield self.get_data_container()
        if data_container is None:
            # create the container
            resp = yield self.docker('create_container', volumes='/notebooks',
                    name=self.data_container_name, image=self.data_image,
                    command='/bin/true')
            data_container_id = resp['Id']
            self.log.info(
                "Created container '%s' (id: %s) from image %s",
                self.data_container_name, data_container_id[:7],
                self.data_image)


        extra_kwargs = kwargs.setdefault('extra_create_kwargs', dict())
        extra_kwargs['cpu_shares'] = self.cpu_share
        host_config = kwargs.setdefault('extra_host_config', dict())
        host_config['volumes_from'] = [self.data_container_name]

        # Needs conditional based on API
        resp = yield self.docker('version')
        if resp['ApiVersion'] < '1.19':
            extra_kwargs['mem_limit'] = self.memory_limit
        else:
            host_config['mem_limit'] = self.memory_limit

        # We'll use the hostname here
        self.log.info('Using hostname: %s', os.environ['HOSTNAME'])
        host_config['links'] = [(os.environ['HOSTNAME'], 'hub')]
        yield DockerSpawner.start(self, *args, **kwargs)

        # get the internal Docker ip
        resp = yield self.docker('inspect_container', container=self.container_id)
        self.user.server.ip = resp['NetworkSettings']['IPAddress']
        # Rely on linking and just use the container name (needs Docker >= 1.6)
        # self.user.server.ip = self.container_name
        self.user.server.port = 8888
        self.log.info('Set user server to %s', self.user.server)
示例#12
0
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        num_nodes = int(info['SystemStatus'][3][1])
        node_info = info['SystemStatus'][4::9]
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            node = node.replace(' ','')
            self.node_info[node] = ip_port.split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # specify extra host configuration
        if extra_host_config is None:
            extra_host_config = {}
        if 'mem_limit' not in extra_host_config:
            extra_host_config['mem_limit'] = '1g'

        # specify extra creation options
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if 'working_dir' not in extra_create_kwargs:
            extra_create_kwargs['working_dir'] = self.homedir

        # start the container
        yield DockerSpawner.start(
            self, image=image,
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info("{} was started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip, self.user.server.port))

        self.log.info(self.env)
示例#13
0
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        self.log.info('SystemStatus: ' + str(info['SystemStatus']))
        num_nodes = int(info['SystemStatus'][3][1])
        self.log.info('num_nodes: ' + str(num_nodes))
        node_info = info['SystemStatus'][4::9] # swarm 1.2.4; docker-py v1.7-1.8
        self.log.info('node_info: ' + str(node_info))
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            if node == '':
                self.log.info('name for ip_port %s is empty.' % ip_port)
            self.node_info[node.strip()] = ip_port.split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # start the container
        self.log.info("starting container: image:{}".format(image))
        yield DockerSpawner.start(
            self, image=image, extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info(self.env)
        self.log.info("api: {} started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip,
            self.user.server.port))

        # Future method of determining ip
        inspection = self.client.inspect_container(self.container_id)
        ip = inspection['Node']['IP']
        node = inspection['Node']['Name']
        container_name = inspection['Name'][1:] # omit leading "/"
        self.log.info("inspector: {} started on {} ({})".format(
            container_name, node, ip))
示例#14
0
    def start(self, image=None, extra_create_kwargs=None, extra_host_config=None):
        # look up mapping of node names to ip addresses
        info = yield self.docker('info')
        self.log.debug(info)
        num_nodes = int(info['SystemStatus'][3][1])
        node_info = info['SystemStatus'][4::9]
        self.node_info = {}
        for i in range(num_nodes):
            node, ip_port = node_info[i]
            self.node_info[node.strip()] = ip_port.strip().split(":")[0]
        self.log.debug("Swarm nodes are: {}".format(self.node_info))

        # specify extra host configuration
        if extra_host_config is None:
            extra_host_config = {}
        if 'mem_limit' not in extra_host_config:
            extra_host_config['mem_limit'] = '1g'

        # specify extra creation options
        if extra_create_kwargs is None:
            extra_create_kwargs = {}
        if 'working_dir' not in extra_create_kwargs:
            extra_create_kwargs['working_dir'] = "/home/{}".format(self.singleuser)
            extra_create_kwargs['hostname'] = self.hostname

        # create and set permissions of home dir if it doesn't exist
        home_dir = os.path.join(self.root_dir, 'home', self.user.name)
        if not os.path.exists(home_dir):
            os.makedirs(home_dir)
        os.chown(home_dir, 1000, 100)

        exchange_dir = os.path.join(
            self.root_dir, 'exchange', self.user.name
        )
        if not os.path.exists(exchange_dir):
            os.makedirs(exchange_dir)
        os.chown(exchange_dir, 1000, 100)

        exchange_course_dir = os.path.join(
            self.root_dir, 'exchange', self.user.name, self.course_id
        )
        if not os.path.exists(exchange_course_dir):
            os.makedirs(exchange_course_dir)
        os.chown(exchange_course_dir, 1000, 100)

        inbound_dir = os.path.join(
            self.root_dir, 'exchange', self.user.name, self.course_id, 'inbound'
        )
        if not os.path.exists(inbound_dir):
            os.makedirs(inbound_dir)
        os.chown(inbound_dir, 0, 0)
        os.chmod(
            inbound_dir,
            stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
                stat.S_IWGRP | stat.S_IXGRP | stat.S_IWOTH | stat.S_IXOTH
        )

        outbound_dir = os.path.join(
            self.root_dir, 'exchange', self.user.name, self.course_id, 'outbound'
        )
        if not os.path.exists(outbound_dir):
            os.makedirs(outbound_dir)
        os.chown(inbound_dir, 0, 0)
        os.chmod(
            outbound_dir,
            stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
                stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
        )

        # start the container
        yield DockerSpawner.start(
            self, image=image,
            extra_create_kwargs=extra_create_kwargs,
            extra_host_config=extra_host_config)

        # figure out what the node is and then get its ip
        name = yield self.lookup_node_name()
        self.user.server.ip = self.node_info[name]
        self.log.info("{} was started on {} ({}:{})".format(
            self.container_name, name, self.user.server.ip, self.user.server.port))

        self.log.info(self.env)