Пример #1
0
    def attach(self, sr_uuid, vdi_uuid):
        util.SMlog("RBDVDI.attach for %s" % self.uuid)

        vdi_ref = self.sr.srcmd.params['vdi_ref']
        sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref)

        if not hasattr(self, 'xenstore_data'):
            self.xenstore_data = {}

        self.xenstore_data.update(
            scsiutil.update_XS_SCSIdata(
                self.uuid, scsiutil.gen_synthetic_page_data(self.uuid)))

        self.xenstore_data['storage-type'] = 'rbd'
        self.xenstore_data['vdi-type'] = self.vdi_type

        self.attached = True
        self.session.xenapi.VDI.remove_from_sm_config(vdi_ref, 'attached')
        self.session.xenapi.VDI.add_to_sm_config(vdi_ref, 'attached', 'true')

        self.size = int(self.session.xenapi.VDI.get_virtual_size(vdi_ref))

        ##########
        vdis = self.session.xenapi.SR.get_VDIs(self.sr.sr_ref)
        has_a_snapshot = False
        for tmp_vdi in vdis:
            tmp_vdi_uuid = self.session.xenapi.VDI.get_uuid(tmp_vdi)
            tmp_sm_config = self.session.xenapi.VDI.get_sm_config(tmp_vdi)
            if tmp_sm_config.has_key("snapshot-of"):
                if tmp_sm_config["snapshot-of"] == vdi_uuid:
                    has_a_snapshot = True
            if tmp_sm_config.has_key("sxm_mirror"):
                sxm_mirror_vdi = vdi_uuid
        ########## SXM VDIs
        if sm_config.has_key("base_mirror"):
            if has_a_snapshot:
                # it's a mirror vdi of storage migrating VM
                # it's attached first
                self.session.xenapi.VDI.add_to_sm_config(
                    vdi_ref, 'sxm_mirror', 'true')
                # creating dm snapshot dev
                self._setup_mirror(vdi_uuid, self.size)
            else:
                # it's a base vdi of storage migrating VM
                # it's attached after mirror VDI and mirror snapshot VDI has been created
                self._map_VHD(vdi_uuid)
        ########## not SXM VDIs
        else:
            # it's not SXM VDI, just attach it
            self._map_VHD(vdi_uuid)

        if not util.pathexists(self.path):
            raise xs_errors.XenError('VDIUnavailable',
                                     opterr='Could not find: %s' % self.path)

        return VDI.VDI.attach(self, self.sr.uuid, self.uuid)
Пример #2
0
    def attach(self, sr_uuid, vdi_uuid):
        if not self._checkpath(self.path):
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))
        try:
            self.attached = True
            if self.sr.srcmd.params.has_key("vdi_ref"):
                vdi_ref = self.sr.srcmd.params['vdi_ref']
                scsiutil.update_XS_SCSIdata(self.session, vdi_ref, vdi_uuid, \
                                        scsiutil.gen_synthetic_page_data(vdi_uuid))

                if self.sr.handles("file"):
                    self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
                                        "vdi-type")
                    self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
                                        "storage-type")
                    self.session.xenapi.VDI.add_to_xenstore_data(vdi_ref, \
                                        "storage-type", "ext")
            return super(FileVDI, self).attach(sr_uuid, vdi_uuid)
        except util.CommandException, inst:
            raise xs_errors.XenError('VDILoad', opterr='error %d' % inst.code)
Пример #3
0
    def attach(self, sr_uuid, vdi_uuid):
        if not self._checkpath(self.path):
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))
        try:
            self.attached = True
            if self.sr.srcmd.params.has_key("vdi_ref"):
                vdi_ref = self.sr.srcmd.params['vdi_ref']
                scsiutil.update_XS_SCSIdata(self.session, vdi_ref, vdi_uuid, \
                                        scsiutil.gen_synthetic_page_data(vdi_uuid))

                if self.sr.handles("file"):
                    self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
                                        "vdi-type")
                    self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
                                        "storage-type")
                    self.session.xenapi.VDI.add_to_xenstore_data(vdi_ref, \
                                        "storage-type", "ext")
            return super(FileVDI, self).attach(sr_uuid, vdi_uuid)
        except util.CommandException, inst:
            raise xs_errors.XenError('VDILoad', opterr='error %d' % inst.code)
Пример #4
0
 def attach(self, sr_uuid, vdi_uuid):
     util.SMlog("RBDVDI.attach for %s" % self.uuid)
     
     vdi_ref = self.sr.srcmd.params['vdi_ref']
     sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref)
     
     if not hasattr(self,'xenstore_data'):
         self.xenstore_data = {}
     
     self.xenstore_data.update(scsiutil.update_XS_SCSIdata(self.uuid, scsiutil.gen_synthetic_page_data(self.uuid)))
     
     self.xenstore_data['storage-type']='rbd'
     self.xenstore_data['vdi-type']=self.vdi_type
     
     self.attached = True
     self.session.xenapi.VDI.remove_from_sm_config(vdi_ref, 'attached')
     self.session.xenapi.VDI.add_to_sm_config(vdi_ref, 'attached', 'true')
     
     self.size = int(self.session.xenapi.VDI.get_virtual_size(vdi_ref))
     
     ##########
     vdis = self.session.xenapi.SR.get_VDIs(self.sr.sr_ref)
     has_a_snapshot = False
     for tmp_vdi in vdis:
         tmp_vdi_uuid = self.session.xenapi.VDI.get_uuid(tmp_vdi)
         tmp_sm_config = self.session.xenapi.VDI.get_sm_config(tmp_vdi)
         if tmp_sm_config.has_key("snapshot-of"):
             if tmp_sm_config["snapshot-of"] == vdi_uuid:
                 has_a_snapshot = True
         if tmp_sm_config.has_key("sxm_mirror"):
                 sxm_mirror_vdi = vdi_uuid
     ########## SXM VDIs
     if sm_config.has_key("base_mirror"):
         if has_a_snapshot:
             # it's a mirror vdi of storage migrating VM
             # it's attached first
             self.session.xenapi.VDI.add_to_sm_config(vdi_ref, 'sxm_mirror', 'true')
             # creating dm snapshot dev
             self._setup_mirror(vdi_uuid, self.size)
         else:
             # it's a base vdi of storage migrating VM
             # it's attached after mirror VDI and mirror snapshot VDI has been created
             self._map_VHD(vdi_uuid)
     ########## not SXM VDIs
     else:
         # it's not SXM VDI, just attach it
         self._map_VHD(vdi_uuid)
     
     if not util.pathexists(self.path):
         raise xs_errors.XenError('VDIUnavailable', opterr='Could not find: %s' % self.path)
     
     return VDI.VDI.attach(self, self.sr.uuid, self.uuid)
Пример #5
0
    def attach(self, sr_uuid, vdi_uuid):
        if not self._checkpath(self.path):
            raise xs_errors.XenError("VDIUnavailable", opterr="VDI %s unavailable %s" % (vdi_uuid, self.path))
        try:
            self.attached = True

            if not hasattr(self, "xenstore_data"):
                self.xenstore_data = {}

            self.xenstore_data.update(scsiutil.update_XS_SCSIdata(vdi_uuid, scsiutil.gen_synthetic_page_data(vdi_uuid)))

            if self.sr.handles("file"):
                # XXX: PR-1255: if these are constants then they should
                # be returned by the attach API call, not persisted in the
                # pool database.
                self.xenstore_data["storage-type"] = "ext"
            return super(FileVDI, self).attach(sr_uuid, vdi_uuid)
        except util.CommandException, inst:
            raise xs_errors.XenError("VDILoad", opterr="error %d" % inst.code)
