Пример #1
0
def remove_endpoint(args):
    obj = Network(args.ip, args.port)
    try:
        obj.remove_endpoint(args.name, args.endpoint)
    except SOSError as e:
        common.format_err_msg_and_raise("remove_endpoint", "network",
                                        e.err_text, e.err_code)
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)
Пример #3
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)
Пример #4
0
def vnasserver_assign(args):
    obj = VnasServer(args.ip, args.port)
    vnas_assign_failure = 0
    total_assignments = len(args.name) * len(args.project)

    for project in args.project:
        for name in args.name:
            vnas_server_list = []
            vnas_server_list.append(name)
            project_name = args.tenant + "/" + project
            try:
                obj.assign(vnas_server_list, project_name)
            except SOSError as e:
                vnas_assign_failure = vnas_assign_failure + 1
    
    if(vnas_assign_failure == total_assignments):
        print "No vnasserver was assigned to any project"
        raise common.format_err_msg_and_raise("assign", "vnasserver",
                                        e.err_text, e.err_code)
    elif(vnas_assign_failure):
        print "Few vnasservers could not be assigned to some projects"
        raise common.format_err_msg_and_raise("assign", "vnasserver",
                                        e.err_text, e.err_code)
        
    return
Пример #5
0
def quotadirectory_update(args):
    obj = QuotaDirectory(args.ip, args.port)
    try:
        resourceUri = obj.storageResource_query(
            args.filesystem,
            args.project,
            args.tenant)

        obj.update(resourceUri, args.name, args.size, args.oplock, 
		   args.securitystyle, args.synchronous)

    except SOSError as e:
        if (e.err_code == SOSError.SOS_FAILURE_ERR):
            raise SOSError(
                SOSError.SOS_FAILURE_ERR,
                "QuotaDirectory: " +
                args.name +
                ", Update Failed\n" +
                e.err_text)
        else:
            common.format_err_msg_and_raise(
                "update",
                "quotadirectory",
                e.err_text,
                e.err_code)
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)
Пример #7
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)
Пример #8
0
def consistencygroup_create(args):
    try:
        obj = ConsistencyGroup(args.ip, args.port)
        res = obj.create(args.name, args.project, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("create", "consistency group",
                                        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)
Пример #10
0
def storageprovider_update(args):

    obj = StorageProvider(args.ip, args.port)
    passwd = None
    if (args.user and len(args.user) > 0):
        passwd = common.get_password("storage provider")

    try:
        
        if (not args.usessl):
            args.usessl = False
            
        secondary_password = None
        if (args.secondary_username and len(args.secondary_username) > 0):
            secondary_password = common.get_password("secondary password")

        res = obj.update(args.name, args.newname, args.providerip,
                         args.providerport, args.user, passwd,
                         args.usessl, args.interface, args.element_manager_url,
                         args.secondary_username, secondary_password)
    except SOSError as e:
        common.format_err_msg_and_raise(
            "update",
            "storageprovider",
            e.err_text,
            e.err_code)
Пример #11
0
def cluster_detach(args):
    obj = Cluster(args.ip, args.port)
    try:
        obj.cluster_detach(args.name, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("detach", "cluster",
                                        e.err_text, e.err_code)
Пример #12
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)
Пример #13
0
def ipinterface_update(args):

    if(args.newprotocol is None and args.newipaddress is None and
       args.newnetmask is None and
       args.newprefixlength is None and args.newscopeid):
        raise SOSError(SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
                       " " + sys.argv[2] + ": error:" +
                       "At least one of the arguments :"
                       "-newprotocol -newipaddress -newnetmask"
                       "-newprefixlength, -newscopeid"
                       " should be provided to update the Host")

    ipinterfaceObj = HostIPInterface(args.ip, args.port)
    try:
        ipinterfaceObj.update(
            args.hostlabel,
            args.ipaddress,
            args.newprotocol,
            args.newipaddress,
            args.newnetmask,
            args.newprefixlength,
            args.newscopeid,
            args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise(
            "update",
            "ipinterface",
            e.err_text,
            e.err_code)
Пример #14
0
def consistencygroup_create(args):
    try:
        obj = ConsistencyGroup(args.ip, args.port)
        res = obj.create(args.name, args.project, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("create", "consistency group",
                                        e.err_text, e.err_code)
Пример #15
0
def db_con_check_cancel(args):
    obj = ControlService(args.ip, ControlService.DEFAULT_SYSMGR_PORT)
    try:
        return obj.db_con_check_cancel()
    except SOSError as e:
        common.format_err_msg_and_raise("db consistency check", "cancel",
                                        e.err_text, e.err_code)
def varray_disallow_tenant(args):
    obj = VirtualArray(args.ip, args.port)
    try:
        obj.varray_disallow_tenant(args.name, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("disallow_tenant", "varray",
                                        e.err_text, e.err_code)
Пример #17
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)
Пример #18
0
def initiator_update(args):

    if (args.newprotocol is None and args.newinitiatorwwn is None
            and args.newinitiatorportwwn is None):
        raise SOSError(
            SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] + " " +
            sys.argv[2] + ": error:" + "At least one of the arguments :"
            "-newprotocol -newinitiatorwwn -newinitiatorportwwn"
            " should be provided to update the Host")
    if (args.newprotocol == "iSCSI" and args.newinitiatorwwn):
        raise SOSError(
            SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] + " " +
            sys.argv[2] + ": error: -newinititorwwn " +
            "is not required for iSCSI type initiator")

    initiatorObj = HostInitiator(args.ip, args.port)
    try:

        initiatorUri = initiatorObj.query_by_portwwn(args.initiatorportwwn,
                                                     args.hostlabel,
                                                     args.tenant)
        initiatorObj.update(initiatorUri, args.newprotocol,
                            args.newinitiatorwwn, args.newinitiatorportwwn,
                            args.newinitname)

    except SOSError as e:
        common.format_err_msg_and_raise("update", "initiator", e.err_text,
                                        e.err_code)
Пример #19
0
def vdc_add(args):
    try:
        VirtualDatacenter(args.ip, args.port).vdc_add(args.name, args.endpoint,
                                                      args.key, args.certfile,
                                                      args.description)
    except SOSError as e:
        common.format_err_msg_and_raise("add", "vdc", e.err_text, e.err_code)
def initiator_create(args):

    if(args.protocol == "FC" and args.initiatorwwn is None):
        raise SOSError(
            SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
            " " + sys.argv[2] + ": error:" +
            "-initiatorwwn is required for FC type initiator")

    if(args.protocol == "iSCSI" and args.initiatorwwn):
        raise SOSError(
            SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
            " " + sys.argv[2] + ": error:" +
            "-initiatorwwn is not required for iSCSI type initiator")

    initiatorObj = HostInitiator(args.ip, args.port)
    try:
        initiatorObj.create(
            args.sync,
            args.hostlabel,
            args.protocol,
            args.initiatorwwn,
            args.initiatorportwwn,
            args.initname)
    except SOSError as e:
        common.format_err_msg_and_raise(
            "create",
            "initiator",
            e.err_text,
            e.err_code)
Пример #21
0
def truststore_update_settings(args):
    obj = TrustStore(args.ip, args.port)
    try:
        obj.truststore_update_settings(args.acceptallcertificates)
    except SOSError as e:
        common.format_err_msg_and_raise("update settings", "truststore",
                                        e.err_text, e.err_code)
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)
Пример #23
0
def varray_delete(args):
    obj = VirtualArray(args.ip, args.port)
    try:
        obj.varray_delete(args.name)
    except SOSError as e:
        common.format_err_msg_and_raise("delete", "varray", e.err_text,
                                        e.err_code)
Пример #24
0
def quotadirectory_update(args):
    if not args.sync and args.synctimeout !=0:
        raise SOSError(SOSError.CMD_LINE_ERR,"error: Cannot use synctimeout without Sync ")
    obj = QuotaDirectory(args.ip, args.port)
    try:
        resourceUri = obj.storageResource_query(
            args.filesystem,
            args.project,
            args.tenant)

        obj.update(resourceUri, args.name, args.size, args.oplock, 
		   args.securitystyle, args.synchronous,args.synctimeout, args.advlim, args.softlim, args.grace)

    except SOSError as e:
        if (e.err_code == SOSError.SOS_FAILURE_ERR):
            raise SOSError(
                SOSError.SOS_FAILURE_ERR,
                "QuotaDirectory: " +
                args.name +
                ", Update Failed\n" +
                e.err_text)
        else:
            common.format_err_msg_and_raise(
                "update",
                "quotadirectory",
                e.err_text,
                e.err_code)
Пример #25
0
def varray_disallow_tenant(args):
    obj = VirtualArray(args.ip, args.port)
    try:
        obj.varray_disallow_tenant(args.name, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("disallow_tenant", "varray",
                                        e.err_text, e.err_code)
Пример #26
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)
Пример #27
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)
Пример #28
0
def filepolicy_create(args):
    obj = FilePolicy(args.ip, args.port)
    SYNC = 'SYNC'
    ASYNC = 'ASYNC'
    if args:
        try:
            obj.filepolicy_create(
                args.name,
                args.policy_type,
                args.tenants_access,
                args.description,
                args.priority,
                args.num_worker_threads,
                args.policy_sched_frequnecy,
                args.policy_schedule_repeat,
                args.policy_schedule_time,
                args.policy_schedule_week,
                args.policy_schedule_month,
                args.replication_type,
                args.snapshot_name_pattern,
                args.snapshot_expire_type,
                args.snapshot_expire_value,
                args.apply_at,
                )
        except SOSError, e:

            common.format_err_msg_and_raise('create', 'filepolicy',
                    e.err_text, e.err_code)
Пример #29
0
def backupset_pull_cancel(args):
    obj = Backup(args.ip, Backup.DEFAULT_SYSMGR_PORT)
    try:
        res = obj.backupset_pull_cancel(args.bname)
        return res
    except SOSError as e:
        common.format_err_msg_and_raise("backupset pull", "cancel", e.err_text, e.err_code)
Пример #30
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)
Пример #31
0
def vcenter_delete(args):
    obj = VCenter(args.ip, args.port)
    try:
        res = obj.vcenter_delete(args.name, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("delete", "vcenter",
                                        e.err_text, e.err_code)
def varray_delete(args):
    obj = VirtualArray(args.ip, args.port)
    try:
        obj.varray_delete(args.name)
    except SOSError as e:
        common.format_err_msg_and_raise("delete", "varray",
                                        e.err_text, e.err_code)
Пример #33
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)
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)
Пример #35
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)
Пример #36
0
def vnasserver_assign(args):
    obj = VnasServer(args.ip, args.port)
    vnas_assign_failure = 0
    total_assignments = len(args.name) * len(args.project)

    for project in args.project:
        for name in args.name:
            vnas_server_list = []
            vnas_server_list.append(name)
            project_name = args.tenant + "/" + project
            try:
                obj.assign(vnas_server_list, project_name)
            except SOSError as e:
                vnas_assign_failure = vnas_assign_failure + 1
    
    if(vnas_assign_failure == total_assignments):
        print "No vnasserver was assigned to any project"
        raise common.format_err_msg_and_raise("assign", "vnasserver",
                                        e.err_text, e.err_code)
    elif(vnas_assign_failure):
        print "Few vnasservers could not be assigned to some projects"
        raise common.format_err_msg_and_raise("assign", "vnasserver",
                                        e.err_text, e.err_code)
        
    return
Пример #37
0
def storageprovider_update(args):

    obj = StorageProvider(args.ip, args.port)
    passwd = None
    secondary_url = None
    if (args.user and len(args.user) > 0):
        passwd = common.get_password("storage provider")

    try:
        
        if (not args.usessl):
            args.usessl = False
            
        secondary_password = None
        if (args.interface =="ibmxiv") :
            if(args.hyperScaleHost is not None and args.hyperScalePort is not None) :
                secondary_url = "https://"+args.hyperScaleHost+":"+args.hyperScalePort;
            else:
                common.format_err_msg_and_raise ("create","storageprovider","IBM XIV needs HyperScale Host and Port as mandatory",SOSError.NOT_FOUND_ERR)

        if (args.secondary_username and len(args.secondary_username) > 0):
            secondary_password = common.get_password("secondary password")

        res = obj.update(args.name, args.newname, args.providerip,
                         args.providerport, args.user, passwd,
                         args.usessl, args.interface, args.element_manager_url,
                         args.secondary_username, secondary_password, secondary_url)
    except SOSError as e:
        common.format_err_msg_and_raise(
            "update",
            "storageprovider",
            e.err_text,
            e.err_code)
Пример #38
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)
Пример #39
0
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)
Пример #40
0
def bucket_acl(args):
    obj = Bucket(args.ip, args.port)
    try:
        if(not args.tenant):
            args.tenant = ""
        if(not args.user and not args.permissions):
            raise SOSError(SOSError.CMD_LINE_ERR, "Anonymous user should be provided to add/update/delete acl rule")
        if(args.user and args.group):
            raise SOSError(SOSError.CMD_LINE_ERR, "User and Group cannot be specified together")	
        
        
        res = obj.put_acl(args.tenant, args.project,
                           args.name, 
                           args.operation,
                           args.permissions,
                           args.domain,
                           args.user,
                           args.group,
                           args.customgroup)


    except SOSError as e:
                
        common.format_err_msg_and_raise("acl", "name",
                                        e.err_text, e.err_code)
Пример #41
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)
def initiator_update(args):

    if(args.newprotocol is None and
       args.newinitiatorwwn is None and
       args.newinitiatorportwwn is None):
        raise SOSError(SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
                       " " + sys.argv[2] + ": error:" +
                       "At least one of the arguments :"
                       "-newprotocol -newinitiatorwwn -newinitiatorportwwn"
                       " should be provided to update the Host")
    if(args.newprotocol == "iSCSI" and args.newinitiatorwwn):
        raise SOSError(SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
                       " " + sys.argv[2] + ": error: -newinititorwwn " +
                       "is not required for iSCSI type initiator")

    initiatorObj = HostInitiator(args.ip, args.port)
    try:

        initiatorUri = initiatorObj.query_by_portwwn(
            args.initiatorportwwn,
            args.hostlabel)
        initiatorObj.update(
            initiatorUri,
            args.newprotocol,
            args.newinitiatorwwn,
            args.newinitiatorportwwn,
            args.newinitname)

    except SOSError as e:
        common.format_err_msg_and_raise(
            "update",
            "initiator",
            e.err_text,
            e.err_code)
Пример #43
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)
def storageprovider_update(args):

    obj = StorageProvider(args.ip, args.port)
    passwd = None
    if args.user and len(args.user) > 0:
        passwd = common.get_password("storage provider")

    try:
        if not args.usessl:
            args.usessl = False

        if args.secondary_username and len(args.secondary_username) > 0:
            secondary_password = common.get_password("secondary password")

        res = obj.update(
            args.name,
            args.newname,
            args.providerip,
            args.providerport,
            args.user,
            passwd,
            args.usessl,
            args.interface,
            args.element_manager_url,
            args.secondary_username,
            secondary_password,
        )
    except SOSError as e:
        common.format_err_msg_and_raise("update", "storageprovider", e.err_text, e.err_code)
Пример #45
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)
Пример #46
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)
Пример #47
0
def restart_service(args):
    nodeId = args.nodeid
    serviceName = args.servicename
    nodename = args.nodename

    try:
        if(args.nodename is not None and args.nodeid is not None):
            print "Error: Enter either Node name or Node ID "
            return
        if(args.nodename is None and args.nodeid is None):
            print "Error : Enter either Node name or Node ID "
            return
            
        response = common.ask_continue(
            "restart service:" +
            serviceName )
        if(str(response) == "y"):
            contrlSvcObj = ControlService(args.ip, args.port)
            contrlSvcObj.restartService(nodeId, serviceName , nodename)
    except SOSError as e:
        common.format_err_msg_and_raise(
            "restart-service",
            serviceName ,
            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 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)
Пример #50
0
def quotadirectory_updates(args):
    obj = QuotaDirectory(args.ip, args.port)    
    try:
        resourceUri = obj.storageResource_query(
            args.filesystem,
            args.project,
            args.tenant)
        respContent = obj.quotadirectory_updates(
            resourceUri,
            args.name, 
            args.size, 
            args.oplock,
            args.securitystyle,
            args.advlim,
            args.softlim,
            args.grace)

        return 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(
                "update",
                "quotadirectory",
                e.err_text,
                e.err_code)
Пример #51
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)
Пример #52
0
def storageport_update(args):
    # get uri of a storage device by name
    obj = Storageport(args.ip, args.port)
    try:
        # validate input
        if (args.network is None and args.varray_add is None
                and args.varray_remove is None
                and args.port_network_id is None):
            raise SOSError(
                SOSError.CMD_LINE_ERR,
                sys.argv[0] + " " + sys.argv[1] + " " + sys.argv[2] +
                ": error:" + "At least one of the arguments : -network "
                "-varray_add -varray_remove -port_network_id"
                " should be provided to update the storageport")
        #For port_network_id update, port name is mandatory as multiple ports
        # can not share the same port_network_id ( WWPN )
        if ((args.port_network_id is not None) and (args.portname is None)):
            raise SOSError(
                SOSError.CMD_LINE_ERR,
                sys.argv[0] + " " + sys.argv[1] + " " + sys.argv[2] +
                ": error:" + "To update port network id, port name should "
                "be provided.")

        obj.command_validation(args.type, args.transporttype,
                               args.port_network_id)
        obj.storageport_update(args.serialnumber, args.storagesystem,
                               args.type, args.transporttype, args.network,
                               args.varray_add, args.varray_remove,
                               args.portname, args.group, args.port_network_id)
    except SOSError as e:
        common.format_err_msg_and_raise("update", "storageport", e.err_text,
                                        e.err_code)
Пример #53
0
def cluster_detach(args):
    obj = Cluster(args.ip, args.port)
    try:
        obj.cluster_detach(args.name, args.tenant)
    except SOSError as e:
        common.format_err_msg_and_raise("detach", "cluster",
                                        e.err_text, e.err_code)
Пример #54
0
def network_assign(args):
    obj = Network(args.ip, args.port)
    try:
        obj.assign(args.name, args.varray)
    except SOSError as e:
        common.format_err_msg_and_raise("assign varray", "network", e.err_text,
                                        e.err_code)
Пример #55
0
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)
Пример #56
0
def network_deregister(args):
    obj = Network(args.ip, args.port)
    try:
        obj.deregister(args.name)
    except SOSError as e:
        common.format_err_msg_and_raise("deregister", "network", e.err_text,
                                        e.err_code)
Пример #57
0
def cluster_update(args):
    obj = Cluster(args.ip, args.port)
    try:
        if (args.label is None and args.tenant is None
                and args.datacenter is None and args.vcenter is None
                and args.autoexportsenabled is None):
            raise SOSError(
                SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] + " " +
                sys.argv[2] + ": error:" + "At least one of the"
                " arguments :-tenant -label -vcenter -datacenter"
                " -autoExportsEnabled "
                " should be provided to update the cluster")

        if (args.datacenter or args.vcenter):
            if (args.datacenter is None or args.vcenter is None):
                raise SOSError(
                    SOSError.CMD_LINE_ERR,
                    sys.argv[0] + " " + sys.argv[1] + " " + sys.argv[2] +
                    ": error:" + "For a vcenter associated cluster, both " +
                    "vcenter and datacenter needs to be specified")

        obj.cluster_update(args.name, args.tenant, args.datacenter,
                           args.vcenter, args.label, args.autoexportsenabled)
    except SOSError as e:
        common.format_err_msg_and_raise("update", "cluster", e.err_text,
                                        e.err_code)