コード例 #1
0
    def collect(self, config):
        ds0 = config.datasources[0]
        client = txovirt.getClient(ds0.zOVirtUrl,
                                   ds0.zOVirtUser,
                                   ds0.zOVirtDomain,
                                   ds0.zOVirtPassword)

        key = "%s%s%s_%s" % (ds0.zOVirtUrl,
                             ds0.zOVirtUser,
                             ds0.zOVirtDomain,
                             ds0.zOVirtPassword)

        if not self.last_event:
            self.last_event = self._saved(config, 'events')
        if key in self.last_event.keys():
            return client.request('events;from=%s' % str(self.last_event[key]))
        else:
            return client.request('events')
コード例 #2
0
    def onError(self, results, config):
        ds0 = config.datasources[0]
        client = txovirt.getClient(ds0.zOVirtUrl,
                                   ds0.zOVirtUser,
                                   ds0.zOVirtDomain,
                                   ds0.zOVirtPassword)

        # Try to reset the login connection on an error.
        client.login()

        errmsg = "ovirt: %s" % results.getErrorMessage()
        log.error('%s %s', config.id, errmsg)
        data = self.new_data()
        data['events'].append({
            'eventClassKey': 'oVirtEventCollectionError',
            'eventKey': eventKey(config),
            'eventClass': '/Status/',
            'summary': errmsg,
            'device': config.id,
            'severity': 4,
        })
        return data
コード例 #3
0
    def collect(self, config):
        ds0 = config.datasources[0]
        client = txovirt.getClient(ds0.zOVirtUrl,
                                   ds0.zOVirtUser,
                                   ds0.zOVirtDomain,
                                   ds0.zOVirtPassword)

        deferreds = []
        stats_deferreds = []
        for call in ['hosts', 'vms', 'storagedomains', 'datacenters', 'clusters']:
            self.request_map.append(call)
            deferreds.append(client.request(call))

        results = yield DeferredList(deferreds, consumeErrors=True)
        for success, result in results:
            if not success:
                log.error("%s", result.getErrorMessage())
                returnValue(None)

        host_tree = etree.parse(StringIO(results[0][1]))

        # get the nic from a host
        deferreds = []
        host_tree = etree.parse(StringIO(results[0][1]))
        for nic in host_tree.xpath("//link[@rel='nics']"):
            call = nic.get('href').split('/api/')[1]
            self.request_map.append(call)
            deferreds.append(client.request(call))
        nic_results = yield DeferredList(deferreds, consumeErrors=True)
        results = results + nic_results

        # host nic statistics
        for success, nic_result in nic_results:
            if success:
                nic_tree = etree.parse(StringIO(nic_result))
                for nic_statistic in nic_tree.xpath("//link[@rel='statistics']"):
                    call = nic_statistic.get('href').split('/api/')[1]
                    self.stats_request_map.append(call)
                    stats_deferreds.append(client.request(call))
                del(nic_tree)
            else:
                log.error("%s: %s", config.id, result.getErrorMessage())
                returnValue(None)

        # host statistics
        for host_statistic in host_tree.xpath("//link[@rel='statistics']"):
            call = host_statistic.get('href').split('/api/')[1]
            self.stats_request_map.append(call)
            stats_deferreds.append(client.request(call))

        del(host_tree)

        vm_tree = etree.parse(StringIO(results[1][1]))
        # vm statistics
        for vm_statistic in vm_tree.xpath("//link[@rel='statistics']"):
            call = vm_statistic.get('href').split('/api/')[1]
            self.stats_request_map.append(call)
            stats_deferreds.append(client.request(call))

        # get the nic from a vm
        deferreds = []
        for nic in vm_tree.xpath("//link[@rel='nics']"):
            call = nic.get('href').split('/api/')[1]
            self.request_map.append(call)
            deferreds.append(client.request(call))
        vm_nic_results = yield DeferredList(deferreds, consumeErrors=True)
        results = results + vm_nic_results

        # vm nic statistics
        for success, vm_nic_result in vm_nic_results:
            if success:
                vm_nic_tree = etree.parse(StringIO(vm_nic_result))
                for vm_nic_statistic in vm_nic_tree.xpath("//link[@rel='statistics']"):
                    call = vm_nic_statistic.get('href').split('/api/')[1]
                    self.stats_request_map.append(call)
                    stats_deferreds.append(client.request(call))
                del(vm_nic_tree)
            else:
                log.error("%s: %s", config.id, result.getErrorMessage())
                returnValue(None)

        # get the disk from a vm
        deferreds = []
        for disk in vm_tree.xpath("//link[@rel='disks']"):
            call = disk.get('href').split('/api/')[1]
            self.request_map.append(call)
            deferreds.append(client.request(call))
        vm_disk_results = yield DeferredList(deferreds, consumeErrors=True)
        results = results + vm_disk_results

        # vm disk statistics
        for success, vm_disk_result in vm_disk_results:
            if success:
                vm_disk_tree = etree.parse(StringIO(vm_disk_result))
                for vm_disk_statistic in vm_disk_tree.xpath("//link[@rel='statistics']"):
                    call = vm_disk_statistic.get('href').split('/api/')[1]
                    self.stats_request_map.append(call)
                    stats_deferreds.append(client.request(call))
                del(vm_disk_tree)
            else:
                log.error("%s: %s", config.id, result.getErrorMessage())
                returnValue(None)

        del(vm_tree)
        stats_results = yield DeferredList(stats_deferreds, consumeErrors=True)

        results = [r[1] for r in results]
        stats_results = [r[1] for r in stats_results]
        returnValue([results, stats_results])
