add new command SetManagerNic in redfish_config module (#64477)
* add new command SetManagerNic in redfish_config module * use a more explicit/rigorous way to select the EthernetInterface, split port for default nic_addr if root_uri has port, update variable name to lower_case_with_underscores instead of CamelCase * add missing whitespace around arithmetic operator, fix inline comment should start with '# '
This commit is contained in:
parent
f51f87a986
commit
a7716ae7a9
2 changed files with 130 additions and 2 deletions
|
@ -2263,3 +2263,92 @@ class RedfishUtils(object):
|
||||||
|
|
||||||
def get_multi_manager_health_report(self):
|
def get_multi_manager_health_report(self):
|
||||||
return self.aggregate_managers(self.get_manager_health_report)
|
return self.aggregate_managers(self.get_manager_health_report)
|
||||||
|
|
||||||
|
def set_manager_nic(self, nic_addr, nic_config):
|
||||||
|
# Get EthernetInterface collection
|
||||||
|
response = self.get_request(self.root_uri + self.manager_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
data = response['data']
|
||||||
|
if 'EthernetInterfaces' not in data:
|
||||||
|
return {'ret': False, 'msg': "EthernetInterfaces resource not found"}
|
||||||
|
ethernetinterfaces_uri = data["EthernetInterfaces"]["@odata.id"]
|
||||||
|
response = self.get_request(self.root_uri + ethernetinterfaces_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
data = response['data']
|
||||||
|
uris = [a.get('@odata.id') for a in data.get('Members', []) if
|
||||||
|
a.get('@odata.id')]
|
||||||
|
|
||||||
|
# Find target EthernetInterface
|
||||||
|
target_ethernet_uri = None
|
||||||
|
target_ethernet_current_setting = None
|
||||||
|
if nic_addr == 'null':
|
||||||
|
# Find root_uri matched EthernetInterface when nic_addr is not specified
|
||||||
|
nic_addr = (self.root_uri).split('/')[-1]
|
||||||
|
nic_addr = nic_addr.split(':')[0] # split port if existing
|
||||||
|
for uri in uris:
|
||||||
|
response = self.get_request(self.root_uri + uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
data = response['data']
|
||||||
|
if '"' + nic_addr + '"' in str(data) or "'" + nic_addr + "'" in str(data):
|
||||||
|
target_ethernet_uri = uri
|
||||||
|
target_ethernet_current_setting = data
|
||||||
|
break
|
||||||
|
if target_ethernet_uri is None:
|
||||||
|
return {'ret': False, 'msg': "No matched EthernetInterface found under Manager"}
|
||||||
|
|
||||||
|
# Convert input to payload and check validity
|
||||||
|
payload = {}
|
||||||
|
for property in nic_config.keys():
|
||||||
|
value = nic_config[property]
|
||||||
|
if property not in target_ethernet_current_setting:
|
||||||
|
return {'ret': False, 'msg': "Property %s in nic_config is invalid" % property}
|
||||||
|
if isinstance(value, dict):
|
||||||
|
if isinstance(target_ethernet_current_setting[property], dict):
|
||||||
|
payload[property] = value
|
||||||
|
elif isinstance(target_ethernet_current_setting[property], list):
|
||||||
|
payload[property] = list()
|
||||||
|
payload[property].append(value)
|
||||||
|
else:
|
||||||
|
return {'ret': False, 'msg': "Value of property %s in nic_config is invalid" % property}
|
||||||
|
else:
|
||||||
|
payload[property] = value
|
||||||
|
|
||||||
|
# If no need change, nothing to do. If error detected, report it
|
||||||
|
need_change = False
|
||||||
|
for property in payload.keys():
|
||||||
|
set_value = payload[property]
|
||||||
|
cur_value = target_ethernet_current_setting[property]
|
||||||
|
# type is simple(not dict/list)
|
||||||
|
if not isinstance(set_value, dict) and not isinstance(set_value, list):
|
||||||
|
if set_value != cur_value:
|
||||||
|
need_change = True
|
||||||
|
# type is dict
|
||||||
|
if isinstance(set_value, dict):
|
||||||
|
for subprop in payload[property].keys():
|
||||||
|
if subprop not in target_ethernet_current_setting[property]:
|
||||||
|
return {'ret': False, 'msg': "Sub-property %s in nic_config is invalid" % subprop}
|
||||||
|
sub_set_value = payload[property][subprop]
|
||||||
|
sub_cur_value = target_ethernet_current_setting[property][subprop]
|
||||||
|
if sub_set_value != sub_cur_value:
|
||||||
|
need_change = True
|
||||||
|
# type is list
|
||||||
|
if isinstance(set_value, list):
|
||||||
|
for i in range(len(set_value)):
|
||||||
|
for subprop in payload[property][i].keys():
|
||||||
|
if subprop not in target_ethernet_current_setting[property][i]:
|
||||||
|
return {'ret': False, 'msg': "Sub-property %s in nic_config is invalid" % subprop}
|
||||||
|
sub_set_value = payload[property][i][subprop]
|
||||||
|
sub_cur_value = target_ethernet_current_setting[property][i][subprop]
|
||||||
|
if sub_set_value != sub_cur_value:
|
||||||
|
need_change = True
|
||||||
|
|
||||||
|
if not need_change:
|
||||||
|
return {'ret': True, 'changed': False, 'msg': "Manager NIC already set"}
|
||||||
|
|
||||||
|
response = self.patch_request(self.root_uri + target_ethernet_uri, payload)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
return {'ret': True, 'changed': True, 'msg': "Modified Manager NIC"}
|
||||||
|
|
|
@ -94,6 +94,19 @@ options:
|
||||||
- The ID of the System, Manager or Chassis to modify
|
- The ID of the System, Manager or Chassis to modify
|
||||||
type: str
|
type: str
|
||||||
version_added: "2.10"
|
version_added: "2.10"
|
||||||
|
nic_addr:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- EthernetInterface Address string on OOB controller
|
||||||
|
default: 'null'
|
||||||
|
type: str
|
||||||
|
version_added: '2.10'
|
||||||
|
nic_config:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- setting dict of EthernetInterface on OOB controller
|
||||||
|
type: dict
|
||||||
|
version_added: '2.10'
|
||||||
|
|
||||||
author: "Jose Delarosa (@jose-delarosa)"
|
author: "Jose Delarosa (@jose-delarosa)"
|
||||||
'''
|
'''
|
||||||
|
@ -180,6 +193,21 @@ EXAMPLES = '''
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
|
||||||
|
- name: Set Manager NIC
|
||||||
|
redfish_config:
|
||||||
|
category: Manager
|
||||||
|
command: SetManagerNic
|
||||||
|
nic_config:
|
||||||
|
DHCPv4:
|
||||||
|
DHCPEnabled: False
|
||||||
|
IPv4StaticAddresses:
|
||||||
|
Address: 192.168.1.3
|
||||||
|
Gateway: 192.168.1.1
|
||||||
|
SubnetMask: 255.255.255.0
|
||||||
|
baseuri: "{{ baseuri }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -199,7 +227,7 @@ from ansible.module_utils._text import to_native
|
||||||
CATEGORY_COMMANDS_ALL = {
|
CATEGORY_COMMANDS_ALL = {
|
||||||
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
||||||
"SetDefaultBootOrder"],
|
"SetDefaultBootOrder"],
|
||||||
"Manager": ["SetNetworkProtocols"]
|
"Manager": ["SetNetworkProtocols", "SetManagerNic"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,7 +249,12 @@ def main():
|
||||||
type='dict',
|
type='dict',
|
||||||
default={}
|
default={}
|
||||||
),
|
),
|
||||||
resource_id=dict()
|
resource_id=dict(),
|
||||||
|
nic_addr=dict(default='null'),
|
||||||
|
nic_config=dict(
|
||||||
|
type='dict',
|
||||||
|
default={}
|
||||||
|
)
|
||||||
),
|
),
|
||||||
supports_check_mode=False
|
supports_check_mode=False
|
||||||
)
|
)
|
||||||
|
@ -251,6 +284,10 @@ def main():
|
||||||
# System, Manager or Chassis ID to modify
|
# System, Manager or Chassis ID to modify
|
||||||
resource_id = module.params['resource_id']
|
resource_id = module.params['resource_id']
|
||||||
|
|
||||||
|
# manager nic
|
||||||
|
nic_addr = module.params['nic_addr']
|
||||||
|
nic_config = module.params['nic_config']
|
||||||
|
|
||||||
# Build root URI
|
# Build root URI
|
||||||
root_uri = "https://" + module.params['baseuri']
|
root_uri = "https://" + module.params['baseuri']
|
||||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
||||||
|
@ -292,6 +329,8 @@ def main():
|
||||||
for command in command_list:
|
for command in command_list:
|
||||||
if command == "SetNetworkProtocols":
|
if command == "SetNetworkProtocols":
|
||||||
result = rf_utils.set_network_protocols(module.params['network_protocols'])
|
result = rf_utils.set_network_protocols(module.params['network_protocols'])
|
||||||
|
elif command == "SetManagerNic":
|
||||||
|
result = rf_utils.set_manager_nic(nic_addr, nic_config)
|
||||||
|
|
||||||
# Return data back or fail with proper message
|
# Return data back or fail with proper message
|
||||||
if result['ret'] is True:
|
if result['ret'] is True:
|
||||||
|
|
Loading…
Reference in a new issue