Update configuration
driver arguments were moved to separate 'args' field in cloud_config Change-Id: If8100b19b56a127b448052e9a8ece5677e9f8ce5
This commit is contained in:
parent
5126c62456
commit
0ff915cc04
12
README.rst
12
README.rst
@ -26,13 +26,17 @@ library:
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'devstack',
|
||||
'address': 'devstack.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'devstack.local',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'libvirt',
|
||||
'address': 'host.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'host.local',
|
||||
'username': 'root',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,13 +14,17 @@ library:
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'devstack',
|
||||
'address': 'devstack.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'devstack.local',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'libvirt',
|
||||
'address': 'host.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'host.local',
|
||||
'username': 'root',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,10 @@ def main():
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'devstack',
|
||||
'address': 'devstack.local',
|
||||
'username': 'developer',
|
||||
'args': {
|
||||
'address': 'devstack.local',
|
||||
'username': 'developer',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,16 +20,20 @@ def main():
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'fuel',
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'ipmi',
|
||||
'mac_to_bmc': {
|
||||
'00:00:00:00:00:00': {
|
||||
'address': '55.55.55.55',
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
'args': {
|
||||
'mac_to_bmc': {
|
||||
'00:00:00:00:00:00': {
|
||||
'address': '55.55.55.55',
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,16 @@ def main():
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'fuel',
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'libvirt',
|
||||
'connection_uri': "qemu+ssh://ubuntu@host.local/system"
|
||||
'args': {
|
||||
'connection_uri': "qemu+ssh://ubuntu@host.local/system"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +48,7 @@ def main():
|
||||
one.poweroff()
|
||||
one.poweron()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
|
||||
level=logging.DEBUG)
|
||||
|
@ -20,13 +20,17 @@ def main():
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'fuel',
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
'private_key_file': '~/.ssh/os_faults',
|
||||
'args': {
|
||||
'address': 'fuel.local',
|
||||
'username': 'root',
|
||||
'private_key_file': '~/.ssh/os_faults',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'libvirt',
|
||||
'connection_uri': 'qemu+ssh://ubuntu@host.local/system'
|
||||
'args': {
|
||||
'connection_uri': 'qemu+ssh://ubuntu@host.local/system'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,16 +52,8 @@ def _read_config(config_filename):
|
||||
|
||||
|
||||
def _init_driver(params):
|
||||
all_drivers = registry.get_drivers()
|
||||
|
||||
name = params.get('driver')
|
||||
if not name:
|
||||
return None
|
||||
|
||||
if name not in all_drivers:
|
||||
raise error.OSFError('Driver %s is not found' % name)
|
||||
|
||||
return all_drivers[name](params)
|
||||
driver_cls = registry.get_driver(params['driver'])
|
||||
return driver_cls(params.get('args', {}))
|
||||
|
||||
|
||||
def connect(cloud_config=None, config_filename=None):
|
||||
@ -71,19 +63,19 @@ def connect(cloud_config=None, config_filename=None):
|
||||
:param config_filename: name of the file where to read config from
|
||||
:return: CloudManagement object
|
||||
"""
|
||||
if not cloud_config:
|
||||
if cloud_config is None:
|
||||
cloud_config = _read_config(config_filename)
|
||||
|
||||
cloud_management_params = cloud_config.get('cloud_management') or {}
|
||||
cloud_management = _init_driver(cloud_management_params)
|
||||
|
||||
if not cloud_management:
|
||||
if 'cloud_management' not in cloud_config:
|
||||
raise error.OSFError('Cloud management driver name is not specified')
|
||||
|
||||
power_management_params = cloud_config.get('power_management') or {}
|
||||
power_management = _init_driver(power_management_params)
|
||||
cloud_management_conf = cloud_config['cloud_management']
|
||||
cloud_management = _init_driver(cloud_management_conf)
|
||||
|
||||
cloud_management.set_power_management(power_management)
|
||||
power_management_conf = cloud_config.get('power_management', {})
|
||||
if power_management_conf:
|
||||
power_management = _init_driver(power_management_conf)
|
||||
cloud_management.set_power_management(power_management)
|
||||
|
||||
return cloud_management
|
||||
|
||||
|
@ -30,3 +30,7 @@ class ServiceError(OSFError):
|
||||
|
||||
class NodeCollectionError(OSFError):
|
||||
"""Base Error class for NodeCollection API"""
|
||||
|
||||
|
||||
class OSFDriverNotFound(OSFError):
|
||||
"""Driver Not Found by os-faults registry"""
|
||||
|
@ -18,6 +18,7 @@ import sys
|
||||
from oslo_utils import importutils
|
||||
|
||||
from os_faults.api import base_driver
|
||||
from os_faults.api import error
|
||||
from os_faults import drivers
|
||||
|
||||
DRIVERS = {}
|
||||
@ -57,7 +58,7 @@ def _list_drivers():
|
||||
klazz = class_info[1]
|
||||
|
||||
if issubclass(klazz, base_driver.BaseDriver):
|
||||
yield class_info[1]
|
||||
yield klazz
|
||||
|
||||
|
||||
def get_drivers():
|
||||
@ -67,3 +68,12 @@ def get_drivers():
|
||||
DRIVERS = dict((k.get_driver_name(), k) for k in _list_drivers())
|
||||
|
||||
return DRIVERS
|
||||
|
||||
|
||||
def get_driver(name):
|
||||
all_drivers = get_drivers()
|
||||
|
||||
if name not in all_drivers:
|
||||
raise error.OSFDriverNotFound('Driver %s is not found' % name)
|
||||
|
||||
return all_drivers[name]
|
||||
|
@ -31,12 +31,16 @@ class OSFaultsTestCase(test.TestCase):
|
||||
self.cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'fuel',
|
||||
'address': '10.30.00.5',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': '10.30.00.5',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'libvirt',
|
||||
'connection_uri': "qemu+ssh://user@10.30.20.21/system"
|
||||
'args': {
|
||||
'connection_uri': "qemu+ssh://user@10.30.20.21/system"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,8 +48,10 @@ class OSFaultsTestCase(test.TestCase):
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'devstack',
|
||||
'address': 'devstack.local',
|
||||
'username': 'developer',
|
||||
'args': {
|
||||
'address': 'devstack.local',
|
||||
'username': 'developer',
|
||||
}
|
||||
}
|
||||
}
|
||||
destructor = os_faults.connect(cloud_config)
|
||||
@ -61,16 +67,20 @@ class OSFaultsTestCase(test.TestCase):
|
||||
cloud_config = {
|
||||
'cloud_management': {
|
||||
'driver': 'fuel',
|
||||
'address': '10.30.00.5',
|
||||
'username': 'root',
|
||||
'args': {
|
||||
'address': '10.30.00.5',
|
||||
'username': 'root',
|
||||
}
|
||||
},
|
||||
'power_management': {
|
||||
'driver': 'ipmi',
|
||||
'mac_to_bmc': {
|
||||
'00:00:00:00:00:00': {
|
||||
'address': '55.55.55.55',
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
'args': {
|
||||
'mac_to_bmc': {
|
||||
'00:00:00:00:00:00': {
|
||||
'address': '55.55.55.55',
|
||||
'username': 'foo',
|
||||
'password': 'bar',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -85,10 +95,11 @@ class OSFaultsTestCase(test.TestCase):
|
||||
'driver': 'non-existing',
|
||||
}
|
||||
}
|
||||
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
|
||||
self.assertRaises(
|
||||
error.OSFDriverNotFound, os_faults.connect, cloud_config)
|
||||
|
||||
def test_connect_driver_not_specified(self):
|
||||
cloud_config = {}
|
||||
cloud_config = {'foo': 'bar'}
|
||||
self.assertRaises(error.OSFError, os_faults.connect, cloud_config)
|
||||
|
||||
@mock.patch('os.path.exists', return_value=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user