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))
def _do_image_pull(self, context, image): LOG.debug('Creating image...') repo_tag = image.repo + ":" + image.tag try: pulled_image = image_driver.pull_image(context, image.repo, image.tag) image_dict = self.driver.inspect_image(repo_tag, pulled_image['path']) image.image_id = image_dict['Id'] image.size = image_dict['Size'] image.save() except exception.ImageNotFound as e: LOG.error(six.text_type(e)) return except exception.DockerError as e: LOG.error(_LE("Error occurred while calling Docker image API: %s"), six.text_type(e)) raise except Exception as e: LOG.exception(_LE("Unexpected exception: %s"), six.text_type(e)) raise
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
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
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