def create_image_target(image_name, file_path, loop_dev, iqn_prefix): """ :returns : string "0:info" specifies SUCCESS, info="target_id:loop_dev" "1:info" specifies WARNING, info indicates image_name exists "2:info" specifies WARNING, info indicates image file_path not exists """ LOG.debug("Virtman: Image Service: create image target started! " "image_name = %s, file_path = %s" % (image_name, file_path)) if not image_name.startswith("volume-"): image_name = "volume-" + image_name if image_name in targetlist: LOG.warn("Virtman: Image Service: Warning! image_name = %s exists! " "Please use another name" % image_name) return "1:" + "Virtman: Image Service: Warning! " \ "image_name = %s exists! Please use another name" \ % image_name if not os.path.exists(file_path): LOG.warn("Virtman: Image Service: Warning! " "image file_path = %s not exists! Please use another " "image file" % file_path) return "2:" + "Virtman: Image Service: Warning!" \ "image file_path = %s not exists! Please use " \ "another image file" % file_path if loop_dev is None: loop_dev = blockservice.findloop() else: blockservice.unlinkloop(loop_dev) blockservice.linkloop(loop_dev, file_path) target_id = iscsi.create_iscsi_target(iqn_prefix + image_name, loop_dev) targetlist[image_name] = target_id + ':' + loop_dev LOG.debug("Virtman: Image Service: create image target completed! " "image_target_id = %s loop_dev = %s" % (target_id, loop_dev)) return "0:" + target_id + ":" + loop_dev
def _create_target(self): if self.is_local_has_image: return if not self.has_target: LOG.debug("Virtman: start to create target, cache path = %s" % self.cached_path) if iscsi.exists(self.iqn): self.has_target = True else: self.target_id = iscsi.create_iscsi_target(self.iqn, self.cached_path) self.has_target = True LOG.debug("Virtman: create target complete, target id = %s" % self.target_id)
def create_target(base_image): """ :type base_image: BlockDeviceBaseImage """ if base_image.is_local_has_image: return if not base_image.has_target: LOG.debug("Virtman: start to create target, cache path = %s" % base_image.cached_path) if iscsi.exists(base_image.iqn): base_image.has_target = True else: base_image.target_id = \ iscsi.create_iscsi_target(base_image.iqn, base_image.cached_path) base_image.has_target = True LOG.debug("Virtman: create target complete, target id = %s" % base_image.target_id)