コード例 #4
0
    def collect(self, device, unused):
        """Collect model-related information using the txovirt library."""

        if not device.zOVirtUrl:
            log.error('zOVirtUrl is not set. Not discovering')
            returnValue(None)

        if not device.zOVirtUser:
            log.error('zOVirtUser is not set. Not discovering')
            returnValue(None)

        if not device.zOVirtDomain:
            log.error('zOVirtDomain is not set. Not discovering')
            returnValue(None)

        if not device.zOVirtPassword:
            log.error('zOVirtPassord is not set. Not discovering')
            returnValue(None)

        client = txovirt.getClient(
             device.zOVirtUrl,
             device.zOVirtUser,
             device.zOVirtDomain,
             device.zOVirtPassword)

        deferreds = []
        data_centers = None

        # Get the /api overview.
        deferreds.append(client.request_elementtree(''))

        for key in self.collector_map_order:
            if key == 'data_centers':
                data_centers = yield client.request_elementtree(self.collector_map[key]['command'])
                for datacenter in data_centers.getchildren():
                    for link in datacenter.findall('link'):
                        if 'storage' in link.attrib['href']:
                            command = link.attrib['href'].rsplit('/api/')[1]
                            deferreds.append(client.request_elementtree(command))

            elif key == 'vms':
                vms = yield client.request_elementtree(self.collector_map[key]['command'])
                for vm in vms.getchildren():
                    for link in vm.findall('link'):
                        if 'disks' in link.attrib['href']:
                            command = link.attrib['href'].rsplit('/api/')[1]
                            deferreds.append(client.request_elementtree(command))
                        if 'nics' in link.attrib['href']:
                            command = link.attrib['href'].rsplit('/api/')[1]
                            deferreds.append(client.request_elementtree(command))

            elif key == 'hosts':
                hosts = yield client.request_elementtree(self.collector_map[key]['command'])
                for host in hosts.getchildren():
                    for link in host.findall('link'):
                        if 'nics' in link.attrib['href']:
                            command = link.attrib['href'].rsplit('/api/')[1]
                            deferreds.append(client.request_elementtree(command))
            else:
                deferreds.append(client.request_elementtree(self.collector_map[key]['command']))

        results = yield DeferredList(deferreds, consumeErrors=True)

        #  Insert data_centers result at the beginning of the list.
        results.insert(0, (True, data_centers))

        # append the vms to the list
        results.append((True, vms))

        # append the hosts to the list
        results.append((True, hosts))

        data = []
        for success, result in results:
            if not success:
                log.error("API Error: %s", result.getErrorMessage())
                # Try to reset the login connection on an error.
                client.login()
            data.append(result)

        returnValue(data)