Пример #1
0
    def remove_PPCI(self, pci_name):
        # Update lspci info
        PciUtil.create_lspci_info()

        # Remove the PPCI
        (domain, bus, slot, func) = PciUtil.parse_pci_name(pci_name)
        ppci_ref = XendPPCI.get_by_sbdf(domain, bus, slot, func)
        XendAPIStore.get(ppci_ref, "PPCI").destroy()

        self.save_PPCIs()
Пример #2
0
    def remove_PSCSI(self, rem_HCTL):
        saved_pscsis = self.state_store.load_state('pscsi')
        if not saved_pscsis:
            return

        # Remove the PSCSI
        for pscsi_record in saved_pscsis.values():
            if rem_HCTL == pscsi_record['physical_HCTL']:
                pscsi_ref = XendPSCSI.get_by_HCTL(rem_HCTL)
                XendAPIStore.get(pscsi_ref, "PSCSI").destroy()
                self.save_PSCSIs()
                return
Пример #3
0
 def save_PSCSI_HBAs(self):
     pscsi_HBA_records = dict([
         (pscsi_HBA_uuid, XendAPIStore.get(pscsi_HBA_uuid,
                                           "PSCSI_HBA").get_record())
         for pscsi_HBA_uuid in XendPSCSI_HBA.get_all()
     ])
     self.state_store.save_state('pscsi_HBA', pscsi_HBA_records)
Пример #4
0
    def _init_networks(self):
        # 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

        # 'tmpbridge' is a temporary bridge created by network-bridge script.
        # Wait a couple of seconds for it to be renamed.
        for i in xrange(20):
            bridges = Brctl.get_state().keys()
            if 'tmpbridge' in bridges:
                time.sleep(0.1)
            else:
                break

        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:
            if unconfigured_bridge != 'tmpbridge':
                XendNetwork.create_phy(unconfigured_bridge)
Пример #5
0
    def _init_networks(self):
        # 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

        # 'tmpbridge' is a temporary bridge created by network-bridge script.
        # Wait a couple of seconds for it to be renamed.
        for i in xrange(20):
            bridges = Brctl.get_state().keys()
            if 'tmpbridge' in bridges:
                time.sleep(0.1)
            else:
                break
            
        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:
            if unconfigured_bridge != 'tmpbridge':
                XendNetwork.create_phy(unconfigured_bridge)
Пример #6
0
    def recreate_active_pools(cls):
        """ Read active pool config from hypervisor and create pool instances.
            - Query pool ids and assigned CPUs from hypervisor.
            - Query additional information for any pool from xenstore.
              If an entry for a pool id is missing in xenstore, it will be
              recreated with a new uuid and generic name (this is an error case)
            - Create an XendCPUPool instance for any pool id
            Function have to be called after recreation of managed pools.
        """
        log.debug('recreate_active_pools')

        for pool_rec in xc.cpupool_getinfo():
            pool = pool_rec['cpupool']

            # read pool data from xenstore
            path = XS_POOLROOT + "%s/" % pool
            uuid = xstransact.Read(path, 'uuid')
            if not uuid:
                # xenstore entry missing / invaild; create entry with new uuid
                uuid = genuuid.createString()
                name = "Pool-%s" % pool
                try:
                    inst = XendCPUPool({'name_label': name}, uuid, False)
                    inst.update_XS(pool)
                except PoolError, ex:
                    # log error and skip domain
                    log.error('cannot recreate pool %s; skipping (reason: %s)' \
                        % (name, ex))
            else:
                (name, descr) = xstransact.Read(path, 'name', 'description')
                other_config = {}
                for key in xstransact.List(path + 'other_config'):
                    other_config[key] = xstransact.Read(path +
                                                        'other_config/%s' %
                                                        key)

                # check existance of pool instance
                inst = XendAPIStore.get(uuid, cls.getClass())
                if inst:
                    # update attributes of existing instance
                    inst.name_label = name
                    inst.name_description = descr
                    inst.other_config = other_config
                else:
                    # recreate instance
                    try:
                        inst = XendCPUPool(
                            {
                                'name_label': name,
                                'name_description': descr,
                                'other_config': other_config,
                                'proposed_CPUs': pool_rec['cpulist'],
                                'ncpu': len(pool_rec['cpulist']),
                            }, uuid, False)
                    except PoolError, ex:
                        # log error and skip domain
                        log.error(
                            'cannot recreate pool %s; skipping (reason: %s)' \
                            % (name, ex))
