Skip to content

Commit

Permalink
Merge pull request #284 from HewlettPackard/server_hardware_facts_issue
Browse files Browse the repository at this point in the history
Server Hardware Facts Issue
  • Loading branch information
nabhajit-ray authored Jan 10, 2024
2 parents 172dd35 + cc27b75 commit a93d4be
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions plugins/modules/oneview_server_hardware_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
'''

from ansible_collections.hpe.oneview.plugins.module_utils.oneview import OneViewModule
import ast


class ServerHardwareFactsModule(OneViewModule):
Expand Down Expand Up @@ -281,10 +282,16 @@ def gather_option_facts(self):
ansible_facts['server_hardware_physical_server_hardware'] = self.current_resource.get_physical_server_hardware()
if self.options.get('remoteConsoleUrl'):
ansible_facts['server_hardware_remote_console_url'] = self.current_resource.get_remote_console_url()
if self.options.get('utilization'):
ansible_facts['server_hardware_utilization'] = self.get_utilization()
if self.options.get('firmware'):
ansible_facts['server_hardware_firmware'] = self.current_resource.get_firmware()
if self.options.get('utilization'):
ansible_facts['server_hardware_utilization'] = self.get_utilization()
else:
keys_list = list(self.options.keys())
for item in keys_list:
if 'utilization' in item:
ansible_facts['server_hardware_utilization'] = self.get_utilization(ast.literal_eval(item))
break

return ansible_facts

Expand All @@ -296,16 +303,15 @@ def get_all_firmwares(self):

return self.resource_client.get_all_firmwares(**params)

def get_utilization(self):
def get_utilization(self, util_params=None):

fields = view = refresh = filter = ''
data = self.options['utilization']

if isinstance(data, dict):
fields = data.get('fields')
view = data.get('view')
refresh = data.get('refresh')
filter = data.get('filter')
if isinstance(util_params, dict):
fields = util_params.get('utilization').get('fields')
view = util_params.get('utilization').get('view')
refresh = util_params.get('utilization').get('refresh')
filter = util_params.get('utilization').get('filter')

return self.current_resource.get_utilization(fields=fields,
filter=filter,
Expand Down

0 comments on commit a93d4be

Please sign in to comment.