Merge "Remove Xen support"

This commit is contained in:
Zuul 2021-06-02 17:42:14 +00:00 committed by Gerrit Code Review
commit 8bdfea78ea
11 changed files with 7 additions and 366 deletions

View File

@ -27,8 +27,7 @@ OPTS = [
cfg.StrOpt('hypervisor_inspector',
default='libvirt',
help='Inspector to use for inspecting the hypervisor layer. '
'Known inspectors are libvirt, hyperv, vsphere '
'and xenapi. Note that xenapi has been deprecated.'),
'Known inspectors are libvirt, hyperv, and vsphere.'),
]
@ -270,9 +269,6 @@ class Inspector(object):
def get_hypervisor_inspector(conf):
if conf.hypervisor_inspector == 'xenapi':
LOG.warning('Support for XenServer/Xen Cloud Platform has been '
'deprecated and will be removed in a future release')
try:
namespace = 'ceilometer.compute.virt'
mgr = driver.DriverManager(namespace,

View File

@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
OPTS = [
cfg.StrOpt('libvirt_type',
default='kvm',
choices=['kvm', 'lxc', 'qemu', 'uml', 'xen'],
choices=['kvm', 'lxc', 'qemu', 'uml'],
help='Libvirt domain type.'),
cfg.StrOpt('libvirt_uri',
default='',
@ -38,7 +38,7 @@ OPTS = [
'(which is dependent on libvirt_type).'),
]
LIBVIRT_PER_TYPE_URIS = dict(uml='uml:///system', xen='xen:///', lxc='lxc:///')
LIBVIRT_PER_TYPE_URIS = dict(uml='uml:///system', lxc='lxc:///')
# We don't use the libvirt constants in case of libvirt is not available

View File

@ -1,192 +0,0 @@
# Copyright 2014 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Implementation of Inspector abstraction for XenAPI."""
from os_xenapi.client import session as xenapi_session
from os_xenapi.client import XenAPI
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import units
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.i18n import _
LOG = logging.getLogger(__name__)
opt_group = cfg.OptGroup(name='xenapi',
title='Options for XenAPI')
OPTS = [
cfg.StrOpt('connection_url',
deprecated_for_removal=True,
deprecated_reason='Support for XenServer/Xen Cloud Platform '
'has been deprecated',
help='URL for connection to XenServer/Xen Cloud Platform.'),
cfg.StrOpt('connection_username',
default='root',
deprecated_for_removal=True,
deprecated_reason='Support for XenServer/Xen Cloud Platform '
'has been deprecated',
help='Username for connection to XenServer/Xen Cloud '
'Platform.'),
cfg.StrOpt('connection_password',
deprecated_for_removal=True,
deprecated_reason='Support for XenServer/Xen Cloud Platform '
'has been deprecated',
help='Password for connection to XenServer/Xen Cloud Platform.',
secret=True),
]
class XenapiException(virt_inspector.InspectorException):
pass
def get_api_session(conf):
url = conf.xenapi.connection_url
username = conf.xenapi.connection_username
password = conf.xenapi.connection_password
if not url or password is None:
raise XenapiException(_('Must specify connection_url, and '
'connection_password to use'))
try:
session = xenapi_session.XenAPISession(url, username, password,
originator="ceilometer")
LOG.debug("XenAPI session is created successfully, %s", session)
except XenAPI.Failure as e:
msg = _("Could not connect to XenAPI: %s") % e.details[0]
raise XenapiException(msg)
return session
class XenapiInspector(virt_inspector.Inspector):
def __init__(self, conf):
super(XenapiInspector, self).__init__(conf)
self.session = get_api_session(self.conf)
def _lookup_by_name(self, instance_name):
vm_refs = self.session.VM.get_by_name_label(instance_name)
n = len(vm_refs)
if n == 0:
raise virt_inspector.InstanceNotFoundException(
_('VM %s not found in XenServer') % instance_name)
elif n > 1:
raise XenapiException(
_('Multiple VM %s found in XenServer') % instance_name)
else:
return vm_refs[0]
def inspect_instance(self, instance, duration):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
cpu_util = self._get_cpu_usage(vm_ref, instance_name)
memory_usage = self._get_memory_usage(vm_ref)
LOG.debug("inspect_instance, cpu_util: %(cpu)s, memory_usage: %(mem)s",
{'cpu': cpu_util, 'mem': memory_usage}, instance=instance)
return virt_inspector.InstanceStats(cpu_util=cpu_util,
memory_usage=memory_usage)
def _get_cpu_usage(self, vm_ref, instance_name):
vcpus_number = int(self.session.VM.get_VCPUs_max(vm_ref))
if vcpus_number <= 0:
msg = _("Could not get VM %s CPU number") % instance_name
raise XenapiException(msg)
cpu_util = 0.0
for index in range(vcpus_number):
cpu_util += float(self.session.VM.query_data_source(
vm_ref, "cpu%d" % index))
return cpu_util / int(vcpus_number) * 100
def _get_memory_usage(self, vm_ref):
total_mem = float(self.session.VM.query_data_source(vm_ref, "memory"))
try:
free_mem = float(self.session.VM.query_data_source(
vm_ref, "memory_internal_free"))
except XenAPI.Failure:
# If PV tools is not installed in the guest instance, it's
# impossible to get free memory. So give it a default value
# as 0.
free_mem = 0
# memory provided from XenServer is in Bytes;
# memory_internal_free provided from XenServer is in KB,
# converting it to MB.
return (total_mem - free_mem * units.Ki) / units.Mi
def inspect_vnics(self, instance, duration):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
dom_id = self.session.VM.get_domid(vm_ref)
vif_refs = self.session.VM.get_VIFs(vm_ref)
bw_all = self.session.call_plugin_serialized('bandwidth',
'fetch_all_bandwidth')
LOG.debug("inspect_vnics, all bandwidth: %s", bw_all,
instance=instance)
for vif_ref in vif_refs:
vif_rec = self.session.VIF.get_record(vif_ref)
bw_vif = bw_all[dom_id][vif_rec['device']]
# TODO(jianghuaw): Currently the plugin can only support
# rx_bytes and tx_bytes, so temporarily set others as -1.
yield virt_inspector.InterfaceStats(
name=vif_rec['uuid'],
mac=vif_rec['MAC'],
fref=None,
parameters=None,
rx_bytes=bw_vif['bw_in'], rx_packets=-1, rx_drop=-1,
rx_errors=-1, tx_bytes=bw_vif['bw_out'], tx_packets=-1,
tx_drop=-1, tx_errors=-1, rx_bytes_delta=-1,
tx_bytes_delta=-1)
def inspect_vnic_rates(self, instance, duration):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
vif_refs = self.session.VM.get_VIFs(vm_ref)
for vif_ref in vif_refs:
vif_rec = self.session.VIF.get_record(vif_ref)
rx_rate = float(self.session.VM.query_data_source(
vm_ref, "vif_%s_rx" % vif_rec['device']))
tx_rate = float(self.session.VM.query_data_source(
vm_ref, "vif_%s_tx" % vif_rec['device']))
yield virt_inspector.InterfaceRateStats(
name=vif_rec['uuid'],
mac=vif_rec['MAC'],
fref=None,
parameters=None,
rx_bytes_rate=rx_rate,
tx_bytes_rate=tx_rate)
def inspect_disk_rates(self, instance, duration):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
vbd_refs = self.session.VM.get_VBDs(vm_ref)
for vbd_ref in vbd_refs:
vbd_rec = self.session.VBD.get_record(vbd_ref)
read_rate = float(self.session.VM.query_data_source(
vm_ref, "vbd_%s_read" % vbd_rec['device']))
write_rate = float(self.session.VM.query_data_source(
vm_ref, "vbd_%s_write" % vbd_rec['device']))
yield virt_inspector.DiskRateStats(
device=vbd_rec['device'],
read_bytes_rate=read_rate,
read_requests_rate=0,
write_bytes_rate=write_rate,
write_requests_rate=0)

View File

@ -21,7 +21,6 @@ import ceilometer.compute.discovery
import ceilometer.compute.virt.inspector
import ceilometer.compute.virt.libvirt.utils
import ceilometer.compute.virt.vmware.inspector
import ceilometer.compute.virt.xenapi.inspector
import ceilometer.event.converter
import ceilometer.hardware.discovery
import ceilometer.hardware.pollsters.generic
@ -120,7 +119,6 @@ def list_opts():
ceilometer.objectstore.swift.SERVICE_OPTS,
ceilometer.volume.discovery.SERVICE_OPTS,)),
('vmware', ceilometer.compute.virt.vmware.inspector.OPTS),
('xenapi', ceilometer.compute.virt.xenapi.inspector.OPTS),
]

