def create(self, sr_uuid, size): # Check whether an SR already exists SRs = self.session.xenapi.SR.get_all_records() for sr in SRs: record = SRs[sr] sm_config = record["sm_config"] if 'datatype' in sm_config and \ sm_config['datatype'] == 'HBA' and \ sm_config['hbatype'] == self.type: raise xs_errors.XenError('SRInUse') self._init_hbadict() if not self.attached: raise xs_errors.XenError('InvalidDev', \ opterr=('No such HBA Device detected [%s]') % self.type) if self._loadvdis() > 0: scanrecord = SR.ScanRecord(self) scanrecord.synchronise() try: self.detach(sr_uuid) except: pass self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) self.sm_config['disktype'] = 'Raw' self.sm_config['datatype'] = 'HBA' self.sm_config['hbatype'] = self.type self.sm_config['multipathable'] = 'true' self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config)
def scan(self, sr_uuid): """ This function is almost a copy of its base class equivalent. Main differences are: - Fixed erroneous size calculation - Set VDI names automatically - Avoid ScanRecord sync for missing VDIS (stale LUNs) The last one is called in the sub-sub class so we cannot simply extend the base class funcion but we need to override it """ self._init_hbadict() if not self.passthrough: if not self.attached: raise xs_errors.XenError('SRUnavailable') self._loadvdis() # This block is almost SR.scan but without missing sync self._db_update() scanrecord = SR.ScanRecord(self) scanrecord.synchronise_new() scanrecord.synchronise_existing() # Fixing sizes calculation phys_util = 0 for key in self.vdis: vdi_ref = self.session.xenapi.VDI.get_by_uuid(key) if B_util.is_vdi_attached(self.session, vdi_ref): phys_util += self.vdis[key].size self._set_stats(phys_util=phys_util) self._set_vdis_name()
def create(self, sr_uuid, size): # Check whether an SR already exists SRs = self.session.xenapi.SR.get_all_records() for sr in SRs: record = SRs[sr] sm_config = record["sm_config"] if 'targetIQN' in sm_config and \ sm_config['targetIQN'] == self.targetIQN: raise xs_errors.XenError('SRInUse') self.attach(sr_uuid) # Wait up to MAX_TIMEOUT for devices to appear util.wait_for_path(self.path, MAX_TIMEOUT) if self._loadvdis() > 0: scanrecord = SR.ScanRecord(self) scanrecord.synchronise() try: self.detach(sr_uuid) except: pass self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) self.sm_config['disktype'] = 'Raw' self.sm_config['datatype'] = 'ISCSI' self.sm_config['target'] = self.target self.sm_config['targetIQN'] = self.targetIQN self.sm_config['multipathable'] = 'true' self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config) return
def scan(self, sr_uuid): util.SMlog("RBDSR.load: sr_uuid=%s" % sr_uuid) cephutils.SR.scan(self, sr_uuid) self.physical_size = self.RBDPOOLs[sr_uuid]['stats'][ 'max_avail'] + self.RBDPOOLs[sr_uuid]['stats']['bytes_used'] self.physical_utilisation = self.RBDPOOLs[sr_uuid]['stats'][ 'bytes_used'] self.virtual_allocation = self._get_allocated_size() self._loadvdis() self._db_update() scanrecord = SR.ScanRecord(self) scanrecord.synchronise_existing() scanrecord.synchronise_new()
def scan(self, sr_uuid): if not self.isMaster: util.SMlog('sr_scan blocked for non-master') raise xs_errors.XenError('LVMMaster') self._loadbuffer() self._loadvdis() stats = lvutil._getVGstats(self.vgname) self.physical_size = stats['physical_size'] self.physical_utilisation = stats['physical_utilisation'] self.virtual_allocation = self.physical_utilisation # Update the SR record self._db_update() # Synchronise the VDIs scanrecord = SR.ScanRecord(self) # XXX: never forget VDI records to work around glitch where some # volumes temporarily disappeared scanrecord.synchronise_new() scanrecord.synchronise_existing()
def scan(self, sr_uuid): """Scan: see _loadvdis""" if not util.isdir(self.path): raise xs_errors.XenError('SRUnavailable', \ opterr='no such directory %s' % self.path) if ('legacy_mode' not in self.dconf) and (not self._checkmount()): raise xs_errors.XenError('SRUnavailable', \ opterr='directory not mounted: %s' % self.path) #try: if not self.vdis: self._loadvdis() self.physical_size = util.get_fs_size(self.path) self.physical_utilisation = util.get_fs_utilisation(self.path) self.virtual_allocation = self.physical_size other_config = self.session.xenapi.SR.get_other_config(self.sr_ref) if 'xenserver_tools_sr' in other_config and \ other_config['xenserver_tools_sr'] == "true": # Out of all the xs-tools ISOs which exist in this dom0, we mark # only one as the official one. # Pass 1: find the latest version latest_build_vdi = None latest_build_number = "0" for vdi_name in self.vdis: vdi = self.vdis[vdi_name] if latest_build_vdi is None: latest_build_vdi = vdi.location latest_build_number = "0" if 'xs-tools-build' in vdi.sm_config: bld = vdi.sm_config['xs-tools-build'] if bld >= latest_build_number: latest_build_vdi = vdi.location latest_build_number = bld # Pass 2: mark all VDIs accordingly for vdi_name in self.vdis: vdi = self.vdis[vdi_name] if vdi.location == latest_build_vdi: vdi.sm_config['xs-tools'] = "true" else: if "xs-tools" in vdi.sm_config: del vdi.sm_config['xs-tools'] # Synchronise the VDIs: this will update the sm_config maps of current records scanrecord = SR.ScanRecord(self) scanrecord.synchronise_new() scanrecord.synchronise_existing() # Everything that looks like an xs-tools ISO but which isn't the # primary one will also be renamed "Old version of ..." sr = self.session.xenapi.SR.get_by_uuid(sr_uuid) all_vdis = self.session.xenapi.VDI.get_all_records_where( "field \"SR\" = \"%s\"" % sr) for vdi_ref in all_vdis.keys(): vdi = all_vdis[vdi_ref] if 'xs-tools-version' in vdi['sm_config']: name = tools_iso_name(vdi['location']) if 'xs-tools' in vdi['sm_config']: self.session.xenapi.VDI.set_name_label(vdi_ref, name) else: self.session.xenapi.VDI.set_name_label( vdi_ref, "Old version of " + name) # never forget old VDI records to cope with rolling upgrade for location in scanrecord.gone: vdi = scanrecord.get_xenapi_vdi(location) util.SMlog( "Marking previous version of tools ISO: location=%s uuid=%s" % (vdi['location'], vdi['uuid'])) vdi = self.session.xenapi.VDI.get_by_uuid(vdi['uuid']) name_label = self.session.xenapi.VDI.get_name_label(vdi) if not (name_label.startswith("Old version of ")): self.session.xenapi.VDI.set_name_label( vdi, "Old version of " + name_label) # Mark it as missing for informational purposes only self.session.xenapi.VDI.set_missing(vdi, True) self.session.xenapi.VDI.remove_from_sm_config(vdi, 'xs-tools') else: return super(ISOSR, self).scan(sr_uuid)