Пример #6
0
    def attach(self, sr_uuid, vdi_uuid):
        if not self._checkpath(self.path):
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))
        try:
            self.attached = True

            if not hasattr(self, 'xenstore_data'):
                self.xenstore_data = {}

            self.xenstore_data.update(scsiutil.update_XS_SCSIdata(vdi_uuid, \
                                                                      scsiutil.gen_synthetic_page_data(vdi_uuid)))

            if self.sr.handles("file"):
                # XXX: PR-1255: if these are constants then they should
                # be returned by the attach API call, not persisted in the
                # pool database.
                self.xenstore_data['storage-type'] = 'ext'
            return super(FileVDI, self).attach(sr_uuid, vdi_uuid)
        except util.CommandException, inst:
            raise xs_errors.XenError('VDILoad', opterr='error %d' % inst.code)
Пример #7
0
    def attach(self, sr_uuid, vdi_uuid):
        if self.path is None:
            self._find_path_with_retries(vdi_uuid)
        if not self._checkpath(self.path):
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))
        try:
            self.attached = True

            if not hasattr(self,'xenstore_data'):
                self.xenstore_data = {}

            self.xenstore_data.update(scsiutil.update_XS_SCSIdata(vdi_uuid, \
                                                                      scsiutil.gen_synthetic_page_data(vdi_uuid)))

            if self.sr.handles("file"):
                    # XXX: PR-1255: if these are constants then they should
                    # be returned by the attach API call, not persisted in the
                    # pool database.
                self.xenstore_data['storage-type']='ext'
            return super(FileVDI, self).attach(sr_uuid, vdi_uuid)
        except util.CommandException, inst:
            raise xs_errors.XenError('VDILoad', opterr='error %d' % inst.code)