View File

@ -1,162 +0,0 @@
# Copyright 2014 Intel
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for xenapi inspector."""
from unittest import mock
from oslotest import base
from ceilometer.compute.virt.xenapi import inspector as xenapi_inspector
from ceilometer import service
class TestXenapiInspection(base.BaseTestCase):
def setUp(self):
super(TestXenapiInspection, self).setUp()
conf = service.prepare_service([], [])
api_session = mock.Mock()
xenapi_inspector.get_api_session = mock.Mock(return_value=api_session)
self.inspector = xenapi_inspector.XenapiInspector(conf)
def test_inspect_instance(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
fake_total_mem = 134217728.0
fake_free_mem = 65536.0
session = self.inspector.session
with mock.patch.object(session.VM, 'get_by_name_label') as mock_name, \
mock.patch.object(session.VM, 'get_VCPUs_max') as mock_vcpu, \
mock.patch.object(session.VM, 'query_data_source') \
as mock_query:
mock_name.return_value = ['vm_ref']
mock_vcpu.return_value = '1'
mock_query.side_effect = [0.4, fake_total_mem, fake_free_mem]
stats = self.inspector.inspect_instance(fake_instance, None)
self.assertEqual(40, stats.cpu_util)
self.assertEqual(64, stats.memory_usage)
def test_inspect_memory_usage_without_freeMem(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
fake_total_mem = 134217728.0
fake_free_mem = 0
session = self.inspector.session
with mock.patch.object(session.VM, 'get_by_name_label') as mock_name, \
mock.patch.object(session.VM, 'get_VCPUs_max') as mock_vcpu, \
mock.patch.object(session.VM, 'query_data_source') \
as mock_query:
mock_name.return_value = ['vm_ref']
mock_vcpu.return_value = '1'
mock_query.side_effect = [0.4, fake_total_mem, fake_free_mem]
stats = self.inspector.inspect_instance(fake_instance, None)
self.assertEqual(128, stats.memory_usage)
def test_inspect_vnics(self):
fake_instance = {
'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
vif_rec = {
'uuid': 'vif_uuid',
'MAC': 'vif_mac',
'device': '0',
}
bandwidth_returns = [{
'10': {
'0': {
'bw_in': 1024, 'bw_out': 2048
}
}
}]
session = self.inspector.session
with mock.patch.object(session.VM, 'get_by_name_label') as mock_name, \
mock.patch.object(session.VM, 'get_domid') as mock_domid, \
mock.patch.object(session.VM, 'get_VIFs') as mock_vif, \
mock.patch.object(session.VIF, 'get_record') as mock_record, \
mock.patch.object(session, 'call_plugin_serialized') \
as mock_plugin:
mock_name.return_value = ['vm_ref']
mock_domid.return_value = '10'
mock_vif.return_value = ['vif_ref']
mock_record.return_value = vif_rec
mock_plugin.side_effect = bandwidth_returns
interfaces = list(self.inspector.inspect_vnics(
fake_instance, None))
self.assertEqual(1, len(interfaces))
vnic0 = interfaces[0]
self.assertEqual('vif_uuid', vnic0.name)
self.assertEqual('vif_mac', vnic0.mac)
self.assertEqual(1024, vnic0.rx_bytes)
self.assertEqual(2048, vnic0.tx_bytes)
def test_inspect_vnic_rates(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
vif_rec = {
'metrics': 'vif_metrics_ref',
'uuid': 'vif_uuid',
'MAC': 'vif_mac',
'device': '0',
}
session = self.inspector.session
with mock.patch.object(session.VM, 'get_by_name_label') as mock_name, \
mock.patch.object(session.VM, 'get_VIFs') as mock_vif, \
mock.patch.object(session.VIF, 'get_record') as mock_record, \
mock.patch.object(session.VM, 'query_data_source') \
as mock_query:
mock_name.return_value = ['vm_ref']
mock_vif.return_value = ['vif_ref']
mock_record.return_value = vif_rec
mock_query.side_effect = [1024.0, 2048.0]
interfaces = list(self.inspector.inspect_vnic_rates(
fake_instance, None))
self.assertEqual(1, len(interfaces))
vnic0 = interfaces[0]
self.assertEqual('vif_uuid', vnic0.name)
self.assertEqual('vif_mac', vnic0.mac)
self.assertEqual(1024.0, vnic0.rx_bytes_rate)
self.assertEqual(2048.0, vnic0.tx_bytes_rate)
def test_inspect_disk_rates(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
vbd_rec = {
'device': 'xvdd'
}
session = self.inspector.session
with mock.patch.object(session.VM, 'get_by_name_label') as mock_name, \
mock.patch.object(session.VM, 'get_VBDs') as mock_vbds, \
mock.patch.object(session.VBD, 'get_record') as mock_records, \
mock.patch.object(session.VM, 'query_data_source') \
as mock_query:
mock_name.return_value = ['vm_ref']
mock_vbds.return_value = ['vbd_ref']
mock_records.return_value = vbd_rec
mock_query.side_effect = [1024.0, 2048.0]
disks = list(self.inspector.inspect_disk_rates(
fake_instance, None))
self.assertEqual(1, len(disks))
disk0 = disks[0]
self.assertEqual('xvdd', disk0.device)
self.assertEqual(1024.0, disk0.read_bytes_rate)
self.assertEqual(2048.0, disk0.write_bytes_rate)

View File

@ -10,7 +10,6 @@ keystoneauth1==3.18.0
lxml==4.5.1
msgpack==0.5.2
os-win==3.0.0
os-xenapi==0.3.3
oslo.cache==1.26.0
oslo.concurrency==3.26.0
oslo.config==6.0.0

View File

@ -0,0 +1,4 @@
---
upgrade:
- |
Support for XenServer/Xen Cloud Platform has been removed.

View File

@ -32,7 +32,6 @@ requests!=2.9.0,>=2.8.1 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0
tenacity>=4.12.0 # Apache-2.0
tooz[zake]>=1.47.0 # Apache-2.0
os-xenapi>=0.3.3 # Apache-2.0
oslo.cache>=1.26.0 # Apache-2.0
gnocchiclient>=7.0.0 # Apache-2.0
python-monascaclient>=1.12.0 # Apache-2.0

View File

@ -195,7 +195,6 @@ ceilometer.compute.virt =
libvirt = ceilometer.compute.virt.libvirt.inspector:LibvirtInspector
hyperv = ceilometer.compute.virt.hyperv.inspector:HyperVInspector
vsphere = ceilometer.compute.virt.vmware.inspector:VsphereInspector
xenapi = ceilometer.compute.virt.xenapi.inspector:XenapiInspector
ceilometer.hardware.inspectors =
snmp = ceilometer.hardware.inspector.snmp:SNMPInspector