コード例 #1
0
    def _do_volume_remove(self, volume, storage_pool, progress):
        if self._is_volume_removed(volume, storage_pool):
            return

        if volume.deviceNumber == 0:
            container = get_compute().get_container(docker_client(),
                                                    volume.instance)
            if container is None:
                return
            remove_container(docker_client(), container)
        elif self._is_managed_volume(volume):
            v = DockerConfig.storage_api_version()
            try:
                docker_client(version=v).remove_volume(volume.name)
            except APIError as e:
                if e.message.response.status_code == 409:
                    log.warn(
                        'Encountered conflict (%s) while deleting '
                        'volume. Orphaning volume.', e)
                else:
                    raise e
        else:
            path = self._path_to_volume(volume)
            if not volume.data.fields['isHostPath']:
                if os.path.exists(path):
                    log.info("Deleting volume: %s" % volume.uri)
                    shutil.rmtree(path)
コード例 #2
0
ファイル: compute.py プロジェクト: cjellick/python-agent
    def _do_instance_remove(self, instance, host, progress):
        client = docker_client()
        container = self.get_container(client, instance)
        if container is None:
            return

        remove_container(client, container)
コード例 #3
0
ファイル: compute.py プロジェクト: jimengliu/python-agent
    def _do_instance_remove(self, instance, host, progress):
        client = docker_client()
        container = self.get_container(client, instance)
        if container is None:
            return

        remove_container(client, container)
コード例 #4
0
ファイル: storage.py プロジェクト: imikushin/python-agent
    def _do_volume_remove(self, volume, storage_pool, progress):
        if self._is_volume_removed(volume, storage_pool):
            return

        if volume.deviceNumber == 0:
            container = get_compute().get_container(docker_client(),
                                                    volume.instance)
            if container is None:
                return
            remove_container(docker_client(), container)
        elif self._is_managed_volume(volume):
            v = DockerConfig.storage_api_version()
            try:
                docker_client(version=v).remove_volume(volume.name)
            except APIError as e:
                if e.message.response.status_code == 409:
                    log.warn('Encountered conflict (%s) while deleting '
                             'volume. Orphaning volume.', e)
                else:
                    raise e
        else:
            path = self._path_to_volume(volume)
            if not volume.data.fields['isHostPath']:
                if os.path.exists(path):
                    log.info("Deleting volume: %s" % volume.uri)
                    shutil.rmtree(path)
コード例 #5
0
ファイル: test_docker.py プロジェクト: dx9/python-agent
def test_404_on_remove():
    # This tests the functionality in DockerCompute._do_instance_remove(),
    # but recreating a scenario where a 404 is returned on a delete is pretty
    # difficult from the event_test framework, so just testing the function
    # ecplicitly
    client = docker_client()
    c = client.create_container('ibuildthecloud/helloworld',
                                name='double_remove')

    client.remove_container(c, force=True, v=True)
    remove_container(client, c)
    remove_container(client, c)
コード例 #6
0
def test_404_on_remove():
    # This tests the functionality in DockerCompute._do_instance_remove(),
    # but recreating a scenario where a 404 is returned on a delete is pretty
    # difficult from the event_test framework, so just testing the function
    # ecplicitly
    client = docker_client()
    c = client.create_container('ibuildthecloud/helloworld',
                                name='double_remove')

    client.remove_container(c, force=True, v=True)
    remove_container(client, c)
    remove_container(client, c)
コード例 #7
0
ファイル: storage.py プロジェクト: keras/python-agent
 def _do_volume_remove(self, volume, storage_pool, progress):
     if volume.deviceNumber == 0:
         container = get_compute().get_container(docker_client(), volume.instance)
         if container is None:
             return
         remove_container(docker_client(), container)
     elif self._is_managed_volume(volume):
         v = DockerConfig.storage_api_version()
         docker_client(version=v).remove_volume(volume.name)
     else:
         path = self._path_to_volume(volume)
         if not volume.data.fields["isHostPath"]:
             if os.path.exists(path):
                 log.info("Deleting volume: %s" % volume.uri)
                 shutil.rmtree(path)
コード例 #8
0
ファイル: storage.py プロジェクト: m4ce/python-agent
 def _do_volume_remove(self, volume, storage_pool, progress):
     if volume.deviceNumber == 0:
         container = get_compute().get_container(docker_client(),
                                                 volume.instance)
         if container is None:
             return
         remove_container(docker_client(), container)
     elif self._is_managed_volume(volume):
         v = DockerConfig.storage_api_version()
         docker_client(version=v).remove_volume(volume.name)
     else:
         path = self._path_to_volume(volume)
         if not volume.data.fields['isHostPath']:
             if os.path.exists(path):
                 log.info("Deleting volume: %s" % volume.uri)
                 shutil.rmtree(path)
コード例 #9
0
ファイル: storage.py プロジェクト: dx9/python-agent
 def _do_volume_remove(self, volume, storage_pool, progress):
     if volume.deviceNumber == 0:
         container = get_compute().get_container(docker_client(),
                                                 volume.instance)
         if container is None:
             return
         remove_container(docker_client(), container)
     else:
         path = self._path_to_volume(volume)
         # Check for volmgr managed volume, must be done before "isHostPath"
         if volmgr.volume_exists(path):
             log.info("Deleting volmgr managed volume: %s" % path)
             volmgr.remove_volume(path)
             return
         if not volume.data.fields['isHostPath']:
             if os.path.exists(path):
                 log.info("Deleting volume: %s" % volume.uri)
                 shutil.rmtree(path)
コード例 #10
0
 def _do_volume_remove(self, volume, storage_pool, progress):
     if volume.deviceNumber == 0:
         container = get_compute().get_container(docker_client(),
                                                 volume.instance)
         if container is None:
             return
         remove_container(docker_client(), container)
     else:
         path = self._path_to_volume(volume)
         # Check for volmgr managed volume, must be done before "isHostPath"
         if volmgr.volume_exists(path):
             log.info("Deleting volmgr managed volume: %s" % path)
             volmgr.remove_volume(path)
             return
         if not volume.data.fields['isHostPath']:
             if os.path.exists(path):
                 log.info("Deleting volume: %s" % volume.uri)
                 shutil.rmtree(path)
コード例 #11
0
ファイル: compute.py プロジェクト: jimengliu/python-agent
    def _do_instance_activate(self, instance, host, progress):
        if is_no_op(instance):
            return

        client = docker_client()

        image_tag = self._get_image_tag(instance)

        name = instance.uuid
        if instance.name and re.match(r'^[a-zA-Z0-9][a-zA-Z0-9_.-]+$',
                                      instance.name):
            try:
                client.inspect_container('r-{}'.format(instance.name))
            except NotFound:
                name = 'r-{}'.format(instance.name)

        create_config = {'name': name, 'detach': True}

        start_config = {
            'publish_all_ports': False,
            'privileged': self._is_true(instance, 'privileged'),
            'read_only': self._is_true(instance, 'readOnly'),
        }

        # These _setup_simple_config_fields calls should happen before all
        # other config because they stomp over config fields that other
        # setup methods might append to. Example: the environment field
        self._setup_simple_config_fields(create_config, instance,
                                         CREATE_CONFIG_FIELDS)

        self._setup_simple_config_fields(start_config, instance,
                                         START_CONFIG_FIELDS)

        add_label(create_config, {UUID_LABEL: instance.uuid})
        if instance.name:
            add_label(create_config,
                      {'io.rancher.container.name': instance.name})
        self._setup_dns_search(start_config, instance)

        self._setup_logging(start_config, instance)

        self._setup_hostname(create_config, instance)

        self._setup_command(create_config, instance)

        self._setup_ports(create_config, instance, start_config)

        self._setup_volumes(create_config, instance, start_config, client)

        self._setup_links(start_config, instance)

        self._setup_networking(instance, host, create_config, start_config)

        self._flag_system_container(instance, create_config)

        self._setup_proxy(instance, create_config)

        setup_cattle_config_url(instance, create_config)

        create_config['host_config'] = \
            client.create_host_config(**start_config)

        self._setup_device_options(create_config['host_config'], instance)

        container = self.get_container(client, instance)
        created = False
        if container is None:
            container = self._create_container(client, create_config,
                                               image_tag, instance, name,
                                               progress)
            created = True

        container_id = container['Id']

        log.info('Starting docker container [%s] docker id [%s] %s', name,
                 container_id, start_config)

        try:
            client.start(container_id)
        except Exception as e:
            if created:
                remove_container(client, container)
            raise e

        self._record_state(client, instance, docker_id=container['Id'])
コード例 #12
0
ファイル: compute.py プロジェクト: StrongMonkey/python-agent
    def _do_instance_activate(self, instance, host, progress):
        if is_no_op(instance):
            return

        client = docker_client()

        image_tag = self._get_image_tag(instance)

        name = instance.uuid
        if instance.name and re.match(r'^[a-zA-Z0-9][a-zA-Z0-9_.-]+$',
                                      instance.name):
            try:
                client.inspect_container('r-{}'.format(instance.name))
            except NotFound:
                name = 'r-{}'.format(instance.name)

        create_config = {
            'name': name,
            'detach': True
        }

        start_config = {
            'publish_all_ports': False,
            'privileged': self._is_true(instance, 'privileged'),
            'read_only': self._is_true(instance, 'readOnly'),
        }

        # These _setup_simple_config_fields calls should happen before all
        # other config because they stomp over config fields that other
        # setup methods might append to. Example: the environment field
        self._setup_simple_config_fields(create_config, instance,
                                         CREATE_CONFIG_FIELDS)

        self._setup_simple_config_fields(start_config, instance,
                                         START_CONFIG_FIELDS)

        add_label(create_config, {UUID_LABEL: instance.uuid})
        if instance.name:
            add_label(create_config,
                      {'io.rancher.container.name': instance.name})
        self._setup_dns_search(start_config, instance)

        self._setup_logging(start_config, instance)

        self._setup_hostname(create_config, instance)

        self._setup_command(create_config, instance)

        self._setup_ports(create_config, instance, start_config)

        self._setup_volumes(create_config, instance, start_config, client)

        self._setup_links(start_config, instance)

        self._setup_networking(instance, host, create_config, start_config)

        self._flag_system_container(instance, create_config)

        self._setup_proxy(instance, create_config)

        setup_cattle_config_url(instance, create_config)

        create_config['host_config'] = \
            client.create_host_config(**start_config)

        self._setup_device_options(create_config['host_config'], instance)

        container = self.get_container(client, instance)
        created = False
        if container is None:
            container = self._create_container(client, create_config,
                                               image_tag, instance, name,
                                               progress)
            created = True

        container_id = container['Id']

        log.info('Starting docker container [%s] docker id [%s] %s', name,
                 container_id, start_config)

        try:
            client.start(container_id)
        except Exception as e:
            if created:
                remove_container(client, container)
            raise e

        self._record_state(client, instance, docker_id=container['Id'])