示例#1
0
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
示例#2
0
 def _create_snap_dev(self):
     LOG.debug("Virtman: creating a snapshot for the VM instance")
     if self.snapshot_dev is None:
         self.snapshot_dev = blockservice.findloop()
     blockservice.try_linkloop(self.snapshot_dev)
     if self.snapshot_with_cache:
         snapshot_path = self._create_cache(self.snapshot_dev)
     else:
         snapshot_path = self.snapshot_dev
     LOG.debug("Virtman: success! snapshot_path = %s" % snapshot_path)
     return snapshot_path
示例#3
0
 def test_findloop(self):
     expected_commands = ["losetup -f"]
     blockservice.findloop()
     self.assertEqual(expected_commands, self.cmds)