Allow set RSD related environment variables
Make this plugin can recognize RSD arguments from environment variables, include RSD_URL, RSD_USERNAME, RSD_PASSWORD and RSD_VERIFY. So user can set them in environment variables to avoid input them in every command. Change-Id: I1b4fe8fc529b504b0f80d40427132e8b9364627c
This commit is contained in:
parent
d87091cc1e
commit
e04d2d5421
@ -51,3 +51,14 @@ def print_dict(obj_list, field_names):
|
||||
pt.add_row([element.get(i.lower(), None) for i in field_names])
|
||||
|
||||
return pt
|
||||
|
||||
|
||||
def str2boolean(string_obj):
|
||||
"""Convert string 'True' and 'False' to corresponding boolean obj"""
|
||||
|
||||
if string_obj.lower() == "true":
|
||||
return True
|
||||
elif string_obj.lower() == "false":
|
||||
return False
|
||||
else:
|
||||
return string_obj
|
||||
|
@ -19,6 +19,9 @@ import logging
|
||||
|
||||
from osc_lib import utils
|
||||
|
||||
from rsdclient.common import utils as rsdclient_utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_API_VERSION = '1.2'
|
||||
@ -37,10 +40,11 @@ def make_client(instance):
|
||||
API_VERSIONS)
|
||||
LOG.debug('Instantiating RSD client: %s', rsd_client)
|
||||
|
||||
client = rsd_client(base_url=instance._cli_options.rsd_url,
|
||||
username=instance._cli_options.rsd_username,
|
||||
password=instance._cli_options.rsd_password,
|
||||
verify=instance._cli_options.rsd_disable_verify)
|
||||
client = rsd_client(
|
||||
base_url=instance._cli_options.rsd_url,
|
||||
username=instance._cli_options.rsd_username,
|
||||
password=instance._cli_options.rsd_password,
|
||||
verify=rsdclient_utils.str2boolean(instance._cli_options.rsd_verify))
|
||||
return client
|
||||
|
||||
|
||||
@ -52,28 +56,41 @@ def build_option_parser(parser):
|
||||
metavar='<rsd-api-version>',
|
||||
default=utils.env(
|
||||
'RSD_API_VERSION',
|
||||
default=DEFAULT_API_VERSION),
|
||||
default='1.3'),
|
||||
help='RSD API version, default=' +
|
||||
DEFAULT_API_VERSION +
|
||||
' (Env: RSD_API_VERSION)')
|
||||
parser.add_argument(
|
||||
'--rsd-url',
|
||||
metavar='<rsd-url>',
|
||||
default='https://localhost:8443/redfish/v1/',
|
||||
help='The base URL to RSD pod manager')
|
||||
default=utils.env(
|
||||
'RSD_URL',
|
||||
default='https://localhost:8443/redfish/v1/'),
|
||||
help='The base URL to RSD pod manager (Env: RSD_URL)')
|
||||
parser.add_argument(
|
||||
'--rsd-username',
|
||||
metavar='<rsd-username>',
|
||||
default='admin',
|
||||
help='User account with admin access')
|
||||
default=utils.env(
|
||||
'RSD_USERNAME',
|
||||
default='admin'),
|
||||
help='User account with admin access (Env: RSD_USERNAME)')
|
||||
parser.add_argument(
|
||||
'--rsd-password',
|
||||
metavar='<rsd-password>',
|
||||
default='admin',
|
||||
help='User account password')
|
||||
default=utils.env(
|
||||
'RSD_PASSWORD',
|
||||
default='admin'),
|
||||
help='User account password (Env: RSD_PASSWORD)')
|
||||
parser.add_argument(
|
||||
'--rsd-disable-verify',
|
||||
action='store_false',
|
||||
help='If this is set, it will ignore verifying the SSL ' +
|
||||
'certificate')
|
||||
'--rsd-verify',
|
||||
metavar='<rsd-username>',
|
||||
default=utils.env(
|
||||
'RSD_VERIFY',
|
||||
default='True'),
|
||||
help='Either a boolean value, a path to a CA_BUNDLE file or directory'
|
||||
' with certificates of trusted CAs. If set to True it will '
|
||||
'verify the host certificates; if False it will ignore verifying'
|
||||
' the SSL certificate; if it\'s a path the driver will use the '
|
||||
'specified certificate or one of the certificates in the '
|
||||
'directory. Defaults to True. (Env: RSD_VERIFY)')
|
||||
return parser
|
||||
|
@ -21,8 +21,16 @@ from rsdclient.tests.common import fakes
|
||||
|
||||
class UtilsTest(testtools.TestCase):
|
||||
|
||||
def test_compose_node(self):
|
||||
def test_extract_attr(self):
|
||||
fake_node = fakes.FakeNode()
|
||||
result = utils.extract_attr(fake_node)
|
||||
expected = fakes.FAKE_NODE_PYTHON_DICT
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
def test_str2boolean(self):
|
||||
self.assertEqual(utils.str2boolean("True"), True)
|
||||
self.assertEqual(utils.str2boolean("true"), True)
|
||||
self.assertEqual(utils.str2boolean("False"), False)
|
||||
self.assertEqual(utils.str2boolean("false"), False)
|
||||
self.assertEqual(utils.str2boolean("fake string"), "fake string")
|
||||
self.assertEqual(utils.str2boolean(""), "")
|
||||
|
@ -23,6 +23,19 @@ from rsdclient.v1 import storage_service
|
||||
class Client(object):
|
||||
|
||||
def __init__(self, base_url, username, password, verify=True):
|
||||
"""A client class to control RSD pod manager
|
||||
|
||||
:param base_url: The base URL to RSD pod manager.
|
||||
:param username: User account with admin access privilege
|
||||
:param password: User account password
|
||||
:param verify: Either a boolean value, a path to a CA_BUNDLE
|
||||
file or directory with certificates of trusted CAs. If set to
|
||||
True it will verify the host certificates; if False it will
|
||||
ignore verifying the SSL certificate; if it's a path the driver
|
||||
will use the specified certificate or one of the certificates
|
||||
in the directory. Defaults to True.
|
||||
"""
|
||||
|
||||
self.client = rsd_lib.RSDLib(base_url, username, password,
|
||||
verify=verify)
|
||||
self.node = node.NodeManager(self.client)
|
||||
|
Loading…
x
Reference in New Issue
Block a user