Ejemplo n.º 1
0
 def change_xenstore(self, action, device, major, minor):
     for type in DEVICE_TYPES:
         path = self.dbpath + '/' + type
         domains = xstransact.List(path)
         log.debug('domains: %s', domains)
         for domain in domains:  # for each domain
             devices = xstransact.List(path + '/' + domain)
             log.debug('devices: %s', devices)
             for device in devices:  # for each vbd device
                 str = device.split('/')
                 vbd_type = None
                 vbd_physical_device = None
                 vbd_media = None
                 vbd_device_path = path + '/' + domain + '/' + device
                 listing = xstransact.List(vbd_device_path)
                 for entry in listing:  # for each entry
                     item = path + '/' + entry
                     value = xstransact.Read(vbd_device_path + '/' + entry)
                     log.debug('%s=%s', item, value)
                     if item.find('media-present') != -1:
                         vbd_media = item
                         vbd_media_path = item
                     if item.find('physical-device') != -1:
                         vbd_physical_device = value
                     if item.find('type') != -1:
                         vbd_type = value
                 if vbd_type is not None and vbd_physical_device is not None and vbd_media is not None:
                     inode = vbd_physical_device.split(':')
                     imajor = parse_hex(inode[0])
                     iminor = parse_hex(inode[1])
                     log.debug(
                         "action:%s major:%s- minor:%s- imajor:%s- iminor:%s- inode: %s",
                         action, major, minor, imajor, iminor, inode)
                     if int(imajor) == int(major) and int(iminor) == int(
                             minor):
                         if action == "add":
                             xs_dict = {'media': "1"}
                             xstransact.Write(vbd_device_path,
                                              'media-present', "1")
                             log.debug(
                                 "wrote xenstore media-present 1 path:%s",
                                 vbd_media_path)
                         else:
                             xstransact.Write(vbd_device_path,
                                              'media-present', "0")
                             log.debug("wrote xenstore media 0 path:%s",
                                       vbd_media_path)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
 def deviceIDs(self, transaction = None):
     """@return The IDs of each of the devices currently configured for
     this instance's deviceClass.
     """
     fe = self.frontendRoot()
     if transaction:
         return map(lambda x: int(x.split('/')[-1]), transaction.list(fe))
     else:
         return map(int, xstransact.List(fe))
Ejemplo n.º 4
0
def diagnose_devices():
    global deviceClass
    global device
    global frontendPath
    global backendPath

    device_path = dompath + '/device'

    device_classes = xstransact.List(device_path)

    print "Found %d device classes in use." % len(device_classes)

    for dc in device_classes:
        deviceClass = dc
        device_class_path = device_path + '/' + deviceClass

        devices = xstransact.List(device_class_path)

        print "Found %d %s devices." % (len(devices), deviceClass)

        for d in devices:
            device = d

            print "Found device %s, %s." % (deviceClass, device)

            frontendPath = device_class_path + '/' + device
            backendPath = xstransact.Read(frontendPath, 'backend')

            if not backendPath:
                print("Cannot find backend path for device %s, %s." %
                      (deviceClass, device))
            else:
                frontend_state = xstransact.Read(frontendPath, 'state')
                backend_state = xstransact.Read(backendPath, 'state')

                print "Backend is in state %s." % stateString(backend_state)
                print "Frontend is in state %s." % stateString(frontend_state)

                check_for_error(True)
                check_for_error(False)

                diagnose_hotplugging()
Ejemplo n.º 5
0
def get_all_assigned_pci_devices(domid=0):
    dom_list = xstransact.List('/local/domain')
    pci_str_list = []
    ti = 0
    ts = xstransact.Read('/local/domain/' + str(domid) + '/target')
    if ts is not None:
        ti = int(ts)
    for d in dom_list:
        target = xstransact.Read('/local/domain/' + d + '/target')
        if int(d) is not ti and target is None:
            pci_str_list = pci_str_list + get_assigned_pci_devices(int(d))
    return pci_str_list
Ejemplo n.º 6
0
 def __init__(self):
     # Table of vnet info indexed by vnet id.
     self.vnet = {}
     listing = xstransact.List(self.dbpath)
     for entry in listing:
         try:
             info = XendVnetInfo(self.dbpath + '/' + entry)
             self.vnet[info.id] = info
             info.configure()
         except XendError, ex:
             log.warning("Failed to configure vnet %s: %s", str(info.id),
                         str(ex))
         except Exception, ex:
             log.exception("Vnet error")
             xstransact.Remove(self.dbpath + '/' + entry)
Ejemplo n.º 7
0
    def query_pool_id(self):
        """ Get corresponding pool-id of pool instance from XenStore.
            @return: pool id or None
            @rytpe:  int
        """
        self.pool_lock.acquire()
        try:
            for pool_id in xstransact.List(XS_POOLROOT):
                uuid = xstransact.Read(XS_POOLROOT + "%s/" % pool_id, 'uuid')
                if uuid == self.get_uuid():
                    return int(pool_id)
        finally:
            self.pool_lock.release()

        return None
Ejemplo n.º 8
0
 def readBackendList(self, devid, *args):
     frontpath = self.frontendPath(devid)
     backpath = xstransact.Read(frontpath + "/backend")
     if backpath:
         paths = map(lambda x: backpath + "/" + x, args)
         return xstransact.List(*paths)