Ejemplo n.º 1
0
    def _resignVdis(self, vg_name, lvUuidMap):
        """
        Changes the parent locators in each VDI so it points to the resigned LVs

        :param vg_name: The Volumegroup where the VDIs reside
        :param lvUuidMap: map from old uuids to new uuids
        """

        for uuid in lvUuidMap.values():

            lv_name = self.LV_VHD_PREFIX + uuid
            self.lvmCache.activateNoRefcount(lv_name)
            self.lvmCache.setReadonly(lv_name, False)

            path = os.path.join(lvhdutil.VG_LOCATION, vg_name, lv_name)
            util.SMlog("RESIGN VDI %s" % path)
            old_parent = vhdutil._getVHDParentNoCheck(path)

            if old_parent:

                old_parent_uuid = old_parent[4:]  # remove the VHD-
                new_parent_uuid = lvUuidMap[old_parent_uuid]

                parent_lv_name = self.LV_VHD_PREFIX + new_parent_uuid
                self.lvmCache.activateNoRefcount(parent_lv_name)

                parent_path = os.path.join(lvhdutil.VG_LOCATION, vg_name, parent_lv_name)

                util.SMlog("RESIGN VDI HAS PARENT  %s" % parent_path)
                vhdutil.setParent(path, parent_path, False)
    def _resignVdis(self, vg_name, lvUuidMap):
        """
        Changes the parent locators in each VDI so it points to the resigned LVs

        :param vg_name: The Volumegroup where the VDIs reside
        :param lvUuidMap: map from old uuids to new uuids
        """

        for uuid in lvUuidMap.values():

            lv_name = self.LV_VHD_PREFIX + uuid
            self.lvmCache.activateNoRefcount(lv_name)
            self.lvmCache.setReadonly(lv_name, False)

            path = os.path.join(lvhdutil.VG_LOCATION, vg_name, lv_name)
            util.SMlog("RESIGN VDI %s" % path)
            old_parent = vhdutil._getVHDParentNoCheck(path)

            if old_parent:

                old_parent_uuid = old_parent[4:]  # remove the VHD-
                new_parent_uuid = lvUuidMap[old_parent_uuid]

                parent_lv_name = self.LV_VHD_PREFIX + new_parent_uuid
                self.lvmCache.activateNoRefcount(parent_lv_name)

                parent_path = os.path.join(lvhdutil.VG_LOCATION, vg_name,
                                           parent_lv_name)

                util.SMlog("RESIGN VDI HAS PARENT  %s" % parent_path)
                vhdutil.setParent(path, parent_path, False)
Ejemplo n.º 3
0
Archivo: FileSR.py Proyecto: rdobson/sm
 def compose(self, sr_uuid, vdi1, vdi2):
     if self.vdi_type != vhdutil.VDI_TYPE_VHD:
         raise xs_errors.XenError("Unimplemented")
     parent_fn = vdi1 + vhdutil.FILE_EXTN[vhdutil.VDI_TYPE_VHD]
     parent_path = os.path.join(self.sr.path, parent_fn)
     assert util.pathexists(parent_path)
     vhdutil.setParent(self.path, parent_path, False)
     vhdutil.setHidden(parent_path)
     util.pread2([vhdutil.VHD_UTIL, "modify", "-p", parent_path, "-n", self.path])
     # Tell tapdisk the chain has changed
     if not blktap2.VDI.tap_refresh(self.session, sr_uuid, vdi2):
         raise util.SMException("failed to refresh VDI %s" % self.uuid)
     util.SMlog("VDI.compose: relinked %s->%s" % (vdi2, vdi1))
Ejemplo n.º 4
0
 def compose(self, sr_uuid, vdi1, vdi2):
     if self.vdi_type != vhdutil.VDI_TYPE_VHD:
         raise xs_errors.XenError('Unimplemented')
     parent_fn = vdi1 + vhdutil.FILE_EXTN[vhdutil.VDI_TYPE_VHD]
     parent_path = os.path.join(self.sr.path, parent_fn)
     assert (util.pathexists(parent_path))
     vhdutil.setParent(self.path, parent_path, False)
     vhdutil.setHidden(parent_path)
     util.pread2(
         [vhdutil.VHD_UTIL, "modify", "-p", parent_path, "-n", self.path])
     # Tell tapdisk the chain has changed
     if not blktap2.VDI.tap_refresh(self.session, sr_uuid, vdi2):
         raise util.SMException("failed to refresh VDI %s" % self.uuid)
     util.SMlog("VDI.compose: relinked %s->%s" % (vdi2, vdi1))
Ejemplo n.º 5
0
    def compose(self, sr_uuid, vdi1_uuid, vdi2_uuid):
        """
        :param sr_uuid:
        :param vdi1_uuid:
        :param vdi2_uuid:
        :return:
        """
        if VERBOSE:
            util.SMlog(
                "rbdsr_vhd.RBDVHDVDI.compose: sr_uuid=%s, vdi1_uuid=%s, vdi2_uuid=%s"
                % (sr_uuid, vdi1_uuid, vdi2_uuid))

        base_uuid = vdi1_uuid
        mirror_uuid = vdi2_uuid

        base_path = self.sr._get_path(base_uuid)
        mirror_path = self.sr._get_path(mirror_uuid)

        base_vdi_ref = self.session.xenapi.VDI.get_by_uuid(base_uuid)
        mirror_vdi_ref = self.session.xenapi.VDI.get_by_uuid(mirror_uuid)

        mirror_sm_config = self.session.xenapi.VDI.get_sm_config(
            mirror_vdi_ref)

        mirror_hostRefs = self._get_vdi_hostRefs(mirror_uuid)
        local_host_uuid = inventory.get_localhost_uuid()

        BaseVDI = self.sr.vdi(base_uuid)

        for host_uuid in mirror_hostRefs.iterkeys():
            RBDVHDVDI.attach(BaseVDI, sr_uuid, base_uuid, host_uuid=host_uuid)
        if local_host_uuid not in mirror_hostRefs:
            RBDVHDVDI.attach(BaseVDI,
                             sr_uuid,
                             base_uuid,
                             host_uuid=local_host_uuid)
            self.attach(sr_uuid, mirror_uuid, host_uuid=local_host_uuid)

        vhdutil.setParent(mirror_path, base_path, False)
        vhdutil.setHidden(base_path)
        self.sr.session.xenapi.VDI.set_managed(base_vdi_ref, False)
        RBDVHDVDI.update(
            BaseVDI, sr_uuid, base_uuid
        )  # TODO: Check if xapi invoke update after set_* op, if it's true then we can remove this line

        if 'vhd-parent' in mirror_sm_config:
            self.session.xenapi.VDI.remove_from_sm_config(
                mirror_vdi_ref, 'vhd-parent')
        self.session.xenapi.VDI.add_to_sm_config(mirror_vdi_ref, 'vhd-parent',
                                                 base_uuid)
        self.sm_config['vhd-parent'] = base_uuid
        self.update(sr_uuid, mirror_uuid)

        if local_host_uuid not in mirror_hostRefs:
            self.detach(sr_uuid, mirror_uuid, host_uuid=local_host_uuid)
            RBDVHDVDI.detach(BaseVDI,
                             sr_uuid,
                             base_uuid,
                             host_uuid=local_host_uuid)

        if not blktap2.VDI.tap_refresh(self.session, self.sr.uuid, mirror_uuid,
                                       True):
            raise util.SMException("failed to refresh VDI %s" % mirror_uuid)

        if VERBOSE:
            util.SMlog("Compose done")