コード例 #1
0
def datastore_list(args):
    obj = Datastore(args.ip, args.port)
    # TO BE COMPLETED AFTER LOOKING AT THE DATASTORE LIST DATA FORMAT
    try:
        uris = obj.datastore_list()
        output = []
        outlst = []
        for uri in uris:
            temp = obj.datastore_show(uri)
            if (temp):
                output.append(temp)

        if (len(output) > 0):
            if (args.verbose):
                return common.format_json_object(output)
            else:
                outlst = []
                for record in output:
                    if (record):
                        outlst.append(common.format_json_object(
                            record['name']))
                return outlst

    except SOSError as e:
        raise e
コード例 #2
0
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)
コード例 #3
0
def exportgroup_tasks_list(args):
    obj = ExportGroup(args.ip, args.port)
    try:
        if not args.tenant:
            args.tenant = ""
        if args.id:
            res = obj.list_tasks(args.tenant + "/" + args.project, args.name, args.id)
            if res:
                return common.format_json_object(res)
        elif args.name:
            res = obj.list_tasks(args.tenant + "/" + args.project, 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 + "/" + args.project)
            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", "export", e.err_text, e.err_code)
コード例 #4
0
ファイル: cluster.py プロジェクト: Lujoel/coprhd-controller
def cluster_list_tasks(args):
    obj = Cluster(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", "cluster",
                                        e.err_text, e.err_code)
コード例 #5
0
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)
            if(res):
                return common.format_json_object(res)
        elif(args.hostlabel):
           
            res = obj.list_tasks(args.hostlabel, args.initiatorportwwn)
           
            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()

    except SOSError as e:
        common.format_err_msg_and_raise("get tasks list", "initiator",
                                        e.err_text, e.err_code)
コード例 #6
0
ファイル: datastore.py プロジェクト: Lidaja/coprhd-controller
def datastore_list(args):
    obj = Datastore(args.ip, args.port)
    # TO BE COMPLETED AFTER LOOKING AT THE DATASTORE LIST DATA FORMAT
    try:
        uris = obj.datastore_list()
        output = []
        outlst = []
        for uri in uris:
            temp = obj.datastore_show(uri)
            if(temp):
                output.append(temp)

        if(len(output) > 0):
            if(args.verbose):
                return common.format_json_object(output)
            else:
                outlst = []
                for record in output:
                    if(record):
                        outlst.append(
                            common.format_json_object(record['name']))
                return outlst

    except SOSError as e:
        raise e
コード例 #7
0
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)
コード例 #8
0
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)
コード例 #9
0
def list_backup(args):

    try:
        obj = Backup(args.ip, args.port)
        res = obj.list_backupsets()
        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)
コード例 #10
0
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)
            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)
コード例 #11
0
def order_show(args):
    orderObj = Order(args.ip, args.uiPort)
    try:

        orderDetails = orderObj.show_by_uri(args.uri, args.xml)

        if (orderDetails is None):
            raise SOSError(SOSError.NOT_FOUND_ERR,
                           "Could not find the matching order")

        if (args.waitForExecution is True):
            orderObj.block_until_complete(args.uri)
            # refresh order details
            orderDetails = orderObj.show_by_uri(args.uri, args.xml)

        if (args.xml):
            return common.format_xml(orderDetails)

        return common.format_json_object(orderDetails)

    except SOSError as e:
        common.format_err_msg_and_raise("show", "order", e.err_text,
                                        e.err_code)

    return
コード例 #12
0
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
コード例 #13
0
def list_authentication_provider(args):
    obj = Authentication(args.ip, args.port)
    try:
        uris = obj.list_authentication_provider()

        output = []

        for uri in uris:
            if(obj.show_authentication_provider_by_uri(uri['id'])):
                output.append(obj.show_authentication_provider_by_uri(uri['id']))
        if(len(output) > 0):
            if(args.verbose == True):
                return common.format_json_object(output)
            elif(args.long == True):
                from common import TableGenerator
                TableGenerator(output, [ 'module/name', 'server_urls', 'mode', 'domains','group_attribute']).printTable()
            else:
                from common import TableGenerator
                TableGenerator(output, [ 'module/name','server_urls','mode']).printTable()
    except SOSError as e:
            if(e.err_code == SOSError.NOT_FOUND_ERR):
                raise SOSError(SOSError.NOT_FOUND_ERR,
                      "Tenant list failed: " + e.err_text)
            else:
                raise e
コード例 #14
0
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)
コード例 #15
0
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
コード例 #16
0
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
コード例 #17
0
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)
コード例 #18
0
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)
コード例 #19
0
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)
コード例 #20
0
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)
コード例 #21
0
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)
コード例 #22
0
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)
コード例 #23
0
def db_con_check_status(args):
    obj = ControlService(args.ip, ControlService.DEFAULT_SYSMGR_PORT)
    try:
        res = obj.db_con_check_status()
        return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("db consistency check", "status", e.err_text, e.err_code)
コード例 #24
0
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)
コード例 #25
0
def monitor_get_events(args):
    obj = Monitor(args.ip, args.port)
    try:
        if (int(args.year) <= 1900):
            print("error: year=" + args.year +
                  " is before 1900, it require year >= 1900")
            return

        time_frame = common.get_formatted_time_string(args.year, args.month,
                                                      args.day, args.hour,
                                                      args.minute)

        res = obj.get_events(args.format, time_frame)

        if (args.format == "json"):
            return common.format_json_object(res)
        return res

    except ValueError as e:
        raise SOSError(SOSError.CMD_LINE_ERR, "error: " + str(e))
    except SOSError as e:
        if (e.err_code == SOSError.SOS_FAILURE_ERR):
            raise SOSError(SOSError.SOS_FAILURE_ERR,
                           "Unable to get requested usage events")
        else:
            raise e
コード例 #26
0
def backupset_restore_status(args):
    obj = Backup(args.ip, Backup.DEFAULT_SYSMGR_PORT)
    try:
        res = obj.backupset_restore_status(args.bname, args.islocal)
        return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("restore", "backup", e.err_text, e.err_code)
コード例 #27
0
def get_backupsets_external(args):
    obj = Backup(args.ip, Backup.DEFAULT_SYSMGR_PORT)
    try:
        return common.format_json_object(obj.get_backupsets_external())
    except SOSError as e:
        common.format_err_msg_and_raise("external", "backups", e.err_text,
                                        e.err_code)
コード例 #28
0
def host_list_ipinterfaces(args):
    hostObj = Host(args.ip, args.port)
    from common import TableGenerator

    try:
        ipinterfacesList = hostObj.list_ipinterfaces(args.hostlabel)

        if len(ipinterfacesList) > 0:
            ipinterfacesListDetails = []
            from hostipinterfaces import HostIPInterface

            hostIpinterfaceObj = HostIPInterface(args.ip, args.port)
            ipinterfacesListDetails = hostIpinterfaceObj.show(ipinterfacesList)

            if args.verbose == True:
                return common.format_json_object(ipinterfacesListDetails)
            else:
                if args.largetable == True:
                    TableGenerator(
                        ipinterfacesListDetails, ["name", "ip_address", "protocol", "netmask", "prefix_length"]
                    ).printTable()
                else:
                    TableGenerator(ipinterfacesListDetails, ["name", "ip_address", "protocol"]).printTable()

    except SOSError as e:
        common.format_err_msg_and_raise("list-ipinterfaces", "host", e.err_text, e.err_code)
