Esempio n. 1
0
 def test_parse_image_name(self):
     self.assertEqual(('test', 'latest'),
                      utils.parse_image_name('test:latest'))
     self.assertEqual(('test', 'latest'), utils.parse_image_name('test'))
     self.assertEqual(('test', 'test'), utils.parse_image_name('test:test'))
     self.assertEqual(('test-test', 'test'),
                      utils.parse_image_name('test-test:test'))
Esempio n. 2
0
 def test_parse_image_name_with_default_registry(self):
     CONF.set_override('default_registry', 'test.io', group='docker')
     self.assertEqual(('test.io/test', 'latest'),
                      utils.parse_image_name('test'))
     self.assertEqual(('test.io/test/test', 'latest'),
                      utils.parse_image_name('test/test'))
     self.assertEqual(('other.com/test/test', 'latest'),
                      utils.parse_image_name('other.com/test/test'))
Esempio n. 3
0
 def test_parse_image_name_with_default_registry(self):
     CONF.set_override('default_registry', 'test.io', group='docker')
     self.assertEqual(('test.io/test', 'latest'),
                      utils.parse_image_name('test'))
     self.assertEqual(('test.io/test/test', 'latest'),
                      utils.parse_image_name('test/test'))
     self.assertEqual(('other.com/test/test', 'latest'),
                      utils.parse_image_name('other.com/test/test'))
Esempio n. 4
0
 def test_parse_image_name(self):
     self.assertEqual(('test', 'latest'),
                      utils.parse_image_name('test:latest'))
     self.assertEqual(('test', 'latest'),
                      utils.parse_image_name('test'))
     self.assertEqual(('test', 'test'),
                      utils.parse_image_name('test:test'))
     self.assertEqual(('test-test', 'test'),
                      utils.parse_image_name('test-test:test'))
Esempio n. 5
0
 def test_parse_image_name_with_custom_registry(self):
     registry = obj_utils.get_test_registry(self.context, domain='test.io')
     self.assertEqual(('test.io/test', 'latest'),
                      utils.parse_image_name('test', registry=registry))
     self.assertEqual(('test.io/test/test', 'latest'),
                      utils.parse_image_name('test/test',
                                             registry=registry))
     self.assertEqual(('other.com/test/test', 'latest'),
                      utils.parse_image_name('other.com/test/test',
                                             registry=registry))
Esempio n. 6
0
 def test_parse_image_name_with_custom_registry(self):
     registry = obj_utils.get_test_registry(self.context, domain='test.io')
     self.assertEqual(('test.io/test', 'latest'),
                      utils.parse_image_name('test', registry=registry))
     self.assertEqual(('test.io/test/test', 'latest'),
                      utils.parse_image_name('test/test',
                                             registry=registry))
     self.assertEqual(('other.com/test/test', 'latest'),
                      utils.parse_image_name('other.com/test/test',
                                             registry=registry))
Esempio n. 7
0
 def _create_sandbox(self,
                     context,
                     container,
                     requested_networks,
                     requested_volumes,
                     reraise=False):
     self._update_task_state(context, container, consts.SANDBOX_CREATING)
     sandbox_image = CONF.sandbox_image
     sandbox_image_driver = CONF.sandbox_image_driver
     sandbox_image_pull_policy = CONF.sandbox_image_pull_policy
     repo, tag = utils.parse_image_name(sandbox_image)
     try:
         image, image_loaded = image_driver.pull_image(
             context, repo, tag, sandbox_image_pull_policy,
             sandbox_image_driver)
         if not image_loaded:
             self.driver.load_image(image['path'])
         sandbox_id = self.driver.create_sandbox(
             context,
             container,
             image=sandbox_image,
             requested_networks=requested_networks,
             requested_volumes=requested_volumes)
         return sandbox_id
     except Exception as e:
         with excutils.save_and_reraise_exception(reraise=reraise):
             LOG.exception("Unexpected exception: %s", six.text_type(e))
             self._fail_container(context, container, six.text_type(e))
Esempio n. 8
0
def search_image(context, image_name, image_driver, exact_match):
    images = []
    repo, tag = parse_image_name(image_name)
    if image_driver:
        image_driver_list = [image_driver.lower()]
    else:
        image_driver_list = CONF.image_driver_list
    for driver in image_driver_list:
        try:
            image_driver = load_image_driver(driver)
            imgs = image_driver.search_image(context, repo, tag, exact_match)
            images.extend(imgs)
        except Exception as e:
            LOG.exception(('Unknown exception occurred while searching '
                           'for image: %s'), six.text_type(e))
            raise exception.ZunException(six.text_type(e))
    return images
Esempio n. 9
0
File: images.py Progetto: zwphit/zun
    def post(self, **image_dict):
        """Create a new image.

        :param image: an image within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, "image:pull", action="image:pull")
        image_dict['project_id'] = context.project_id
        image_dict['user_id'] = context.user_id
        repo_tag = image_dict.get('repo')
        image_dict['repo'], image_dict['tag'] = utils.parse_image_name(
            repo_tag)
        new_image = objects.Image(context, **image_dict)
        new_image.pull(context)
        pecan.request.compute_api.image_pull(context, new_image)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('images', new_image.uuid)
        pecan.response.status = 202
        return view.format_image(pecan.request.host_url, new_image)
Esempio n. 10
0
    def post(self, **image_dict):
        """Create a new image.

        :param image: an image within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, "image:pull", action="image:pull")
        image_dict['project_id'] = context.project_id
        image_dict['user_id'] = context.user_id
        repo_tag = image_dict.get('repo')
        image_dict['repo'], image_dict['tag'] = utils.parse_image_name(
            repo_tag)
        new_image = objects.Image(context, **image_dict)
        new_image.pull(context)
        pecan.request.compute_api.image_pull(context, new_image)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('images', new_image.uuid)
        pecan.response.status = 202
        # TODO(sbiswas7): Schema validation is a better approach than
        # back n forth conversion into dicts and objects.
        return Image.convert_with_links(new_image.as_dict())
Esempio n. 11
0
    def post(self, **image_dict):
        """Create a new image.

        :param image_dict: an image within the request body.
        """
        context = pecan.request.context
        policy.enforce(context, "image:pull",
                       action="image:pull")
        host = _get_host(image_dict.pop('host'))
        image_dict['project_id'] = context.project_id
        image_dict['user_id'] = context.user_id
        repo_tag = image_dict.get('repo')
        image_dict['host'] = host.hostname
        image_dict['repo'], image_dict['tag'] = utils.parse_image_name(
            repo_tag)
        new_image = objects.Image(context, **image_dict)
        new_image.pull(context)
        pecan.request.compute_api.image_pull(context, new_image)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('images', new_image.uuid)
        pecan.response.status = 202
        return view.format_image(pecan.request.host_url, new_image)
Esempio n. 12
0
    def _do_container_create(self, context, container, reraise=False):
        LOG.debug('Creating container: %s', container.uuid)

        container.task_state = fields.TaskState.SANDBOX_CREATING
        container.save(context)
        sandbox_id = None
        sandbox_image = 'kubernetes/pause'
        repo, tag = utils.parse_image_name(sandbox_image)
        try:
            image = image_driver.pull_image(context, repo, tag, 'ifnotpresent')
            sandbox_id = self.driver.create_sandbox(context,
                                                    container,
                                                    image=sandbox_image)
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._fail_container(context, container, six.text_type(e))
            return

        self.driver.set_sandbox_id(container, sandbox_id)
        container.task_state = fields.TaskState.IMAGE_PULLING
        container.save(context)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        try:
            image = image_driver.pull_image(context, repo, tag,
                                            image_pull_policy)
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(
                    _LE("Error occurred while calling Docker image API: %s"),
                    six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = fields.TaskState.CONTAINER_CREATING
        container.save(context)
        try:
            container = self.driver.create(context, container, sandbox_id,
                                           image)
            container.addresses = self._get_container_addresses(
                context, container)
            container.task_state = None
            container.save(context)
            return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(
                    _LE("Error occurred while calling Docker create API: %s"),
                    six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception(_LE("Unexpected exception: %s"),
                              six.text_type(e))
                self._do_sandbox_cleanup(context, sandbox_id)
                self._fail_container(context, container, six.text_type(e))
            return
Esempio n. 13
0
    def _do_container_create_base(self,
                                  context,
                                  container,
                                  requested_networks,
                                  requested_volumes,
                                  sandbox=None,
                                  limits=None,
                                  reraise=False):
        self._update_task_state(context, container, consts.IMAGE_PULLING)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        image_driver_name = container.image_driver
        try:
            image, image_loaded = image_driver.pull_image(
                context, repo, tag, image_pull_policy, image_driver_name)
            image['repo'], image['tag'] = repo, tag
            if not image_loaded:
                self.driver.load_image(image['path'])
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker image API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s", six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = consts.CONTAINER_CREATING
        container.image_driver = image.get('driver')
        container.save(context)
        try:
            if image['driver'] == 'glance':
                self.driver.read_tar_image(image)
            container = self.driver.create(context, container, image,
                                           requested_networks,
                                           requested_volumes)
            self._update_task_state(context, container, None)
            return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker create API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context,
                                     container,
                                     six.text_type(e),
                                     unset_host=True)
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s", six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context,
                                     container,
                                     six.text_type(e),
                                     unset_host=True)
            return
Esempio n. 14
0
    def _do_container_create(self, context, container, requested_networks,
                             limits=None, reraise=False):
        LOG.debug('Creating container: %s', container.uuid)

        # check if container driver is NovaDockerDriver and
        # security_groups is non empty, then return by setting
        # the error message in database
        if ('NovaDockerDriver' in CONF.container_driver and
                container.security_groups):
            msg = "security_groups can not be provided with NovaDockerDriver"
            self._fail_container(self, context, container, msg)
            return

        sandbox_id = None
        if self.use_sandbox:
            sandbox_id = self._create_sandbox(context, container,
                                              requested_networks, reraise)
            if sandbox_id is None:
                return

        self._update_task_state(context, container, consts.IMAGE_PULLING)
        repo, tag = utils.parse_image_name(container.image)
        image_pull_policy = utils.get_image_pull_policy(
            container.image_pull_policy, tag)
        image_driver_name = container.image_driver
        try:
            image, image_loaded = image_driver.pull_image(
                context, repo, tag, image_pull_policy, image_driver_name)
            if not image_loaded:
                self.driver.load_image(image['path'])
        except exception.ImageNotFound as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error(six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker image API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s",
                              six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e))
            return

        container.task_state = consts.CONTAINER_CREATING
        container.image_driver = image.get('driver')
        container.save(context)
        try:
            limits = limits
            rt = self._get_resource_tracker()
            with rt.container_claim(context, container, container.host,
                                    limits):
                container = self.driver.create(context, container, image)
                self._update_task_state(context, container, None)
                return container
        except exception.DockerError as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.error("Error occurred while calling Docker create API: %s",
                          six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e),
                                     unset_host=True)
            return
        except Exception as e:
            with excutils.save_and_reraise_exception(reraise=reraise):
                LOG.exception("Unexpected exception: %s",
                              six.text_type(e))
                self._do_sandbox_cleanup(context, container)
                self._fail_container(context, container, six.text_type(e),
                                     unset_host=True)
            return