Пример #8
0
    def attach(self, sr_uuid, vdi_uuid):
        util.SMlog("RBDVDI.attach: sr_uuid=%s, vdi_uuid=%s" %
                   (sr_uuid, vdi_uuid))

        vdi_ref = self.session.xenapi.VDI.get_by_uuid(vdi_uuid)
        sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref)
        sr_sm_config = self.session.xenapi.SR.get_sm_config(self.sr.sr_ref)
        host_uuid = inventory.get_localhost_uuid()
        self.size = int(self.session.xenapi.VDI.get_virtual_size(vdi_ref))

        if sr_sm_config.has_key("dev_instances"):
            sr_dev_instances = json.loads(sr_sm_config["dev_instances"])
            self.session.xenapi.SR.remove_from_sm_config(
                self.sr.sr_ref, "dev_instances")
        else:
            sr_dev_instances = {"hosts": {}}

        first_free_instance = -1
        if sr_dev_instances["hosts"].has_key(host_uuid):
            for i in range(cephutils.NBDS_MAX):
                if sr_dev_instances["hosts"][host_uuid][i] == None:
                    first_free_instance = i
                    break
            sr_dev_instances["hosts"][host_uuid][
                first_free_instance] = vdi_uuid
        else:
            #sr_dev_instances["hosts"].append({host_uuid:[None]*cephutils.NBDS_MAX})
            sr_dev_instances["hosts"][host_uuid] = [None] * cephutils.NBDS_MAX
            sr_dev_instances["hosts"][host_uuid][0] = "reserved"
            sr_dev_instances["hosts"][host_uuid][1] = vdi_uuid
            first_free_instance = 1

        self.session.xenapi.SR.add_to_sm_config(self.sr.sr_ref,
                                                "dev_instances",
                                                json.dumps(sr_dev_instances))
        if sm_config.has_key("dev_instance"):
            self.session.xenapi.VDI.remove_from_sm_config(
                vdi_ref, "dev_instance")
        self.session.xenapi.VDI.add_to_sm_config(vdi_ref, "dev_instance",
                                                 str(first_free_instance))

        self.path = self.sr._get_path(vdi_uuid)

        if not hasattr(self, 'xenstore_data'):
            self.xenstore_data = {}

        self.xenstore_data.update(
            scsiutil.update_XS_SCSIdata(
                self.uuid, scsiutil.gen_synthetic_page_data(self.uuid)))

        self.xenstore_data['storage-type'] = 'rbd'
        self.xenstore_data['vdi-type'] = self.vdi_type

        try:
            ##########
            vdis = self.session.xenapi.SR.get_VDIs(self.sr.sr_ref)
            has_a_snapshot = False
            for tmp_vdi in vdis:
                tmp_vdi_uuid = self.session.xenapi.VDI.get_uuid(tmp_vdi)
                tmp_sm_config = self.session.xenapi.VDI.get_sm_config(tmp_vdi)
                if tmp_sm_config.has_key("snapshot-of"):
                    if tmp_sm_config["snapshot-of"] == vdi_uuid:
                        has_a_snapshot = True
            #    if tmp_sm_config.has_key("sxm_mirror"):
            #            sxm_mirror_vdi = vdi_uuid
            ########## SXM VDIs
            if sm_config.has_key("snapshot-of"):
                base_uuid = sm_config["snapshot-of"]
                # it's a snapshot VDI, attach it as snapshot
                self._map_SNAP(base_uuid, vdi_uuid, self.size, "none")
            elif sm_config.has_key("base_mirror"):
                if has_a_snapshot:
                    # it's a mirror vdi of storage migrating VM
                    # it's attached first
                    self.session.xenapi.VDI.add_to_sm_config(
                        vdi_ref, 'sxm_mirror', 'true')
                    # creating dm snapshot dev
                    self._map_sxm_mirror(vdi_uuid, self.size)
                else:
                    # it's a base vdi of storage migrating VM
                    # it's attached after mirror VDI and mirror snapshot VDI has been created
                    self._map_VHD(vdi_uuid, self.size, "none")
            ########## not SXM VDIs
            else:
                # it's not SXM VDI, just attach it
                self._map_VHD(vdi_uuid, self.size, "none")

            if not util.pathexists(self.path):
                raise xs_errors.XenError('VDIUnavailable',
                                         opterr='Could not find: %s' %
                                         self.path)

            self.attached = True
            if sm_config.has_key("attached"):
                self.session.xenapi.VDI.remove_from_sm_config(
                    vdi_ref, 'attached')
            self.session.xenapi.VDI.add_to_sm_config(vdi_ref, 'attached',
                                                     'true')

        except:
            self.session.xenapi.SR.remove_from_sm_config(
                self.sr.sr_ref, "dev_instances")
            sr_dev_instances["hosts"][host_uuid][first_free_instance] = None
            self.session.xenapi.SR.add_to_sm_config(
                self.sr.sr_ref, "dev_instances", json.dumps(sr_dev_instances))
            self.session.xenapi.VDI.remove_from_sm_config(
                vdi_ref, "dev_instance")

        return VDI.VDI.attach(self, self.sr.uuid, self.uuid)
Пример #9
0
            self._db_forget()
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMDelete', \
                  opterr='lv operation failed error is %d' % inst.code)

    def attach(self, sr_uuid, vdi_uuid):
        try:
            if not os.path.exists(self.path) or not self._isactive(self.path):
                cmd = ["lvchange", "-ay", self.path]
                text = util.ioretry(lambda: util.pread2(cmd))
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMMount', \
                  opterr='lvchange failed error is %d' % inst.code)
        if self.sr.srcmd.params.has_key("vdi_ref"):
            vdi_ref = self.sr.srcmd.params['vdi_ref']
            scsiutil.update_XS_SCSIdata(self.session, vdi_ref, vdi_uuid, \
                                    scsiutil.gen_synthetic_page_data(vdi_uuid))
        return super(LVMVDI, self).attach(sr_uuid, vdi_uuid)

    def detach(self, sr_uuid, vdi_uuid):
        try:
            if os.path.exists(self.path):
                cmd = ["lvchange", "-an", self.path]
                text = util.ioretry(lambda:util.pread2(cmd))
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMUnMount', \
                  opterr='lvchange failed error is %d' % inst.code)

    def resize(self, sr_uuid, vdi_uuid, size):
        if not self.sr.isMaster:
            util.SMlog('vdi_resize blocked for non-master')
            raise xs_errors.XenError('LVMMaster')