Пример #1
0
 def _init_lock_devices(self):
     if xendoptions().get_xend_domain_lock():
         if xendoptions().get_xend_domain_lock_utility().endswith("domain-lock-sfex"):
             lock_device = xendoptions().get_xend_domain_lock_device()
             if not lock_device:
                 raise XendError("The block device for sfex is not properly configured")
             status = os.system("lvchange -ay %s" % lock_device) >> 8
             if status != 0:
                 raise XendError("The block device for sfex could not be initialized")
Пример #2
0
 def _init_lock_devices(self):
     if xendoptions().get_xend_domain_lock():
         if xendoptions().get_xend_domain_lock_utility().endswith(
                 "domain-lock-sfex"):
             lock_device = xendoptions().get_xend_domain_lock_device()
             if not lock_device:
                 raise XendError(
                     "The block device for sfex is not properly configured")
             status = os.system("lvchange -ay %s" % lock_device) >> 8
             if status != 0:
                 raise XendError(
                     "The block device for sfex could not be initialized")
Пример #3
0
 def __init__(self, sr_uuid, sr_type='local_gpfs',
              name_label='local_gpfs',
              name_description='Traditional Local Storage Repo',
              other_config={'location':'/local_gpfs', 'auto-scan':'False'},
              content_type='vhd',
              shared=False,
              sm_config={}):
 
     XendGpfsStorageRepo.__init__(self, sr_uuid, sr_type,
                                    name_label, name_description)
     #log.debug(self.lock)
     #log.debug(self.uuid)
     self.type = sr_type
     self.name_label = name_label
     self.name_description = name_description
     self.other_config = other_config
     self.content_type = content_type
     self.shared = shared
     self.sm_config = sm_config
     
     self.location = other_config.get('location')
     encode_passwd = other_config.get('password')
     self.passwd = encoding.ansi_decode(encode_passwd)
     auto = other_config.get('auto-scan', False)
     self.gpfs_name = self._get_gpfs_location(self.location)
     
     self.state = XendStateStore(xendoptions().get_xend_state_path()
                                 + '/local_sr/%s' % self.uuid)
     stored_images = self.state.load_state('vdi')
     images_path = {}
     if stored_images:
         for image_uuid, image in stored_images.items():
             images_path[image['location'].replace(VDI_TYPE, '')] = image_uuid
             self.images[image_uuid] = XendGpfsVDI(image)
