mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
redfish: refactor service_root variable (#56198)
This commit is contained in:
parent
64b30b172e
commit
0d842ff539
7 changed files with 36 additions and 44 deletions
|
@ -20,12 +20,13 @@ DELETE_HEADERS = {'accept': 'application/json', 'OData-Version': '4.0'}
|
||||||
|
|
||||||
class RedfishUtils(object):
|
class RedfishUtils(object):
|
||||||
|
|
||||||
def __init__(self, creds, root_uri, timeout):
|
def __init__(self, creds, root_uri, timeout, module):
|
||||||
self.root_uri = root_uri
|
self.root_uri = root_uri
|
||||||
self.creds = creds
|
self.creds = creds
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.module = module
|
||||||
|
self.service_root = '/redfish/v1/'
|
||||||
self._init_session()
|
self._init_session()
|
||||||
return
|
|
||||||
|
|
||||||
# The following functions are to send GET/POST/PATCH/DELETE requests
|
# The following functions are to send GET/POST/PATCH/DELETE requests
|
||||||
def get_request(self, uri):
|
def get_request(self, uri):
|
||||||
|
@ -154,8 +155,8 @@ class RedfishUtils(object):
|
||||||
def _init_session(self):
|
def _init_session(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _find_accountservice_resource(self, uri):
|
def _find_accountservice_resource(self):
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
@ -173,8 +174,8 @@ class RedfishUtils(object):
|
||||||
self.accounts_uri = accounts
|
self.accounts_uri = accounts
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
def _find_sessionservice_resource(self, uri):
|
def _find_sessionservice_resource(self):
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
@ -192,8 +193,8 @@ class RedfishUtils(object):
|
||||||
self.sessions_uri = sessions
|
self.sessions_uri = sessions
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
def _find_systems_resource(self, uri):
|
def _find_systems_resource(self):
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
@ -210,8 +211,8 @@ class RedfishUtils(object):
|
||||||
'msg': "ComputerSystem's Members array is either empty or missing"}
|
'msg': "ComputerSystem's Members array is either empty or missing"}
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
def _find_updateservice_resource(self, uri):
|
def _find_updateservice_resource(self):
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
@ -228,9 +229,9 @@ class RedfishUtils(object):
|
||||||
self.firmware_uri = firmware_inventory
|
self.firmware_uri = firmware_inventory
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
def _find_chassis_resource(self, uri):
|
def _find_chassis_resource(self):
|
||||||
chassis_service = []
|
chassis_service = []
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
@ -247,8 +248,8 @@ class RedfishUtils(object):
|
||||||
self.chassis_uri_list = chassis_service
|
self.chassis_uri_list = chassis_service
|
||||||
return {'ret': True}
|
return {'ret': True}
|
||||||
|
|
||||||
def _find_managers_resource(self, uri):
|
def _find_managers_resource(self):
|
||||||
response = self.get_request(self.root_uri + uri)
|
response = self.get_request(self.root_uri + self.service_root)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
|
|
@ -149,8 +149,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
@ -166,14 +165,14 @@ def main():
|
||||||
|
|
||||||
if category == "Systems":
|
if category == "Systems":
|
||||||
# execute only if we find a System resource
|
# execute only if we find a System resource
|
||||||
result = rf_utils._find_systems_resource(rf_uri)
|
result = rf_utils._find_systems_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
for command in command_list:
|
for command in command_list:
|
||||||
if command == "CreateBiosConfigJob":
|
if command == "CreateBiosConfigJob":
|
||||||
# execute only if we find a Managers resource
|
# execute only if we find a Managers resource
|
||||||
result = rf_utils._find_managers_resource(rf_uri)
|
result = rf_utils._find_managers_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
result = rf_utils.create_bios_config_job()
|
result = rf_utils.create_bios_config_job()
|
||||||
|
|
|
@ -100,7 +100,6 @@ msg:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.redfish_utils import RedfishUtils
|
from ansible.module_utils.redfish_utils import RedfishUtils
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
@ -184,8 +183,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
@ -201,7 +199,7 @@ def main():
|
||||||
|
|
||||||
if category == "Manager":
|
if category == "Manager":
|
||||||
# execute only if we find a Manager resource
|
# execute only if we find a Manager resource
|
||||||
result = rf_utils._find_managers_resource(rf_uri)
|
result = rf_utils._find_managers_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,6 @@ msg:
|
||||||
sample: List of Manager attributes
|
sample: List of Manager attributes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.redfish_utils import RedfishUtils
|
from ansible.module_utils.redfish_utils import RedfishUtils
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
@ -128,8 +127,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = IdracRedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = IdracRedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
@ -145,7 +143,7 @@ def main():
|
||||||
|
|
||||||
if category == "Manager":
|
if category == "Manager":
|
||||||
# execute only if we find a Manager resource
|
# execute only if we find a Manager resource
|
||||||
result = rf_utils._find_managers_resource(rf_uri)
|
result = rf_utils._find_managers_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
|
|
@ -238,8 +238,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = RedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
@ -263,7 +262,7 @@ def main():
|
||||||
}
|
}
|
||||||
|
|
||||||
# execute only if we find an Account service resource
|
# execute only if we find an Account service resource
|
||||||
result = rf_utils._find_accountservice_resource(rf_uri)
|
result = rf_utils._find_accountservice_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
@ -272,7 +271,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Systems":
|
elif category == "Systems":
|
||||||
# execute only if we find a System resource
|
# execute only if we find a System resource
|
||||||
result = rf_utils._find_systems_resource(rf_uri)
|
result = rf_utils._find_systems_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
@ -286,7 +285,7 @@ def main():
|
||||||
module.params['boot_next'])
|
module.params['boot_next'])
|
||||||
|
|
||||||
elif category == "Chassis":
|
elif category == "Chassis":
|
||||||
result = rf_utils._find_chassis_resource(rf_uri)
|
result = rf_utils._find_chassis_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
@ -308,7 +307,7 @@ def main():
|
||||||
}
|
}
|
||||||
|
|
||||||
# execute only if we find a Manager service resource
|
# execute only if we find a Manager service resource
|
||||||
result = rf_utils._find_managers_resource(rf_uri)
|
result = rf_utils._find_managers_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
|
|
@ -157,8 +157,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = RedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Check that Category is valid
|
# Check that Category is valid
|
||||||
if category not in CATEGORY_COMMANDS_ALL:
|
if category not in CATEGORY_COMMANDS_ALL:
|
||||||
|
@ -173,7 +172,7 @@ def main():
|
||||||
# Organize by Categories / Commands
|
# Organize by Categories / Commands
|
||||||
if category == "Systems":
|
if category == "Systems":
|
||||||
# execute only if we find a System resource
|
# execute only if we find a System resource
|
||||||
result = rf_utils._find_systems_resource(rf_uri)
|
result = rf_utils._find_systems_resource()
|
||||||
if result['ret'] is False:
|
if result['ret'] is False:
|
||||||
module.fail_json(msg=to_native(result['msg']))
|
module.fail_json(msg=to_native(result['msg']))
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,6 @@ CATEGORY_COMMANDS_DEFAULT = {
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
result = {}
|
result = {}
|
||||||
resource = {}
|
|
||||||
category_list = []
|
category_list = []
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
|
@ -258,8 +257,7 @@ def main():
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_uri = "/redfish/v1/"
|
rf_utils = RedfishUtils(creds, root_uri, timeout, module)
|
||||||
rf_utils = RedfishUtils(creds, root_uri, timeout)
|
|
||||||
|
|
||||||
# Build Category list
|
# Build Category list
|
||||||
if "all" in module.params['category']:
|
if "all" in module.params['category']:
|
||||||
|
@ -294,7 +292,7 @@ def main():
|
||||||
# Organize by Categories / Commands
|
# Organize by Categories / Commands
|
||||||
if category == "Systems":
|
if category == "Systems":
|
||||||
# execute only if we find a Systems resource
|
# execute only if we find a Systems resource
|
||||||
resource = rf_utils._find_systems_resource(rf_uri)
|
resource = rf_utils._find_systems_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
@ -322,7 +320,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Chassis":
|
elif category == "Chassis":
|
||||||
# execute only if we find Chassis resource
|
# execute only if we find Chassis resource
|
||||||
resource = rf_utils._find_chassis_resource(rf_uri)
|
resource = rf_utils._find_chassis_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
@ -340,7 +338,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Accounts":
|
elif category == "Accounts":
|
||||||
# execute only if we find an Account service resource
|
# execute only if we find an Account service resource
|
||||||
resource = rf_utils._find_accountservice_resource(rf_uri)
|
resource = rf_utils._find_accountservice_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
@ -350,7 +348,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Update":
|
elif category == "Update":
|
||||||
# execute only if we find UpdateService resources
|
# execute only if we find UpdateService resources
|
||||||
resource = rf_utils._find_updateservice_resource(rf_uri)
|
resource = rf_utils._find_updateservice_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
@ -362,7 +360,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Sessions":
|
elif category == "Sessions":
|
||||||
# excute only if we find SessionService resources
|
# excute only if we find SessionService resources
|
||||||
resource = rf_utils._find_sessionservice_resource(rf_uri)
|
resource = rf_utils._find_sessionservice_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
@ -372,7 +370,7 @@ def main():
|
||||||
|
|
||||||
elif category == "Manager":
|
elif category == "Manager":
|
||||||
# execute only if we find a Manager service resource
|
# execute only if we find a Manager service resource
|
||||||
resource = rf_utils._find_managers_resource(rf_uri)
|
resource = rf_utils._find_managers_resource()
|
||||||
if resource['ret'] is False:
|
if resource['ret'] is False:
|
||||||
module.fail_json(msg=resource['msg'])
|
module.fail_json(msg=resource['msg'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue