def create(self, request, image_name, image_id, root_volume_id=None, network_info={}, block_device_info={}, inject_files=[], admin_password=None): """ create the container. """ if root_volume_id: # Create VM from volume, create a symbolic link for the device. LOG.info(_("Create new container from volume %s"), root_volume_id) self._add_root_mapping(root_volume_id) def _do_create(): if admin_password is not None: self._inject_password(admin_password) if inject_files: self._inject_files(inject_files, plain=True) if block_device_info: try: self._attach_bdm(block_device_info) except Exception as e: LOG.exception(e) try: container = self.container LOG.warn(_("Already a container exists")) # Do the work anyway _do_create() return FAKE_SUCCESS_TASK except exception.ContainerNotFound: repository = self._get_repository(image_name) #local_image_name = repository + ':' + image_id local_image_name = image_id def _do_create_after_download_image(name): LOG.debug(_("Create container from image %s"), name) self.manager.create_container(name, network_disabled=True) _do_create() if self.manager.images(name=local_image_name): LOG.debug(_("Repository = %s already exists"), local_image_name) _do_create_after_download_image(local_image_name) return FAKE_SUCCESS_TASK else: def _do_pull_image(): name = local_image_name try: import re m = re.search(r'\d+\.\d+\.\d+\.\d+', repository) if m: utils.execute('ping', '-W', '3', '-c', '1', m.group()) LOG.debug(_("Starting pull image repository=%s:%s"), repository, image_id) resp = self.manager.pull(repository, tag=image_id, insecure_registry=True) LOG.debug(_("Done pull image repository=%s:%s, resp %s"), repository, image_id, resp) if any(resp.find(s)!=-1 for s in ['"error":', image_name + " not found"]): LOG.warn(_("Can't pull image, use the local image with name=%s"), image_name) name = image_name except Exception as e: name = image_name LOG.exception(e) _do_create_after_download_image(name) task = addtask(_do_pull_image) LOG.debug(_("Pull image task %s"), task) return task
def clone_volume(self, request, volume, src_vref): LOG.debug("clone volume %s, src_vref %s", volume, src_vref) srcstr = self.get_device(src_vref["id"]) dststr = self.get_device(volume["id"]) size_in_g = min(int(src_vref['size']), int(volume['size'])) clone_callback = functools.partial(utils.copy_volume, srcstr, dststr, size_in_g*units.Ki, CONF.volume_dd_blocksize) task_id = addtask(clone_callback) return {"task_id": task_id }
def clone_volume(self, request, volume, src_vref): LOG.debug("clone volume %s, src_vref %s", volume, src_vref) srcstr = self.get_device(src_vref["id"]) dststr = self.get_device(volume["id"]) size_in_g = min(int(src_vref['size']), int(volume['size'])) clone_callback = functools.partial(utils.copy_volume, srcstr, dststr, size_in_g * units.Ki, CONF.volume_dd_blocksize) task_id = addtask(clone_callback) return {"task_id": task_id}
def create_image(self, request, image_name, image_id): """ Create a image from the container. """ repository = self._get_repository(image_name) LOG.debug(_("Creating image from repo = %s, tag = %s"), repository, image_id) def _create_image_cb(): LOG.debug(_("Pushing image %s"), repository) self.manager.commit(self.container['id'], repository=repository, tag=image_id) self.manager.push(repository, tag=image_id, insecure_registry=True) LOG.debug(_("Doing image %s"), repository) task = addtask(_create_image_cb) LOG.debug(_("Created image task %s"), task) return task
def create(self, request, image_name, image_id, root_volume_id=None, network_info={}, block_device_info={}, inject_files=[], admin_password=None): """ create the container. """ if root_volume_id: # Create VM from volume, create a symbolic link for the device. LOG.info(_("Create new container from volume %s"), root_volume_id) self._add_root_mapping(root_volume_id) def _do_create(): if admin_password is not None: self._inject_password(admin_password) if inject_files: self._inject_files(inject_files, plain=True) if block_device_info: try: self._attach_bdm(block_device_info) except Exception as e: LOG.exception(e) try: container = self.container LOG.warn(_("Already a container exists")) # Do the work anyway _do_create() return FAKE_SUCCESS_TASK except exception.ContainerNotFound: repository = self._get_repository(image_name) # local_image_name = repository + ':' + image_id local_image_name = image_id def _do_create_after_download_image(name): LOG.debug(_("Create container from image %s"), name) self.manager.create_container(name, network_disabled=True) _do_create() if self.manager.images(name=local_image_name): LOG.debug(_("Repository = %s already exists"), local_image_name) _do_create_after_download_image(local_image_name) return FAKE_SUCCESS_TASK else: def _do_pull_image(): name = local_image_name try: import re m = re.search(r'\d+\.\d+\.\d+\.\d+', repository) if m: utils.execute('ping', '-W', '3', '-c', '1', m.group()) LOG.debug(_("Starting pull image repository=%s:%s"), repository, image_id) resp = self.manager.pull(repository, tag=image_id, insecure_registry=True) LOG.debug( _("Done pull image repository=%s:%s, resp %s"), repository, image_id, resp) if any( resp.find(s) != -1 for s in ['"error":', image_name + " not found"]): LOG.warn( _("Can't pull image, use the local image with " "name=%s"), image_name) name = image_name except Exception as e: name = image_name LOG.exception(e) _do_create_after_download_image(name) task = addtask(_do_pull_image) LOG.debug(_("Pull image task %s"), task) return task