diff options
author | Ruby Loo <rloo@yahoo-inc.com> | 2014-07-15 10:02:18 -0400 |
---|---|---|
committer | Ruby Loo <rloo@yahoo-inc.com> | 2014-07-23 03:10:45 +0000 |
commit | c75a070520b02deafe61343157d3a4219374f6d3 (patch) | |
tree | ca0f468abab952939f4d52bbb3f2835915cbff57 /ironic/drivers/modules/ssh.py | |
parent | bf809fdf085357b244fda82f86341add3b8bd316 (diff) | |
download | ironic-c75a070520b02deafe61343157d3a4219374f6d3.tar.gz |
Add drivers.base.BaseDriver.get_properties()
Adds ironic.drivers.base.BaseDriver.get_properties() which returns a
dictionary of <property>:<description> entries.
The driver interfaces (DeployInterface, PowerInterface, ...) have a
new get_properties() method that returns a dictionary of
<property>:<description>.
These changes are needed in order to provide an API to get driver_info
properties.
Change-Id: I5994e990deb26841633ca26de1a5fb63b743271a
Blueprint: get-required-driver-info
Partial-Bug: #1261915
Diffstat (limited to 'ironic/drivers/modules/ssh.py')
-rw-r--r-- | ironic/drivers/modules/ssh.py | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/ironic/drivers/modules/ssh.py b/ironic/drivers/modules/ssh.py index 2d8d470f8..50cc0270a 100644 --- a/ironic/drivers/modules/ssh.py +++ b/ironic/drivers/modules/ssh.py @@ -35,6 +35,7 @@ from ironic.common import utils from ironic.conductor import task_manager from ironic.drivers import base from ironic.drivers import utils as driver_utils +from ironic.openstack.common.gettextutils import _ from ironic.openstack.common import log as logging from ironic.openstack.common import processutils @@ -49,6 +50,27 @@ CONF.register_opts(libvirt_opts, group='ssh') LOG = logging.getLogger(__name__) +REQUIRED_PROPERTIES = { + 'ssh_address': _("IP address or hostname of the node to ssh into. " + "Required."), + 'ssh_username': _("username to authenticate as. Required."), + 'ssh_virt_type': _("virtualization software to use; one of vbox, virsh, " + "vmware. Required.") +} +OTHER_PROPERTIES = { + 'ssh_key_contents': _("private key(s). One of this, ssh_key_filename, " + "or ssh_password must be specified."), + 'ssh_key_filename': _("(list of) filename(s) of optional private key(s) " + "for authentication. One of this, ssh_key_contents, " + "or ssh_password must be specified."), + 'ssh_password': _("password to use for authentication or for unlocking a " + "private key. One of this, ssh_key_contents, or " + "ssh_key_filename must be specified."), + 'ssh_port': _("port on the node to connect to; default is 22. Optional.") +} +COMMON_PROPERTIES = REQUIRED_PROPERTIES.copy() +COMMON_PROPERTIES.update(OTHER_PROPERTIES) + def _get_command_sets(virt_type): if virt_type == 'vbox': @@ -155,6 +177,12 @@ def _parse_driver_info(node): """ info = node.driver_info or {} + missing_info = [key for key in REQUIRED_PROPERTIES if not info.get(key)] + if missing_info: + raise exception.InvalidParameterValue(_( + "SSHPowerDriver requires the following to be set: %s.") + % missing_info) + address = info.get('ssh_address') username = info.get('ssh_username') password = info.get('ssh_password') @@ -176,16 +204,9 @@ def _parse_driver_info(node): 'uuid': node.uuid } - if not virt_type: - raise exception.InvalidParameterValue(_( - "SSHPowerDriver requires virt_type be set.")) - cmd_set = _get_command_sets(virt_type) res['cmd_set'] = cmd_set - if not address or not username: - raise exception.InvalidParameterValue(_( - "SSHPowerDriver requires both address and username be set.")) # Only one credential may be set (avoids complexity around having # precedence etc). if len(filter(None, (password, key_filename, key_contents))) != 1: @@ -354,6 +375,9 @@ class SSHPower(base.PowerInterface): NOTE: This driver does not currently support multi-node operations. """ + def get_properties(self): + return COMMON_PROPERTIES + def validate(self, task): """Check that the node's 'driver_info' is valid. |