Пример #7
0
 def _get_ovs_name(self):
     network_refs = XendNetwork.get_all()
     network_names = []
     for ref in network_refs:
         network = XendAPIStore.get(ref, "network")
         namelabel = network.get_name_label()
         network_names.append(namelabel)
     return network_names
Пример #8
0
 def save_cpu_pools(self):
     cpu_pool_records = dict([
         (cpu_pool_uuid,
          XendAPIStore.get(cpu_pool_uuid,
                           XendCPUPool.getClass()).get_record())
         for cpu_pool_uuid in XendCPUPool.get_all_managed()
     ])
     self.state_store.save_state(XendCPUPool.getClass(), cpu_pool_records)
Пример #9
0
 def get_by_uuid(cls, uuid):
     # Sanity check the uuid is one of us
     me = XendAPIStore.get(uuid, cls.getClass())
     if me is not None and me.getClass() == cls.getClass():
         # In OSS, ref == uuid
         return uuid
     else:
         raise "Big Error.. TODO!"
Пример #10
0
    def unplug(self):
        """Unplug the PIF from the network"""
        network = XendAPIStore.get(self.network, "network")
        bridge_name = network.get_name_label()

        from xen.util import Brctl

        Brctl.vif_bridge_rem({"bridge": bridge_name, "vif": self.get_interface_name()})
Пример #11
0
 def get_by_uuid(cls, uuid):
     # Sanity check the uuid is one of us
     me = XendAPIStore.get(uuid, cls.getClass())
     if me is not None and me.getClass() == cls.getClass():
         # In OSS, ref == uuid
         return uuid
     else:
         raise ValueError("Big Error.. TODO!")
Пример #12
0
    def recreate_active_pools(cls):
        """ Read active pool config from hypervisor and create pool instances.
            - Query pool ids and assigned CPUs from hypervisor.
            - Query additional information for any pool from xenstore.
              If an entry for a pool id is missing in xenstore, it will be
              recreated with a new uuid and generic name (this is an error case)
            - Create an XendCPUPool instance for any pool id
            Function have to be called after recreation of managed pools.
        """
        log.debug('recreate_active_pools')

        for pool_rec in xc.cpupool_getinfo():
            pool = pool_rec['cpupool']

            # read pool data from xenstore
            path = XS_POOLROOT + "%s/" % pool
            uuid = xstransact.Read(path, 'uuid')
            if not uuid:
                # xenstore entry missing / invaild; create entry with new uuid
                uuid = genuuid.createString()
                name = "Pool-%s" % pool
                try:
                    inst = XendCPUPool( { 'name_label' : name }, uuid, False )
                    inst.update_XS(pool)
                except PoolError, ex:
                    # log error and skip domain
                    log.error('cannot recreate pool %s; skipping (reason: %s)' \
                        % (name, ex))
            else:
                (name, descr) = xstransact.Read(path, 'name', 'description')
                other_config = {}
                for key in xstransact.List(path + 'other_config'):
                    other_config[key] = xstransact.Read(
                        path + 'other_config/%s' % key)

                # check existance of pool instance
                inst = XendAPIStore.get(uuid, cls.getClass())
                if inst:
                    # update attributes of existing instance
                    inst.name_label = name
                    inst.name_description = descr
                    inst.other_config = other_config
                else:
                    # recreate instance
                    try:
                        inst = XendCPUPool(
                            { 'name_label' : name,
                              'name_description' : descr,
                              'other_config' : other_config,
                              'proposed_CPUs' : pool_rec['cpulist'],
                              'ncpu' : len(pool_rec['cpulist']),
                            },
                            uuid, False )
                    except PoolError, ex:
                        # log error and skip domain
                        log.error(
                            'cannot recreate pool %s; skipping (reason: %s)' \
                            % (name, ex))
Пример #13
0
    def move_domain(cls, pool_ref, domid):
        cls.pool_lock.acquire()
        try:
            pool = XendAPIStore.get(pool_ref, cls.getClass())
            pool_id = pool.query_pool_id()

            xc.cpupool_movedomain(pool_id, domid)
        finally:
            cls.pool_lock.release()
Пример #14
0
    def move_domain(cls, pool_ref, domid):
        cls.pool_lock.acquire()
        try:
            pool = XendAPIStore.get(pool_ref, cls.getClass())
            pool_id = pool.query_pool_id()

            xc.cpupool_movedomain(pool_id, domid)
        finally:
            cls.pool_lock.release()
Пример #15
0
 def __init__(self):
     self.host_instance = XendNode.instance()
     self.host_cpus = self.host_instance.get_host_cpu_refs()
     
     pif_refs = self.host_instance.get_PIF_refs()
     self.host_pifs = []
     for pif_ref in pif_refs:
         pif = XendAPIStore.get(pif_ref, "PIF")
         self.host_pifs.append(pif)
Пример #16
0
    def unplug(self):
        """Unplug the PIF from the network"""
        network = XendAPIStore.get(self.network, "network")
        bridge_name = network.get_name_label()

        from xen.util import Brctl
        Brctl.vif_bridge_rem({
            "bridge": bridge_name,
            "vif": self.get_interface_name()
        })
Пример #17
0
    def _init_PIFs(self):
        # 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))     
Пример #18
0
    def remove_PSCSI(self, rem_HCTL):
        saved_pscsis = self.state_store.load_state('pscsi')
        if not saved_pscsis:
            return

        # Remove the PSCSI
        for pscsi_record in saved_pscsis.values():
            if rem_HCTL == pscsi_record['physical_HCTL']:
                pscsi_ref = XendPSCSI.get_by_HCTL(rem_HCTL)
                XendAPIStore.get(pscsi_ref, "PSCSI").destroy()
                self.save_PSCSIs()

                physical_host = int(rem_HCTL.split(':')[0])
                pscsi_HBA_ref = XendPSCSI_HBA.get_by_physical_host(physical_host)
                if pscsi_HBA_ref:
                    if not XendAPIStore.get(pscsi_HBA_ref, 'PSCSI_HBA').get_PSCSIs():
                        XendAPIStore.get(pscsi_HBA_ref, 'PSCSI_HBA').destroy()
                self.save_PSCSI_HBAs()

                return
Пример #19
0
 def get_PSCSI_HBAs(self):
     PSCSIs = []
     uuid = self.get_uuid()
     for dscsi in XendAPIStore.get_all('DSCSI'):
         if dscsi.get_VM() == self.VM and dscsi.get_HBA() == uuid:
             PSCSIs.append(dscsi.get_PSCSI())
     PSCSI_HBAs = []
     for pscsi_uuid in PSCSIs:
         pscsi_HBA_uuid = XendAPIStore.get(pscsi_uuid, 'PSCSI').get_HBA()
         if not pscsi_HBA_uuid in PSCSI_HBAs:
             PSCSI_HBAs.append(pscsi_HBA_uuid)
     return PSCSI_HBAs
Пример #20
0
 def get_PSCSI_HBAs(self):
     PSCSIs = []
     uuid = self.get_uuid()
     for dscsi in XendAPIStore.get_all('DSCSI'):
         if dscsi.get_VM() == self.VM and dscsi.get_HBA() == uuid:
             PSCSIs.append(dscsi.get_PSCSI())
     PSCSI_HBAs = []
     for pscsi_uuid in PSCSIs:
         pscsi_HBA_uuid = XendAPIStore.get(pscsi_uuid, 'PSCSI').get_HBA()
         if not pscsi_HBA_uuid in PSCSI_HBAs:
             PSCSI_HBAs.append(pscsi_HBA_uuid)
     return PSCSI_HBAs
Пример #21
0
    def _init_PIFs(self):
        # 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))
Пример #22
0
    def remove_PSCSI(self, rem_HCTL):
        saved_pscsis = self.state_store.load_state('pscsi')
        if not saved_pscsis:
            return

        # Remove the PSCSI
        for pscsi_record in saved_pscsis.values():
            if rem_HCTL == pscsi_record['physical_HCTL']:
                pscsi_ref = XendPSCSI.get_by_HCTL(rem_HCTL)
                XendAPIStore.get(pscsi_ref, "PSCSI").destroy()
                self.save_PSCSIs()

                physical_host = int(rem_HCTL.split(':')[0])
                pscsi_HBA_ref = XendPSCSI_HBA.get_by_physical_host(
                    physical_host)
                if pscsi_HBA_ref:
                    if not XendAPIStore.get(pscsi_HBA_ref,
                                            'PSCSI_HBA').get_PSCSIs():
                        XendAPIStore.get(pscsi_HBA_ref, 'PSCSI_HBA').destroy()
                self.save_PSCSI_HBAs()

                return
Пример #23
0
    def lookup_pool(cls, id_or_name):
        """ Search XendCPUPool instance with given id_or_name.
            @param id_or_name: pool id or pool nameto search
            @type id_or_name:  [int, str]
            @return: instane or None if not found
            @rtype:  XendCPUPool
        """
        pool_uuid = None
        try:
            pool_id = int(id_or_name)
            # pool id given ?
            pool_uuid = cls.query_pool_ref(pool_id)
            if not pool_uuid:
                # not found -> search name
                pool_uuid = cls.get_by_name_label(id_or_name)
        except ValueError:
            # pool name given
            pool_uuid = cls.get_by_name_label(id_or_name)

        if len(pool_uuid) > 0:
            return XendAPIStore.get(pool_uuid[0], cls.getClass())
        else:
            return None
Пример #24
0
    def bridge_to_network(self, bridge):
        """
        Determine which network a particular bridge is attached to.

        @param bridge The name of the bridge.  If empty, the default bridge
        will be used instead (the first one in the list returned by brctl
        show); this is the behaviour of the vif-bridge script.
        @return The XendNetwork instance to which this bridge is attached.
        @raise Exception if the interface is not connected to a network.
        """
        if not bridge:
            rc, bridge = commands.getstatusoutput(
                'brctl show | cut -d "\n" -f 2 | cut -f 1')
            if rc != 0 or not bridge:
                raise Exception(
                    'Could not find default bridge, and none was specified')

        for network_uuid in XendNetwork.get_all():
            network = XendAPIStore.get(network_uuid, "network")
            if network.get_name_label() == bridge:
                return network
        else:
            raise Exception('Cannot find network for bridge %s' % bridge)
Пример #25
0
    def bridge_to_network(self, bridge):
        """
        Determine which network a particular bridge is attached to.

        @param bridge The name of the bridge.  If empty, the default bridge
        will be used instead (the first one in the list returned by brctl
        show); this is the behaviour of the vif-bridge script.
        @return The XendNetwork instance to which this bridge is attached.
        @raise Exception if the interface is not connected to a network.
        """
        if not bridge:
            rc, bridge = commands.getstatusoutput(
                'brctl show | cut -d "\n" -f 2 | cut -f 1')
            if rc != 0 or not bridge:
                raise Exception(
                    'Could not find default bridge, and none was specified')

        for network_uuid in XendNetwork.get_all():
            network = XendAPIStore.get(network_uuid, "network")
            if network.get_name_label() == bridge:
                return network
        else:
            raise Exception('Cannot find network for bridge %s' % bridge)
Пример #26
0
    def lookup_pool(cls, id_or_name):
        """ Search XendCPUPool instance with given id_or_name.
            @param id_or_name: pool id or pool nameto search
            @type id_or_name:  [int, str]
            @return: instane or None if not found
            @rtype:  XendCPUPool
        """
        pool_uuid = None
        try:
            pool_id = int(id_or_name)
            # pool id given ?
            pool_uuid = cls.query_pool_ref(pool_id)
            if not pool_uuid:
                # not found -> search name
                pool_uuid = cls.get_by_name_label(id_or_name)
        except ValueError:
            # pool name given
            pool_uuid = cls.get_by_name_label(id_or_name)

        if len(pool_uuid) > 0:
            return XendAPIStore.get(pool_uuid[0], cls.getClass())
        else:
            return None
Пример #27
0
 def save_cpu_pools(self):
     cpu_pool_records = dict([(cpu_pool_uuid, XendAPIStore.get(
                 cpu_pool_uuid, XendCPUPool.getClass()).get_record())
                 for cpu_pool_uuid in XendCPUPool.get_all_managed()])
     self.state_store.save_state(XendCPUPool.getClass(), cpu_pool_records)
Пример #28
0
 def save_PSCSI_HBAs(self):
     pscsi_HBA_records = dict([(pscsi_HBA_uuid, XendAPIStore.get(
                                   pscsi_HBA_uuid, "PSCSI_HBA").get_record())
                             for pscsi_HBA_uuid in XendPSCSI_HBA.get_all()])
     self.state_store.save_state('pscsi_HBA', pscsi_HBA_records)
Пример #29
0
 def save_PPCIs(self):
     ppci_records = dict([(ppci_uuid, XendAPIStore.get(
                              ppci_uuid, "PPCI").get_record())
                         for ppci_uuid in XendPPCI.get_all()])
     self.state_store.save_state('ppci', ppci_records)
Пример #30
0
 def save_PBDs(self):
     pbd_records = dict([(pbd_uuid, XendAPIStore.get(
                              pbd_uuid, "PBD").get_record())
                         for pbd_uuid in XendPBD.get_all()])
     self.state_store.save_state('pbd', pbd_records)
Пример #31
0
 def save_networks(self):
     net_records = dict([(network_uuid, XendAPIStore.get(
                              network_uuid, "network").get_record())
                         for network_uuid in XendNetwork.get_all()])
     self.state_store.save_state('network', net_records)
Пример #32
0
 def save_PIFs(self):
     pif_records = dict([(pif_uuid, XendAPIStore.get(
                              pif_uuid, "PIF").get_record())
                         for pif_uuid in XendPIF.get_all()])
     self.state_store.save_state('pif', pif_records)
Пример #33
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)
Пример #34
0
 def get_pif_metrics(self, pif):
     return XendAPIStore.get(pif.get_metrics(), "PIF_metrics")
Пример #35
0
 def get_vcpus_num(self, vm):
     return XendAPIStore.get(vm.get_metrics(),"VM_metrics").get_VCPUs_number()
Пример #36
0
 def save_PIFs(self):
     pif_records = dict([(pif_uuid, XendAPIStore.get(pif_uuid,
                                                     "PIF").get_record())
                         for pif_uuid in XendPIF.get_all()])
     self.state_store.save_state('pif', pif_records)
Пример #37
0
 def save_networks(self):
     net_records = dict([(network_uuid,
                          XendAPIStore.get(network_uuid,
                                           "network").get_record())
                         for network_uuid in XendNetwork.get_all()])
     self.state_store.save_state('network', net_records)
Пример #38
0
 def save_PPCIs(self):
     ppci_records = dict([(ppci_uuid, XendAPIStore.get(ppci_uuid,
                                                       "PPCI").get_record())
                          for ppci_uuid in XendPPCI.get_all()])
     self.state_store.save_state('ppci', ppci_records)
Пример #39
0
 def save_PBDs(self):
     pbd_records = dict([(pbd_uuid, XendAPIStore.get(pbd_uuid,
                                                     "PBD").get_record())
                         for pbd_uuid in XendPBD.get_all()])
     self.state_store.save_state('pbd', pbd_records)