示例#1
0
def main():
    s = NaServer("10.128.153.60", 1 , 21)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user("BNELAB\\duanes", "D3m0open")

    cs = statsd.StatsClient('localhost',8125)


    for v in get_volumes(s):
	try:
	    v_cn  = v['cluster-name']
	    v_svm = v['owning-vserver-name']
	    v_vol = v['name']
	    c = get_counters(s, v['instance-uuid'])

	    c_ts = c['timestamp']
	    c_read_ops  = c['read_ops']
	    c_write_ops = c['write_ops']
	    c_total_ops = c['total_ops']

	    metric_string =  "brisvegas.%s.%s.read_ops" % (v_svm, v_vol)
	    print metric_string, c_read_ops, c_write_ops

	    cs.gauge(metric_string, c_read_ops)
	    metric_string =  "brisvegas.%s.%s.write_ops" % (v_svm, v_vol)
	    cs.gauge(metric_string, c_write_ops)

	    #print c

	except KeyError:
	    continue
def cdotconnect(filer, username, password) :
    """ return a filer connection handle """
    s = NaServer(filer, 1 , 31)
    s.set_server_type("FILER")
    s.set_transport_type("HTTP") # would like to use HTTPS but I get ssl cert errors on Ubuntu 15.x
    s.set_port(80)
    s.set_style("LOGIN")
    s.set_admin_user(username, password)
    return s
def connect(hostname, user, password, minor_version=1, major_version=21):
    global conn
    conn = NaServer(hostname, minor_version, major_version)
    conn.set_server_type('filer')
    conn.set_transport_type('HTTPS')
    conn.set_port(443)
    conn.set_style('LOGIN')
    conn.set_admin_user(user, password)
    return conn
示例#4
0
def create_qtree_quota():
    
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set transport type " + r + "\n")
        sys.exit (2)

    if(args >  5):
        out = s.invoke("qtree-create", "qtree", qtree, "volume", volume, "mode", mode )

    else :
        out = s.invoke( "qtree-create", "qtree", qtree, "volume", volume)

    if (out.results_status() == "failed"):
        print(out.results_reason())
        print("\n")
        sys.exit (2)

    print ("Created new qtree\n")
示例#5
0
def main() :
    s = NaServer(filer, 1, 3)

    out = s.set_transport_type('HTTP')
    if (out and out.results_errno() != 0) :
        r = out.results_reason()
        print ("Connection to filer failed: " + r + "\n")
        sys.exit(2)

    out = s.set_style('LOGIN')
    
    if (out and out.results_errno() != 0) :
        r = out.results_reason()
        print ("Connection to filer failed: " + r + "\n")
        sys.exit(2)

    out = s.set_admin_user(user, pw)

    if(command == "object-list"):
        get_object_list(s)

    elif(command == "instance-list"):
        get_instance_list(s)

    elif(command == "counter-list"):
        get_counter_list(s)

    elif(command == "get-counter-values"):
        get_counter_values(s)

    else:
        print ("Invalid operation\n")
        print_usage()
示例#6
0
文件: snmp.py 项目: raykuan/docs
def main():
    s = NaServer (filer, 1, 3)
    response = s.set_style('LOGIN')
    
    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)
        
    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set HTTP transport" + r + "\n")
        sys.exit (2)

    if(command == "get"):
        snmp_get(s)

    elif(command == "status"):
        snmp_status(s)

    elif(command == "addCommunity"):
        add_community(s)

    elif(command == "deleteCommunity"):
        delete_community(s)

    else:
        print ("Invalid operation\n")
        print_usage()
def main():
    
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    if(option == "get"):
        get_option_info(s)

    elif(option == "set"):
        set_option_info(s)

    elif(option == "optionsList"):
        options_list_info(s)

    else:
        print("Invalid Option \n")
        print_usage()
示例#8
0
def main():
    s = NaServer(filer, 1, 3)
    resp = s.set_style('LOGIN')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Failed to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    if((command == "raw-capacity") or (command == "formatted-capacity")	or (command == "spare-capacity")) :
        calc_raw_fmt_spare_capacity(s)

    elif((command == "raid-overhead") or (command == "wafl-overhead")) :
        calc_raid_wafl_overhead(s)

    elif(command == "allocated-capacity") :
        calc_allocated_capacity(s)

    elif(command == "avail-user-data-capacity") :
        calc_avail_user_data_capacity(s)

    elif(command == "provisioning-capacity") :
        calc_provisioning_capacity(s)

    else :
        print ("Invalid operation\n")
def main():
    s = NaServer(filer, 1, 3)

    out = s.set_transport_type('HTTP')
    if (out and out.results_errno() != 0):
        r = out.results_reason()
        print("Connection to filer failed: " + r + "\n")
        sys.exit(2)

    out = s.set_style('LOGIN')

    if (out and out.results_errno() != 0):
        r = out.results_reason()
        print("Connection to filer failed: " + r + "\n")
        sys.exit(2)

    out = s.set_admin_user(user, pw)

    if (command == "object-list"):
        get_object_list(s)

    elif (command == "instance-list"):
        get_instance_list(s)

    elif (command == "counter-list"):
        get_counter_list(s)

    elif (command == "get-counter-values"):
        get_counter_values(s)

    else:
        print("Invalid operation\n")
        print_usage()
示例#10
0
def main():
    s = NaServer(filer, 1, 3)
    resp = s.set_style('LOGIN')

    if (resp and resp.results_errno() != 0):
        r = resp.results_reason()
        print("Failed to set authentication style " + r + "\n")
        sys.exit(2)

    s.set_admin_user(user, pw)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0):
        r = resp.results_reason()
        print("Unable to set HTTP transport " + r + "\n")
        sys.exit(2)

    if ((command == "raw-capacity") or (command == "formatted-capacity")
            or (command == "spare-capacity")):
        calc_raw_fmt_spare_capacity(s)

    elif ((command == "raid-overhead") or (command == "wafl-overhead")):
        calc_raid_wafl_overhead(s)

    elif (command == "allocated-capacity"):
        calc_allocated_capacity(s)

    elif (command == "avail-user-data-capacity"):
        calc_avail_user_data_capacity(s)

    elif (command == "provisioning-capacity"):
        calc_provisioning_capacity(s)

    else:
        print("Invalid operation\n")
示例#11
0
文件: san_mgmt.py 项目: raykuan/docs
def main():
    s = NaServer (filer, 1, 3)
    response = s.set_style('LOGIN')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set HTTP transport" + r + "\n")
        sys.exit (2)

    if(command == "lun"):
        process_LUN(s)

    elif(command == "igroup"):
        process_igroup(s)

    elif(command == "fcp"):
        process_fcp(s)

    elif(command == "iscsi"):
        process_iscsi(s)

    else:
        print ("Invalid operation\n")
        print_usage()
示例#12
0
def main():
    s = NaServer (filer, 1, 3)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    resp = s.set_style('LOGIN')
    
    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Failed to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)

    if(command == "file-get-snaplock-retention-time"):
        file_get_retention(s)

    elif(command == "file-set-snaplock-retention-time"):
        file_set_retention(s)

    elif(command == "file-snaplock-retention-time-list-info"):
        file_get_retention_list(s)

    elif(command == "file-get-snaplock-retention-time-list-info-max"):
        file_get_retention_list_info_max(s)

    else:
        print ("Invalid operation\n")
        print_usage()
示例#13
0
def main():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')
    
    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)
        
    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set HTTP transport" + r + "\n")
        sys.exit (2)

    if(command == "getStatus"):
        get_status(s)

    elif(command == "getVolStatus"):
        get_vol_status(s)

    elif(command == "off"):
        snapmirror_off(s)

    elif(command == "on"):
        snapmirror_on(s)

    else:
        print ("Invalid operation\n")
        print_usage()
示例#14
0
def main():

    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

    if (response and response.results_errno() != 0):
        r = response.results_reason()
        print("Unable to set authentication style " + r + "\n")
        sys.exit(2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0):
        r = response.results_reason()
        print("Unable to set HTTP transport " + r + "\n")
        sys.exit(2)

    if (command == "scheduleList"):
        schedule_list(s)

    elif (command == "relationshipStatus"):
        relationship_status(s)

    else:
        print("Invalid operation \n")
        print_usage()
示例#15
0
def aggr_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    node = module.params['node']
    disk_type = module.params['disk_type']
    aggr = module.params['aggr']
    disk_count = module.params['disk_count']
    disk_size = module.params['disk_size']
    raid_size = module.params['raid_size']
    raid_type = module.params['raid_type']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("aggr-create")
    api.child_add_string("disk-type", disk_type)
    api.child_add_string("aggregate", aggr)
    api.child_add_string("disk-count", disk_count)
    api.child_add_string("disk-size-with-unit", disk_size)
    api.child_add_string("raid-size", raid_size)
    api.child_add_string("raid-type", raid_type)

    xi = NaElement("nodes")
    api.child_add(xi)
    xi.child_add_string("node-name", node)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#16
0
def vserver_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    vserver = module.params['vserver']
    comment = module.params['comment']
    ipspace = module.params['ipspace']
    language = module.params['language']
    root_vol = module.params['root_vol']
    root_vol_aggr = module.params['root_vol_aggr']
    security = module.params['security']
    vserver_sub = module.params['vserver_sub']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement('vserver-create')
    api.child_add_string('comment', comment)
    api.child_add_string('ipspace', ipspace)
    api.child_add_string('language', language)
    api.child_add_string('vserver-name', vserver)
    api.child_add_string('root-volume', root_vol)
    api.child_add_string('root-volume-aggregate', root_vol_aggr)
    api.child_add_string('root-volume-security-style', security)
    api.child_add_string('vserver-subtype', vserver_sub)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#17
0
def subnet_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    subnet_name = module.params['subnet_name']
    subnet = module.params['subnet']
    ip_ranges = module.params['ip_ranges']
    bc_domain = module.params['bc_domain']
    gateway = module.params['gateway']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("net-subnet-create")
    api.child_add_string("broadcast-domain", bc_domain)
    api.child_add_string("subnet-name", subnet_name)
    api.child_add_string("subnet", subnet)

    if module.params['gateway']:
        api.child_add_string("gateway", gateway)

    xi = NaElement("ip-ranges")
    api.child_add(xi)
    for ip in ip_ranges:
        xi.child_add_string("ip-range", ip)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#18
0
def connect_to_api(module, vserver=None):
    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    validate_certs = module.params['validate_certs']

    if not validate_certs:
        invoke_ssl_no_verify()

    connection = NaServer(cluster, 1, 0)
    connection.set_server_type("FILER")
    connection.set_transport_type("HTTPS")
    connection.set_port(443)
    connection.set_style("LOGIN")
    connection.set_admin_user(user_name, password)
    if vserver:
        connection.set_vserver(vserver)
    return connection
示例#19
0
def login_naserver(cluster):
    '''Global variables'''
    hostname = cluster
    username = config.username
    password = config.password
    port = 80
    serverType = 'FILER'
    transportType = 'HTTP'

    # Connect to NaServer
    server = NaServer(hostname, 1, 101)
    server.set_server_type(serverType)
    server.set_transport_type(transportType)
    server.set_port(port)
    server.set_style('LOGIN')
    server.set_admin_user(username, password)

    return server
示例#20
0
def date_time(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    timezone = module.params['timezone']
    date = module.params['date']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    args = NaElement("args")

    args.child_add(NaElement("arg", "cluster"))
    args.child_add(NaElement("arg", "date"))
    args.child_add(NaElement("arg", "modify"))
    if module.params['timezone']:
        args.child_add(NaElement("arg", "-timezone"))
        args.child_add(NaElement("arg", timezone))
    if module.params['date']:
        args.child_add(NaElement("arg", "-date"))
        args.child_add(NaElement("arg", date))

    systemCli = NaElement("system-cli")
    systemCli.child_add(args)
    xo = s.invoke_elem(systemCli)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
def failover_group_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    failover_group = module.params['failover_group']
    return_record = module.params['return_record']
    targets = module.params['targets']
    vserver = module.params['vserver']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("net-failover-group-create")
    api.child_add_string("failover-group", failover_group)
    if module.params['return_record']:
        api.child_add_string("ipspace", ipspace)
    api.child_add_string("vserver", vserver)

    xi = NaElement("targets")
    api.child_add(xi)

    for target in targets:
        xi.child_add_string("net-qualified-port-name", target)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#22
0
def sp_modify(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    node = module.params['node']
    addr_family = module.params['addr_family']
    dhcp = module.params['dhcp']
    ip = module.params['ip']
    netmask = module.params['netmask']
    gateway = module.params['gateway']
    enabled = module.params['enabled']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("service-processor-network-modify")
    api.child_add_string("address-type", addr_family)
    api.child_add_string("dhcp", dhcp)
    api.child_add_string("node", node)
    api.child_add_string("ip-address", ip)
    api.child_add_string("netmask", netmask)
    api.child_add_string("gateway-ip-address", gateway)
    api.child_add_string("is-enabled", enabled)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#23
0
def dns_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    vserver = module.params['vserver']
    domains = module.params['domains']
    dns_servers = module.params['dns_servers']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    args = NaElement("args")

    args.child_add(NaElement("arg", "dns"))
    args.child_add(NaElement("arg", "create"))
    args.child_add(NaElement("arg", "-vserver"))
    args.child_add(NaElement("arg", vserver))
    args.child_add(NaElement("arg", "-domains"))
    args.child_add(NaElement("arg", domains))
    args.child_add(NaElement("arg", "-name-servers"))
    args.child_add(NaElement("arg", dns_servers))

    systemCli = NaElement("system-cli")
    systemCli.child_add(args)
    xo = s.invoke_elem(systemCli)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#24
0
def asup_invoke(module):

  cluster = module.params['cluster']
  user_name = module.params['user_name']
  password = module.params['password']
  node = module.params['node']
  message = module.params['message']
  asup_type = module.params['asup_type']
  uri = module.params['uri']

  results = {}

  results['changed'] = False

  s = NaServer(cluster, 1 , 0)
  s.set_server_type("FILER")
  s.set_transport_type("HTTPS")
  s.set_port(443)
  s.set_style("LOGIN")
  s.set_admin_user(user_name, password)

  api = NaElement("autosupport-invoke")
  api.child_add_string("node-name", node)
  api.child_add_string("type", asup_type)

  if module.params['message']:
    api.child_add_string("message", message)

  if module.params['uri']:
    api.child_add_string("uri", uri)


  xo = s.invoke_elem(api)

  if(xo.results_errno() != 0):
    r = xo.results_reason()
    module.fail_json(msg=r)
    results['changed'] = False

  else:
    results['changed'] = True

  return results
def nfs_service_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    vserver = module.params['vserver']
    nfs_access = module.params['nfs_access']
    nfsv3_enabled = module.params['nfsv3_enabled']
    nfsv40_enabled = module.params['nfsv40_enabled']
    nfsv41_enabled = module.params['nfsv41_enabled']
    vstorage_enabled = module.params['vstorage_enabled']
    nfsv41_pnfs_enabled = module.params['nfsv41_pnfs_enabled']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 15)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)
    s.set_vserver(vserver)

    api = NaElement("nfs-service-create")
    api.child_add_string("is-nfs-access-enabled", nfs_access)
    api.child_add_string("is-nfsv3-enabled", nfsv3_enabled)
    api.child_add_string("is-nfsv40-enabled", nfsv40_enabled)
    api.child_add_string("is-nfsv41-enabled", nfsv41_enabled)
    api.child_add_string("is-vstorage-enabled", vstorage_enabled)
    api.child_add_string("is-nfsv41-pnfs-enabled", nfsv41_pnfs_enabled)
    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#26
0
def lockcheck(node ,cluster_ip, username, password):
    s = NaServer(cluster_ip, 1, 110)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(username, password)
    cmd = shlex.split('statistics show -object nfsv4_diag -instance nfs4_diag -counter storePool_OpenAlloc -raw -node '+node)
    args = NaElement('args')
    for arg in cmd:
        args.child_add(NaElement('arg', arg))
    cli = NaElement('system-cli')
    cli.child_add(args)
    cli.child_add(NaElement('priv', 'diagnostic'))
    out = s.invoke_elem(cli)
    format_output = out.sprintf()
    result = format_output.split('storePool_OpenAlloc')[1].splitlines()[0].strip(" ")
    result = int(result)
    return result
示例#27
0
def cluster_peer_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    remote_user = module.params['remote_user']
    remote_pass = module.params['remote_pass']
    peer_addrs = module.params['peer_addrs']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("cluster-peer-create")
    if module.params['remote_user']:
        api.child_add_string("user-name", remote_user)
        api.child_add_string("password", remote_pass)

    xi = NaElement("peer-addresses")
    api.child_add(xi)

    for ip in peer_addrs:
        xi.child_add_string("remote-inet-address", ip)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#28
0
def broadcast_domain_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    bc_domain = module.params['bc_domain']
    mtu = module.params['mtu']
    ports = module.params['ports']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("net-port-broadcast-domain-create")
    api.child_add_string("broadcast-domain", bc_domain)
    api.child_add_string("mtu", mtu)

    xi = NaElement("ports")
    api.child_add(xi)

    for port in ports:
        xi.child_add_string("net-qualified-port-name", port)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#29
0
def vlan_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    node = module.params['node']
    int_name = module.params['int_name']
    vlanid = module.params['vlanid']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("net-vlan-create")

    xi = NaElement("vlan-info")
    api.child_add(xi)

    xi.child_add_string('node', node)
    xi.child_add_string('parent-interface', int_name)
    xi.child_add_string('vlanid', vlanid)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#30
0
def aggr_hybrid(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    aggr = module.params['aggr']
    hybrid = module.params['hybrid']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    args = NaElement("args")

    args.child_add(NaElement("arg", "aggregate"))
    args.child_add(NaElement("arg", "modify"))
    args.child_add(NaElement("arg", aggr))
    args.child_add(NaElement("arg", "-hybrid-enabled"))
    args.child_add(NaElement("arg", hybrid))

    systemCli = NaElement("system-cli")
    systemCli.child_add(args)
    xo = s.invoke_elem(systemCli)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#31
0
def list_lifs_from_locked_node(cluster, problem_node, problem_vserver, username, password):
    s = NaServer(cluster, 1 , 110)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(username, password)

    # Set tag to null in order to use the iter-api properly
    tag = "";
    interfaces = []
    while tag != None:
        if not tag:
            result = s.invoke('net-interface-get-iter', 'max-records', 1)
        else:
            result = s.invoke('net-interface-get-iter', 'tag', tag, 'max-records', 1)

        if result.results_status() == "failed":
            reason = result.results_reason()
            print(reason + "\n")
            return
            #sys.exit(2)

        if result.child_get_int('num-records') == 0:
            # print("Migrating interfaces")
            # for i in interfaces:
            #     print(i['name'])
            #sys.exit(0)
            return interfaces

        tag = result.child_get_string('next-tag')

        for interface in result.child_get('attributes-list').children_get():
            name = interface.child_get_string('interface-name')
            vserver = interface.child_get_string('vserver')
            home_port = interface.child_get_string('home-port')
            home_node = interface.child_get_string('home-node')
            if vserver == problem_vserver and home_node == problem_node:
                interfaces.append({'name':name, 'vserver': vserver, 'home_port':home_port, 'home_node':home_node})
示例#32
0
def get_volume_info():


    args = len(sys.argv) - 1
    
    if(args < 3):
        print_usage()
 
    filer = sys.argv[1]
    user = sys.argv[2]
    pw = sys.argv[3]
   
    if(args == 4):
        volume = sys.argv[4]

    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')
    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')
    
    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    if(args == 3):
        out = s.invoke("volume-list-info")

    else:
        out = s.invoke("volume-list-info", "volume", volume)

    if(out.results_status() == "failed"):
        print (out.results_reason() + "\n")
        sys.exit (2)

    volume_info = out.child_get("volumes")
    result = volume_info.children_get()

    for vol in result:
        vol_name = vol.child_get_string("name")
        print ("Volume name :" + vol_name + "\n")
        size_total = vol.child_get_int("size-total")
        print ("Total size: " + str(size_total) + " bytes \n")
        size_used = vol.child_get_int("size-used")
        print ("Used Size : " + str(size_used) + " bytes\n")
        print ("-------------------------------------------\n")
示例#33
0
def volume_set_option(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    vserver = module.params['vserver']
    volume = module.params['volume']
    option_name = module.params['option_name']
    option_value = module.params['option_value']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 15)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)
    s.set_vserver(vserver)

    api = NaElement("volume-set-option")
    api.child_add_string("volume", volume)
    api.child_add_string("option-name", option_name)
    api.child_add_string("option-value", option_value)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#34
0
def ifgrp_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    node = module.params['node']
    ifgrp = module.params['ifgrp']
    mode = module.params['mode']
    dist_func = module.params['dist_func']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("net-port-ifgrp-create")
    api.child_add_string("distribution-function", dist_func)
    api.child_add_string("ifgrp-name", ifgrp)
    api.child_add_string("mode", mode)
    api.child_add_string("node", node)

    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
示例#35
0
def port_flow(module):

  cluster = module.params['cluster']
  user_name = module.params['user_name']
  password = module.params['password']
  node = module.params['node']
  port = module.params['port']
  flow_admin = module.params['flow_admin']

  results = {}

  results['changed'] = False

  s = NaServer(cluster, 1 , 0)
  s.set_server_type("FILER")
  s.set_transport_type("HTTPS")
  s.set_port(443)
  s.set_style("LOGIN")
  s.set_admin_user(user_name, password)

  api = NaElement("net-port-modify")
  api.child_add_string("administrative-flowcontrol", flow_admin)
  api.child_add_string("node", node)
  api.child_add_string("port", port)


  xo = s.invoke_elem(api)

  if(xo.results_errno() != 0):
    r = xo.results_reason()
    module.fail_json(msg=r)
    results['changed'] = False

  else:
    results['changed'] = True

  return results
示例#36
0
def license_add(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    license_keys = module.params['license_keys']

    results = {}

    results['changed'] = False

    s = NaServer(cluster, 1, 0)
    s.set_server_type("FILER")
    s.set_transport_type("HTTPS")
    s.set_port(443)
    s.set_style("LOGIN")
    s.set_admin_user(user_name, password)

    api = NaElement("license-v2-add")
    xi = NaElement("codes")

    api.child_add(xi)

    for key in license_keys:
        xi.child_add_string("license-code-v2", key)
    xo = s.invoke_elem(api)

    if (xo.results_errno() != 0):
        r = xo.results_reason()
        module.fail_json(msg=r)
        results['changed'] = False

    else:
        results['changed'] = True

    return results
def export_policy_create(module):

  cluster = module.params['cluster']
  user_name = module.params['user_name']
  password = module.params['password']
  vserver = module.params['vserver']
  policy_name = module.params['policy_name']
  return_record = module.params['return_record']

  results = {}

  results['changed'] = False

  s = NaServer(cluster, 1 , 15)
  s.set_server_type("FILER")
  s.set_transport_type("HTTPS")
  s.set_port(443)
  s.set_style("LOGIN")
  s.set_admin_user(user_name, password)
  s.set_vserver(vserver)

  api = NaElement("export-policy-create")
  api.child_add_string("policy-name", policy_name)
  if module.params['return_record']:
    api.child_add_string("return-record", return_record)
  xo = s.invoke_elem(api)

  if(xo.results_errno() != 0):
    r = xo.results_reason()
    module.fail_json(msg=r)
    results['changed'] = False

  else:
    results['changed'] = True

  return results
def main() :
    SevenMode = Get7ModeSystems()

    for toaster in SevenMode:
        drives_mapped = defaultdict(list)
        filer = toaster[0]
        user = toaster[1]
        pw = toaster[2]

        s = NaServer(filer, 1, 3)
        out = s.set_transport_type('HTTPS')

        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)

        out = s.set_style('LOGIN')
    
        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)

        out = s.set_admin_user(user, pw)

        if(command == "object-list"):
            get_object_list(s)

        elif(command == "instance-list"):
            get_instance_list(s)

        elif(command == "counter-list"):
           get_counter_list(s)

        elif(command == "get-counter-values"):
            message_lines = []
            #turn the filer FQDN into something more Graphite Friendly
            filername = filer.split(".")[0]
            message_lines = get_counter_values(filername, s)
            message = '\n'.join(message_lines) + '\n' 
            #print message
            SendToGraphite(message)


        else:
            print ("Invalid operation\n")
            print_usage()
def main():

    if (not ((command == "create") or (command == "estimate") or
             (command == "split") or (command == "status"))):
        print(command + " is not a valid command\n")
        print_usage()

    if ((command == "create") and (parent_vol == None)):
        print(command + " operation requires <parent-volname>\n")
        print("Usage: flexclone.py <filer> <user> <password>" + command +
              " <clone-volname> <parent-volname>\n")
        sys.exit(2)

    s = NaServer(filer, 1, 3)
    resp = s.set_style('LOGIN')

    if (resp and resp.results_errno() != 0):
        r = resp.results_reason()
        print("Failed to set authentication style " + r + "\n")
        sys.exit(2)

    s.set_admin_user(user, pw)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0):
        r = resp.results_reason()
        print("Unable to set HTTP transport " + r + "\n")
        sys.exit(2)

    if (command == "create"):
        create_flexclone(s)

    elif (command == "estimate"):
        estimate_flexclone_split(s)

    elif (command == "split"):
        start_flexclone_split(s)

    elif (command == "status"):
        flexclone_split_status(s)

    else:
        print("Invalid operation\n")
        print_usage()
示例#40
0
def connect_filer(host,user,passwd):
   plog.print_debug("Host: %s, User: %s" %(host,user))
   s = NaServer(host, 1, 1)
   s.set_server_type("Filer")
   s.set_admin_user(user,passwd)
   response = s.set_transport_type('HTTP')

   if(response and response.results_errno() != 0 ):
      r = response.results_reason()
      plog.print_error("Unable to set HTTP transport " + r + "\n")
      sys.exit (1)

   response = s.set_style('LOGIN')
   if(response and response.results_errno() != 0 ):
      r = response.results_reason()
      plog.print_error("Unable to set authentication style " + r + "\n")
      sys.exit (1)

   return s
示例#41
0
文件: flexclone.py 项目: raykuan/docs
def main():

    if(not ((command == "create") or (command == "estimate") or (command == "split") or (command == "status"))):
        print(command + " is not a valid command\n")
        print_usage()

    if ((command == "create") and (parent_vol == None)):
        print(command + " operation requires <parent-volname>\n")
        print("Usage: flexclone.py <filer> <user> <password>" + command + " <clone-volname> <parent-volname>\n")
        sys.exit (2)

    s = NaServer(filer, 1, 3)
    resp = s.set_style('LOGIN')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Failed to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    if(command == "create"):
        create_flexclone(s)

    elif(command == "estimate") :
        estimate_flexclone_split(s)

    elif(command == "split") :
        start_flexclone_split(s)

    elif(command == "status"):
        flexclone_split_status(s)

    else :
        print ("Invalid operation\n")
        print_usage()
示例#42
0
文件: quotalist.py 项目: raykuan/docs
def get_quota_info():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if(response and response.results_errno() != 0 ):
        r = response.results_reason()
        print ("Unable to set transport type " + r + "\n")
        sys.exit (2)

    out = s.invoke( "quota-list-entries" )

    if (out.results_status() == "failed"):
        print(out.results_reason() + "\n")
        sys.exit (2)

    quota_info = out.child_get("quota-entries")
    result = quota_info.children_get()
    print("-----------------------------------------------------\n")

    for quota in result :
        if(quota.child_get_string("quota-target")):
            quota_target = quota.child_get_string("quota-target")
            print  ("Quota Target: " + quota_target + " \n")
            
        if(quota.child_get_string("volume")):
            volume = quota.child_get_string("volume")
            print  ("Volume: " + volume + "\n")

        if(quota.child_get_string("quota-type")):
            quota_type = quota.child_get_string("quota-type")
            print  ("Quota Type: " + quota_type + "\n")

        print ("-----------------------------------------------------\n")
示例#43
0
def get_quota_info():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

    if (response and response.results_errno() != 0):
        r = response.results_reason()
        print("Unable to set authentication style " + r + "\n")
        sys.exit(2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0):
        r = response.results_reason()
        print("Unable to set transport type " + r + "\n")
        sys.exit(2)

    out = s.invoke("quota-list-entries")

    if (out.results_status() == "failed"):
        print(out.results_reason() + "\n")
        sys.exit(2)

    quota_info = out.child_get("quota-entries")
    result = quota_info.children_get()
    print("-----------------------------------------------------\n")

    for quota in result:
        if (quota.child_get_string("quota-target")):
            quota_target = quota.child_get_string("quota-target")
            print("Quota Target: " + quota_target + " \n")

        if (quota.child_get_string("volume")):
            volume = quota.child_get_string("volume")
            print("Volume: " + volume + "\n")

        if (quota.child_get_string("quota-type")):
            quota_type = quota.child_get_string("quota-type")
            print("Quota Type: " + quota_type + "\n")

        print("-----------------------------------------------------\n")
    def run(self):
        self.filer_metrics = {}
        metric = self.MetricName
        filer = self.FilerName
        s = NaServer(filerdict[filer]['ipaddr'], 1, 3)
        out = s.set_transport_type('HTTPS')
        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)
            
        out = s.set_style('LOGIN')
        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)
        out = s.set_admin_user(filerdict[filer]['user'], filerdict[filer]['password'])

        #Get the volume performance metrics
        self.volume_perf_metrics(s)
        self.volume_capacity_metrics(s)
        self.quota_metrics(s)
示例#45
0
def get_volume_info():
    s = NaServer (filer, 1, 3)
    response = s.set_style('LOGIN')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set HTTP transport" + r + "\n")
        sys.exit (2)

    for volume in volumes:
        out = s.invoke( "volume-list-info","volume", volume )
        
        if (out.results_status() == "failed"):
            print(out.results_reason() + "\n")
            sys.exit (2)

        volume_info = out.child_get("volumes")
        result = volume_info.children_get()

        global total_volume_size
        global used_volume_size
        global percent_space_avail

        for vol in result:
            total_volume_size = vol.child_get_int("size-total")
            used_volume_size = vol.child_get_int("size-used")
            space_avail = (total_volume_size - used_volume_size)
            percent_space_avail = (float(space_avail)/float(total_volume_size))*100

            if (percent_space_avail < threshold):
                send_mail(volume)
示例#46
0
#!/usr/bin/env python

import sys
sys.path.append("NMSDKpy")
from NaServer import *

cluster = "svlngen4-c01-trad-gen001"
transport = "HTTPS"
port = 443 
style = "CERTIFICATE"
cert = "devops_cert.pem"
key = "devops_cert.key"

s = NaServer(cluster, 1, 30)
s.set_transport_type(transport)
s.set_port(port)
s.set_style(style)
s.set_server_cert_verification(0)
s.set_client_cert_and_key(cert, key)

api = NaElement("system-get-version")
output = s.invoke_elem(api)
if (output.results_status() == "failed"):
    r = output.results_reason()
    print("Failed: " + str(r))
    sys.exit(2)

ontap_version = output.child_get_string("version")
print ("V: " + ontap_version)
示例#47
0
#!/usr/bin/python
import sys
sys.path.append("../lib/NetappSDK/")
from NaServer import *

filerIP = raw_input("filer IP: ")
myPass = raw_input("filer password: "******"dir path: ")

s = NaServer(filerIP, 1 , 15)
s.set_server_type("FILER")
s.set_transport_type("HTTPS")
s.set_port(443)
s.set_style("LOGIN")
s.set_admin_user("root", myPass)

# Obtain the Data ONTAP version.
api = NaElement("system-get-version")

xo = s.invoke_elem(api)
if (xo.results_status() == "failed") :
      print ("Error:\n")
      print (xo.sprintf())
      sys.exit (1)

print ("Received:\n")
print (xo.sprintf())
# Delete a directory.
print "Deleting....\n"
api = NaElement('file-delete-directory')
# Path of the directory to delete. The value is expected to begin with /vol/<volumename>. The directory must be empty in order for this API to succeed.
class Toaster(nagiosplugin.Resource):
    """
    Determines the system Network interface stats
    The `probe` method returns the following for all interfaces
    'recv_packets'
    'recv_errors'
    'send_packets'
    'send_errors'
    'collisions'
    'recv_data'
    'send_data'
    'recv_mcasts'
    'send_mcasts'
    'recv_drop_packets
    """

    def __init__(self, filer, user, pw, interface=False):
        self.filer = filer
        self.user = user
        self.pw = pw
        self.specific_interface = interface
        self.perf_obj = "ifnet"
        self.counter_values = ["recv_packets",
                  "recv_errors",
                  "send_packets",
                  "send_errors",
                  "collisions",
                  "recv_data", 
                  "send_data",
                  "recv_mcasts", 
                  "send_mcasts",
                  "recv_drop_packets"
                 ]


    def Connect(self):
        """
        connect to the netapp via the API
        """

        #self.s = NaServer(self.filer, 1, 3)
        self.s = NaServer(self.filer, 1, 9)
        self.out = self.s.set_transport_type('HTTPS')
        _log.debug("attempting to connect to filer via HTTPS")

        if (self.out and self.out.results_errno() != 0) :
            r = self.out.results_reason()
            _log.warn("Connection to filer failed: " + r + "\n")
            sys.exit(3)

        self.out = self.s.set_style('LOGIN')
        _log.debug("attempting to login to " + self.filer + "\n")
    
        if (self.out and self.out.results_errno() != 0) :
            r = self.out.results_reason()
            _log.warn("Connection to filer failed: " + r + "\n")
            sys.exit(3)

        self.out = self.s.set_admin_user(self.user, self.pw)
        _log.debug("set admin user to" + self.user + "\n")


    def cpus(self):
        _log.info('counting cpus with "nproc"')
        cpus = int(subprocess.check_output(['nproc']))
        _log.debug('found %i cpus in total', cpus)
        return cpus



    def probe(self):
        """
        use the netapp API and connection object
        to extract the specified counters for the object
        and return in a dictionary of dictionaries
        in the self.data var e.g.
        print self.data[self.specific_interface]["send_data"]
        This is implicity used by the nagiosplugin class to generate the metrics
        if an interface is specified, it returns that, otherwise returns 
        all interfaces, skipping the 'filername' aggregate metric, which seems
        to be a 'since boot' set of counters

        """


        #turn the filer FQDN into something more Graphite Friendly
        self.filername = self.filer.split(".")[0]
        self.Connect()

        _log.info('attempting to grab all interface data')

        self.data = \
                get_counter_values(self.filername, 
                                   self.s, 
                                   self.perf_obj, 
                                   self.counter_values,
                                  )
        #import pprint
        #pp = pprint.PrettyPrinter(indent=4)
        #pp.pprint(self.data)

        if self.specific_interface:
            #print self.data[self.specific_interface]["send_data"]
            metricname = \
                    self.filer + "_" + self.specific_interface + "_" + "send_errors"
            testm = nagiosplugin.Metric( metricname,
                                self.data[self.specific_interface]["send_errors"],
                                'c', 
                                min=0, 
                                context='errors', # set this to errors
                               )
            #import pprint
            #pp = pprint.PrettyPrinter(indent=4)
            #pp.pprint(testm)
            yield testm

        else:
            for metric in ["send_errors", "recv_errors", "collisions",
                           "recv_drop_packets" ]:
                _log.debug('reporting on %s', metric)
                # a number of interfaces are provided by the API as totals since
                # boot, which isn't useful for point in time alerting, so ignore
                # them
                for instance in self.data:
                    _log.debug('reporting on if %s', instance)

                    #skip the api provided filenamed interface thats just totals
                    if self.filername in instance:

                        _log.debug('skipping totaled interface: %s',\
                                   str(instance))
                        continue 
                   #skip the interface groups, just look at individual if's
                   # pre OnTAP 8.1
                    if "ifgrp" in instance:
                        _log.debug('skipping ifgrp interface: %s',\
                                   str(instance))
                        continue
                   #skip the virtual interface (vif) groups, just look at individual if's
                   # pre OnTAP 8.1
                    if "vif" in instance:
                        _log.debug('skipping vif interface: %s',\
                                   str(instance))
                        continue
                    
                    #print "interface: " + str(instance) + " errors: " + \
                    #        str(self.data[instance][metric])
                    metricname = \
                        self.filer + "_" + instance + "_" + metric
                    yield nagiosplugin.Metric( \
                                            metricname,
                                            self.data[instance][metric],
                                            min=0,
                                            context='errors',
                                            )
示例#49
0
文件: vfiler.py 项目: raykuan/docs
def main() :
    s = NaServer(filer, 1, 3)
    resp = s.set_style('LOGIN')
  
    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Failed to set authentication style " + r + "\n")
        sys.exit (2)

    s.set_admin_user(user, pw)
    resp = s.set_transport_type('HTTP')

    if (resp and resp.results_errno() != 0) :
        r = resp.results_reason()
        print ("Unable to set HTTP transport " + r + "\n")
        sys.exit (2)

    if(command == "create") :
        vfiler_create(s)
	
    elif(command == "list") :
        vfiler_list(s)

    if(args < 5 and (command == "start" or command == "stop" or  command == "status" or  command == "destroy")):
        print ("This operation requires <vfiler-name> \n\n")
        print_usage()

    if(command == "start") :
        out = s.invoke("vfiler-start", "vfiler", vfiler)

        if(out.results_status() == "failed") :
            print(out.results_reason() + "\n")
            sys.exit(2)
	
    elif(command == "status") :
        out = s.invoke("vfiler-get-status", "vfiler", vfiler)

        if(out.results_status() == "failed") :
            print(out.results_reason() + "\n")
            sys.exit(2)
		
        status = out.child_get_string("status")
        print("status:" + status + "\n")

	
    elif(command == "stop") :
        out = s.invoke("vfiler-stop", "vfiler", vfiler)

        if(out.results_status() == "failed") :
            print(out.results_reason() + "\n")
            sys.exit(2)

    elif(command == "destroy"):
        out = s.invoke("vfiler-destroy","vfiler",vfiler)

        if(out.results_status() == "failed") :
            print(out.results_reason() + "\n")
            sys.exit(2)

    else :
        print ("Invalid operation\n")
        print_usage()
示例#50
0
class QoS_info:
    def __init__(self, cluster_name, cluster_ip, username, password, sdk_ver, server_type="FILER", transport_type="HTTPS", port="443", style="LOGIN"):
	major, minor = string.split(sdk_ver, '.')
	self.CLUSTER_NAME = cluster_name
	self.MAX_VOLUMES  = 2000
	self.s = NaServer(cluster_ip, major, minor)
	self.s.set_server_type(server_type)
	self.s.set_transport_type(transport_type)
	self.s.set_port(port)
	self.s.set_style(style)
	self.s.set_admin_user(username, password)

    def get_qos_stats(self):
	self.policy_groups = self.get_qos_pgs()
	self.workloads     = self.get_qos_workloads()
	self.pgs = {}
	for pg in self.policy_groups['results']['attributes-list']['qos-policy-group-info']:
	    max_iops = int(string.split(pg['max-throughput'], 'IOPS')[0])
	    curr_pg = pg['policy-group']
	    self.pgs[curr_pg] = {}
	    self.pgs[curr_pg]['policy-group']       = pg['policy-group']
	    self.pgs[curr_pg]['max-throughput']     = max_iops
	    self.pgs[curr_pg]['pgid']               = pg['pgid']
	    self.pgs[curr_pg]['policy-group-class'] = pg['policy-group-class']
	    self.pgs[curr_pg]['uuid']               = pg['uuid']
	    self.pgs[curr_pg]['timestamp']          = string.split(str(time.time()),'.')[0]
	for wl in self.workloads['results']['attributes-list']['qos-workload-info']:
	    targ_pg = wl['policy-group']
	    try:
		self.pgs[targ_pg]['vserver'] = wl['vserver']
		self.pgs[targ_pg]['volume'] = wl['volume']
	    except:
		pass
	lines = []
	for line in self.pgs.values():
	    try:
		metric_string =  "%s.%s.qos_max_iops" % (line['vserver'], line['volume'])
		data = {}
		data[metric_string] = float(line['max-throughput'])
		lines.append(data)
	    except KeyError:
		pass
	return lines

    def get_vol_stats(self):
	ret = []
	for v in self.get_volumes():
	    try:
		v_cn  = v['cluster-name']
		v_svm = v['owning-vserver-name']
		v_vol = v['name']
		c = self.get_vol_counters(v['instance-uuid'])
		c_ts = c['timestamp']                                                                                                                                                             
		c_read_ops  = c['read_ops']                                                                                                                                                       
		c_write_ops = c['write_ops']                                                                                                                                                      
		c_total_ops = c['total_ops']                                                                                                                                                      
		metric_string =  "%s.%s.total_ops" % (v_svm, v_vol)                                                                                                                                
		data = {}
		read_ops_key_u = "%s.%s.%s.read_ops" % (self.CLUSTER_NAME, v_svm, v_vol)
		read_ops_key = read_ops_key_u.encode('ascii','ignore')
		data[read_ops_key] = float(c['read_ops'])

		write_ops_key_u = "%s.%s.%s.write_ops" % (self.CLUSTER_NAME, v_svm, v_vol)
		write_ops_key = write_ops_key_u.encode('ascii','ignore')
		data[write_ops_key] = float(c['write_ops'])

		total_ops_key_u = "%s.%s.%s.total_ops" % (self.CLUSTER_NAME, v_svm, v_vol)
		total_ops_key = total_ops_key_u.encode('ascii','ignore')
		data[total_ops_key] = float(c['total_ops'])
		ret.append(data)
	    except KeyError:                                                                                                                                                                      
		continue                                                         
	return ret


    def get_volumes(self):
	api = NaElement("volume-get-iter")
	xi = NaElement("desired-attributes")
	api.child_add(xi)
	## This specifies max number of volume records to pull from sdk api
	## Default is 20. 20000 is enough for most clusters
	api.child_add_string("max-records",self.MAX_VOLUMES)
	xi1 = NaElement("volume-attributes")
	xi.child_add(xi1)
	xi41 = NaElement("volume-id-attributes")
	xi41.child_add_string("instance-uuid","<instance-uuid>")
	xi41.child_add_string("name","<name>")
	xi41.child_add_string("owning-vserver-name","<owning-vserver-name>")
	xi41.child_add_string("uuid","<uuid>")
	xi1.child_add(xi41)
	xo = self.s.invoke_elem(api)
	f = xmltodict.parse(xo.sprintf())
	volumes = f['results']['attributes-list']['volume-attributes']
	vol_list = []
	for volume in volumes:
	    vol_list.append({
			     'cluster-name':self.CLUSTER_NAME,
			     'owning-vserver-name':volume['volume-id-attributes']['owning-vserver-name'],
			     'name':volume['volume-id-attributes']['name'],
			     'instance-uuid':volume['volume-id-attributes']['instance-uuid']
			    })
	return vol_list


    def get_vol_counters(self, instance_uuid):
	api = NaElement("perf-object-get-instances")
	xi = NaElement("counters")
	api.child_add(xi)
	xi2 = NaElement("instances")
	api.child_add(xi2)
	api.child_add_string("objectname","volume")
	xi1 = NaElement("instance-uuids")
	api.child_add(xi1)
	xi1.child_add_string("instance-uuid",instance_uuid)
	ctrs = {}
	xo = self.s.invoke_elem(api)
	if (xo.results_status() == "failed") :
	    ##
	    ## Volumes which are currently offline will error here as no counters are collected
	    ##
	    fp = open('/var/tmp/ctrs-fail.xml','a')
	    fp.write(xo.sprintf())
	    fp.close()
	    return ctrs
	fp = open('/var/tmp/ctrs.xml','a')
	fp.write(xo.sprintf())
	fp.close()
	try:
	    f = xmltodict.parse(xo.sprintf())
	except xml.parsers.expat.ExpatError:
	    print xo.sprintf()
	ctrs['timestamp'] = f['results']['timestamp']
	ctrs['volname']   = f['results']['instances']['instance-data']['name']
	ctrs['voluuid']   = f['results']['instances']['instance-data']['uuid']
	for ctr in f['results']['instances']['instance-data']['counters']['counter-data']:
	    ctrs[ctr['name']] = ctr['value']
	return ctrs

    def get_qos_pgs(self):
	api = NaElement("qos-policy-group-get-iter")
	xi = NaElement("desired-attributes")
	api.child_add(xi)
	xi1 = NaElement("qos-policy-group-info")
	xi.child_add(xi1)
	# These control what fields are returned for each record
	xi1.child_add_string("max-throughput","<max-throughput>")
	#xi1.child_add_string("num-workloads","<num-workloads>")
	xi1.child_add_string("pgid","<pgid>")
	xi1.child_add_string("policy-group","<policy-group>")
	xi1.child_add_string("policy-group-class","<policy-group-class>")
	xi1.child_add_string("uuid","<uuid>")
	xi1.child_add_string("vserver","<vserver>")
	api.child_add_string("max-records",100000)
	xi2 = NaElement("query")
	api.child_add(xi2)
	xi3 = NaElement("qos-policy-group-info")
	xi2.child_add(xi3)
	# These control what records are returned
	#xi3.child_add_string("max-throughput","<max-throughput>")
	#xi3.child_add_string("num-workloads","<num-workloads>")
	#xi3.child_add_string("pgid","<pgid>")
	#xi3.child_add_string("policy-group","<policy-group>")
	xi3.child_add_string("policy-group-class","user-defined")
	#xi3.child_add_string("uuid","<uuid>")
	#xi3.child_add_string("vserver","<vserver>")
	#api.child_add_string("tag","<tag>")
	xo = self.s.invoke_elem(api)
	if (xo.results_status() == "failed") :
	    print ("Error:\n")
	    print (xo.sprintf())
	    sys.exit (1)
	return xmltodict.parse(xo.sprintf())

    def get_qos_workloads(self):
	api = NaElement("qos-workload-get-iter")
	xi = NaElement("desired-attributes")
	api.child_add(xi)
	xi1 = NaElement("qos-workload-info")
	xi.child_add(xi1)
	xi1.child_add_string("category","<category>")
	xi1.child_add_string("file","<file>")
	xi1.child_add_string("lun","<lun>")
	xi1.child_add_string("policy-group","<policy-group>")
	xi1.child_add_string("qtree","<qtree>")
	xi1.child_add_string("read-ahead","<read-ahead>")
	xi1.child_add_string("volume","<volume>")
	xi1.child_add_string("vserver","<vserver>")
	xi1.child_add_string("wid","<wid>")
	xi1.child_add_string("workload-class","<workload-class>")
	xi1.child_add_string("workload-name","<workload-name>")
	xi1.child_add_string("workload-uuid","<workload-uuid>")
	api.child_add_string("max-records",100000)
	xi2 = NaElement("query")
	api.child_add(xi2)
	xi3 = NaElement("qos-workload-info")
	xi2.child_add(xi3)
	#xi3.child_add_string("category","<category>")
	#xi3.child_add_string("file","<file>")
	#xi3.child_add_string("lun","<lun>")
	#xi3.child_add_string("policy-group","<policy-group>")
	#xi3.child_add_string("qtree","<qtree>")
	#xi3.child_add_string("read-ahead","<read-ahead>")
	#xi3.child_add_string("volume","<volume>")
	#xi3.child_add_string("vserver","<vserver>")
	#xi3.child_add_string("wid","<wid>")
	xi3.child_add_string("workload-class","user_defined")
	#xi3.child_add_string("workload-name","<workload-name>")
	#xi3.child_add_string("workload-uuid","<workload-uuid>")
	#api.child_add_string("tag","<tag>")
	xo = self.s.invoke_elem(api)
	if (xo.results_status() == "failed") :
	    print ("Error:\n")
	    print (xo.sprintf())
	    sys.exit (1)
	return xmltodict.parse(xo.sprintf())
示例#51
0
文件: apitest.py 项目: raykuan/docs
    print ("Unable to set server transport" + r + "\n")
    sys.exit (2)

if(set_timeout == 1) :

    if(timeout > 0) :
        s.set_timeout(timeout)
    
    else :
        print ("Invalid value for connection timeout." + " Connection timeout value should be greater than 0.\n") 
        sys.exit (2)

#Set the style of the server

if(host_equiv == 1) :
    s.set_style("HOSTS")


if (use_cba == 1) :
    response = s.set_style("CERTIFICATE")
    if (response):
        print("Unable to set style: " + response.results_reason() + "\n")
        sys.exit(2)
    response = s.set_client_cert_and_key(cert_file, client_key)
    if (response):
        print(response.results_reason() + "\n")
        sys.exit(2)

if (dossl or need_server_cert_verification):
    response = s.set_server_cert_verification(need_server_cert_verification)
    if (response):
    # Set the working dir prefix
    set_script_path(options.work_dir)

    # Credentials db must be initialized using the cred_mgmt.py file
    cdb = script_db.CredDB(options.work_dir + r'\cred_db')
	
    # Initialize the script database
    sdb = script_db.ScriptDB(options.work_dir + r'\script_db')
    sdb.setup()

    # Connect to Netapp server
    conn = NaServer(options.storage_array, 1 , 7)
    conn.set_server_type("FILER")
    conn.set_transport_type("HTTPS")
    conn.set_port(443)
    conn.set_style("LOGIN")
    user, pwd = cdb.get_enc_info(options.storage_array)
    conn.set_admin_user(user, pwd)

    if options.operation == 'HELLO':
        check_lun(conn, options.serial)
    elif options.operation == 'CREATE_SNAP':   
        create_snap(cdb, sdb, conn, options.serial, options.snap_name, 
                    options.access_group, options.proxy_host,
					options.category, options.protect_category)
    elif options.operation == 'REMOVE_SNAP':
        remove_snap(cdb, sdb, conn, options.serial,
		            options.snap_name, options.proxy_host)
    else:
        print ('Invalid operation: %s' % str(options.operation))
        cdb.close()
def define_metrics(Desc_Skel,params):
    max_records = 10
    for filer in params.keys():
        s = NaServer(params[filer]['ipaddr'], 1, 3)
        out = s.set_transport_type('HTTPS')
        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)
            
        out = s.set_style('LOGIN')
        if (out and out.results_errno() != 0) :
            r = out.results_reason()
            print ("Connection to filer failed: " + r + "\n")
            sys.exit(2)
        out = s.set_admin_user(params[filer]['user'], params[filer]['password'])
        perf_in = NaElement("perf-object-get-instances-iter-start")
        #Hard coded volume, only volume stats gathered at present
        obj_name = "volume"
        perf_in.child_add_string("objectname", obj_name)
        #Create object of type counters
        counters = NaElement("counters")
        #Add counter names to the object
        counters.child_add_string("counter", "total_ops")
        counters.child_add_string("counter", "avg_latency")
        counters.child_add_string("counter", "read_ops")
        counters.child_add_string("counter", "read_latency")
        counters.child_add_string("counter", "write_ops")
        counters.child_add_string("counter", "write_latency")

        perf_in.child_add(counters)

        #Invoke API
        out = s.invoke_elem(perf_in)

        if(out.results_status() == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)
    
        iter_tag = out.child_get_string("tag")
        num_records = 1
        filername = params[filer]['name']

        while(int(num_records) != 0):
            perf_in = NaElement("perf-object-get-instances-iter-next")
            perf_in.child_add_string("tag", iter_tag)
            perf_in.child_add_string("maximum", max_records)
            out = s.invoke_elem(perf_in)

            if(out.results_status() == "failed"):
                print(out.results_reason() + "\n")
                sys.exit(2)

            num_records = out.child_get_int("records")
	
            if(num_records > 0) :
                instances_list = out.child_get("instances")            
                instances = instances_list.children_get()

                for inst in instances:
                    inst_name = unicodedata.normalize('NFKD',inst.child_get_string("name")).encode('ascii','ignore')
                    #print ("Instance = " + inst_name + "\n")
                    counters_list = inst.child_get("counters")
                    counters = counters_list.children_get()

                    for counter in counters:
                        counter_name = unicodedata.normalize('NFKD',counter.child_get_string("name")).encode('ascii','ignore')
                        counter_value = counter.child_get_string("value")
                        counter_unit = counter.child_get_string("unit")
                        if 'total_ops' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'iops',
                                        "description" : "volume iops",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "iops"
                                        }))
                        elif 'avg_latency' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'ms',
                                        "description" : "volume avg latency",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "latency"
                                        }))
                        elif 'read_ops' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'iops',
                                        "description" : "volume read iops",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "iops"
                                        }))
                        elif 'read_latency' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'ms',
                                        "description" : "volume read latency",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "latency"
                                        }))
                        elif 'write_ops' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'iops',
                                        "description" : "volume write iops",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "iops"
                                        }))
                        elif 'write_latency' in counter_name:
                            descriptors.append(create_desc(Desc_Skel, {
                                        "name"        : filername + '_vol_' + inst_name + '_' + counter_name,
                                        "units"       : 'ms',
                                        "description" : "volume write latency",
                                        "spoof_host"  : params[filer]['ipaddr'] + ':' + params[filer]['name'],
                                        "groups"      : "latency"
                                        }))
                        
    return descriptors
def get_metrics(name):
    global FASMETRICS, LAST_FASMETRICS, FASMETRICS_CACHE_MAX, params
    max_records = 10
    metrics = {}
    if (time.time() - FASMETRICS['time']) > FASMETRICS_CACHE_MAX:
        
        for filer in filerdict.keys():
            s = NaServer(filerdict[filer]['ipaddr'], 1, 3)
            out = s.set_transport_type('HTTPS')
            if (out and out.results_errno() != 0) :
                r = out.results_reason()
                print ("Connection to filer failed: " + r + "\n")
                sys.exit(2)
            
            out = s.set_style('LOGIN')
            if (out and out.results_errno() != 0) :
                r = out.results_reason()
                print ("Connection to filer failed: " + r + "\n")
                sys.exit(2)
            out = s.set_admin_user(filerdict[filer]['user'], filerdict[filer]['password'])
            perf_in = NaElement("perf-object-get-instances-iter-start")
            #Hard coding volume object for testing
            obj_name = "volume"
            perf_in.child_add_string("objectname", obj_name)
            #Create object of type counters
            counters = NaElement("counters")
            #Add counter names to the object
            counters.child_add_string("counter", "total_ops")
            counters.child_add_string("counter", "avg_latency")
            counters.child_add_string("counter", "read_ops")
            counters.child_add_string("counter", "read_latency")
            counters.child_add_string("counter", "write_ops")
            counters.child_add_string("counter", "write_latency")

            perf_in.child_add(counters)

            #Invoke API
            out = s.invoke_elem(perf_in)

            if(out.results_status() == "failed"):
                print(out.results_reason() + "\n")
                sys.exit(2)
    
            iter_tag = out.child_get_string("tag")
            num_records = 1

            filername = filerdict[filer]['name']

            while(int(num_records) != 0):
                perf_in = NaElement("perf-object-get-instances-iter-next")
                perf_in.child_add_string("tag", iter_tag)
                perf_in.child_add_string("maximum", max_records)
                out = s.invoke_elem(perf_in)

                if(out.results_status() == "failed"):
                    print(out.results_reason() + "\n")
                    sys.exit(2)

                num_records = out.child_get_int("records")
	
                if(num_records > 0) :
                    instances_list = out.child_get("instances")            
                    instances = instances_list.children_get()

                    for inst in instances:
                        inst_name = unicodedata.normalize('NFKD',inst.child_get_string("name")).encode('ascii','ignore')
                        counters_list = inst.child_get("counters")
                        counters = counters_list.children_get()

                        for counter in counters:
                            counter_name = unicodedata.normalize('NFKD',counter.child_get_string("name")).encode('ascii','ignore')         
                            counter_value = counter.child_get_string("value")
                            counter_unit = counter.child_get_string("unit")           
                            metrics[filername + '_vol_' + inst_name + '_' + counter_name] = float(counter_value)
        # update cache
        LAST_FASMETRICS = dict(FASMETRICS)
        FASMETRICS = {
            'time': time.time(),
            'data': metrics
            }


    else: 
        metrics = FASMETRICS['data']
    #print name
    #calculate change in values and return
    if 'total_ops' in name:
        try:
            delta = float(FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name])/(FASMETRICS['time'] - LAST_FASMETRICS['time'])
            if delta < 0:
                print "Less than 0"
                delta = 0
        except StandardError:
            delta = 0
        #This is the Operations per second
        return delta

    elif 'avg_latency' in name:
        try: 
            #T1 and T2
            #(T2_lat - T1_lat) / (T2_ops - T1_ops)
            #Find the metric name of the base counter
            total_ops_name = name.replace('avg_latency', 'total_ops')
            #Calculate latency in time (div 100 to change to ms)
            return float((FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name]) / (FASMETRICS['data'][total_ops_name] -LAST_FASMETRICS['data'][total_ops_name])) / 100
        except StandardError:
            return 0
    elif 'read_ops' in name:

        try:
            delta = float(FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name])/(FASMETRICS['time'] - LAST_FASMETRICS['time'])
            if delta < 0:
                print "Less than 0"
                delta = 0
        except StandardError:
            delta = 0
        return delta

    elif 'read_latency' in name:
        try: 
            read_ops_name = name.replace('read_latency', 'read_ops')
            return float((FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name]) / (FASMETRICS['data'][read_ops_name] -LAST_FASMETRICS['data'][read_ops_name])) / 100
        except StandardError:
            return 0
    elif 'write_ops' in name:
        try:
            delta = float(FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name])/(FASMETRICS['time'] - LAST_FASMETRICS['time'])
            if delta < 0:
                print "Less than 0"
                delta = 0
        except StandardError:
            delta = 0
        return delta

    elif 'write_latency' in name:
        try: 
            write_ops_name = name.replace('write_latency', 'write_ops')
            return float((FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name]) / (FASMETRICS['data'][write_ops_name] -LAST_FASMETRICS['data'][write_ops_name])) / 100
        except StandardError:
            return 0
            

    return 0    
class Filer(object):
  """ NetApp Filer """

  def __init__(self, hostname, user, passwd):
      self.api = NaServer(hostname, 1, 3)
      response = self.api.set_style('LOGIN')

      if (response and response.results_errno() != 0):
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)

      self.api.set_admin_user(user, passwd)
      self.api.set_transport_type('HTTPS')

      self.name = hostname

  def get_name(self):
    return self.name

  # Get list of volumes (OBJECTS)
  def get_volumes(self):
    volume_list_info = self.api.invoke("volume-list-info")

    if(volume_list_info.results_status() == "failed"):
        print (volume_list_info.results_reason() + "\n")
        sys.exit (2)

    volumes = volume_list_info.child_get("volumes")

    # Create a list of volumes based off the 'volumes' XML representation
    # User instance/object.sprintf()
    volume_list = volumes.children_get()
    return volume_list
                     
  def is_vol_online(self,volume):
    if not isinstance(volume, str):
      vol_state = volume.child_get_string("state")

    if vol_state == 'online':
      return True
    else:
      return False 

  # Return BOOL for volume protected/SnapMirrored status
  def is_vol_snapmirror_source(self, volume):
    if not isinstance(volume, str):
      volume = volume.child_get_string("name")

    snapmirror_vol_status = self.api.invoke("snapmirror-get-volume-status", "volume", volume)

    if(snapmirror_vol_status.results_status() == "failed"):
      print(snapmirror_vol_status.results_reason() + "\n")
      sys.exit(2)

    if snapmirror_vol_status.child_get_string("is-source") == 'true':
      return True
    else:
      return False

  # Get snapmirror_status_info object
  def get_vol_snapmirror_status_info(self,volume):
    if not isinstance(volume, str):
      volume = volume.child_get_string("name")

    snapmirror_get_status = self.api.invoke("snapmirror-get-status","location",volume)
    if(snapmirror_get_status.results_status() == "failed"):
      print(snapmirror_get_status.results_reason() + "\n")
      sys.exit(2)

    snapmirror_status = snapmirror_get_status.child_get("snapmirror-status")

    if (not(snapmirror_status == None)):
      snapmirror_status_info = snapmirror_status.child_get('snapmirror-status-info')
    else:
      sys.exit(0)

    return snapmirror_status_info

  # Source location string
  def get_vol_snapmirror_source(self, volume):
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_string('source-location')

  # Destination location string
  def get_vol_snapmirror_destination(self, volume):
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_string('destination-location')

  # Lag time in seconds
  def get_vol_snapmirror_lag(self, volume):
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_int('lag-time')

  # Size in KB (int)
  def get_vol_snapmirror_last_transfer_size(self, volume):
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_int('last-transfer-size')

  # Duration in seconds
  def get_vol_snapmirror_last_transfer_duration(self, volume):
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_int('last-transfer-duration')

  # Current progress status
  def get_vol_snapmirror_progress(self, volume): 
    snapmirror_status_info = self.get_vol_snapmirror_status_info(volume)
    return snapmirror_status_info.child_get_string('transfer-progress')

  # List of Snapmirrored Volumes
  def get_snapmirrored_volumes(self):
    snapmirrored_vols = []
    vols = self.get_volumes()

    for vol in vols:
      if self.is_vol_online(vol) and self.is_vol_snapmirror_source(vol):
        snapmirrored_vols.append(vol)
    
    return snapmirrored_vols

  # List of non-Snapmirrored Volumes
  def get_non_snapmirrored_volumes(self):
    non_snapmirrored_vols = []
    vols = self.get_volumes()

    for vol in vols:
      if self.is_vol_online(vol) and not self.is_vol_snapmirror_source(vol):
        non_snapmirrored_vols.append(vol)

    return non_snapmirrored_vols

  # Volume protection report
  def vol_snapmirror_report(self, rpo=86400, ignore_volumes=[]):
    # Get list of Volume Objects
    vols = self.get_volumes()

    # Initialize [non]snapmirrored volumes arrays
    snapmirrored_vols = self.get_snapmirrored_volumes()
    non_snapmirrored_vols = self.get_non_snapmirrored_volumes()

    # Apply ignore_volumes exclusion
    snapmirrored_vols = [vol for vol in snapmirrored_vols if vol.child_get_string("name") not in ignore_volumes]
    non_snapmirrored_vols = [vol for vol in non_snapmirrored_vols if vol.child_get_string("name") not in ignore_volumes]

    # Generate report for non protected volumes
    # non_snapmirrored_vols_report 'string'
    if non_snapmirrored_vols:
      non_snapmirrored_vols_report = "------------------------------------------------------\n"
      non_snapmirrored_vols_report += "The following volumes are not protected by SnapMirror:\n"
      non_snapmirrored_vols_report += "------------------------------------------------------\n"

      # Output volumes not snapmirrored
      for vol in sorted(non_snapmirrored_vols, key=lambda elm: elm.child_get_string("name")):
         non_snapmirrored_vols_report += vol.child_get_string("name") + "\n"

    # Generate report for protected volumes that have a lag
    if snapmirrored_vols:
      report_lag = ''
      for vol in sorted(snapmirrored_vols, key=lambda elm: elm.child_get_string("name")):
        if self.get_vol_snapmirror_lag(vol) > int(rpo):
          report_lag += "%30s | %40s | %18s | %18.2f(GB) | %25s | %8.2f(GB) " % (
                                                      self.get_vol_snapmirror_source(vol),
                                                      self.get_vol_snapmirror_destination(vol),
                                                      str(datetime.timedelta(seconds=self.get_vol_snapmirror_lag(vol))),
                                                      float(self.get_vol_snapmirror_last_transfer_size(vol))/1048576,
                                                      str(datetime.timedelta(seconds=self.get_vol_snapmirror_last_transfer_duration(vol))),
                                                      float(self.get_vol_snapmirror_progress(vol))/1024/1024
                                                      )
          report_lag += "\n"

      if report_lag:
        # Output Volumes snapmirrored with more than 24h RPO
        snapmirrored_vols_report = "\n\nThe following volumes are over %.1fh RPO:\n" % (float(rpo)/3600)
        
        header = "%30s | %40s | %18s | %20s | %25s | %12s \n" % ('source-location','destination-location','lag-time(h)','last-transfer-size(GB)','last-transfer-duration(h)','transfering')
        separator = "-" * len(header) + "\n"

        snapmirrored_vols_report += separator + header + separator
        snapmirrored_vols_report += report_lag

    # Report Filer Name/Header + non protected vols + reported lag
    if report_lag or non_snapmirrored_vols:
      report = "\n" + "="*10 + self.get_name().upper() + "="*10 + "\n"
      
      if non_snapmirrored_vols:
        report += non_snapmirrored_vols_report
      
      if report_lag:      
        report += snapmirrored_vols_report
      
      return report
    else:
      return ''
def netapp_info(module) :
   
    results = {}

    #This module is not built to make changes, so we are returning false here.
    results['changed'] = False
    results['rc'] = 0
    results['ansible_facts'] = {}

    s = NaServer(module.params['host'], 1 , 21)
    s.set_server_type(module.params['na_server_type'])
    s.set_transport_type(module.params['na_transport_type'])
    s.set_port(module.params['na_port'])
    s.set_style(module.params['na_style'])
    s.set_admin_user(module.params['nauser'], module.params['napass'])

    # first we get base cluster OnTap version information
    cluster_version_info = {}
    api = NaElement("system-get-version")
    xo = s.invoke_elem(api)
    if (xo.results_status() == "failed") :
        errmsg = "errno: ", xo.results_errno(), "reason: ", xo.results_reason()
        module.fail_json(msg=errmsg)
    
    cluster_version = {}
    cluster_version['build_timestamp'] = xo.child_get_string('build-timestamp')
    cluster_version['is_clustered'] = xo.child_get_string('is-clustered')
    cluster_version['version'] = xo.child_get_string('version')
    cluster_version['version_tuple'] = xmltodict.parse(xo.child_get('version-tuple').sprintf())
    cluster_version_info['cluster_version_info'] = cluster_version
    #o = xmltodict.parse(xo.sprintf())
    results['ansible_facts'].update(cluster_version_info)

    # cluster identity info
    cluster_identity_info = {}
    api = NaElement("cluster-identity-get")
    xo = s.invoke_elem(api)
    if (xo.results_status() == "failed") :
        errmsg = "errno: ", xo.results_errno(), "reason: ", xo.results_reason()
        module.fail_json(msg=errmsg)
    
    cluster_identity = {}
    attr = xo.child_get('attributes') 
    id_info = attr.child_get('cluster-identity-info')
    for cid in id_info.children_get() :
        cluster_name = id_info.child_get_string('cluster-name')
        cluster_identity[cluster_name] = xmltodict.parse(id_info.sprintf())
        
    cluster_identity_info['cluster_identity'] = cluster_identity
    results['ansible_facts'].update(cluster_identity_info)


    # get node specific info
    system_node_info = {}
    system_info = {}
    api = NaElement("system-get-node-info-iter")
    xo = s.invoke_elem(api)
    if (xo.results_status() == "failed") :
        errmsg = "errno: ", xo.results_errno(), "reason: ", xo.results_reason()
        module.fail_json(msg=errmsg)
        
    system_nodes = xo.child_get('attributes-list')
    for node in system_nodes.children_get() :
        system_name = node.child_get_string('system-name')
        system_info[system_name] = xmltodict.parse(node.sprintf())
        
    system_node_info['system_node_info'] = system_info
    results['ansible_facts'].update(system_node_info)

    # get svm info
    svm_info = {}
    vserver_info = {}
    api = NaElement("vserver-get-iter")
    xo = s.invoke_elem(api)
    if (xo.results_status() == "failed") :
        errmsg = "errno: ", xo.results_errno(), "reason: ", xo.results_reason()
        module.fail_json(msg=errmsg)
        
    vservers = xo.child_get('attributes-list')
    for vserver in vservers.children_get() :
        svm_name = vserver.child_get_string('vserver-name')
        vserver_info[svm_name] = xmltodict.parse(vserver.sprintf())
        
    svm_info['svm_info'] = vserver_info
    results['ansible_facts'].update(svm_info)
    
    # get aggr info
    aggr_info = {}
    aggregate_info = {}
    api = NaElement("aggr-get-iter")
    xo = s.invoke_elem(api)
    if (xo.results_status() == "failed") :
        errmsg = "errno: ", xo.results_errno(), "reason: ", xo.results_reason()
        module.fail_json(msg=errmsg)
        
    aggr_list = xo.child_get('attributes-list')
    for aggrs in aggr_list.children_get() :
        aggr_attrs = aggr_list.child_get('aggr-attributes')
        for aggr in aggr_attrs.children_get() :
            aggregate_name = aggrs.child_get_string('aggregate-name')
            aggregate_info[aggregate_name] = xmltodict.parse(aggrs.sprintf())
            
    aggr_info['aggr_info'] = aggregate_info
            
    results['ansible_facts'].update(aggr_info)


    return results
示例#57
0
文件: nfs.py 项目: raykuan/docs
def do_nfs():
    s = NaServer(filer, 1, 3)
    out = s.set_transport_type('HTTP')

    if(out and (out.results_errno() != 0)) :
        r = out.results_reason()
        print("Connection to filer failed" + r + "\n")
        sys.exit(2)

    out = s.set_style('LOGIN')

    if( out and (out.results_errno() != 0)):

        r = out.results_reason()
        print("Connection to filer failed" + r + "\n")
        sys.exit(2)

    out = s.set_admin_user(user, pw)

    if(cmd == "enable"):
        out = s.invoke("nfs-enable")

        if(out.results_status() == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        else:
            print("Operation successful\n")

    elif (cmd == "disable"):
        out = s.invoke("nfs=disable")

        if(out.results_status == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        else:
            print("Operation successful\n")

    elif (cmd == "status"):
        out = s.invoke("nfs-status")

        if(out.results_status == "failed"):
            print(out.results_reason() + "\n")
            sys.exit(2)

        enabled = out.child_get_string("is-enabled")

        if(enabled == "true"):
            print("NFS Server is enabled\n")

        else:
            print("NFS Server is disabled\n")

    elif ( cmd == "list") :
        out = s.invoke( "nfs-exportfs-list-rules" )
        export_info = out.child_get("rules")
      
        if(export_info):
            result = export_info.children_get()

        else :
            sys.exit(2)

        for export in result:
            path_name = export.child_get_string("pathname")
            rw_list = "rw="
            ro_list = "ro="
            root_list = "root="
            if(export.child_get("read-only")):
                ro_results = export.child_get("read-only")
                ro_hosts = ro_results.children_get()			
                for ro in ro_hosts:

                    if(ro.child_get_string("all-hosts")):
                        all_hosts = ro.child_get_string("all-hosts")

                        if(all_hosts == "true") :
                            ro_list = ro_list + "all-hosts"
                            break

                    elif(ro.child_get_string("name")) :
                        host_name = ro.child_get_string("name")
                        ro_list = ro_list + host_name + ":"
					
            if(export.child_get("read-write")):
                rw_results = export.child_get("read-write")
                rw_hosts = rw_results.children_get()
                for rw in rw_hosts:

                    if(rw.child_get_string("all-hosts")):
                        all_hosts = rw.child_get_string("all-hosts")

                        if(all_hosts == "true") :
                            rw_list = rw_list + "all-hosts"
                            break

                    elif(rw.child_get_string("name")):
                        host_name = rw.child_get_string("name")
                        rw_list = rw_list + host_name + ":"

            if(export.child_get("root")):
                root_results = export.child_get("root")
                root_hosts = root_results.children_get()

                for root in root_hosts:

                    if(root.child_get_string("all-hosts")):
                        all_hosts = root.child_get_string("all-hosts")

                        if(all_hosts == "true"):
                            root_list = root_list + "all-hosts"
                            break
						
                    elif(root.child_get_string("name")):
                        host_name = root.child_get_string("name")
                        root_list = root_list + host_name + ":"

            path_name = path_name + "  "

            if(ro_list != "ro="):
                path_name = path_name + ro_list

            if(rw_list != "rw=") :
                path_name = path_name + "," + rw_list

            if(root_list != "root="):
                path_name = path_name + "," + root_list

            print(path_name + "\n")

    else :
        print ("Invalid operation\n")
        print_usage()
示例#58
0
class CdotPerf:
    def __init__(self, cluster_name, cluster_ip, username, password, sdk_ver, server_type="FILER", transport_type="HTTPS", port="443", style="LOGIN"):
        major, minor = string.split(sdk_ver, '.')
        self.CLUSTER_NAME = cluster_name
        self.MAX_VOLUMES  = 20000
        self.s = NaServer(cluster_ip, major, minor)
        self.s.set_server_type(server_type)
        self.s.set_transport_type(transport_type)
        self.s.set_port(port)
        self.s.set_style(style)
        self.s.set_admin_user(username, password)
	self.sd = statsd.StatsClient('localhost',8125)
	self.fp = open("/var/tmp/tellme.log", "a")
	try:
	    self.debug = open("/var/tmp/debugenabled")
	    self.debug.close()
	    self.debug = True
	except IOError:
	    self.debug = False
	    pass
	self.targ_vol_counters = "avg_latency,cifs_other_latency,cifs_other_ops,cifs_read_data,cifs_read_latency,cifs_read_ops,cifs_write_data,cifs_write_latency,cifs_write_ops,fcp_other_latency,fcp_other_ops,fcp_read_data,fcp_read_latency,fcp_read_ops,fcp_write_data,fcp_write_latency,fcp_write_ops,flexcache_other_ops,flexcache_read_data,flexcache_read_ops,flexcache_receive_data,flexcache_send_data,flexcache_write_data,flexcache_write_ops,iscsi_other_latency,iscsi_other_ops,iscsi_read_data,iscsi_read_latency,iscsi_read_ops,iscsi_write_data,iscsi_write_latency,iscsi_write_ops,nfs_other_latency,nfs_other_ops,nfs_read_data,nfs_read_latency,nfs_read_ops,nfs_write_data,nfs_write_latency,nfs_write_ops,other_latency,other_ops,read_blocks,read_data,read_latency,read_ops,san_other_latency,san_other_ops,san_read_data,san_read_latency,san_read_ops,san_write_data,san_write_latency,san_write_ops,total_ops,write_blocks,write_data,write_latency,write_ops"



    def tellme(self, message):
	if (self.debug):
	    self.fp.write("%s\n" % message)

    def get_aggregates(self):
	"""
	    Get list of volumes from cluster
	"""
	api = NaElement("aggr-get-iter")
	#xi = NaElement("desired-attributes")
	#api.child_add(xi)
	## This specifies max number of volume records to pull from sdk api
	## Default is 20. 20000 is enough for most clusters
	api.child_add_string("max-records",self.MAX_VOLUMES)
	#xi1 = NaElement("aggr-attributes")
	#xi.child_add(xi1)
	#xi41 = NaElement("volume-id-attributes")
	#xi41.child_add_string("instance-uuid","<instance-uuid>")
	#xi41.child_add_string("name","<name>")
	#xi41.child_add_string("owning-vserver-name","<owning-vserver-name>")
	#xi41.child_add_string("uuid","<uuid>")
	#xi1.child_add(xi41)
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	#print xo.sprintf()
	f = xmltodict.parse(xo.sprintf())
	#print xo.sprintf()
	aggrs = f['results']['attributes-list']['aggr-attributes']
	aggr_list = []
	for aggr in aggrs:
	    for z in aggr.keys():
		try:
		    if (z == 'aggregate-name'):
			aggr_name = aggr[z]
			#print "aggr_name: %s" % aggr_name
		    elif (z == 'aggregate-uuid'):
			aggr_uuid = aggr[z]
			#print "aggr_uuid: %s" % aggr_uuid
		    elif (z == 'aggr-ownership-attributes'):
			aggr_ownr = aggr[z]['owner-name']
			#print "aggr_ownr: %s" % aggr_ownr
		    #print "z: %s" % z
		    #print "kggr[z].keys: %s" % aggr[z].keys()
		except AttributeError:
		    #print "In Exception - aggr[z]: %s" % aggr[z]
		    pass
	    aggr_list.append({
			      'cluster-name':self.CLUSTER_NAME,
			      'aggr-name':aggr_name,
			      'aggr-uuid':aggr_uuid,
			      'owner-name':aggr_ownr
			     })
	return aggr_list

    def get_volumes(self):
	"""
	    Get list of volumes from cluster
	"""
	api = NaElement("volume-get-iter")
	xi = NaElement("desired-attributes")
	api.child_add(xi)
	## This specifies max number of volume records to pull from sdk api
	## Default is 20. 20000 is enough for most clusters
	api.child_add_string("max-records",self.MAX_VOLUMES)
	xi1 = NaElement("volume-attributes")
	xi.child_add(xi1)
	xi41 = NaElement("volume-id-attributes")
	xi41.child_add_string("instance-uuid","<instance-uuid>")
	xi41.child_add_string("name","<name>")
	xi41.child_add_string("owning-vserver-name","<owning-vserver-name>")
	xi41.child_add_string("uuid","<uuid>")
	xi1.child_add(xi41)
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	f = xmltodict.parse(xo.sprintf())
	volumes = f['results']['attributes-list']['volume-attributes']
	vol_list = []
	for volume in volumes:
	    vol_list.append({'cluster-name':self.CLUSTER_NAME,
			     'owning-vserver-name':volume['volume-id-attributes']['owning-vserver-name'],
			     'name':volume['volume-id-attributes']['name'],
			     'instance-uuid':volume['volume-id-attributes']['instance-uuid']
			    })
	return vol_list


    def get_counters_by_name(self, instance_name, object_name, counter_filter_list=None):
	api = NaElement("perf-object-get-instances")
	#xi = NaElement("counters")
	#api.child_add(xi)
	#xi.child_add_string("counter",counter_filter_list)
	xi2 = NaElement("instances")
	api.child_add(xi2)
	xi2.child_add_string("instance",instance_name)
	#xi3 = NaElement("instance-uuids")
	#api.child_add(xi3)
	#xi3.child_add_string("instance-uuid",instance_uuid)
	##
	## TODO - make this generic to get counters for non-volume uuids
	##
	api.child_add_string("objectname",object_name)
	#xi1 = NaElement("instance-uuids")
	#api.child_add(xi1)
	#xi1.child_add_string("instance-uuid",instance_uuid)
	ctrs = {}
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	if (xo.results_status() == "failed") :
	    ## Volumes which are currently offline will error here as no counters are collected
	    print xo.sprintf()
	    return ctrs
	try:
	    f = xmltodict.parse(xo.sprintf())
	except xml.parsers.expat.ExpatError:
	    print xo.sprintf()
	ctrs['timestamp'] = f['results']['timestamp']
	ctrs['name']   = f['results']['instances']['instance-data']['name']
	ctrs['uuid']   = f['results']['instances']['instance-data']['uuid']
	for ctr in f['results']['instances']['instance-data']['counters']['counter-data']:
	    ctrs[ctr['name']] = ctr['value']
	return ctrs

    def get_object_instance_list_info(self, object_name):

	api = NaElement("perf-object-instance-list-info-iter")
	#
	xi = NaElement("desired-attributes")
	api.child_add(xi)
	#
	#
	#xi1 = NaElement("instance-info")
	#xi.child_add(xi1)
	#
	#xi1.child_add_string("name","<name>")
	#xi1.child_add_string("uuid","<uuid>")
	#api.child_add_string("filter-data","<filter-data>")
	api.child_add_string("max-records",1000000)
	api.child_add_string("objectname",object_name)
	#
#	xi2 = NaElement("query")
#	api.child_add(xi2)
	#
	#
#	xi3 = NaElement("instance-info")
#	xi2.child_add(xi3)
	#
#	xi3.child_add_string("name","<name>")
#	xi3.child_add_string("uuid","<uuid>")
#	api.child_add_string("tag","<tag>")
	#
	xo = self.s.invoke_elem(api)
	if (xo.results_status() == "failed") :
	    print ("Error:\n")
	    print (xo.sprintf())
	    sys.exit (1)
	#
	print ("Received:\n")
	print (xo.sprintf())

	ctrs = {}
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	if (xo.results_status() == "failed") :
	    ## Volumes which are currently offline will error here as no counters are collected
	    print xo.sprintf()
	    return ctrs
	try:
	    f = xmltodict.parse(xo.sprintf())
	except xml.parsers.expat.ExpatError:
	    print xo.sprintf()
#	ctrs['timestamp'] = f['results']['timestamp']
#	ctrs['volname']   = f['results']['instances']['instance-data']['name']
#	ctrs['voluuid']   = f['results']['instances']['instance-data']['uuid']
#	for ctr in f['results']['instances']['instance-data']['counters']['counter-data']:
#	    ctrs[ctr['name']] = ctr['value']
#	return ctrs



    def get_counters_by_uuid(self, instance_uuid, object_name, counter_filter_list=None):
	api = NaElement("perf-object-get-instances")
	xi = NaElement("counters")
	api.child_add(xi)
	xi.child_add_string("counter",counter_filter_list)
	#xi2 = NaElement("instances")
	#api.child_add(xi2)
	#xi2.child_add_string("instance",instance)
	xi3 = NaElement("instance-uuids")
	api.child_add(xi3)
	xi3.child_add_string("instance-uuid",instance_uuid)
	##
	## TODO - make this generic to get counters for non-volume uuids
	##
	api.child_add_string("objectname",object_name)
	#xi1 = NaElement("instance-uuids")
	#api.child_add(xi1)
	#xi1.child_add_string("instance-uuid",instance_uuid)
	ctrs = {}
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	if (xo.results_status() == "failed") :
	    ## Volumes which are currently offline will error here as no counters are collected
	    print xo.sprintf()
	    return ctrs
	try:
	    f = xmltodict.parse(xo.sprintf())
	except xml.parsers.expat.ExpatError:
	    print xo.sprintf()
	ctrs['timestamp'] = f['results']['timestamp']
	ctrs['name']   = f['results']['instances']['instance-data']['name']
	ctrs['uuid']   = f['results']['instances']['instance-data']['uuid']
	for ctr in f['results']['instances']['instance-data']['counters']['counter-data']:
	    ctrs[ctr['name']] = ctr['value']
	return ctrs

    def get_object_counter_info(self,targObject):
	api = NaElement("perf-object-counter-list-info")
	api.child_add_string("objectname",targObject)
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	if (xo.results_status() == "failed") :
	    sys.exit (1)
	f = xmltodict.parse(xo.sprintf())
	lines = []
	for c in f['results']['counters']['counter-info']:
	    ## Need more code to handle case where base-counter is present and where data type is array / histogram
	    ##
	    ## Mandatory fields returned: name, desc, privilege-level
	    ## Optional fields returned:  aggregation-style, base-counter, is-key, labels, properties, translation-input-counter, type, unit
	    poss_fields = ["name","desc","privilege-level","aggregation-style","base-counter","is-key","labels","properties","translation-input-counter","type","unit"]
	    fields = []
	    for pf in poss_fields:
		if (pf in c.keys()):
		    if (pf == "labels"):
			try:
			    fields.append(c[pf]['label-info'].encode('ascii','ignore'))
			except AttributeError:
			    fields.append(c[pf]['label-info'][0].encode('ascii','ignore'))
		    else:
			try:
			    fields.append(c[pf].encode('ascii','ignore'))
			except AttributeError:
			    print "In AttributeError in get_object_counter_info"
		else:
		    fields.append("")
	    lines.append(string.join(fields, "|"))
	return lines

    def get_perf_objects(self):
	api = NaElement("perf-object-list-info")
	xo = self.s.invoke_elem(api)
	self.sd.incr("api.invoke")
	if (xo.results_status() == "failed") :
	    print ("Error:\n")
	    print (xo.sprintf())
	    sys.exit (1)
	f = xmltodict.parse(xo.sprintf())
	objects = []
	for obj in f['results']['objects']['object-info']:
	    objects.append(obj['name'])
	return objects

    def load_vol_counters(self, targ_file="/home/duane/cdot_api_pull/vol-perf-counters.txt"):
	self.vol_ctr_info = {}
	lines = open(targ_file).read()
	for line in string.split(lines, '\n'):
	    try:
		fields    = string.split(line, '|')
		f_cluster = fields[0]
		f_svm     = fields[1]
		f_vol     = fields[2]
		f_ctr     = fields[3]
		f_desc    = fields[4]
		f_priv    = fields[5]
		f_junk    = fields[6]
		f_basec   = fields[7]    # use
		f_iskey   = fields[8]
		f_labels  = fields[9]
		f_props   = fields[10]   # use
		f_junk    = fields[11]
		f_type    = fields[12]   # use
		f_unit    = fields[13]   # use
		#
		if f_cluster not in self.vol_ctr_info:
		    self.vol_ctr_info[f_cluster] = {}
		if f_svm not in self.vol_ctr_info[f_cluster]:
		    self.vol_ctr_info[f_cluster][f_svm] = {}
		if f_vol not in self.vol_ctr_info[f_cluster][f_svm]:
		    self.vol_ctr_info[f_cluster][f_svm][f_vol] = {}
		if f_ctr not in self.vol_ctr_info[f_cluster][f_svm][f_vol]:
		    self.vol_ctr_info[f_cluster][f_svm][f_vol][f_ctr] = {}
		#
		self.vol_ctr_info[f_cluster][f_svm][f_vol][f_ctr]['base-counter'] = f_basec
		self.vol_ctr_info[f_cluster][f_svm][f_vol][f_ctr]['properties'] = f_props
		self.vol_ctr_info[f_cluster][f_svm][f_vol][f_ctr]['type'] = f_type
		self.vol_ctr_info[f_cluster][f_svm][f_vol][f_ctr]['unit'] = f_unit
	    except IndexError:
		self.tellme("caught exception parsing %s - %s" % (targ_file, line))

    def load_perf_counters(self, targ_file="/home/duane/cdot_api_pull/perf-counter-list.out"):
	self.perf_ctr_info = {}
	lines = open(targ_file).read()
	for line in string.split(lines, '\n'):
	    try:
		fields = string.split(line, '|')
		if (len(fields) == 14):
		    f_object_name   = fields[0]
		    f_instance_name = fields[1]
		    f_instance_uuid = fields[2]
		    f_counter_name  = fields[3]
		    f_counter_desc  = fields[4]
		    f_privs         = fields[5]
		    f_junk          = fields[6]
		    f_base_counter  = fields[7]    # use
		    f_iskey         = fields[8]
		    f_labels        = fields[9]    # use
		    f_properties    = fields[10]   # use
		    f_junk          = fields[11]
		    f_type          = fields[12]   # use
		    f_unit          = fields[13]   # use
		    #
		    # Store details as;
		    #  { object_name : { instance_name : { instance_uuid : { counter_name : { counter_name : value
		    #                                                                         
		    # f_object_name.f_instance_uuid.f_counter_name
		    if f_object_name not in self.perf_ctr_info:
			self.perf_ctr_info[f_object_name] = {}
		    if f_instance_uuid not in self.perf_ctr_info[f_object_name]:
			self.perf_ctr_info[f_object_name][f_instance_uuid] = {}
		    if f_counter_name not in self.perf_ctr_info[f_object_name][f_instance_uuid]:
			self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name] = {}
		    #
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['object-name'] = f_object_name
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['counter-name'] = f_counter_name
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['instance-name'] = f_instance_name
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['instance-uuid'] = f_instance_uuid
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['base-counter'] = f_base_counter
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['labels'] = f_labels
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['properties'] = f_properties
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['type'] = f_type
		    self.perf_ctr_info[f_object_name][f_instance_uuid][f_counter_name]['unit'] = f_unit
		else:
		    pass
		    #print "parsing line failed for >>%s<<" % line

	    except IndexError:
		#print "caught exception parsing %s - %s" % (targ_file, line)
		self.tellme("caught exception parsing %s - %s" % (targ_file, line))