37,720
社区成员
发帖
与我相关
我的任务
分享
def advanced_info_of_resource(resource, needed_attributes, storwize_connection, *id_of_resource):
""" needed_attributes - list of parameters, that we wont to get
id_of_resource - list of additional parameters, that uniquely determine resource.
Example: for PSU - first element of list is enclosure_id, secondary element of list is PSU_id"""
if resource == 'lsenclosure':
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} {1}'.format(resource, id_of_resource[0]))
elif resource == 'lsenclosurepsu':
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} -psu {1} {2}'.format(resource, id_of_resource[1], id_of_resource[0]))
if len(stderr.read()) > 0:
storwize_logger.info("Error Occurs in advanced info of enclosure - {0}".format(stderr.read()))
storwize_logout(storwize_connection)
sys.exit("1100")
else:
attributes_of_resource = stdout.read() # (variable contain advanced attributes in string)
dict_of_attributes = {} # (will contain advanced attributes in key-value)
try:
for attribute in attributes_of_resource.split('\n'):
if len(attribute) > 0:
temp = attribute.split(' ')
dict_of_attributes[temp[0]] = temp[1]
except Exception as oops:
storwize_logger.error("Error occures in function advanced_info_of_resource - {0}".format(oops))
storwize_logout(storwize_connection)
sys.exit("1100")
# (create dictionary that contain properies of resource)
result = {}
for each_value in needed_attributes:
result[each_value] = dict_of_attributes[each_value]
return result
def advanced_info_of_resource(resource, needed_attributes, storwize_connection, *id_of_resource):
""" needed_attributes - list of parameters, that we wont to get
id_of_resource - list of additional parameters, that uniquely determine resource.
Example: for PSU - first element of list is enclosure_id, secondary element of list is PSU_id"""
if resource == 'lsenclosure':
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} {1}'.format(resource, id_of_resource[0]))
elif resource == 'lsenclosurepsu':
stdin, stdout, stderr = storwize_connection.exec_command('svcinfo {0} -psu {1} {2}'.format(resource, id_of_resource[1], id_of_resource[0]))
if len(stderr.read()) > 0:
storwize_logger.info("Error Occurs in advanced info of enclosure - {0}".format(stderr.read()))
storwize_logout(storwize_connection)
sys.exit("1100")
else:
attributes_of_resource = stdout.read() # variable contain advanced attributes in string
attributes_of_resource = attributes_of_resource.decode()
dict_of_attributes = {} # will contain advanced attributes in key-value
try:
for attribute in attributes_of_resource.split('\n'): # Separate the lines and receive a list from a red attribute
if len(attribute) > 0:
temp = attribute.split(' ')
dict_of_attributes[temp[0]] = temp[1]
except Exception as oops:
storwize_logger.error("Error occures in function advanced_info_of_resource - {0}".format(oops, attributes_of_resource.decode()))
storwize_logout(storwize_connection)
sys.exit("1100")
# create dictionary that contain properies of resource
result = {}
for each_value in needed_attributes:
result[each_value] = dict_of_attributes[each_value]
return result