def _init_PPCIs(self): saved_ppcis = self.state_store.load_state('ppci') saved_ppci_table = {} if saved_ppcis: for ppci_uuid, ppci_record in saved_ppcis.items(): try: saved_ppci_table[ppci_record['name']] = ppci_uuid except KeyError: pass for pci_dev in PciUtil.get_all_pci_devices(): ppci_record = { 'domain': pci_dev.domain, 'bus': pci_dev.bus, 'slot': pci_dev.slot, 'func': pci_dev.func, 'vendor_id': pci_dev.vendor, 'vendor_name': pci_dev.vendorname, 'device_id': pci_dev.device, 'device_name': pci_dev.devicename, 'revision_id': pci_dev.revision, 'class_code': pci_dev.classcode, 'class_name': pci_dev.classname, 'subsystem_vendor_id': pci_dev.subvendor, 'subsystem_vendor_name': pci_dev.subvendorname, 'subsystem_id': pci_dev.subdevice, 'subsystem_name': pci_dev.subdevicename, 'driver': pci_dev.driver } # If saved uuid exists, use it. Otherwise create one. ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString()) XendPPCI(ppci_uuid, ppci_record)
def _init_SRs(self): # initialise storage saved_srs = self.state_store.load_state('sr') if saved_srs: for sr_uuid, sr_cfg in saved_srs.items(): if sr_cfg['type'] == 'qcow_file': self.srs[sr_uuid] = XendQCoWStorageRepo(sr_uuid) elif sr_cfg['type'] == 'local': self.srs[sr_uuid] = XendLocalStorageRepo(sr_uuid) # Create missing SRs if they don't exist if not self.get_sr_by_type('local'): image_sr_uuid = uuid.createString() self.srs[image_sr_uuid] = XendLocalStorageRepo(image_sr_uuid) if not self.get_sr_by_type('qcow_file'): qcow_sr_uuid = uuid.createString() self.srs[qcow_sr_uuid] = XendQCoWStorageRepo(qcow_sr_uuid)
def create_vdi(self, vdi_struct): """ Creates a fake VDI image for a traditional image string. The image uri is stored in the attribute 'uri' """ vdi_struct['uuid'] = uuid.createString() vdi_struct['SR'] = self.uuid new_image = XendLocalVDI(vdi_struct) self.images[new_image.uuid] = new_image self.save_state() return new_image.uuid
def add_PSCSI(self, add_HCTL): saved_pscsis = self.state_store.load_state('pscsi') saved_pscsi_table = {} if saved_pscsis: for saved_uuid, saved_record in saved_pscsis.items(): try: saved_pscsi_table[saved_record['scsi_id']] = saved_uuid except KeyError: pass saved_pscsi_HBAs = self.state_store.load_state('pscsi_HBA') saved_pscsi_HBA_table = {} if saved_pscsi_HBAs: for saved_HBA_uuid, saved_HBA_record in saved_pscsi_HBAs.items(): try: physical_host = int(saved_HBA_record['physical_host']) saved_pscsi_HBA_table[physical_host] = saved_HBA_uuid except (KeyError, ValueError): pass # Initialise the PSCSI and the PSCSI_HBA pscsi_record = vscsi_util.get_scsi_device(add_HCTL) if pscsi_record and pscsi_record['scsi_id']: pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'], None) if pscsi_uuid is None: physical_host = int(add_HCTL.split(':')[0]) pscsi_HBA_uuid = saved_pscsi_HBA_table.get(physical_host, None) if pscsi_HBA_uuid is None: pscsi_HBA_uuid = uuid.createString() XendPSCSI_HBA(pscsi_HBA_uuid, {'physical_host': physical_host}) pscsi_record['HBA'] = pscsi_HBA_uuid pscsi_uuid = uuid.createString() XendPSCSI(pscsi_uuid, pscsi_record) self.save_PSCSIs() self.save_PSCSI_HBAs()
def create_vdi(self, vdi_struct, transient = False): """ Creates a fake VDI image for a traditional image string. The image uri is stored in the attribute 'uri' """ if not vdi_struct.get('uuid') or vdi_struct.get('uuid') == '': vdi_struct['uuid'] = uuid.createString() vdi_struct['SR'] = self.uuid new_image = XendLocalVDI(vdi_struct) if vdi_struct.get('type') == 'user': # self.create_img_file(vdi_struct) self.create_logical_volume(vdi_struct) self.images[new_image.uuid] = new_image self.save_state(transient) return new_image.uuid
def _init_PSCSIs(self): # Initialise PSCSIs saved_pscsis = self.state_store.load_state('pscsi') saved_pscsi_table = {} if saved_pscsis: for pscsi_uuid, pscsi_record in saved_pscsis.items(): try: saved_pscsi_table[pscsi_record['scsi_id']] = pscsi_uuid except KeyError: pass for pscsi_record in vscsi_util.get_all_scsi_devices(): if pscsi_record['scsi_id']: # If saved uuid exists, use it. Otherwise create one. pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'], uuid.createString()) XendPSCSI(pscsi_uuid, pscsi_record)
def create_vdi(self, vdi_struct, transient = False, create_file=True): """ Creates a fake VDI image for a traditional image string. The image uri is stored in the attribute 'uri' """ if not vdi_struct.get('uuid') or vdi_struct.get('uuid') == '': vdi_struct['uuid'] = uuid.createString() vdi_struct['SR'] = self.uuid # vdi_struct['name_label'] = vdi_struct['uuid'] if vdi_struct.get('type') == 'user' and create_file: self.create_img_file(vdi_struct) vdi_struct['physical_utilisation'] = int(vdi_struct['virtual_size']) * BYTE new_image = XendLocalVDI(vdi_struct) # self.create_logical_volume(vdi_struct) self.images[new_image.uuid] = new_image self.save_state(transient) return new_image.uuid
def add_PSCSI(self, add_HCTL): saved_pscsis = self.state_store.load_state('pscsi') saved_pscsi_table = {} if saved_pscsis: for saved_uuid, saved_record in saved_pscsis.items(): try: saved_pscsi_table[saved_record['scsi_id']] = saved_uuid except KeyError: pass # Initialise the PSCSI pscsi_record = vscsi_util.get_scsi_device(add_HCTL) if pscsi_record and pscsi_record['scsi_id']: pscsi_uuid = saved_pscsi_table.get(pscsi_record['scsi_id'], None) if pscsi_uuid is None: pscsi_uuid = uuid.createString() XendPSCSI(pscsi_uuid, pscsi_record) self.save_PSCSIs()
def create_vdi_append_state(self, vdi_struct, transient = True): """ Creates a fake VDI image for a traditional image string. The image uri is stored in the attribute 'uri' """ f = open("/opt/xen/bug", "a") # if not vdi_struct.get('uuid') or vdi_struct.get('uuid') == '': vdi_struct['uuid'] = uuid.createString() vdi_struct['SR'] = self.uuid new_image = XendLocalVDI(vdi_struct) # if vdi_struct.get('type') == 'user': ## self.create_img_file(vdi_struct) # self.create_logical_volume(vdi_struct) self.images[new_image.uuid] = new_image self.append_state(new_image, transient) f.write("go to here\n") f.close() return new_image.uuid
def add_PPCI(self, pci_name): # Update lspci info PciUtil.create_lspci_info() # Initialise the PPCI saved_ppcis = self.state_store.load_state('ppci') saved_ppci_table = {} if saved_ppcis: for ppci_uuid, ppci_record in saved_ppcis.items(): try: saved_ppci_table[ppci_record['name']] = ppci_uuid except KeyError: pass (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name) pci_dev = PciUtil.PciDevice(domain, bus, slot, func) ppci_record = { 'domain': pci_dev.domain, 'bus': pci_dev.bus, 'slot': pci_dev.slot, 'func': pci_dev.func, 'vendor_id': pci_dev.vendor, 'vendor_name': pci_dev.vendorname, 'device_id': pci_dev.device, 'device_name': pci_dev.devicename, 'revision_id': pci_dev.revision, 'class_code': pci_dev.classcode, 'class_name': pci_dev.classname, 'subsystem_vendor_id': pci_dev.subvendor, 'subsystem_vendor_name': pci_dev.subvendorname, 'subsystem_id': pci_dev.subdevice, 'subsystem_name': pci_dev.subdevicename, 'driver': pci_dev.driver } # If saved uuid exists, use it. Otherwise create one. ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString()) XendPPCI(ppci_uuid, ppci_record) self.save_PPCIs()
def add_PPCI(self, pci_name): # Update lspci info PciUtil.create_lspci_info() # Initialise the PPCI saved_ppcis = self.state_store.load_state('ppci') saved_ppci_table = {} if saved_ppcis: for ppci_uuid, ppci_record in saved_ppcis.items(): try: saved_ppci_table[ppci_record['name']] = ppci_uuid except KeyError: pass pci_dev = PciUtil.PciDevice(PciUtil.parse_pci_name(pci_name)) ppci_record = { 'domain': pci_dev.domain, 'bus': pci_dev.bus, 'slot': pci_dev.slot, 'func': pci_dev.func, 'vendor_id': pci_dev.vendor, 'vendor_name': pci_dev.vendorname, 'device_id': pci_dev.device, 'device_name': pci_dev.devicename, 'revision_id': pci_dev.revision, 'class_code': pci_dev.classcode, 'class_name': pci_dev.classname, 'subsystem_vendor_id': pci_dev.subvendor, 'subsystem_vendor_name': pci_dev.subvendorname, 'subsystem_id': pci_dev.subdevice, 'subsystem_name': pci_dev.subdevicename, 'driver': pci_dev.driver } # If saved uuid exists, use it. Otherwise create one. ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString()) XendPPCI(ppci_uuid, ppci_record) self.save_PPCIs()
def _create_image_files(self, desired_size_bytes): """Create an image and return its assigned UUID. @param desired_size_bytes: Desired image size in bytes @type desired_size_bytes: int @rtype: string @return: uuid @raises XendError: If an error occurs. """ self.lock.acquire() try: if not self._has_space_available_for(desired_size_bytes): raise XendError("Not enough space (need %d)" % desired_size_bytes) image_uuid = uuid.createString() qcow_path = os.path.join(self.location, XEND_STORAGE_QCOW_FILENAME % image_uuid) if qcow_path and os.path.exists(qcow_path): raise XendError("Image with same UUID alreaady exists:" % image_uuid) cmd = QCOW_CREATE_COMMAND % (desired_size_bytes / MB, qcow_path) rc, output = commands.getstatusoutput(cmd) if rc != 0: # cleanup the image file os.unlink(qcow_path) raise XendError("Failed to create QCOW Image: %s" % output) self._refresh() return image_uuid finally: self.lock.release()
def _create_image_files(self, desired_size_bytes): """Create an image and return its assigned UUID. @param desired_size_bytes: Desired image size in bytes @type desired_size_bytes: int @rtype: string @return: uuid @raises XendError: If an error occurs. """ self.lock.acquire() try: if not self._has_space_available_for(desired_size_bytes): raise XendError("Not enough space (need %d)" % desired_size_bytes) image_uuid = uuid.createString() qcow_path = os.path.join(self.location, XEND_STORAGE_QCOW_FILENAME % image_uuid) if qcow_path and os.path.exists(qcow_path): raise XendError("Image with same UUID alreaady exists:" % image_uuid) cmd = QCOW_CREATE_COMMAND % (desired_size_bytes/MB, qcow_path) rc, output = commands.getstatusoutput(cmd) if rc != 0: # cleanup the image file os.unlink(qcow_path) raise XendError("Failed to create QCOW Image: %s" % output) self._refresh() return image_uuid finally: self.lock.release()
def __init__(self): """Initalises the state of all host specific objects such as * host * host_CPU * host_metrics * PIF * PIF_metrics * network * Storage Repository * PPCI * PSCSI """ self.xc = xen.lowlevel.xc.xc() self.state_store = XendStateStore(xendoptions().get_xend_state_path()) self.monitor = XendMonitor() self.monitor.start() # load host state from XML file saved_host = self.state_store.load_state('host') if saved_host and len(saved_host.keys()) == 1: self.uuid = saved_host.keys()[0] host = saved_host[self.uuid] self.name = host.get('name_label', socket.gethostname()) self.desc = host.get('name_description', '') self.host_metrics_uuid = host.get('metrics_uuid', uuid.createString()) try: self.other_config = eval(host['other_config']) except: self.other_config = {} self.cpus = {} else: self.uuid = uuid.createString() self.name = socket.gethostname() self.desc = '' self.other_config = {} self.cpus = {} self.host_metrics_uuid = uuid.createString() # put some arbitrary params in other_config as this # is directly exposed via XenAPI self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"] self.other_config["platform_params"] = self.xeninfo_dict()["platform_params"] self.other_config["xen_commandline"] = self.xeninfo_dict()["xen_commandline"] # load CPU UUIDs saved_cpus = self.state_store.load_state('cpu') for cpu_uuid, cpu in saved_cpus.items(): self.cpus[cpu_uuid] = cpu cpuinfo = osdep.get_cpuinfo() physinfo = self.physinfo_dict() cpu_count = physinfo['nr_cpus'] cpu_features = physinfo['hw_caps'] virt_caps = physinfo['virt_caps'] # If the number of CPUs don't match, we should just reinitialise # the CPU UUIDs. if cpu_count != len(self.cpus): self.cpus = {} for i in range(cpu_count): u = uuid.createString() self.cpus[u] = {'uuid': u, 'number': i } for u in self.cpus.keys(): number = self.cpus[u]['number'] # We can run off the end of the cpuinfo list if domain0 does not # have #vcpus == #pcpus. In that case we just replicate one that's # in the hash table. if not cpuinfo.has_key(number): number = cpuinfo.keys()[0] if arch.type == "x86": self.cpus[u].update( { 'host' : self.uuid, 'features' : cpu_features, 'virt_caps': virt_caps, 'speed' : int(float(cpuinfo[number]['cpu MHz'])), 'vendor' : cpuinfo[number]['vendor_id'], 'modelname': cpuinfo[number]['model name'], 'stepping' : cpuinfo[number]['stepping'], 'flags' : cpuinfo[number]['flags'], }) elif arch.type == "ia64": self.cpus[u].update( { 'host' : self.uuid, 'features' : cpu_features, 'speed' : int(float(cpuinfo[number]['cpu MHz'])), 'vendor' : cpuinfo[number]['vendor'], 'modelname': cpuinfo[number]['family'], 'stepping' : cpuinfo[number]['model'], 'flags' : cpuinfo[number]['features'], }) else: self.cpus[u].update( { 'host' : self.uuid, 'features' : cpu_features, }) self.srs = {} self._init_networks() self._init_PIFs() self._init_SRs() self._init_PBDs() self._init_PPCIs() self._init_PSCSIs() self._init_cpu_pools()
def _init_PSCSIs(self): # Initialise PSCSIs and PSCSI_HBAs saved_pscsis = self.state_store.load_state('pscsi') saved_pscsi_table = {} if saved_pscsis: for pscsi_uuid, pscsi_record in saved_pscsis.items(): try: saved_pscsi_table[pscsi_record['scsi_id']] = pscsi_uuid except KeyError: pass saved_pscsi_HBAs = self.state_store.load_state('pscsi_HBA') saved_pscsi_HBA_table = {} if saved_pscsi_HBAs: for pscsi_HBA_uuid, pscsi_HBA_record in saved_pscsi_HBAs.items(): try: physical_host = int(pscsi_HBA_record['physical_host']) saved_pscsi_HBA_table[physical_host] = pscsi_HBA_uuid except (KeyError, ValueError): pass pscsi_table = {} pscsi_HBA_table = {} pscsi_records = [] for pscsi_mask in xendoptions().get_pscsi_device_mask(): pscsi_records += vscsi_util.get_all_scsi_devices(pscsi_mask) log.debug("pscsi record count: %s" % len(pscsi_records)) for pscsi_record in pscsi_records: scsi_id = pscsi_record['scsi_id'] if scsi_id: saved_HBA_uuid = None pscsi_uuid = saved_pscsi_table.get(scsi_id, None) if pscsi_uuid is None: pscsi_uuid = uuid.createString() saved_pscsi_table[scsi_id] = pscsi_uuid else: try: saved_HBA_uuid = saved_pscsis[pscsi_uuid].get('HBA', None) except KeyError: log.warn("Multi-path SCSI devices are not supported for XenAPI") return physical_host = int(pscsi_record['physical_HCTL'].split(':')[0]) if pscsi_HBA_table.has_key(physical_host): pscsi_HBA_uuid = pscsi_HBA_table[physical_host] elif saved_pscsi_HBA_table.has_key(physical_host): pscsi_HBA_uuid = saved_pscsi_HBA_table[physical_host] pscsi_HBA_table[physical_host] = pscsi_HBA_uuid else: pscsi_HBA_uuid = uuid.createString() pscsi_HBA_table[physical_host] = pscsi_HBA_uuid if saved_HBA_uuid is not None and \ saved_HBA_uuid != pscsi_HBA_uuid: log.debug('The PSCSI(%s) host number was changed', scsi_id) pscsi_record['HBA'] = pscsi_HBA_uuid pscsi_table[pscsi_uuid] = pscsi_record for pscsi_uuid, pscsi_record in pscsi_table.items(): XendPSCSI(pscsi_uuid, pscsi_record) for physical_host, pscsi_HBA_uuid in pscsi_HBA_table.items(): XendPSCSI_HBA(pscsi_HBA_uuid, {'physical_host': physical_host})
def __init__(self): """Initalises the state of all host specific objects such as * host * host_CPU * host_metrics * PIF * PIF_metrics * network * Storage Repository * PPCI """ self.xc = xen.lowlevel.xc.xc() self.state_store = XendStateStore(xendoptions().get_xend_state_path()) self.monitor = XendMonitor() self.monitor.start() # load host state from XML file saved_host = self.state_store.load_state('host') if saved_host and len(saved_host.keys()) == 1: self.uuid = saved_host.keys()[0] host = saved_host[self.uuid] self.name = host.get('name_label', socket.gethostname()) self.desc = host.get('name_description', '') self.host_metrics_uuid = host.get('metrics_uuid', uuid.createString()) try: self.other_config = eval(host['other_config']) except: self.other_config = {} self.cpus = {} else: self.uuid = uuid.createString() self.name = socket.gethostname() self.desc = '' self.other_config = {} self.cpus = {} self.host_metrics_uuid = uuid.createString() # put some arbitrary params in other_config as this # is directly exposed via XenAPI self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"] self.other_config["platform_params"] = self.xeninfo_dict( )["platform_params"] # load CPU UUIDs saved_cpus = self.state_store.load_state('cpu') for cpu_uuid, cpu in saved_cpus.items(): self.cpus[cpu_uuid] = cpu cpuinfo = osdep.get_cpuinfo() physinfo = self.physinfo_dict() cpu_count = physinfo['nr_cpus'] cpu_features = physinfo['hw_caps'] virt_caps = physinfo['virt_caps'] # If the number of CPUs don't match, we should just reinitialise # the CPU UUIDs. if cpu_count != len(self.cpus): self.cpus = {} for i in range(cpu_count): u = uuid.createString() self.cpus[u] = {'uuid': u, 'number': i} for u in self.cpus.keys(): number = self.cpus[u]['number'] # We can run off the end of the cpuinfo list if domain0 does not # have #vcpus == #pcpus. In that case we just replicate one that's # in the hash table. if not cpuinfo.has_key(number): number = cpuinfo.keys()[0] if arch.type == "x86": self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, 'virt_caps': virt_caps, 'speed': int(float(cpuinfo[number]['cpu MHz'])), 'vendor': cpuinfo[number]['vendor_id'], 'modelname': cpuinfo[number]['model name'], 'stepping': cpuinfo[number]['stepping'], 'flags': cpuinfo[number]['flags'], }) elif arch.type == "ia64": self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, 'speed': int(float(cpuinfo[number]['cpu MHz'])), 'vendor': cpuinfo[number]['vendor'], 'modelname': cpuinfo[number]['family'], 'stepping': cpuinfo[number]['model'], 'flags': cpuinfo[number]['features'], }) else: self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, }) self.srs = {} # Initialise networks # First configure ones off disk saved_networks = self.state_store.load_state('network') if saved_networks: for net_uuid, network in saved_networks.items(): try: XendNetwork.recreate(network, net_uuid) except CreateUnspecifiedAttributeError: log.warn("Error recreating network %s", net_uuid) # Next discover any existing bridges and check # they are not already configured bridges = Brctl.get_state().keys() configured_bridges = [ XendAPIStore.get(network_uuid, "network").get_name_label() for network_uuid in XendNetwork.get_all() ] unconfigured_bridges = [ bridge for bridge in bridges if bridge not in configured_bridges ] for unconfigured_bridge in unconfigured_bridges: XendNetwork.create_phy(unconfigured_bridge) # Initialise PIFs # First configure ones off disk saved_pifs = self.state_store.load_state('pif') if saved_pifs: for pif_uuid, pif in saved_pifs.items(): try: XendPIF.recreate(pif, pif_uuid) except CreateUnspecifiedAttributeError: log.warn("Error recreating PIF %s", pif_uuid) # Next discover any existing PIFs and check # they are not already configured configured_pifs = [ XendAPIStore.get(pif_uuid, "PIF").get_interface_name() for pif_uuid in XendPIF.get_all() ] unconfigured_pifs = [(name, mtu, mac) for name, mtu, mac in linux_get_phy_ifaces() if name not in configured_pifs] # Get a mapping from interface to bridge if_to_br = dict([(i, b) for (b, ifs) in Brctl.get_state().items() for i in ifs]) for name, mtu, mac in unconfigured_pifs: # Check PIF is on bridge # if not, ignore bridge_name = if_to_br.get(name, None) if bridge_name is not None: # Translate bridge name to network uuid for network_uuid in XendNetwork.get_all(): network = XendAPIStore.get(network_uuid, 'network') if network.get_name_label() == bridge_name: XendPIF.create_phy(network_uuid, name, mac, mtu) break else: log.debug( "Cannot find network for bridge %s " "when configuring PIF %s", (bridge_name, name)) # initialise storage saved_srs = self.state_store.load_state('sr') if saved_srs: for sr_uuid, sr_cfg in saved_srs.items(): if sr_cfg['type'] == 'qcow_file': self.srs[sr_uuid] = XendQCoWStorageRepo(sr_uuid) elif sr_cfg['type'] == 'local': self.srs[sr_uuid] = XendLocalStorageRepo(sr_uuid) # Create missing SRs if they don't exist if not self.get_sr_by_type('local'): image_sr_uuid = uuid.createString() self.srs[image_sr_uuid] = XendLocalStorageRepo(image_sr_uuid) if not self.get_sr_by_type('qcow_file'): qcow_sr_uuid = uuid.createString() self.srs[qcow_sr_uuid] = XendQCoWStorageRepo(qcow_sr_uuid) saved_pbds = self.state_store.load_state('pbd') if saved_pbds: for pbd_uuid, pbd_cfg in saved_pbds.items(): try: XendPBD.recreate(pbd_uuid, pbd_cfg) except CreateUnspecifiedAttributeError: log.warn("Error recreating PBD %s", pbd_uuid) # Initialise PPCIs saved_ppcis = self.state_store.load_state('ppci') saved_ppci_table = {} if saved_ppcis: for ppci_uuid, ppci_record in saved_ppcis.items(): try: saved_ppci_table[ppci_record['name']] = ppci_uuid except KeyError: pass for pci_dev in PciUtil.get_all_pci_devices(): ppci_record = { 'domain': pci_dev.domain, 'bus': pci_dev.bus, 'slot': pci_dev.slot, 'func': pci_dev.func, 'vendor_id': pci_dev.vendor, 'vendor_name': pci_dev.vendorname, 'device_id': pci_dev.device, 'device_name': pci_dev.devicename, 'revision_id': pci_dev.revision, 'class_code': pci_dev.classcode, 'class_name': pci_dev.classname, 'subsystem_vendor_id': pci_dev.subvendor, 'subsystem_vendor_name': pci_dev.subvendorname, 'subsystem_id': pci_dev.subdevice, 'subsystem_name': pci_dev.subdevicename, 'driver': pci_dev.driver } # If saved uuid exists, use it. Otherwise create one. ppci_uuid = saved_ppci_table.get(pci_dev.name, uuid.createString()) XendPPCI(ppci_uuid, ppci_record)
def __init__(self): """Initalises the state of all host specific objects such as * host * host_CPU * host_metrics * PIF * PIF_metrics * network * Storage Repository * PPCI * PSCSI """ self.xc = xen.lowlevel.xc.xc() self.state_store = XendStateStore(xendoptions().get_xend_state_path()) self.monitor = XendMonitor() self.monitor.start() # load host state from XML file saved_host = self.state_store.load_state('host') if saved_host and len(saved_host.keys()) == 1: self.uuid = saved_host.keys()[0] host = saved_host[self.uuid] self.name = host.get('name_label', socket.gethostname()) self.desc = host.get('name_description', '') self.host_metrics_uuid = host.get('metrics_uuid', uuid.createString()) try: self.other_config = eval(host['other_config']) except: self.other_config = {} self.cpus = {} else: self.uuid = uuid.createString() self.name = socket.gethostname() self.desc = '' self.other_config = {} self.cpus = {} self.host_metrics_uuid = uuid.createString() # put some arbitrary params in other_config as this # is directly exposed via XenAPI self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"] self.other_config["platform_params"] = self.xeninfo_dict( )["platform_params"] self.other_config["xen_commandline"] = self.xeninfo_dict( )["xen_commandline"] # load CPU UUIDs saved_cpus = self.state_store.load_state('cpu') for cpu_uuid, cpu in saved_cpus.items(): self.cpus[cpu_uuid] = cpu cpuinfo = osdep.get_cpuinfo() physinfo = self.physinfo_dict() cpu_count = physinfo['nr_cpus'] cpu_features = physinfo['hw_caps'] virt_caps = physinfo['virt_caps'] # If the number of CPUs don't match, we should just reinitialise # the CPU UUIDs. if cpu_count != len(self.cpus): self.cpus = {} for i in range(cpu_count): u = uuid.createString() self.cpus[u] = {'uuid': u, 'number': i} for u in self.cpus.keys(): number = self.cpus[u]['number'] # We can run off the end of the cpuinfo list if domain0 does not # have #vcpus == #pcpus. In that case we just replicate one that's # in the hash table. if not cpuinfo.has_key(number): number = cpuinfo.keys()[0] if arch.type == "x86": self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, 'virt_caps': virt_caps, 'speed': int(float(cpuinfo[number]['cpu MHz'])), 'vendor': cpuinfo[number]['vendor_id'], 'modelname': cpuinfo[number]['model name'], 'stepping': cpuinfo[number]['stepping'], 'flags': cpuinfo[number]['flags'], }) elif arch.type == "ia64": self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, 'speed': int(float(cpuinfo[number]['cpu MHz'])), 'vendor': cpuinfo[number]['vendor'], 'modelname': cpuinfo[number]['family'], 'stepping': cpuinfo[number]['model'], 'flags': cpuinfo[number]['features'], }) else: self.cpus[u].update({ 'host': self.uuid, 'features': cpu_features, }) self.srs = {} self._init_networks() self._init_PIFs() self._init_SRs() self._init_PBDs() self._init_PPCIs() self._init_PSCSIs()
def _init_PSCSIs(self): # Initialise PSCSIs and PSCSI_HBAs saved_pscsis = self.state_store.load_state('pscsi') saved_pscsi_table = {} if saved_pscsis: for pscsi_uuid, pscsi_record in saved_pscsis.items(): try: saved_pscsi_table[pscsi_record['scsi_id']] = pscsi_uuid except KeyError: pass saved_pscsi_HBAs = self.state_store.load_state('pscsi_HBA') saved_pscsi_HBA_table = {} if saved_pscsi_HBAs: for pscsi_HBA_uuid, pscsi_HBA_record in saved_pscsi_HBAs.items(): try: physical_host = int(pscsi_HBA_record['physical_host']) saved_pscsi_HBA_table[physical_host] = pscsi_HBA_uuid except (KeyError, ValueError): pass pscsi_table = {} pscsi_HBA_table = {} pscsi_records = [] for pscsi_mask in xendoptions().get_pscsi_device_mask(): pscsi_records += vscsi_util.get_all_scsi_devices(pscsi_mask) log.debug("pscsi record count: %s" % len(pscsi_records)) for pscsi_record in pscsi_records: scsi_id = pscsi_record['scsi_id'] if scsi_id: saved_HBA_uuid = None pscsi_uuid = saved_pscsi_table.get(scsi_id, None) if pscsi_uuid is None: pscsi_uuid = uuid.createString() saved_pscsi_table[scsi_id] = pscsi_uuid else: try: saved_HBA_uuid = saved_pscsis[pscsi_uuid].get( 'HBA', None) except KeyError: log.warn( "Multi-path SCSI devices are not supported for XenAPI" ) return physical_host = int( pscsi_record['physical_HCTL'].split(':')[0]) if pscsi_HBA_table.has_key(physical_host): pscsi_HBA_uuid = pscsi_HBA_table[physical_host] elif saved_pscsi_HBA_table.has_key(physical_host): pscsi_HBA_uuid = saved_pscsi_HBA_table[physical_host] pscsi_HBA_table[physical_host] = pscsi_HBA_uuid else: pscsi_HBA_uuid = uuid.createString() pscsi_HBA_table[physical_host] = pscsi_HBA_uuid if saved_HBA_uuid is not None and \ saved_HBA_uuid != pscsi_HBA_uuid: log.debug('The PSCSI(%s) host number was changed', scsi_id) pscsi_record['HBA'] = pscsi_HBA_uuid pscsi_table[pscsi_uuid] = pscsi_record for pscsi_uuid, pscsi_record in pscsi_table.items(): XendPSCSI(pscsi_uuid, pscsi_record) for physical_host, pscsi_HBA_uuid in pscsi_HBA_table.items(): XendPSCSI_HBA(pscsi_HBA_uuid, {'physical_host': physical_host})