Пример #4
0
    def __init__(self, sr_uuid, sr_type,
                 name_label, name_description, physical_size, other_config, content_type, shared, sm_config):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """
        XendStorageRepository.__init__(self, sr_uuid, sr_type,
                                       name_label, name_description)
        #log.debug(self.lock)
        #log.debug(self.uuid)
        self.type = sr_type
        self.name_label = name_label
        self.name_description = name_description
        self.other_config = other_config
        self.content_type = content_type
        self.shared = shared
        self.sm_config = sm_config
#        location = other_config.get('location')
        encode_passwd = other_config.get('password')
        self.passwd = encoding.ansi_decode(encode_passwd)
        auto = other_config.get('auto-scan', True)
#        local = location.split(':')[1]
#        if cmp(int(storage_max())*KB, physical_size) > 0:
#            self.physical_size = physical_size
#        else:
        location = self.other_config.get('location')
        self.local_sr_dir = location
        self.location = location
        self.mount_point = self._get_mount_point(self.location)
#        s_max = storage_max(self.local_sr_dir)
#        if s_max:
#            self.physical_size = int(s_max)*KB
#        else:
#            self.physical_size = 0
#        s_util = storage_util(self.local_sr_dir)
#        if s_util:
#            self.physical_utilisation = int(s_util)*KB
#        else:
#            self.physical_utilisation = 0
#        d_util = dir_util(self.local_sr_dir)
#        if d_util:
#            self.virtual_allocation = int(d_util)*KB
#        else:
#            self.virtual_allocation = 0
        self.state = XendStateStore(xendoptions().get_xend_state_path()
                                    + '/gpfs_iso_sr/%s' % self.uuid)
        stored_images = self.state.load_state('vdi')
        images_path = {}
        if stored_images:
            for image_uuid, image in stored_images.items():
                images_path[image['location'].replace(VDI_TYPE, '')] = image_uuid
                self.images[image_uuid] = XendLocalVDI(image)
Пример #5
0
    def __init__(self, sr_uuid, sr_type='local',
                 name_label='local',
                 name_description='Traditional Local Storage Repo',
                 other_config={'location':'/home/local_sr', 'auto-scan':'False'},
                 content_type='vhd',
                 shared=False,
                 sm_config={}):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type,
                                       name_label, name_description)
        
        self.type = sr_type
        self.name_label = name_label
        self.name_description = name_description
        self.other_config = other_config
        self.content_type = content_type
        self.shared = shared
        self.sm_config = sm_config
        self.local_sr_dir = self.other_config.get('location')
        self.location = self.local_sr_dir
#        self.local_sr_dir = os.path.join(self.location, self.uuid)
        if not os.path.exists(self.local_sr_dir): 
            os.makedirs(self.local_sr_dir)
#        s_max = storage_max(self.local_sr_dir)
#        if s_max:
#            self.physical_size = int(s_max)*KB
#        else:
#            self.physical_size = 0
#        s_util = storage_util(self.local_sr_dir)
#        if s_util:
#            self.physical_utilisation = int(s_util)*KB
#        else:
#            self.physical_utilisation = 0
#        d_util = dir_util(self.local_sr_dir)
#        if d_util:
#            self.virtual_allocation = int(d_util)*KB
#        else:
#            self.virtual_allocation = 0       
        
        self.state = XendStateStore(xendoptions().get_xend_state_path()
                                    + '/local_sr/%s' % self.uuid)

        stored_images = self.state.load_state('vdi')
        if stored_images:
            for image_uuid, image in stored_images.items():
                self.images[image_uuid] = XendLocalVDI(image)
Пример #6
0
    def __init__(self, sr_uuid, sr_type,
                 name_label, name_description, physical_size, other_config, content_type, shared, sm_config):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type,
                                       name_label, name_description)
        #log.debug(self.lock)
        #log.debug(self.uuid)
        self.record_changed = True
        
        self.type = sr_type
        self.name_label = name_label
        self.name_description = name_description
        self.other_config = other_config
        self.content_type = content_type
        self.shared = shared
        self.sm_config = sm_config
        location = other_config.get('location')
        auto = other_config.get('auto-scan', True)
        self.local_sr_dir = DEFAULT_HA_PATH
#        encode_passwd = other_config.get('password')
#        self.passwd = encoding.ansi_decode(encode_passwd)
#        if cmp(int(storage_free())*KB, physical_size) > 0:
#            self.physical_size = physical_size
#        else:
#        s_max = storage_max()
#        if s_max:
#            self.physical_size = int(s_max)*KB
#        else:
#            self.physical_size = 0
#        s_util = storage_util()
#        if s_util:
#            self.physical_utilisation = int(s_util)*KB
#        else:
#            self.physical_utilisation = 0
#        self.virtual_allocation = self.physical_size
        self.state = XendStateStore(xendoptions().get_xend_state_path()
                                    + '/nfs_ha_sr/%s' % self.uuid)
        stored_images = self.state.load_state('vdi')
        images_path = {}
        if stored_images:
            for image_uuid, image in stored_images.items():
                images_path[image['location']] = image_uuid
                self.images[image_uuid] = XendLocalVDI(image)
    def __init__(self, sr_uuid, sr_type = 'local',
                 name_label = 'Local',
                 name_description = 'Traditional Local Storage Repo'):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type,
                                       name_label, name_description)
        
        self.state = XendStateStore(xendoptions().get_xend_state_path()
                                    + '/local_sr')

        stored_images = self.state.load_state('vdi')
        if stored_images:
            for image_uuid, image in stored_images.items():
                self.images[image_uuid] = XendLocalVDI(image)
    def __init__(self, sr_uuid,
                 sr_type = "qcow_file",
                 name_label = "QCoW",
                 name_description = "Xend QCoW Storage Repository",
                 storage_max = XEND_STORAGE_NO_MAXIMUM):
        """
        @keyword storage_max: Maximum disk space to use in bytes.
        @type    storage_max: int

        @ivar    storage_free: storage space free for this repository
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type, name_label,
                                       name_description, storage_max)
        self.storage_free = 0
        self.location = xendoptions().get_xend_storage_path()
        self._refresh()
    def __init__(self,
                 sr_uuid,
                 sr_type='local',
                 name_label='Local',
                 name_description='Traditional Local Storage Repo'):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type, name_label,
                                       name_description)

        self.state = XendStateStore(xendoptions().get_xend_state_path() +
                                    '/local_sr')

        stored_images = self.state.load_state('vdi')
        if stored_images:
            for image_uuid, image in stored_images.items():
                self.images[image_uuid] = XendLocalVDI(image)
    def __init__(self,
                 sr_uuid,
                 sr_type="qcow_file",
                 name_label="QCoW",
                 name_description="Xend QCoW Storage Repository",
                 storage_max=XEND_STORAGE_NO_MAXIMUM):
        """
        @keyword storage_max: Maximum disk space to use in bytes.
        @type    storage_max: int

        @ivar    storage_free: storage space free for this repository
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type, name_label,
                                       name_description, storage_max)
        self.storage_free = 0
        self.location = xendoptions().get_xend_storage_path()
        self._refresh()
Пример #11
0
    def __init__(self, sr_uuid, sr_type,
                 name_label, name_description, physical_size, other_config, content_type, shared, sm_config):
        """
        @ivar    images: mapping of all the images.
        @type    images: dictionary by image uuid.
        @ivar    lock:   lock to provide thread safety.
        """

        XendStorageRepository.__init__(self, sr_uuid, sr_type,
                                       name_label, name_description)
        #log.debug(self.lock)
        #log.debug(self.uuid)
        self.type = sr_type
        self.name_label = name_label
        self.name_description = name_description
        self.other_config = other_config
        self.content_type = content_type
        self.shared = shared
        self.sm_config = sm_config
        location = other_config.get('location')
        auto = other_config.get('auto-scan', False)
        self.local_sr_dir = self.other_config.get('location')
        self.location = location
#        if cmp(int(storage_free())*KB, physical_size) > 0:
#            self.physical_size = physical_size
#        else:
#        self.physical_size = int(storage_max())*KB
#        self.physical_utilisation = int(storage_util())*KB
#        self.virtual_allocation = self.physical_size
        self.state = XendStateStore(xendoptions().get_xend_state_path()
                                    + '/iso_sr/%s' % self.uuid)
        stored_images = self.state.load_state('vdi')
        images_path = {}
        if stored_images:
            for image_uuid, image in stored_images.items():
                images_path[image['location'].replace(VDI_TYPE, '')] = image_uuid
                self.images[image_uuid] = XendLocalVDI(image)
Пример #12
0
    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})
Пример #13
0
    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()
Пример #14
0
    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()
Пример #15
0
    def physinfo(self, show_numa):
        info = self.xc.physinfo()
        tinfo = self.xc.topologyinfo()
        ninfo = self.xc.numainfo()

        info['cpu_mhz'] = info['cpu_khz'] / 1000
        
        configured_floor = xendoptions().get_dom0_min_mem() * 1024
        from xen.xend import balloon
        try:
            kernel_floor = balloon.get_dom0_min_target()
        except:
            kernel_floor = 0
        dom0_min_mem = max(configured_floor, kernel_floor)
        dom0_mem = balloon.get_dom0_current_alloc()
        extra_mem = 0
        if dom0_min_mem > 0 and dom0_mem > dom0_min_mem:
            extra_mem = dom0_mem - dom0_min_mem
        info['free_memory']     = info['free_memory'] + info['scrub_memory']
        info['max_free_memory'] = info['free_memory'] + extra_mem
        info['free_cpus'] = len(XendCPUPool.unbound_cpus())

        # Convert KiB to MiB, rounding down to be conservative
        info['total_memory']    = info['total_memory'] / 1024
        info['free_memory']     = info['free_memory'] / 1024
        info['max_free_memory'] = info['max_free_memory'] / 1024

        # FIXME:  These are hard-coded to be the inverse of the getXenMemory
        #         functions in image.py.  Find a cleaner way.
        info['max_para_memory'] = info['max_free_memory'] - 4
        if info['max_para_memory'] < 0:
            info['max_para_memory'] = 0
        info['max_hvm_memory'] = int((info['max_free_memory']-12) * (1-2.4/1024))
        if info['max_hvm_memory'] < 0:
            info['max_hvm_memory'] = 0

        ITEM_ORDER = ['nr_cpus',
                      'nr_nodes',
                      'cores_per_socket',
                      'threads_per_core',
                      'cpu_mhz',
                      'hw_caps',
                      'virt_caps',
                      'total_memory',
                      'free_memory',
                      'free_cpus',
                      'max_free_memory',
                      'max_para_memory',
                      'max_hvm_memory',
                      ]

        if show_numa != 0:
            info['cpu_topology']  = \
                 self.format_cpu_to_core_socket_node(tinfo)

            info['numa_info']  = \
                 self.format_numa_info(ninfo)

            ITEM_ORDER += [ 'cpu_topology', 'numa_info' ]

        return [[k, info[k]] for k in ITEM_ORDER]
Пример #16
0
    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})
Пример #17
0
    def physinfo(self, show_numa):
        info = self.xc.physinfo()
        tinfo = self.xc.topologyinfo()
        ninfo = self.xc.numainfo()

        info['cpu_mhz'] = info['cpu_khz'] / 1000

        configured_floor = xendoptions().get_dom0_min_mem() * 1024
        from xen.xend import balloon
        try:
            kernel_floor = balloon.get_dom0_min_target()
        except:
            kernel_floor = 0
        dom0_min_mem = max(configured_floor, kernel_floor)
        dom0_mem = balloon.get_dom0_current_alloc()
        extra_mem = 0
        if dom0_min_mem > 0 and dom0_mem > dom0_min_mem:
            extra_mem = dom0_mem - dom0_min_mem
        info['free_memory'] = info['free_memory'] + info['scrub_memory']
        info['max_free_memory'] = info['free_memory'] + extra_mem
        info['free_cpus'] = len(XendCPUPool.unbound_cpus())

        # Convert KiB to MiB, rounding down to be conservative
        info['total_memory'] = info['total_memory'] / 1024
        info['free_memory'] = info['free_memory'] / 1024
        info['max_free_memory'] = info['max_free_memory'] / 1024

        # FIXME:  These are hard-coded to be the inverse of the getXenMemory
        #         functions in image.py.  Find a cleaner way.
        info['max_para_memory'] = info['max_free_memory'] - 4
        if info['max_para_memory'] < 0:
            info['max_para_memory'] = 0
        info['max_hvm_memory'] = int(
            (info['max_free_memory'] - 12) * (1 - 2.4 / 1024))
        if info['max_hvm_memory'] < 0:
            info['max_hvm_memory'] = 0

        ITEM_ORDER = [
            'nr_cpus',
            'nr_nodes',
            'cores_per_socket',
            'threads_per_core',
            'cpu_mhz',
            'hw_caps',
            'virt_caps',
            'total_memory',
            'free_memory',
            'free_cpus',
            'max_free_memory',
            'max_para_memory',
            'max_hvm_memory',
        ]

        if show_numa != 0:
            info['cpu_topology']  = \
                 self.format_cpu_to_core_socket_node(tinfo)

            info['numa_info']  = \
                 self.format_numa_info(ninfo)

            ITEM_ORDER += ['cpu_topology', 'numa_info']

        return [[k, info[k]] for k in ITEM_ORDER]
Пример #18
0
    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)