Add vCenter driver
Implements blueprint: vcenter-driver Change-Id: Ifc9334d79295fa5edaaebc66a0484492977a1e36
This commit is contained in:
parent
5ba1af5699
commit
75a0d511a9
|
@ -0,0 +1,317 @@
|
|||
# Copyright (c) 2014 Marist SDN Innovation lab Joint with Plexxi Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# 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.vmware import api
|
||||
from oslo.vmware import vim_util
|
||||
|
||||
from congress.datasources.datasource_driver import DataSourceDriver
|
||||
from congress.datasources import datasource_utils
|
||||
from congress.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def d6service(name, keys, inbox, datapath, args):
|
||||
"""This method is called by d6cage to create a dataservice instance.
|
||||
|
||||
"""
|
||||
|
||||
return VCenterDriver(name, keys, inbox, datapath, args)
|
||||
|
||||
|
||||
class VCenterDriver(DataSourceDriver):
|
||||
HOSTS = "hosts"
|
||||
HOST_DNS = "host.DNS_IPs"
|
||||
HOST_PNICS = "host.PNICs"
|
||||
HOST_VNICS = "host.VNICs"
|
||||
VMS = "vms"
|
||||
|
||||
value_trans = {'translation-type': 'VALUE'}
|
||||
|
||||
vms_translator = {
|
||||
'translation-type': 'HDICT',
|
||||
'table-name': VMS,
|
||||
'selector-type': 'DICT_SELECTOR',
|
||||
'field-translators':
|
||||
({'fieldname': 'name', 'translator': value_trans},
|
||||
{'fieldname': 'uuid', 'translator': value_trans},
|
||||
{'fieldname': 'host_uuid', 'translator': value_trans},
|
||||
{'fieldname': 'pathName', 'translator': value_trans},
|
||||
{'fieldname': 'status', 'translator': value_trans},
|
||||
{'fieldname': 'CpuDemand', 'translator': value_trans},
|
||||
{'fieldname': 'CpuUsage', 'translator': value_trans},
|
||||
{'fieldname': 'memorySizeMB', 'translator': value_trans},
|
||||
{'fieldname': 'MemoryUsage', 'translator': value_trans},
|
||||
{'fieldname': 'committedStorage', 'translator': value_trans},
|
||||
{'fieldname': 'uncommittedStorage', 'translator': value_trans},
|
||||
{'fieldname': 'annotation', 'translator': value_trans})}
|
||||
|
||||
pnic_translator = {
|
||||
'translation-type': 'HDICT',
|
||||
'table-name': HOST_PNICS,
|
||||
'selector-type': 'DICT_SELECTOR',
|
||||
'field-translators':
|
||||
({'fieldname': 'host_uuid', 'translator': value_trans},
|
||||
{'fieldname': 'device', 'translator': value_trans},
|
||||
{'fieldname': 'mac', 'translator': value_trans},
|
||||
{'fieldname': 'ipAddress', 'translator': value_trans},
|
||||
{'fieldname': 'subnetMask', 'translator': value_trans})}
|
||||
|
||||
vnic_translator = {
|
||||
'translation-type': 'HDICT',
|
||||
'table-name': HOST_VNICS,
|
||||
'selector-type': 'DICT_SELECTOR',
|
||||
'field-translators':
|
||||
({'fieldname': 'host_uuid', 'translator': value_trans},
|
||||
{'fieldname': 'device', 'translator': value_trans},
|
||||
{'fieldname': 'mac', 'translator': value_trans},
|
||||
{'fieldname': 'portgroup', 'translator': value_trans},
|
||||
{'fieldname': 'ipAddress', 'translator': value_trans},
|
||||
{'fieldname': 'subnetMask', 'translator': value_trans})}
|
||||
|
||||
hosts_translator = {
|
||||
'translation-type': 'HDICT',
|
||||
'table-name': HOSTS,
|
||||
'selector-type': 'DICT_SELECTOR',
|
||||
'field-translators':
|
||||
({'fieldname': 'name', 'translator': value_trans},
|
||||
{'fieldname': 'uuid', 'translator': value_trans},
|
||||
{'fieldname': HOST_DNS, 'col': 'Host:DNS_id',
|
||||
'translator': {'translation-type': 'LIST',
|
||||
'table-name': HOST_DNS,
|
||||
'id-col': 'Host:DNS_id',
|
||||
'val-col': 'DNS_IPs',
|
||||
'translator': value_trans}})}
|
||||
|
||||
def __init__(self, name='', keys='', inbox=None, datapath=None, args=None,
|
||||
session=None):
|
||||
if args is None:
|
||||
args = self.empty_credentials()
|
||||
else:
|
||||
args['tenant_name'] = None
|
||||
super(VCenterDriver, self).__init__(name, keys, inbox, datapath, args)
|
||||
self.register_translator(VCenterDriver.hosts_translator)
|
||||
self.register_translator(VCenterDriver.pnic_translator)
|
||||
self.register_translator(VCenterDriver.vnic_translator)
|
||||
self.register_translator(VCenterDriver.vms_translator)
|
||||
try:
|
||||
self.max_VMs = int(args['max_vms'])
|
||||
except (KeyError, ValueError):
|
||||
LOG.warning("max_vms has not been configured in "
|
||||
"datasources.conf, defaulting to 999.")
|
||||
self.max_VMs = 999
|
||||
try:
|
||||
self.max_Hosts = int(args['max_hosts'])
|
||||
except (KeyError, ValueError):
|
||||
LOG.warning("max_hosts has not been configured in "
|
||||
"datasources.conf, defaulting to 999.")
|
||||
self.max_Hosts = 999
|
||||
self.raw_state = {}
|
||||
self.creds = datasource_utils.get_credentials(name, args)
|
||||
if session is None:
|
||||
self.session = api.VMwareAPISession(self.creds['auth_url'],
|
||||
self.creds['username'],
|
||||
self.creds['password'],
|
||||
10, 1,
|
||||
create_session=True)
|
||||
self.initialized = True
|
||||
|
||||
def update_from_datasource(self):
|
||||
"""Called when it is time to pull new data from this datasource.
|
||||
|
||||
Pulls lists of objects from vCenter, if the data does not match
|
||||
the correspondig table in the driver's raw state or has not yet been
|
||||
added to the state, the driver calls methods to parse this data.
|
||||
"""
|
||||
|
||||
rawHosts = self.get_hosts()
|
||||
if (self.HOSTS not in self.raw_state or
|
||||
rawHosts != self.raw_state[self.HOSTS]):
|
||||
self._translate_hosts(rawHosts)
|
||||
self.raw_state[self.HOSTS] = rawHosts
|
||||
else:
|
||||
self.hosts = self.state[self.HOSTS]
|
||||
self.pnics = self.state[self.HOST_PNICS]
|
||||
self.nics = self.state[self.HOST_VNICS]
|
||||
|
||||
rawVMs = self.get_vms()
|
||||
if (self.VMS not in self.raw_state or
|
||||
rawVMs != self.raw_state[self.VMS]):
|
||||
self._translate_vms(rawVMs)
|
||||
self.raw_state[self.VMS] = rawVMs
|
||||
else:
|
||||
self.vms = self.state[self.VMS]
|
||||
|
||||
def _translate_hosts(self, rawhosts):
|
||||
"""Translate the host data from vCenter
|
||||
|
||||
First the raw host data aquired from vCenter is parsed and organized
|
||||
into a simple format that can be read by congress translators. This
|
||||
creates three lists, hosts, pnics and vnics. These lists are then
|
||||
parsed by congress translators to create tables.
|
||||
"""
|
||||
|
||||
hosts = []
|
||||
pnics = []
|
||||
vnics = []
|
||||
for host in rawhosts['objects']:
|
||||
h = {}
|
||||
h['vCenter_id'] = host.obj['value']
|
||||
for prop in host['propSet']:
|
||||
if prop.name == "hardware.systemInfo.uuid":
|
||||
h['uuid'] = prop.val
|
||||
break
|
||||
for prop in host['propSet']:
|
||||
if prop.name == "name":
|
||||
h['name'] = prop.val
|
||||
continue
|
||||
if prop.name == "config.network.dnsConfig.address":
|
||||
try:
|
||||
h[self.HOST_DNS] = prop.val.string
|
||||
except AttributeError:
|
||||
h[self.HOST_DNS] = ["No DNS IP adddresses configured"]
|
||||
continue
|
||||
if prop.name == "config.network.pnic":
|
||||
for pnic in prop.val.PhysicalNic:
|
||||
p = {}
|
||||
p['host_uuid'] = h['uuid']
|
||||
p['mac'] = pnic['mac']
|
||||
p['device'] = pnic['device']
|
||||
p['ipAddress'] = pnic['spec']['ip']['ipAddress']
|
||||
p['subnetMask'] = pnic['spec']['ip']['subnetMask']
|
||||
pnics.append(p)
|
||||
if prop.name == "config.network.vnic":
|
||||
for vnic in prop.val.HostVirtualNic:
|
||||
v = {}
|
||||
v['host_uuid'] = h['uuid']
|
||||
v['device'] = vnic['device']
|
||||
v['portgroup'] = vnic['portgroup']
|
||||
v['mac'] = vnic['spec']['mac']
|
||||
v['ipAddress'] = vnic['spec']['ip']['ipAddress']
|
||||
v['subnetMask'] = vnic['spec']['ip']['subnetMask']
|
||||
vnics.append(v)
|
||||
hosts.append(h)
|
||||
row_data = VCenterDriver.convert_objs(hosts,
|
||||
VCenterDriver.hosts_translator)
|
||||
host_tables = (self.HOSTS, self.HOST_DNS)
|
||||
for table in host_tables:
|
||||
self.state[table] = set()
|
||||
for table, row in row_data:
|
||||
assert table in host_tables
|
||||
self.state[table].add(row)
|
||||
self.hosts = hosts
|
||||
|
||||
row_data = VCenterDriver.convert_objs(pnics,
|
||||
VCenterDriver.pnic_translator)
|
||||
self.state[self.HOST_PNICS] = set()
|
||||
for table, row in row_data:
|
||||
assert table == self.HOST_PNICS
|
||||
self.state[table].add(row)
|
||||
self.pnics = pnics
|
||||
|
||||
row_data = VCenterDriver.convert_objs(vnics,
|
||||
VCenterDriver.vnic_translator)
|
||||
self.state[self.HOST_VNICS] = set()
|
||||
for table, row in row_data:
|
||||
assert table == self.HOST_VNICS
|
||||
self.state[table].add(row)
|
||||
self.vnics = vnics
|
||||
|
||||
def _translate_vms(self, rawvms):
|
||||
"""Translate the VM data from vCenter
|
||||
|
||||
First the raw VM data aquired from vCenter is parsed and organized
|
||||
into a simple format that can be read by congress translators. This
|
||||
is a single list named vms that is then parsed by a congress
|
||||
translator to create the vms table.
|
||||
"""
|
||||
|
||||
vms = []
|
||||
for vm in rawvms['objects']:
|
||||
v = {}
|
||||
for prop in vm['propSet']:
|
||||
if prop.name == "name":
|
||||
v['name'] = prop.val
|
||||
continue
|
||||
if prop.name == "config.uuid":
|
||||
v['uuid'] = prop.val
|
||||
continue
|
||||
if prop.name == "config.annotation":
|
||||
v['annotation'] = prop.val
|
||||
continue
|
||||
if prop.name == "summary.config.vmPathName":
|
||||
v['pathName'] = prop.val
|
||||
continue
|
||||
if prop.name == "summary.config.memorySizeMB":
|
||||
v['memorySizeMB'] = prop.val
|
||||
continue
|
||||
if prop.name == "summary.quickStats":
|
||||
v['MemoryUsage'] = prop.val['guestMemoryUsage']
|
||||
v['CpuDemand'] = prop.val['overallCpuDemand']
|
||||
v['CpuUsage'] = prop.val['overallCpuUsage']
|
||||
continue
|
||||
if prop.name == "summary.overallStatus":
|
||||
v['status'] = prop.val
|
||||
if prop.name == "summary.storage":
|
||||
v['committedStorage'] = prop.val['committed']
|
||||
v['uncommittedStorage'] = prop.val['uncommitted']
|
||||
continue
|
||||
if prop.name == 'runtime.host':
|
||||
for host in self.hosts:
|
||||
if host['vCenter_id'] == prop.val['value']:
|
||||
v['host_uuid'] = host['uuid']
|
||||
continue
|
||||
continue
|
||||
vms.append(v)
|
||||
row_data = VCenterDriver.convert_objs(vms,
|
||||
VCenterDriver.vms_translator)
|
||||
self.state[self.VMS] = set()
|
||||
for table, row in row_data:
|
||||
assert table == self.VMS
|
||||
self.state[table].add(row)
|
||||
self.vms = vms
|
||||
|
||||
def get_hosts(self):
|
||||
"""Called to pull host data from vCenter
|
||||
|
||||
"""
|
||||
|
||||
dataFields = ['name',
|
||||
'hardware.systemInfo.uuid',
|
||||
'config.network.dnsConfig.address',
|
||||
'config.network.pnic',
|
||||
'config.network.vnic']
|
||||
return self.session.invoke_api(vim_util, 'get_objects',
|
||||
self.session.vim, 'HostSystem',
|
||||
self.max_Hosts, dataFields)
|
||||
|
||||
def get_vms(self):
|
||||
"""Called to pull VM data from vCenter
|
||||
|
||||
"""
|
||||
|
||||
dataFields = ['name',
|
||||
'config.uuid',
|
||||
'config.annotation',
|
||||
'summary.config.vmPathName',
|
||||
'runtime.host',
|
||||
'summary.config.memorySizeMB',
|
||||
'summary.quickStats',
|
||||
'summary.overallStatus',
|
||||
'summary.storage']
|
||||
return self.session.invoke_api(vim_util, 'get_objects',
|
||||
self.session.vim, 'VirtualMachine',
|
||||
self.max_VMs, dataFields)
|
|
@ -0,0 +1,278 @@
|
|||
# Copyright (c) 2014 Marist SDN Innovation lab Joint with Plexxi Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# 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 congress.datasources import vCenter_driver
|
||||
from congress.tests import base
|
||||
from congress.tests.datasources.vCenter_fakes import MockDNSInfo
|
||||
from congress.tests.datasources.vCenter_fakes import MockNicContainer
|
||||
from congress.tests.datasources.vCenter_fakes import MockProperty
|
||||
from congress.tests.datasources.vCenter_fakes import MockvCenterHost
|
||||
from congress.tests import helper
|
||||
|
||||
|
||||
class TestvCenterDriver(base.TestCase):
|
||||
def setUp(self):
|
||||
super(TestvCenterDriver, self).setUp()
|
||||
args = helper.datasource_openstack_args()
|
||||
args['max_hosts'] = 999
|
||||
args['max_vms'] = 999
|
||||
self.driver = vCenter_driver.VCenterDriver(args=args,
|
||||
session="Testing")
|
||||
self.mock_rawhosts = {}
|
||||
h1_obj = {}
|
||||
h1_obj['value'] = 'Host1'
|
||||
mock_host1 = MockvCenterHost(h1_obj)
|
||||
h1_uuid = MockProperty('9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'hardware.systemInfo.uuid')
|
||||
h1_name = MockProperty('Host1', 'name')
|
||||
h1_DNS_obj = MockDNSInfo(['10.11.12.1', '10.11.12.2'])
|
||||
h1_DNS = MockProperty(h1_DNS_obj,
|
||||
'config.network.dnsConfig.address')
|
||||
h1_pnic1 = {}
|
||||
h1_pnic1['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f1'
|
||||
h1_pnic1['mac'] = '3F-0B-DD-8A-F3-B9'
|
||||
h1_pnic1['device'] = 'vmnic1'
|
||||
h1_pnic1['spec'] = {}
|
||||
h1_pnic1['spec']['ip'] = {}
|
||||
h1_pnic1['spec']['ip']['ipAddress'] = '10.11.13.1'
|
||||
h1_pnic1['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h1_pnic2 = {}
|
||||
h1_pnic2['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f2'
|
||||
h1_pnic2['mac'] = '3F-0B-DD-8A-F3-BA'
|
||||
h1_pnic2['device'] = 'vmnic2'
|
||||
h1_pnic2['spec'] = {}
|
||||
h1_pnic2['spec']['ip'] = {}
|
||||
h1_pnic2['spec']['ip']['ipAddress'] = '10.11.13.2'
|
||||
h1_pnic2['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h1_pnic_list = (h1_pnic1, h1_pnic2)
|
||||
h1_pnic_obj = MockNicContainer(h1_pnic_list)
|
||||
h1_pnics = MockProperty(h1_pnic_obj, 'config.network.pnic')
|
||||
h1_vnic1 = {}
|
||||
h1_vnic1['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f3'
|
||||
h1_vnic1['device'] = 'vmk1'
|
||||
h1_vnic1['portgroup'] = 'Management'
|
||||
h1_vnic1['spec'] = {}
|
||||
h1_vnic1['spec']['mac'] = '3F-0B-DD-8A-F3-BB'
|
||||
h1_vnic1['spec']['ip'] = {}
|
||||
h1_vnic1['spec']['ip']['ipAddress'] = '10.11.13.3'
|
||||
h1_vnic1['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h1_vnic2 = {}
|
||||
h1_vnic2['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f4'
|
||||
h1_vnic2['device'] = 'vmk2'
|
||||
h1_vnic2['portgroup'] = 'Public'
|
||||
h1_vnic2['spec'] = {}
|
||||
h1_vnic2['spec']['mac'] = '3F-0B-DD-8A-F3-BC'
|
||||
h1_vnic2['spec']['ip'] = {}
|
||||
h1_vnic2['spec']['ip']['ipAddress'] = '10.11.13.4'
|
||||
h1_vnic2['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h1_vnic_list = [h1_vnic1, h1_vnic2]
|
||||
h1_vnic_obj = MockNicContainer(h1_vnic_list)
|
||||
h1_vnics = MockProperty(h1_vnic_obj, 'config.network.vnic')
|
||||
mock_host1['propSet'] = [h1_uuid, h1_name, h1_DNS, h1_pnics, h1_vnics]
|
||||
h2_obj = {}
|
||||
h2_obj['value'] = 'Host2'
|
||||
mock_host2 = MockvCenterHost(h2_obj)
|
||||
h2_uuid = MockProperty('9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'hardware.systemInfo.uuid')
|
||||
h2_name = MockProperty('Host2', 'name')
|
||||
h2_DNS_obj = MockDNSInfo(['10.11.12.1', '10.11.12.2'])
|
||||
h2_DNS = MockProperty(h2_DNS_obj,
|
||||
'config.network.dnsConfig.address')
|
||||
h2_pnic1 = {}
|
||||
h2_pnic1['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f6'
|
||||
h2_pnic1['mac'] = '3F-0B-DD-8A-F3-BD'
|
||||
h2_pnic1['device'] = 'vmnic1'
|
||||
h2_pnic1['spec'] = {}
|
||||
h2_pnic1['spec']['ip'] = {}
|
||||
h2_pnic1['spec']['ip']['ipAddress'] = '10.11.14.1'
|
||||
h2_pnic1['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h2_pnic2 = {}
|
||||
h2_pnic2['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f7'
|
||||
h2_pnic2['mac'] = '3F-0B-DD-8A-F3-BE'
|
||||
h2_pnic2['device'] = 'vmnic2'
|
||||
h2_pnic2['spec'] = {}
|
||||
h2_pnic2['spec']['ip'] = {}
|
||||
h2_pnic2['spec']['ip']['ipAddress'] = '10.11.14.2'
|
||||
h2_pnic2['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h2_pnic_list = (h2_pnic1, h2_pnic2)
|
||||
h2_pnic_obj = MockNicContainer(h2_pnic_list)
|
||||
h2_pnics = MockProperty(h2_pnic_obj, 'config.network.pnic')
|
||||
h2_vnic1 = {}
|
||||
h2_vnic1['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f8'
|
||||
h2_vnic1['device'] = 'vmk1'
|
||||
h2_vnic1['portgroup'] = 'Management'
|
||||
h2_vnic1['spec'] = {}
|
||||
h2_vnic1['spec']['mac'] = '3F-0B-DD-8A-F3-BF'
|
||||
h2_vnic1['spec']['ip'] = {}
|
||||
h2_vnic1['spec']['ip']['ipAddress'] = '10.11.14.3'
|
||||
h2_vnic1['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h2_vnic2 = {}
|
||||
h2_vnic2['uuid'] = '9912c61d-79e0-4423-bb43-d79926e0d1f9'
|
||||
h2_vnic2['device'] = 'vmk2'
|
||||
h2_vnic2['portgroup'] = 'Public'
|
||||
h2_vnic2['spec'] = {}
|
||||
h2_vnic2['spec']['mac'] = '3F-0B-DD-8A-F3-C0'
|
||||
h2_vnic2['spec']['ip'] = {}
|
||||
h2_vnic2['spec']['ip']['ipAddress'] = '10.11.14.4'
|
||||
h2_vnic2['spec']['ip']['subnetMask'] = '255.255.255.0'
|
||||
h2_vnic_list = [h2_vnic1, h2_vnic2]
|
||||
h2_vnic_obj = MockNicContainer(h2_vnic_list)
|
||||
h2_vnics = MockProperty(h2_vnic_obj, 'config.network.vnic')
|
||||
mock_host2['propSet'] = [h2_uuid, h2_name, h2_DNS, h2_pnics, h2_vnics]
|
||||
mock_hostlist = [mock_host1, mock_host2]
|
||||
self.mock_rawhosts['objects'] = mock_hostlist
|
||||
self.mock_rawvms = {}
|
||||
mock_vm1 = {}
|
||||
mock_vm1['value'] = 'VM1'
|
||||
vm1_name = MockProperty('VM1', 'name')
|
||||
vm1_uuid = MockProperty('9912c61d-79e0-4423-bb43-d79926e0d200',
|
||||
'config.uuid')
|
||||
vm1_annotation = MockProperty('First VM', 'config.annotation')
|
||||
vm1_path = MockProperty('[Datastore] VM1/VM1.vmtx',
|
||||
'summary.config.vmPathName')
|
||||
vm1_memSize = MockProperty(4096, 'summary.config.memorySizeMB')
|
||||
vm1_status = MockProperty('green', 'summary.overallStatus')
|
||||
host1_referance = {}
|
||||
host1_referance['value'] = 'Host1'
|
||||
vm1_host = MockProperty(host1_referance, 'runtime.host')
|
||||
vm1_quickstats = {}
|
||||
vm1_quickstats['guestMemoryUsage'] = 245
|
||||
vm1_quickstats['overallCpuDemand'] = 216
|
||||
vm1_quickstats['overallCpuUsage'] = 192
|
||||
vm1_quickstats_property = MockProperty(vm1_quickstats,
|
||||
'summary.quickStats')
|
||||
vm1_storage = {}
|
||||
vm1_storage['committed'] = 25294964803
|
||||
vm1_storage['uncommitted'] = 32812040762
|
||||
vm1_storage_property = MockProperty(vm1_storage, 'summary.storage')
|
||||
mock_vm1['propSet'] = [vm1_name, vm1_uuid, vm1_annotation, vm1_path,
|
||||
vm1_memSize, vm1_status, vm1_host,
|
||||
vm1_quickstats_property, vm1_storage_property]
|
||||
mock_vm2 = {}
|
||||
mock_vm2['value'] = 'VM2'
|
||||
vm2_name = MockProperty('VM2', 'name')
|
||||
vm2_uuid = MockProperty('9912c61d-79e0-4423-bb43-d79926e0d201',
|
||||
'config.uuid')
|
||||
vm2_annotation = MockProperty('Second VM', 'config.annotation')
|
||||
vm2_path = MockProperty('[Datastore] VM2/VM2.vmtx',
|
||||
'summary.config.vmPathName')
|
||||
vm2_memSize = MockProperty(4096, 'summary.config.memorySizeMB')
|
||||
vm2_status = MockProperty('green', 'summary.overallStatus')
|
||||
host2_referance = {}
|
||||
host2_referance['value'] = 'Host2'
|
||||
vm2_host = MockProperty(host2_referance, 'runtime.host')
|
||||
vm2_quickstats = {}
|
||||
vm2_quickstats['guestMemoryUsage'] = 0
|
||||
vm2_quickstats['overallCpuDemand'] = 0
|
||||
vm2_quickstats['overallCpuUsage'] = 0
|
||||
vm2_quickstats_property = MockProperty(vm1_quickstats,
|
||||
'summary.quickStats')
|
||||
vm2_storage = {}
|
||||
vm2_storage['committed'] = 6271694636
|
||||
vm2_storage['uncommitted'] = 34110177822
|
||||
vm2_storage_property = MockProperty(vm2_storage, 'summary.storage')
|
||||
mock_vm2['propSet'] = [vm2_name, vm2_uuid, vm2_annotation, vm2_path,
|
||||
vm2_memSize, vm2_status, vm2_host,
|
||||
vm2_quickstats_property, vm2_storage_property]
|
||||
mock_vmlist = [mock_vm1, mock_vm2]
|
||||
self.mock_rawvms['objects'] = mock_vmlist
|
||||
|
||||
def test_translators(self):
|
||||
self.driver._translate_hosts(self.mock_rawhosts)
|
||||
expected_hosts = set([('Host1',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'895f69d340dac8cd4c9550e745703c77'),
|
||||
('Host2',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'895f69d340dac8cd4c9550e745703c77')])
|
||||
self.assertEqual(self.driver.state['hosts'], expected_hosts)
|
||||
expected_DNS = set([('895f69d340dac8cd4c9550e745703c77',
|
||||
'10.11.12.1'),
|
||||
('895f69d340dac8cd4c9550e745703c77',
|
||||
'10.11.12.2')])
|
||||
self.assertEqual(self.driver.state['host.DNS_IPs'], expected_DNS)
|
||||
expected_pnics = set([('9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'vmnic1',
|
||||
'3F-0B-DD-8A-F3-B9',
|
||||
'10.11.13.1',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'vmnic2',
|
||||
'3F-0B-DD-8A-F3-BA',
|
||||
'10.11.13.2',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'vmnic1',
|
||||
'3F-0B-DD-8A-F3-BD',
|
||||
'10.11.14.1',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'vmnic2',
|
||||
'3F-0B-DD-8A-F3-BE',
|
||||
'10.11.14.2',
|
||||
'255.255.255.0')])
|
||||
self.assertEqual(self.driver.state['host.PNICs'], expected_pnics)
|
||||
expected_vnics = set([('9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'vmk1',
|
||||
'3F-0B-DD-8A-F3-BB',
|
||||
'Management',
|
||||
'10.11.13.3',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'vmk2',
|
||||
'3F-0B-DD-8A-F3-BC',
|
||||
'Public',
|
||||
'10.11.13.4',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'vmk1',
|
||||
'3F-0B-DD-8A-F3-BF',
|
||||
'Management',
|
||||
'10.11.14.3',
|
||||
'255.255.255.0'),
|
||||
('9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'vmk2',
|
||||
'3F-0B-DD-8A-F3-C0',
|
||||
'Public',
|
||||
'10.11.14.4',
|
||||
'255.255.255.0')])
|
||||
self.assertEqual(self.driver.state['host.VNICs'], expected_vnics)
|
||||
self.driver._translate_vms(self.mock_rawvms)
|
||||
expected_vms = set([('VM1',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d200',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d1f0',
|
||||
'[Datastore] VM1/VM1.vmtx',
|
||||
'green',
|
||||
216,
|
||||
192,
|
||||
4096,
|
||||
245,
|
||||
25294964803,
|
||||
32812040762,
|
||||
'First VM'),
|
||||
('VM2',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d201',
|
||||
'9912c61d-79e0-4423-bb43-d79926e0d1f5',
|
||||
'[Datastore] VM2/VM2.vmtx',
|
||||
'green',
|
||||
216,
|
||||
192,
|
||||
4096,
|
||||
245,
|
||||
6271694636,
|
||||
34110177822,
|
||||
'Second VM')])
|
||||
self.assertEqual(self.driver.state['vms'], expected_vms)
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2014 Marist SDN Innovation lab Joint with Plexxi Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
class MockProperty(object):
|
||||
def __init__(self, val, name):
|
||||
self.val = val
|
||||
self.name = name
|
||||
|
||||
|
||||
class MockDNSInfo(object):
|
||||
def __init__(self, string):
|
||||
self.string = string
|
||||
|
||||
|
||||
class MockvCenterHost(dict):
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
|
||||
|
||||
class MockNicContainer(object):
|
||||
def __init__(self, nicList):
|
||||
self.PhysicalNic = nicList
|
||||
self.HostVirtualNic = nicList
|
|
@ -54,3 +54,10 @@ tenant_name: admin
|
|||
#auth_url: http://PlexxiCoreURL/PlexxiCore/api
|
||||
#unique_names: False
|
||||
|
||||
#[vCenter]
|
||||
#module:datasources/vCenter_driver.py
|
||||
#username: vCenter_username
|
||||
#password: vCenter_password
|
||||
#auth_url: vCenterURL
|
||||
#max_Hosts: 999
|
||||
#max_VMs: 999
|
||||
|
|
|
@ -24,4 +24,5 @@ oslo.config>=1.4.0 # Apache-2.0
|
|||
oslo.db>=1.1.0 # Apache-2.0
|
||||
oslo.serialization>=1.0.0 # Apache-2.0
|
||||
oslo.middleware>=0.1.0 # Apache-2.0
|
||||
oslo.vmware>=0.8.0
|
||||
WebOb>=1.2.3
|
||||
|
|
Loading…
Reference in New Issue