mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Add GetHostInterfaces command to redfish_info (#3693)
* Add GetHostInterfaces command to redfish_info Adding a GetHostInterfaces command to redfish_info in order to report the following: - Properties about the HostInterface(s) like Status, InterfaceEnabled, etc - ManagerEthernetInterface (info on BMC -> host NIC) - HostEthernetInterfaces (list of NICs for host -> BMC connectivity) fixes #3692 * add fragment * fixup for linter * redfish_utils.py cleanup - Remove unneeded Properties list from get_nic_inventory() - Remove bogus key variable from get_hostinterfaces() - Add additional Properties to collect from HostInterface objects * fixup for stray deletion
This commit is contained in:
parent
d29aecad26
commit
98cca3c19c
3 changed files with 110 additions and 17 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- redfish_command - add ``GetHostInterfaces`` command to enable reporting Redfish Host Interface information (https://github.com/ansible-collections/community.general/issues/3693).
|
|
@ -2029,15 +2029,28 @@ class RedfishUtils(object):
|
||||||
def get_multi_memory_inventory(self):
|
def get_multi_memory_inventory(self):
|
||||||
return self.aggregate_systems(self.get_memory_inventory)
|
return self.aggregate_systems(self.get_memory_inventory)
|
||||||
|
|
||||||
|
def get_nic(self, resource_uri):
|
||||||
|
result = {}
|
||||||
|
properties = ['Name', 'Id', 'Description', 'FQDN', 'IPv4Addresses', 'IPv6Addresses',
|
||||||
|
'NameServers', 'MACAddress', 'PermanentMACAddress',
|
||||||
|
'SpeedMbps', 'MTUSize', 'AutoNeg', 'Status']
|
||||||
|
response = self.get_request(self.root_uri + resource_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
nic = {}
|
||||||
|
for property in properties:
|
||||||
|
if property in data:
|
||||||
|
nic[property] = data[property]
|
||||||
|
result['entries'] = nic
|
||||||
|
return(result)
|
||||||
|
|
||||||
def get_nic_inventory(self, resource_uri):
|
def get_nic_inventory(self, resource_uri):
|
||||||
result = {}
|
result = {}
|
||||||
nic_list = []
|
nic_list = []
|
||||||
nic_results = []
|
nic_results = []
|
||||||
key = "EthernetInterfaces"
|
key = "EthernetInterfaces"
|
||||||
# Get these entries, but does not fail if not found
|
|
||||||
properties = ['Name', 'Id', 'Description', 'FQDN', 'IPv4Addresses', 'IPv6Addresses',
|
|
||||||
'NameServers', 'MACAddress', 'PermanentMACAddress',
|
|
||||||
'SpeedMbps', 'MTUSize', 'AutoNeg', 'Status']
|
|
||||||
|
|
||||||
response = self.get_request(self.root_uri + resource_uri)
|
response = self.get_request(self.root_uri + resource_uri)
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
|
@ -2061,18 +2074,9 @@ class RedfishUtils(object):
|
||||||
nic_list.append(nic[u'@odata.id'])
|
nic_list.append(nic[u'@odata.id'])
|
||||||
|
|
||||||
for n in nic_list:
|
for n in nic_list:
|
||||||
nic = {}
|
nic = self.get_nic(n)
|
||||||
uri = self.root_uri + n
|
if nic['ret']:
|
||||||
response = self.get_request(uri)
|
nic_results.append(nic['entries'])
|
||||||
if response['ret'] is False:
|
|
||||||
return response
|
|
||||||
data = response['data']
|
|
||||||
|
|
||||||
for property in properties:
|
|
||||||
if property in data:
|
|
||||||
nic[property] = data[property]
|
|
||||||
|
|
||||||
nic_results.append(nic)
|
|
||||||
result["entries"] = nic_results
|
result["entries"] = nic_results
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -2876,3 +2880,80 @@ class RedfishUtils(object):
|
||||||
if response['ret'] is False:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
return {'ret': True, 'changed': True, 'msg': "Modified Host Interface"}
|
return {'ret': True, 'changed': True, 'msg': "Modified Host Interface"}
|
||||||
|
|
||||||
|
def get_hostinterfaces(self):
|
||||||
|
result = {}
|
||||||
|
hostinterface_results = []
|
||||||
|
properties = ['Id', 'Name', 'Description', 'HostInterfaceType', 'Status',
|
||||||
|
'InterfaceEnabled', 'ExternallyAccessible', 'AuthenticationModes',
|
||||||
|
'AuthNoneRoleId', 'CredentialBootstrapping']
|
||||||
|
manager_uri_list = self.manager_uris
|
||||||
|
for manager_uri in manager_uri_list:
|
||||||
|
response = self.get_request(self.root_uri + manager_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
|
||||||
|
if 'HostInterfaces' in data:
|
||||||
|
hostinterfaces_uri = data[u'HostInterfaces'][u'@odata.id']
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
response = self.get_request(self.root_uri + hostinterfaces_uri)
|
||||||
|
data = response['data']
|
||||||
|
|
||||||
|
if 'Members' in data:
|
||||||
|
for hostinterface in data['Members']:
|
||||||
|
hostinterface_uri = hostinterface['@odata.id']
|
||||||
|
hostinterface_response = self.get_request(self.root_uri + hostinterface_uri)
|
||||||
|
# dictionary for capturing individual HostInterface properties
|
||||||
|
hostinterface_data_temp = {}
|
||||||
|
if hostinterface_response['ret'] is False:
|
||||||
|
return hostinterface_response
|
||||||
|
hostinterface_data = hostinterface_response['data']
|
||||||
|
for property in properties:
|
||||||
|
if property in hostinterface_data:
|
||||||
|
if hostinterface_data[property] is not None:
|
||||||
|
hostinterface_data_temp[property] = hostinterface_data[property]
|
||||||
|
# Check for the presence of a ManagerEthernetInterface
|
||||||
|
# object, a link to a _single_ EthernetInterface that the
|
||||||
|
# BMC uses to communicate with the host.
|
||||||
|
if 'ManagerEthernetInterface' in hostinterface_data:
|
||||||
|
interface_uri = hostinterface_data['ManagerEthernetInterface']['@odata.id']
|
||||||
|
interface_response = self.get_nic(interface_uri)
|
||||||
|
if interface_response['ret'] is False:
|
||||||
|
return interface_response
|
||||||
|
hostinterface_data_temp['ManagerEthernetInterface'] = interface_response['entries']
|
||||||
|
|
||||||
|
# Check for the presence of a HostEthernetInterfaces
|
||||||
|
# object, a link to a _collection_ of EthernetInterfaces
|
||||||
|
# that the host uses to communicate with the BMC.
|
||||||
|
if 'HostEthernetInterfaces' in hostinterface_data:
|
||||||
|
interfaces_uri = hostinterface_data['HostEthernetInterfaces']['@odata.id']
|
||||||
|
interfaces_response = self.get_request(self.root_uri + interfaces_uri)
|
||||||
|
if interfaces_response['ret'] is False:
|
||||||
|
return interfaces_response
|
||||||
|
interfaces_data = interfaces_response['data']
|
||||||
|
if 'Members' in interfaces_data:
|
||||||
|
for interface in interfaces_data['Members']:
|
||||||
|
interface_uri = interface['@odata.id']
|
||||||
|
interface_response = self.get_nic(interface_uri)
|
||||||
|
if interface_response['ret'] is False:
|
||||||
|
return interface_response
|
||||||
|
# Check if this is the first
|
||||||
|
# HostEthernetInterfaces item and create empty
|
||||||
|
# list if so.
|
||||||
|
if 'HostEthernetInterfaces' not in hostinterface_data_temp:
|
||||||
|
hostinterface_data_temp['HostEthernetInterfaces'] = []
|
||||||
|
|
||||||
|
hostinterface_data_temp['HostEthernetInterfaces'].append(interface_response['entries'])
|
||||||
|
|
||||||
|
hostinterface_results.append(hostinterface_data_temp)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
result["entries"] = hostinterface_results
|
||||||
|
if not result["entries"]:
|
||||||
|
return {'ret': False, 'msg': "No HostInterface objects found"}
|
||||||
|
return result
|
||||||
|
|
|
@ -269,6 +269,14 @@ EXAMPLES = '''
|
||||||
baseuri: "{{ baseuri }}"
|
baseuri: "{{ baseuri }}"
|
||||||
username: "{{ username }}"
|
username: "{{ username }}"
|
||||||
password: "{{ password }}"
|
password: "{{ password }}"
|
||||||
|
|
||||||
|
- name: Get manager Redfish Host Interface inventory
|
||||||
|
community.general.redfish_info:
|
||||||
|
category: Manager
|
||||||
|
command: GetHostInterfaces
|
||||||
|
baseuri: "{{ baseuri }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -293,7 +301,7 @@ CATEGORY_COMMANDS_ALL = {
|
||||||
"Sessions": ["GetSessions"],
|
"Sessions": ["GetSessions"],
|
||||||
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory"],
|
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory"],
|
||||||
"Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols",
|
"Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols",
|
||||||
"GetHealthReport"],
|
"GetHealthReport", "GetHostInterfaces"],
|
||||||
}
|
}
|
||||||
|
|
||||||
CATEGORY_COMMANDS_DEFAULT = {
|
CATEGORY_COMMANDS_DEFAULT = {
|
||||||
|
@ -475,6 +483,8 @@ def main():
|
||||||
result["network_protocols"] = rf_utils.get_network_protocols()
|
result["network_protocols"] = rf_utils.get_network_protocols()
|
||||||
elif command == "GetHealthReport":
|
elif command == "GetHealthReport":
|
||||||
result["health_report"] = rf_utils.get_multi_manager_health_report()
|
result["health_report"] = rf_utils.get_multi_manager_health_report()
|
||||||
|
elif command == "GetHostInterfaces":
|
||||||
|
result["host_interfaces"] = rf_utils.get_hostinterfaces()
|
||||||
|
|
||||||
# Return data back
|
# Return data back
|
||||||
module.exit_json(redfish_facts=result)
|
module.exit_json(redfish_facts=result)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue