def computelement_list(args): try: obj = ComputeElement(args.ip, args.port) uris = obj.list_compute_element(args.name) output = [] for uri in uris: temp = obj.computelement_show_by_uri(uri['id'], False) if (temp): output.append(temp) if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): TableGenerator(output, [ 'name', 'system_type', 'num_of_cores', 'number_of_processors', 'processor_speed', 'ram', 'registration_status', 'job_discovery_status' ]).printTable() else: TableGenerator(output, [ 'name', 'system_type', 'registration_status', 'job_discovery_status' ]).printTable() except SOSError as e: raise common.format_err_msg_and_raise("list", "computelement", e.err_text, e.err_code)
def computevpool_list(args): try: obj = ComputeVpool(args.ip, args.port) uris = obj.computevpool_list() output = [] for uri in uris: temp = obj.computepool_show_by_uri(uri['id'], False) if (temp): if (args.verbose == False): del temp["service_profile_templates"] output.append(temp) if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): TableGenerator( output, ['name', 'system_type', 'in_use', 'use_matched_elements' ]).printTable() else: TableGenerator(output, ['name', 'system_type', 'in_use']).printTable() except SOSError as e: raise common.format_err_msg_and_raise("list", "computevpool", e.err_text, e.err_code)
def varray_list(args): obj = VirtualArray(args.ip, args.port) from common import TableGenerator try: uris = obj.varray_list(args.vdcname, args.tenant) output = [] for uri in uris: temp = obj.varray_show(uri) if (temp): # add column for auto_tier_policy if (args.long): autotierlist = [] returnlist = obj.get_autotier_policy_by_uri(uri) # get auto_tier policy object list for item in returnlist: autotierlist.append(item['name']) # append new column temp["auto_tier_policy"] = autotierlist output.append(temp) if (len(output) > 0): if (args.verbose is True): return common.format_json_object(output) elif (args.long is True): TableGenerator( output, ['name', 'module/auto_san_zoning', 'auto_tier_policy' ]).printTable() else: TableGenerator(output, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "varray", e.err_text, e.err_code)
def network_list(args): obj = Network(args.ip, args.port) from common import TableGenerator try: uris = obj.list_networks(args.varray) if (len(uris) > 0): output = [] for item in (uris): onetwork = common.show_by_href(args.ip, args.port, item) if ("varray" in onetwork): ovarray = common.show_by_href(args.ip, args.port, onetwork['varray']) onetwork["varray"] = ovarray['name'] output.append(onetwork) # show a short table if (args.verbose is False and args.long is False): TableGenerator(output, [ 'module/name', 'transport_type', "varray", "fabric_id", "registration_status" ]).printTable() # show a long table if (args.verbose is False and args.long is True): TableGenerator(output, [ 'module/name', 'transport_type', "varray", "fabric_id", "endpoints", "registration_status" ]).printTable() # show all items in json format if (args.verbose): return common.format_json_object(output) else: return except SOSError as e: raise e
def cluster_list(args): obj = Cluster(args.ip, args.port) try: clusters = obj.cluster_list(args.tenant) output = [] vdatacenterobj = VcenterDatacenter(args.ip, args.port) for cluster_uri in clusters: clobj = obj.cluster_show_uri(cluster_uri['id']) if(clobj): # add vdatacenter name to cluster object if('vcenter_data_center' in clobj and args.long): vobj = vdatacenterobj.vcenterdatacenter_show_by_uri( clobj['vcenter_data_center']['id']) clobj['vcenter_data_center'] = vobj['name'] output.append(clobj) if(len(output) > 0): if(args.verbose): return common.format_json_object(output) elif(args.long): TableGenerator(output, ['name', 'vcenter_data_center']).printTable() else: TableGenerator(output, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "cluster", e.err_text, e.err_code)
def vcenter_list_tasks(args): obj = VCenter(args.ip, args.port) try: if(not args.tenant): args.tenant = "" if(args.id): res = obj.list_tasks(args.tenant, args.name, args.id) if(res): return common.format_json_object(res) elif(args.name): res = obj.list_tasks(args.tenant, args.name) if(res and len(res) > 0): if(args.verbose): return common.format_json_object(res) else: from common import TableGenerator TableGenerator(res, ["module/id", "name", "state"]).printTable() else: res = obj.list_tasks(args.tenant) if(res and len(res) > 0): if(not args.verbose): from common import TableGenerator TableGenerator(res, ["module/id", "name", "state"]).printTable() else: return common.format_json_object(res) except SOSError as e: common.format_err_msg_and_raise("get tasks list", "vcenter", e.err_text, e.err_code)
def filepolicy_list(args): obj = FilePolicy(args.ip, args.port) try: from common import TableGenerator filepolicies = obj.list_file_polices() records = [] for filepolicy in filepolicies: filepolicy_uri = filepolicy['id'] filepolicy_detail = obj.filepolicy_show_by_uri(filepolicy_uri) if (filepolicy_detail): records.append(filepolicy_detail) if (len(records) > 0): if (args.verbose is True): return common.format_json_object(records) if (args.long is True): TableGenerator(records, ['name', 'type', 'description', 'applied_at' ]).printTable() else: TableGenerator(records, ['name']).printTable() else: return except SOSError as e: raise e
def ps_list(args): obj = ProtectionSystem(args.ip, args.port) try: output = [] uris = obj.ps_list() if (len(uris) > 0): for item in obj.ps_list_by_hrefs(uris): output.append(item) if (args.verbose == True): return common.format_json_object(output) if (len(output) > 0): if (args.long == True): from common import TableGenerator TableGenerator(output, [ 'name', 'system_type', 'ip_address', 'port_number', 'installation_id', 'job_discovery_status' ]).printTable() else: from common import TableGenerator TableGenerator( output, ['name', 'system_type', 'ip_address', 'port_number' ]).printTable() except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError(SOSError.SOS_FAILURE_ERR, "Protection system list failed\n" + e.err_text) else: common.format_err_msg_and_raise("list", "protectionsystem", e.err_text, e.err_code)
def computeimage_list(args): try: obj = ComputeImage(args.ip, args.port) uris = obj.list_computeimage(args.imagetype) output = [] for uri in uris: temp = obj.computeimage_show_by_uri(uri['id'], False) if (temp): output.append(temp) if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): from common import TableGenerator TableGenerator(output, [ 'name', 'image_name', 'image_type', 'compute_image_status', 'image_url' ]).printTable() else: from common import TableGenerator TableGenerator(output, [ 'name', 'image_name', 'image_type', 'compute_image_status', 'last_import_status_message' ]).printTable() except SOSError as e: raise common.format_err_msg_and_raise("list", "computeimage", e.err_text, e.err_code)
def vcenterdatacenter_list(args): obj = VcenterDatacenter(args.ip, args.port) try: uris = obj.vcenterdatacenter_list(args.vcenter, args.tenant) output = [] outlst = [] for uri in uris: temp = obj.vcenterdatacenter_show_by_uri(uri['id'], False) if (temp): output.append(temp) if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): from common import TableGenerator TableGenerator(output, ['name', 'auto_san_zoning', 'auto_tier_policy' ]).printTable() else: from common import TableGenerator TableGenerator(output, ['name']).printTable() except SOSError as e: raise e
def storageprovider_list(args): obj = StorageProvider(args.ip, args.port) from common import TableGenerator try: output = obj.list_storageproviders_with_details(args.interface) if(output and len(output) > 0): if(args.verbose): return common.format_json_object(output) elif(args.long): TableGenerator( output, [ 'name', 'interface', 'ip_address', 'port_number', 'use_ssl', 'job_scan_status', 'registration_status', 'compatibility_status']).printTable() else: TableGenerator( output, ['name', 'interface']).printTable() except SOSError as e: common.format_err_msg_and_raise( "list", "storageprovider", e.err_text, e.err_code)
def vnasserver_list(args): obj = VnasServer(args.ip, args.port) from common import TableGenerator from project import Project try: vnasServerList = obj.list_vnasserver_names() resultList = [] for iter in vnasServerList: rslt = obj.vnasserver_show(iter['name']) #rslt['parent_nas']['name'] should be printed under PARENT_NAS_SERVER. #Updating it as a new element in the map if('parent_nas' in rslt) and ('name' in rslt['parent_nas']): rslt['parent_nas_server'] = rslt['parent_nas']['name'] pr_object = None project_list = '' if ('associated_projects' in rslt): for project_id in rslt['associated_projects']: pr_object = Project(args.ip, args.port).project_show_by_uri(project_id) if pr_object and ('name' in pr_object): if (project_list == ''): project_list = pr_object['name'] else : project_list = project_list + ',' + pr_object['name'] st_object = None if ('storage_device' in rslt) and ('id' in rslt['storage_device']): st_object = StorageSystem(args.ip, args.port).show_by_uri(rslt['storage_device']['id']) if pr_object and ('name' in pr_object): rslt['project_name'] = project_list if st_object and ('name' in st_object): rslt['storage_system'] = st_object['name'] if(rslt is not None): resultList.append(rslt) if(len(resultList) > 0): # show a short table if(args.verbose is False and args.long is False): TableGenerator(vnasServerList, ["name"]).printTable() # show a long table if(args.verbose is False and args.long is True): TableGenerator( resultList, ["nas_name","parent_nas_server","nas_state","storage_domains","project_name","protocols", "storage_system"]).printTable() # show all items in json format if(args.verbose): return common.format_json_object(resultList) else: return except SOSError as e: raise e
def computeimageserver_list(args): obj = ComputeImageServers(args.ip, args.port) from common import TableGenerator try: computeImageServerList = obj.list_imageservers() resultList = [] for iter in computeImageServerList: rslt = obj.computeimageserver_show(iter['name']) if (rslt is not None): resultList.append(rslt) if (len(resultList) > 0): # show a short table if (args.verbose is False and args.long is False): TableGenerator(computeImageServerList, ['name']).printTable() # show a long table if (args.verbose is False and args.long is True): TableGenerator(resultList, [ "name", "imageserverip", "imageserversecondip", "tftpBootdir", "imageserver_status" ]).printTable() # show all items in json format if (args.verbose): return common.format_json_object(resultList) else: return except SOSError as e: raise e
def computesystem_list(args): try: obj = ComputeSystem(args.ip, args.port) uris = obj.list_computesystem() output = [] for uri in uris: temp = obj.computesystem_show_by_uri(uri['id'], False) if (temp): if (args.verbose == False): del temp["service_profile_templates"] output.append(temp) temp = None if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): TableGenerator(output, ['name', 'ip_address', 'os_install_network',\ 'system_type', 'job_discovery_status']).printTable() else: TableGenerator(output, [ 'name', 'system_type', 'ip_address', 'job_discovery_status' ]).printTable() except SOSError as e: raise common.format_err_msg_and_raise("list", "computesystem", e.err_text, e.err_code)
def quotadirectory_list(args): obj = QuotaDirectory(args.ip, args.port) try: resourceUri = obj.storageResource_query(args.filesystem, args.project, args.tenant) uris = obj.quotadirectory_list(resourceUri) records = [] for uri in uris: quotadirectory_obj = obj.quotadirectory_show_uri(uri['id']) if (quotadirectory_obj is not None): records.append(quotadirectory_obj) if (len(records) > 0): if (args.verbose is True): return common.format_json_object(records) else: from common import TableGenerator if (args.long is True): TableGenerator( records, ['name', 'quota_size_gb', 'oplock', 'security_style' ]).printTable() else: TableGenerator(records, ['name', 'quota_size_gb']).printTable() else: return except SOSError as e: common.format_err_msg_and_raise("list", "quotadirectory", e.err_text, e.err_code)
def storageprovider_show(args): obj = StorageProvider(args.ip, args.port) from common import TableGenerator try: resultfinal = [] hyperScale = [] output = obj.show(args.name, args.xml) if(args.xml): return common.format_xml(output) if("secondary_url" in output): hyperScale = obj.portremoval(output["secondary_url"]) output["hyperscale_host"] = hyperScale[0] output["hyperscale_port"] = hyperScale[1] if ("provider_id" not in output): print "Provider ID not there" return [] else: resultfinal.append(output) if("secondary_url" in output): TableGenerator( resultfinal, [ 'provider_id', 'name', 'interface', 'ip_address', 'port_number', 'hyperscale_host', 'hyperscale_port']).printTable() else : TableGenerator( resultfinal, [ 'provider_id', 'name', 'interface', 'ip_address', 'port_number']).printTable() except SOSError as e: common.format_err_msg_and_raise( "show", "storageprovider", e.err_text, e.err_code)
def list_fabric_san_zones(args): obj = SanFabrics(args.ip, args.port) try: zones = obj.san_fabrics_zones_list(args.name, args.fabricid) sanzone = zones['san_zone'] output = [] strwwp = "" for zone in sanzone: param = {'name': zone['name']} members = zone['members'] #get zone and then process wwn for member in members: strwwp = strwwp + member['wwn'] strwwp = strwwp + " " param["wwn_members"] = strwwp strwwp = "" output.append(param) if (len(output) > 0): if (args.verbose): return common.format_json_object(zones) elif (args.long): TableGenerator(output, ['name', 'wwn_members']).printTable() else: TableGenerator(output, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("list-sanzones", "sanfabrics", e.err_text, e.err_code)
def vcenter_list(args): obj = VCenter(args.ip, args.port) try: uris = obj.vcenter_list(args.tenant) output = [] outlst = [] for uri in uris: temp = obj.vcenter_show(uri['id'], uri) if(temp): output.append(temp) if(len(output) > 0): if(args.verbose): return common.format_json_object(output) elif(args.long): from common import TableGenerator TableGenerator( output, ['name', 'ip_address', 'job_discovery_status', 'job_metering_status']).printTable() else: from common import TableGenerator TableGenerator(output, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "vcenter", e.err_text, e.err_code)
def storageport_list(args): # get uri of a storage device by name obj = Storageport(args.ip, args.port) try: uris = obj.storageport_list(args.storagesystem, args.serialnumber, args.type) if (len(uris) > 0): output = [] ssuri = obj.storagesystem_query(args.storagesystem, args.serialnumber, args.type) tz_name = [] for port in uris: is_active_obj = obj.storageport_show_id(ssuri, port['id']) # network name is display in long list if ('network' in is_active_obj): if ('id' in is_active_obj['network']): # using tranportzone uri, get zone details tzob = Network(args.ip, args.port).show_by_uri( is_active_obj['network']['id'], False) if (tzob): # append zone name into 'tz_name' varible( or # directory) tz_name.append(tzob['name']) # then added tranportzone name attribute into port # object is_active_obj['network_name'] = tz_name output.append(is_active_obj) tz_name = [] else: if (is_active_obj is not None): output.append(is_active_obj) if (args.verbose is True): return common.format_json_object(output) else: from common import TableGenerator if (args.long is True): TableGenerator(output, [ 'port_name', 'transport_type', 'network_name', 'port_network_id', 'port_speed', 'port_group', 'registration_status' ]).printTable() elif (args.metrics is True): TableGenerator(output, [ 'port_name', 'port_network_id', 'allocation_metric', 'initiator_load', 'volume_load', 'port_percent_busy', 'cpu_percent_busy', 'network_name' ]).printTable() else: TableGenerator(output, [ 'port_name', 'transport_type', 'network_name', 'port_network_id', 'registration_status' ]).printTable() except SOSError as e: raise e
def ipinterface_list(args): ipinterfaceList = None ipinterfaceObj = HostIPInterface(args.ip, args.port) from common import TableGenerator try: if(args.hostlabel): hostUri = ipinterfaceObj.get_host_uri(args.hostlabel, args.tenant) ipinterfaceList = ipinterfaceObj.get_host_object( ).list_ipinterfaces( hostUri) else: ipinterfaceList = ipinterfaceObj.list_all() if(len(ipinterfaceList) > 0): ipinterfaceListDetails = [] if(args.protocol is None): ipinterfaceListDetails = ipinterfaceObj.show(ipinterfaceList) else: ipinterfaceListDetails = ipinterfaceObj.show_by_protocol( ipinterfaceList, args.protocol) if(args.verbose): return common.format_json_object(ipinterfaceListDetails) else: if(args.largetable): TableGenerator( ipinterfaceListDetails, ['name', 'ip_address', 'protocol', 'netmask', 'prefix_length']).printTable() else: TableGenerator( ipinterfaceListDetails, ['name', 'ip_address', 'protocol']).printTable() except SOSError as e: common.format_err_msg_and_raise( "list", "ip-interface", e.err_text, e.err_code)
def list_backup(args): try: obj = Backup(args.ip, args.port) res = obj.listBackup() if(len(res) > 0): if(args.verbose is True): return common.format_json_object(res) else: from datetime import datetime from common import TableGenerator for item in res: value = datetime.fromtimestamp(float(item['create_time']) / 1000) item['creation_time'] = value.strftime('%Y-%m-%d %H:%M:%S') item['size_in_mb'] = float(float(item['size']) / (1024 * 1024)) TableGenerator( res, ['name', 'size_in_mb', 'creation_time']).printTable() except SOSError as e: common.format_err_msg_and_raise( 'list', 'backup', e.err_text, e.err_code)
def storageportgroup_list(args): # get uri of a storage device by name obj = Storageportgroup(args.ip, args.port) try: uris = obj.storageportgroup_list(args.storagesystem, args.serialnumber, args.type) if (len(uris) > 0): output = [] ssuri = obj.storagesystem_query(args.storagesystem, args.serialnumber, args.type) for portgroup in uris: is_active_obj = obj.storageportgroup_show_id( ssuri, portgroup['id']) if (is_active_obj): storageports = is_active_obj['storage_ports'][ 'storage_port'] ports = [] for storageport in storageports: ports.append(storageport['name']) is_active_obj['storageports'] = ports is_active_obj['portgroupname'] = is_active_obj['name'] output.append(is_active_obj) if (args.verbose is True): return common.format_json_object(output) else: from common import TableGenerator TableGenerator( output, ['portgroupname', 'storageports', 'registration_status' ]).printTable() except SOSError as e: raise e
def consistencygroup_list(args): obj = ConsistencyGroup(args.ip, args.port) try: uris = obj.list(args.project, args.tenant) output = [] rawoutput = [] for uri in uris: cg = obj.show(uri, args.project, args.tenant) if (cg): rawoutput.append(cg) from volume import Volume from storagesystem import StorageSystem cg["system_consistency_groups"] = " " if ("volumes" in cg): volumeuris = common.get_node_value(cg, "volumes") volobj = Volume(args.ip, args.port) volumenames = [] for volume in volumeuris: vol = volobj.show_by_uri(volume['id']) if (vol): volumenames.append(vol['name']) cg['volumes'] = volumenames volumenames = [] output.append(cg) if (not args.verbose): if (len(output)): TableGenerator(output, ['name', 'volumes']).printTable() else: if (len(rawoutput)): return common.format_json_object(rawoutput) except SOSError as e: raise SOSError(SOSError.SOS_FAILURE_ERR, "Consistency Group List failed:\n" + e.err_text)
def host_initiator_list_tasks(args): obj = HostInitiator(args.ip, args.port) try: # if(not args.tenant): # args.tenant = "" if (args.id): res = obj.list_tasks(args.hostlabel, args.initiatorportwwn, args.id, args.tenant) if (res): return common.format_json_object(res) elif (args.hostlabel): res = obj.list_tasks(args.hostlabel, args.initiatorportwwn, None, args.tenant) if (res and len(res) > 0): if (args.verbose): return common.format_json_object(res) else: from common import TableGenerator TableGenerator(res, ["module/id", "state"]).printTable() except SOSError as e: common.format_err_msg_and_raise("get tasks list", "initiator", e.err_text, e.err_code)
def vcenter_get_clusters(args): obj = VCenter(args.ip, args.port) try: res = obj.vcenter_get_clusters(args.name, args.tenant) if(len(res) > 0): if(args.verbose): return common.format_json_object(res) elif(args.long): from common import TableGenerator TableGenerator(res, ['name']).printTable() else: from common import TableGenerator TableGenerator(res, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("get clusters", "vcenter", e.err_text, e.err_code)
def snapshot_list(args): obj = ConsistencyGroup(args.ip, args.port) try: if (not args.tenant): args.tenant = "" res = obj.snapshot_list(args.name, args.project, args.tenant) if (len(res)): TableGenerator(res, ['name']).printTable() except SOSError as e: raise e
def cluster_get_hosts(args): obj = Cluster(args.ip, args.port) try: res = obj.cluster_get_hosts(args.name, args.tenant) if(len(res) > 0): if(args.verbose): return common.format_json_object(res) elif(args.long): from common import TableGenerator TableGenerator(res, ['name', 'type', 'job_discovery_status', 'job_metering_status']).printTable() else: from common import TableGenerator TableGenerator(res, ['name']).printTable() except SOSError as e: common.format_err_msg_and_raise("get hosts", "cluster", e.err_text, e.err_code)
def vdc_list(args): vdcob = VirtualDatacenter(args.ip, args.port) try: vdclist = vdcob.vdc_get_list() output = [] for vdc in vdclist: vdcdetail = vdcob.vdc_show_by_uri(vdc['id']) if (vdcdetail): output.append(vdcdetail) if (len(output) > 0): if (args.verbose == True): return common.format_json_object(output) elif (args.long == True): TableGenerator(output, ['name', 'apiEndpoint', \ 'connectionStatus']).printTable() else: TableGenerator(output, ['name', 'apiEndpoint']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "vdc", e.err_text, e.err_code)
def san_fabrics_list(args): obj = SanFabrics(args.ip, args.port) try: uris = obj.san_fabrics_list(args.name) output = [] for uri in uris: param = {'fabricname': uri} output.append(param) if (len(output) > 0): if (args.verbose): return common.format_json_object(output) elif (args.long): TableGenerator(output, ['fabricname']).printTable() else: TableGenerator(output, ['fabricname']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "sanfabrics", e.err_text, e.err_code)
def initiator_list(args): initiatorList = None initiatorObj = HostInitiator(args.ip, args.port) from common import TableGenerator try: if (args.hostlabel): hostUri = initiatorObj.get_host_uri(args.hostlabel, args.tenant) initiatorList = initiatorObj.get_host_object().list_initiators( hostUri) else: initiatorList = initiatorObj.list_all() if (len(initiatorList) > 0): initiatorListDetails = [] if (args.protocol is None): initiatorListDetails = initiatorObj.show(initiatorList) else: initiatorListDetails = initiatorObj.show_by_protocol( initiatorList, args.protocol) if (args.verbose): return common.format_json_object(initiatorListDetails) else: if (args.largetable): for item in initiatorListDetails: if (not ('initiator_node' in item) or item['initiator_node'] == ""): item['initiator_node'] = ' ' TableGenerator( initiatorListDetails, ['initiator_node', 'initiator_port', 'protocol' ]).printTable() else: TableGenerator(initiatorListDetails, ['initiator_port']).printTable() except SOSError as e: common.format_err_msg_and_raise("list", "initiator", e.err_text, e.err_code)