コード例 #29
0
def host_list(args):

    hostList = None
    hostObj = Host(args.ip, args.port)
    from common import TableGenerator

    try:
        hostList = hostObj.list_all(args.tenant, args.project)

        if len(hostList) > 0:
            hostListDetails = []
            if args.hosttype is None:
                hostListDetails = hostObj.show(hostList)
            else:
                hostListDetails = hostObj.show_by_type(hostList, args.hosttype)

            if args.verbose == True:
                return common.format_json_object(hostListDetails)
            else:
                if args.largetable == True:
                    TableGenerator(
                        hostListDetails, ["name", "host_name", "type", "user_name", "registration_status"]
                    ).printTable()
                else:
                    TableGenerator(hostListDetails, ["name", "host_name", "type"]).printTable()

    except SOSError as e:
        common.format_err_msg_and_raise("list", "host", e.err_text, e.err_code)
コード例 #30
0
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)
コード例 #31
0
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
コード例 #32
0
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)
コード例 #33
0
ファイル: network.py プロジェクト: Lidaja/coprhd-controller
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
コード例 #34
0
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)
コード例 #35
0
def network_list(args):
    obj = Network(args.ip, args.port)
    try:
        uris = obj.list_networks(args.varray)
        if len(uris) > 0:
            output = []
            # for uri in uris:
            #    output.append(obj.show_by_uri(uri))
            # if(len(uris) > 0):
            for item in obj.list_by_hrefs(uris):
                output.append(item)
            # show a short table
            if args.verbose == False and args.long == False:
                from common import TableGenerator

                TableGenerator(output, ["module/name", "endpoints"]).printTable()
            # show a long table
            if args.verbose == False and args.long == True:
                from common import TableGenerator

                TableGenerator(output, ["module/name", "transport_type", "endpoints"]).printTable()
            # show all items in json format
            if args.verbose == True:
                return common.format_json_object(output)

        else:
            return
    except SOSError as e:
        raise e
コード例 #36
0
ファイル: cluster.py プロジェクト: Lujoel/coprhd-controller
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)
コード例 #37
0
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)
コード例 #38
0
def show_authentication_provider(args):
    obj = Authentication(args.ip, args.port)
    try:
        res = obj.show_authentication_provider(args.name, args.xml)
	return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("show", "Authentication Provider", e.err_text, e.err_code)
コード例 #39
0
def list(args):
    obj = VolumeGroup(args.ip, args.port)

    try:
        from common import TableGenerator
        volume_groups = obj.list()
        records = []
        for volume_group in volume_groups:
            volume_group_uri = volume_group['id']
            app_detail = obj.show_by_uri(volume_group_uri)
            if(app_detail):
                records.append(app_detail)

        if(len(records) > 0):
            if(args.verbose == True):
                return common.format_json_object(records)

            elif(args.largetable == True):
                TableGenerator(records, ['name', 'description',
                                          'roles', 'tags']).printTable()
            else:
                TableGenerator(records, ['name']).printTable()

        else:
            return

    except SOSError as e:
        raise e
コード例 #40
0
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)
コード例 #41
0
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
コード例 #42
0
def varray_list(args):
    obj = VirtualArray(args.ip, args.port)
    from common import TableGenerator
    try:
        uris = obj.varray_list(args.vdcname)
        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)
コード例 #43
0
def vnasserver_list(args):
    obj = VnasServer(args.ip, args.port)
    from common import TableGenerator
    try:
        vnasServerList = obj.list_vnasserver_names()
        resultList = []
    
        for iter in vnasServerList:
            rslt = obj.vnasserver_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(vnasServerList,
                               ["name"]).printTable()
                
            # show a long table
            if(args.verbose is False and args.long is True):
                TableGenerator(
                    resultList,
                    ["nas_name","parent_nas/name","assigned_varrays","nas_state","storage_domains","project/id","protocols"]).printTable()
                    
            # show all items in json format
            if(args.verbose):
                return common.format_json_object(resultList)

        else:
            return
    except SOSError as e:
        raise e
