Example #1
0
    def create(self, sr_uuid, vdi_uuid, size):
        if not self.sr.isMaster:
            util.SMlog('vdi_create blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        try:
            mb = 1024L * 1024L
            size_mb = (long(size) + mb - 1L) / mb # round up
            # Rather than bailing out for small sizes, just round up to 1 MiB. The
            # LVM code will round up to the nearest PE size anyway (probably 4 MiB)
            if size_mb == 0:
                size_mb = 1
            
            if lvutil._checkLV(self.path):
                raise xs_errors.XenError('VDIExists')

            # Verify there's sufficient space for the VDI
            stats = lvutil._getVGstats(self.sr.vgname)
            freespace = stats['physical_size'] - stats['physical_utilisation']
            if freespace < long(size):
                raise xs_errors.XenError('SRNoSpace')              

            cmd = ["lvcreate", "-n", self.lvname, "-L", str(size_mb), \
                   self.sr.vgname]
            text = util.pread2(cmd)

            cmd = ["lvchange", "-an", self.path]
            text = util.pread2(cmd)

            self.size = lvutil._getLVsize(self.path)
            self.utilisation = self.size
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation failed error is %d' % inst.code)
Example #2
0
File: EXTSR.py Project: stormi/sm
    def create(self, sr_uuid, size):
        if self._checkmount():
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, sr_uuid, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')

        if not lvutil._checkVG(self.vgname):
            lvutil.createVG(self.root, self.vgname)

        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')

        try:
            numdevs = len(self.root.split(','))
            cmd = ["lvcreate", "-n", sr_uuid]
            if numdevs > 1:
                lowest = -1
                for dev in self.root.split(','):
                    stats = lvutil._getPVstats(dev)
                    if lowest < 0 or stats['freespace'] < lowest:
                        lowest = stats['freespace']
                size_mb = (lowest / (1024 * 1024)) * numdevs

                # Add stripe parameter to command
                cmd += ["-i", str(numdevs), "-I", "2048"]
            else:
                stats = lvutil._getVGstats(self.vgname)
                size_mb = stats['freespace'] / (1024 * 1024)
            assert (size_mb > 0)
            cmd += ["-L", str(size_mb), self.vgname]
            text = util.pread(cmd)

            cmd = ["lvchange", "-ay", self.remotepath]
            text = util.pread(cmd)
        except util.CommandException as inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation, error %d' % inst.code)
        except AssertionError:
            raise xs_errors.XenError('SRNoSpace', \
                  opterr='Insufficient space in VG %s' % self.vgname)

        try:
            util.pread2(["mkfs.ext4", "-F", self.remotepath])
        except util.CommandException as inst:
            raise xs_errors.XenError('LVMFilesystem', \
                  opterr='mkfs failed error %d' % inst.code)

        #Update serial number string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                  scsiutil.devlist_to_serialstring(self.root.split(',')))
 def generate_config(self, sr_uuid, vdi_uuid):
     if not lvutil._checkLV(self.path):
         raise xs_errors.XenError("VDIUnavailable")
     dict = {}
     self.sr.dconf["multipathing"] = self.sr.mpath
     self.sr.dconf["multipathhandle"] = self.sr.mpathhandle
     dict["device_config"] = self.sr.dconf
     dict["sr_uuid"] = sr_uuid
     dict["vdi_uuid"] = vdi_uuid
     dict["command"] = "vdi_attach_from_config"
     # Return the 'config' encoded within a normal XMLRPC response so that
     # we can use the regular response/error parsing code.
     config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
     return xmlrpclib.dumps((config,), "", True)
Example #4
0
    def create(self, sr_uuid, size):
        # THIS DRIVER IS DEPRECATED. RAISE.
        raise Exception(
            'The `ext4` SR type is deprecated since XCP-ng 8.1.\n'
            'Use the main `ext` driver instead. It will create an EXT4 filesystem now, '
            'not EXT3 anymore as it used to.')

        if self._checkmount():
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, sr_uuid, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')

        if not lvutil._checkVG(self.vgname):
            lvutil.createVG(self.root, self.vgname)

        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')

        try:
            numdevs = len(self.root.split(','))
            cmd = ["lvcreate", "-n", sr_uuid]
            if numdevs > 1:
                lowest = -1
                for dev in self.root.split(','):
                    stats = lvutil._getPVstats(dev)
                    if lowest < 0 or stats['freespace'] < lowest:
                        lowest = stats['freespace']
                size_mb = (lowest / (1024 * 1024)) * numdevs

                # Add stripe parameter to command
                cmd += ["-i", str(numdevs), "-I", "2048"]
            else:
                stats = lvutil._getVGstats(self.vgname)
                size_mb = stats['freespace'] / (1024 * 1024)
            assert (size_mb > 0)
            cmd += ["-L", str(size_mb), self.vgname]
            text = util.pread(cmd)

            cmd = ["lvchange", "-ay", self.remotepath]
            text = util.pread(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation, error %d' % inst.code)
    def generate_config(self, sr_uuid, vdi_uuid):
        if not lvutil._checkLV(self.path):
                raise xs_errors.XenError('VDIUnavailable')
        dict = {}
        self.sr.dconf['multipathing'] = self.sr.mpath
        self.sr.dconf['multipathhandle'] = self.sr.mpathhandle
        dict['device_config'] = self.sr.dconf
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['command'] = 'vdi_attach_from_config'
	# Return the 'config' encoded within a normal XMLRPC response so that
	# we can use the regular response/error parsing code.
	config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)
Example #6
0
 def generate_config(self, sr_uuid, vdi_uuid):
     util.SMlog("LVHDoHBAVDI.generate_config")
     if not lvutil._checkLV(self.path):
         raise xs_errors.XenError('VDIUnavailable')
     dict = {}
     self.sr.dconf['multipathing'] = self.sr.mpath
     self.sr.dconf['multipathhandle'] = self.sr.mpathhandle
     dict['device_config'] = self.sr.dconf
     dict['sr_uuid'] = sr_uuid
     dict['vdi_uuid'] = vdi_uuid
     dict['command'] = 'vdi_attach_from_config'
     # Return the 'config' encoded within a normal XMLRPC response so that
     # we can use the regular response/error parsing code.
     config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
     return xmlrpclib.dumps((config,), "", True)
Example #7
0
    def delete(self, sr_uuid, vdi_uuid):
        if not self.sr.isMaster:
            util.SMlog('vdi_delete blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        if not lvutil._checkLV(self.path):
            return

        try:
            cmd = ["lvremove", "-f", self.path]
            text = util.pread2(cmd)
            self._db_forget()
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMDelete', \
                  opterr='lv operation failed error is %d' % inst.code)
Example #8
0
    def create(self, sr_uuid, size):
        if self._checkmount():
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, sr_uuid, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')

        if not lvutil._checkVG(self.vgname):
            lvutil.createVG(self.root, self.vgname)

        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')

        try:
            numdevs = len(self.root.split(','))
            cmd = ["lvcreate", "-n", sr_uuid]
            if numdevs > 1:
                lowest = -1
                for dev in self.root.split(','):
                    stats = lvutil._getPVstats(dev)
                    if lowest < 0  or stats['freespace'] < lowest:
                        lowest = stats['freespace']
                size_mb = (lowest / (1024 * 1024)) * numdevs

                # Add stripe parameter to command
                cmd += ["-i", str(numdevs), "-I", "2048"]
            else:
                stats = lvutil._getVGstats(self.vgname)
                size_mb = stats['freespace'] / (1024 * 1024)
            assert(size_mb > 0)
            cmd += ["-L", str(size_mb), self.vgname]
            text = util.pread(cmd)

            cmd = ["lvchange", "-ay", self.remotepath]
            text = util.pread(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation, error %d' % inst.code)
    def generate_config(self, sr_uuid, vdi_uuid):
        if not lvutil._checkLV(self.path):
                raise xs_errors.XenError('VDIUnavailable')
        dict = {}
        self.sr.dconf['localIQN'] = self.sr.iscsi.localIQN
        self.sr.dconf['multipathing'] = self.sr.mpath
        self.sr.dconf['multipathhandle'] = self.sr.mpathhandle
        dict['device_config'] = self.sr.dconf
        if dict['device_config'].has_key('chappassword_secret'):
            s = util.get_secret(self.session, dict['device_config']['chappassword_secret'])
            del dict['device_config']['chappassword_secret']
            dict['device_config']['chappassword'] = s
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['command'] = 'vdi_attach_from_config'
	# Return the 'config' encoded within a normal XMLRPC response so that
	# we can use the regular response/error parsing code.
	config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)
Example #10
0
 def generate_config(self, sr_uuid, vdi_uuid):
     util.SMlog("LVHDoISCSIVDI.generate_config")
     if not lvutil._checkLV(self.path):
             raise xs_errors.XenError('VDIUnavailable')
     dict = {}
     self.sr.dconf['localIQN'] = self.sr.iscsi.localIQN
     self.sr.dconf['multipathing'] = self.sr.mpath
     self.sr.dconf['multipathhandle'] = self.sr.mpathhandle
     dict['device_config'] = self.sr.dconf
     if dict['device_config'].has_key('chappassword_secret'):
         s = util.get_secret(self.session, dict['device_config']['chappassword_secret'])
         del dict['device_config']['chappassword_secret']
         dict['device_config']['chappassword'] = s
     dict['sr_uuid'] = sr_uuid
     dict['vdi_uuid'] = vdi_uuid
     dict['command'] = 'vdi_attach_from_config'
     # Return the 'config' encoded within a normal XMLRPC response so that
     # we can use the regular response/error parsing code.
     config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
     return xmlrpclib.dumps((config,), "", True)
Example #11
0
 def generate_config(self, sr_uuid, vdi_uuid):
     util.SMlog("LVHDoISCSIVDI.generate_config")
     if not lvutil._checkLV(self.path):
         raise xs_errors.XenError("VDIUnavailable")
     if self.sr.sm_config["allocation"] == "xlvhd":
         lvutil.flushLV(self.path)
     dict = {}
     self.sr.dconf["localIQN"] = self.sr.iscsi.localIQN
     self.sr.dconf["multipathing"] = self.sr.mpath
     self.sr.dconf["multipathhandle"] = self.sr.mpathhandle
     dict["device_config"] = self.sr.dconf
     if dict["device_config"].has_key("chappassword_secret"):
         s = util.get_secret(self.session, dict["device_config"]["chappassword_secret"])
         del dict["device_config"]["chappassword_secret"]
         dict["device_config"]["chappassword"] = s
     dict["sr_uuid"] = sr_uuid
     dict["vdi_uuid"] = vdi_uuid
     dict["allocation"] = self.sr.sm_config["allocation"]
     dict["command"] = "vdi_attach_from_config"
     # Return the 'config' encoded within a normal XMLRPC response so that
     # we can use the regular response/error parsing code.
     config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
     return xmlrpclib.dumps((config,), "", True)
Example #12
0
                raise xs_errors.XenError('LVMGroupCreate')

            # Then add any additional devs into the VG
            for dev in self.root.split(',')[1:]:
                try:
                    cmd = ["vgextend", self.vgname, dev]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    # One of the PV args failed, delete SR
                    try:
                        cmd = ["vgremove", self.vgname]
                        util.pread2(cmd)                   
                    except:
                        pass
                    raise xs_errors.XenError('LVMGroupCreate')
        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')
        try:
            stats = lvutil._getVGstats(self.vgname)
            size_mb = stats['freespace'] / (1024 * 1024)
            assert(size_mb > 0)
            cmd = ["lvcreate", "-n", sr_uuid, "-L", str(size_mb), \
                   self.vgname]
            text = util.pread(cmd)

            cmd = ["lvchange", "-ay", self.remotepath]
            text = util.pread(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation, error %d' % inst.code)
        except AssertionError:
Example #13
0
                raise xs_errors.XenError('LVMGroupCreate')

            # Then add any additional devs into the VG
            for dev in self.root.split(',')[1:]:
                try:
                    cmd = ["vgextend", self.vgname, dev]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    # One of the PV args failed, delete SR
                    try:
                        cmd = ["vgremove", self.vgname]
                        util.pread2(cmd)                   
                    except:
                        pass
                    raise xs_errors.XenError('LVMGroupCreate')
        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')
        try:
            numdevs = len(self.root.split(','))
            cmd = ["lvcreate", "-n", sr_uuid]
            if numdevs > 1:
                lowest = -1
                for dev in self.root.split(','):
                    stats = lvutil._getPVstats(dev)
                    if lowest < 0  or stats['freespace'] < lowest:
                        lowest = stats['freespace']
                size_mb = (lowest / (1024 * 1024)) * numdevs

                # Add stripe parameter to command
                cmd += ["-i", str(numdevs), "-I", "2048"]
            else: