use global conf for zvm inspector
register zvm options into global conf Change-Id: Id435e440991f3e1fe1bf7d70c998e240f56c7da8
This commit is contained in:
parent
e6e9b9efb0
commit
5891f881c2
@ -1,28 +0,0 @@
|
||||
# Copyright 2017 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
||||
zvm_opts = [
|
||||
cfg.URIOpt('zvm_cloud_connector_url',
|
||||
help="""
|
||||
URL to be used to communicate with z/VM Cloud Connector.
|
||||
Example: https://10.10.10.1:8080.
|
||||
"""),
|
||||
]
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(zvm_opts)
|
@ -19,15 +19,28 @@ from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer.i18n import _
|
||||
from ceilometer_zvm.compute.virt.zvm import exception
|
||||
from ceilometer_zvm.compute.virt.zvm import utils as zvmutils
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import units
|
||||
|
||||
|
||||
zvm_opts = [
|
||||
cfg.URIOpt('zvm_cloud_connector_url',
|
||||
help="""
|
||||
URL to be used to communicate with z/VM Cloud Connector.
|
||||
Example: https://10.10.10.1:8080.
|
||||
"""),
|
||||
]
|
||||
|
||||
|
||||
class ZVMInspector(virt_inspector.Inspector):
|
||||
|
||||
def __init__(self):
|
||||
self._reqh = zvmutils.zVMConnectorRequestHandler()
|
||||
def __init__(self, conf):
|
||||
super(ZVMInspector, self).__init__(conf)
|
||||
self.conf.register_opts(zvm_opts)
|
||||
self._reqh = zvmutils.zVMConnectorRequestHandler(
|
||||
self.conf.zvm_cloud_connector_url)
|
||||
|
||||
def inspect_vnics(self, instance):
|
||||
def inspect_vnics(self, instance, duration):
|
||||
nics_data = self._inspect_inst_data(instance, 'vnics')
|
||||
# Construct the final result
|
||||
for nic in nics_data:
|
||||
|
@ -15,12 +15,10 @@
|
||||
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from ceilometer_zvm.compute.virt.zvm import conf
|
||||
from ceilometer_zvm.compute.virt.zvm import exception
|
||||
from oslo_log import log as logging
|
||||
from zvmconnector import connector
|
||||
|
||||
CONF = conf.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -34,8 +32,8 @@ def get_inst_power_state(instance):
|
||||
|
||||
class zVMConnectorRequestHandler(object):
|
||||
|
||||
def __init__(self):
|
||||
_url = urlparse.urlparse(CONF.zvm_cloud_connector_url)
|
||||
def __init__(self, connector_url):
|
||||
_url = urlparse.urlparse(connector_url)
|
||||
self._conn = connector.ZVMConnector(_url.hostname, _url.port)
|
||||
|
||||
def call(self, func_name, *args, **kwargs):
|
||||
|
@ -17,21 +17,18 @@ import mock
|
||||
import unittest
|
||||
|
||||
from ceilometer.compute.virt import inspector as virt_inspector
|
||||
from ceilometer_zvm.compute.virt.zvm import conf
|
||||
from ceilometer_zvm.compute.virt.zvm import exception as zvmexception
|
||||
from ceilometer_zvm.compute.virt.zvm import inspector as zvminspector
|
||||
from ceilometer_zvm.compute.virt.zvm import utils as zvmutils
|
||||
|
||||
|
||||
CONF = conf.CONF
|
||||
|
||||
|
||||
class TestZVMInspector(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
unittest.TestCase.setUp(self)
|
||||
CONF.zvm_cloud_connector_url = 'https://1.1.1.1:1111'
|
||||
self._inspector = zvminspector.ZVMInspector()
|
||||
conf = mock.Mock()
|
||||
conf.zvm_cloud_connector_url = 'https://1.1.1.1:1111'
|
||||
self._inspector = zvminspector.ZVMInspector(conf)
|
||||
self._inst = mock.MagicMock()
|
||||
self._stats_dict = {'guest_cpus': 1,
|
||||
'used_cpu_time_us': 7185838,
|
||||
@ -82,7 +79,8 @@ class TestZVMInspector(unittest.TestCase):
|
||||
def test_inspect_vnics(self, get_inst_name, inspect_data):
|
||||
get_inst_name.return_value = 'INST1'
|
||||
inspect_data.return_value = self._vnics_list
|
||||
interface = list(self._inspector.inspect_vnics({'inst1': 'INST1'}))[0]
|
||||
interface = list(self._inspector.inspect_vnics(
|
||||
{'inst1': 'INST1'}, 0))[0]
|
||||
if interface.name == '0600':
|
||||
self.assertEqual(99999, interface.rx_packets)
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user