コード例 #44
0
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
コード例 #45
0
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
コード例 #46
0
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)
コード例 #47
0
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)
コード例 #48
0
def quotadirectory_show(args):
    obj = QuotaDirectory(args.ip, args.port)    
    try:
        resourceUri = obj.storageResource_query(
            args.filesystem,
            args.project,
            args.tenant)
        respContent = obj.quotadirectory_show(
            resourceUri,
            args.name,
            args.xml)

        if(args.xml):
            return common.format_xml(respContent)
        else:
            return common.format_json_object(respContent)

    except SOSError as e:
        if (e.err_code == SOSError.SOS_FAILURE_ERR):
            raise SOSError(
                SOSError.SOS_FAILURE_ERR,
                "quotadirectory " +
                args.name +
                ": Not Found")
        else:
            common.format_err_msg_and_raise(
                "show",
                "quotadirectory",
                e.err_text,
                e.err_code)
コード例 #49
0
def project_list(args):
    obj = Project(args.ip, args.port)
    try:
        from common import TableGenerator
        projects = obj.project_list(args.tenantname)
        records = []
        for project in projects:
            proj_detail = obj.project_show_by_uri(project['id'])
            if(proj_detail):
                if("tenant" in proj_detail and "name" in proj_detail["tenant"]):
                    del proj_detail["tenant"]["name"]
                records.append(proj_detail)
                
        if(len(records) > 0):
            if(args.verbose == True):
                return common.format_json_object(records)
                
            elif(args.largetable == True):
                TableGenerator(records, ['name', 'owner']).printTable()
            else:
                TableGenerator(records, ['name']).printTable()
                    
        else:
            return
            
    except SOSError as e:
        raise e
コード例 #50
0
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
コード例 #51
0
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)
コード例 #52
0
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)
コード例 #53
0
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)
コード例 #54
0
def monitor_get_events(args):
    obj = Monitor(args.ip, args.port)
    try:
        if(int(args.year) <= 1900):
            print("error: year=" + args.year +
                  " is before 1900, it require year >= 1900")
            return

        time_frame = common.get_formatted_time_string(args.year,
                                                      args.month, args.day,
                                                      args.hour, args.minute)

        res = obj.get_events(args.format, time_frame)

        if (args.format == "json"):
            return common.format_json_object(res)
        return res

    except ValueError as e:
        raise SOSError(SOSError.CMD_LINE_ERR, "error: " + str(e))
    except SOSError as e:
        if (e.err_code == SOSError.SOS_FAILURE_ERR):
            raise SOSError(SOSError.SOS_FAILURE_ERR,
                           "Unable to get requested usage events")
        else:
            raise e
コード例 #55
0
def vcenter_query(args):
    obj = VCenter(args.ip, args.port)
    try:
        res = obj.vcenter_query(args.name, args.tenant)
        return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("query", "vcenter",
                                        e.err_text, e.err_code)
コード例 #56
0
def backupset_restore_status(args):
    obj = Backup(args.ip, Backup.DEFAULT_SYSMGR_PORT)
    try:
        res = obj.backupset_restore_status(args.bname, args.islocal)
        return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("restore", "backup", e.err_text,
                                        e.err_code)
コード例 #57
0
def varray_query(args):
    obj = VirtualArray(args.ip, args.port)
    try:
        res = obj.varray_query(args.name)
        return common.format_json_object(res)
    except SOSError as e:
        common.format_err_msg_and_raise("query", "varray", e.err_text,
                                        e.err_code)
コード例 #58
0
def remove_vcenter_acls(args):
    obj = VCenter(args.ip, args.port)
    try:
        res = obj.add_or_remove_vcenter_acls(args.name, args.tenants, "remove")
        if res:
            return common.format_json_object(res)
    except SOSError as e:
        raise e
コード例 #59
0
def get_vcenter_acls(args):
    obj = VCenter(args.ip, args.port)
    try:
        res = obj.get_vcenter_acls(args.name)
        if res:
            return common.format_json_object(res)
    except SOSError as e:
        raise e