def snmp_community_add(module):

  cluster = module.params['cluster']
  user_name = module.params['user_name']
  password = module.params['password']
  vserver = module.params['vserver']
  access_control = module.params['access_control']
  community = module.params['community']

  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("snmp-community-add")
  api.child_add_string("access-control", access_control)
  api.child_add_string("community", community)
  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
예제 #2
0
def connect_svm(in_args):

    # type and syntax checking on command line args
    obj_regexp = re.compile(
        r'^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](\.[a-zA-Z0-9\-]{2,}){0,6}$'
    )
    if (not (obj_regexp.match(in_args.svm))):
        sys.exit(
            "error: the svm parameter must be either an IP address or a hostname"
        )

    # connect to svm
    obj_svm = NaServer(in_args.svm, 1, 3)
    obj_svm.set_transport_type('HTTPS')
    if (in_args.cert is None):
        obj_svm.set_style('LOGIN')
        string_username = raw_input("login as: ")
        string_password = getpass.getpass()
        obj_svm.set_admin_user(string_username, string_password)
    else:
        result = obj_svm.set_style('CERTIFICATE')
        obj_svm.set_server_cert_verification(0)
        obj_svm.set_client_cert_and_key(in_args.cert[0], in_args.cert[1])

    # check that the api is reachable
    result = obj_svm.invoke("system-get-version")
    if (result.results_status() == "failed"):
        sys.exit("error: cannot connect to filer; " + result.results_reason())

    return obj_svm
예제 #3
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
예제 #4
0
def aggr_rename(module):

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

	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-rename")
	api.child_add_string("aggregate",aggr)
	api.child_add_string("new-aggregate-name",new_aggr_name)
	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
예제 #5
0
def vol_size(module):

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

    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-size")
    api.child_add_string("volume", volume)
    api.child_add_string("new-size", size)
    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 construct_server(hostname, username, password):
    server = NaServer(hostname, 1, 0 )
    server.set_style('LOGIN')
    server.set_transport_type('HTTP')
    server.set_server_type('DFM')
    server.set_port(8088)
    server.set_admin_user(username, password)
    return server
예제 #7
0
 def create_conn(self, host):
     conn = NaServer(host, 1, 21)
     conn.set_server_type("FILER")
     conn.set_transport_type("HTTP")
     conn.set_port(80)
     conn.set_style("LOGIN")
     conn.set_admin_user("root", "root1234")
     return conn
예제 #8
0
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
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
예제 #10
0
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
예제 #11
0
def date_time(module):

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

    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 not val_certs:
        try:
            _create_unverified_https_context = ssl._create_unverified_context

        except AttributeError:
            # Legacy Python that doesn't verify HTTPS certificates by default
            pass
        else:
            # Handle target environment that doesn't support HTTPS verification
            ssl._create_default_https_context = _create_unverified_https_context

    results = {}

    results['changed'] = False

    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 = connection.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
예제 #12
0
def int_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    node = module.params['node']
    vserver = module.params['vserver']
    lif = module.params['lif']
    role = module.params['role']
    data_proto = module.params['data_proto']
    port = module.params['port']
    ip = module.params['ip']
    netmask = module.params['netmask']
    subnet = module.params['subnet']

    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-interface-create')
    api.child_add_string('address', ip)

    xi = NaElement('data-protocols')
    api.child_add(xi)

    for proto in data_proto:
        xi.child_add_string('data-protocol', proto)

    api.child_add_string('home-node', node)
    api.child_add_string('home-port', port)
    api.child_add_string('interface-name', lif)
    api.child_add_string('netmask', netmask)
    api.child_add_string('role', role)
    api.child_add_string('vserver', vserver)
    if module.params['subnet']:
        api.child_add_string('subnet-name', subnet)

    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
예제 #13
0
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 storage_pool_create(module):

    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    val_certs = module.params['val_certs']
    disk_list = module.params['disk_list']
    storage_pool = module.params['storage_pool']
    simulate = module.params['simulate']

    results = {}

    results['changed'] = False

    if not val_certs:
        try:
            _create_unverified_https_context = ssl._create_unverified_context

        except AttributeError:
            # Legacy Python that doesn't verify HTTPS certificates by default
            pass
        else:
            # Handle target environment that doesn't support HTTPS verification
            ssl._create_default_https_context = _create_unverified_https_context

    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("storage-pool-create")
    api.child_add_string("storage-pool", storage_pool)
    if module.params['simulate']:
        api.child_add_string("simulate", simulate)

    xi = NaElement("disk-list")
    api.child_add(xi)

    for disk in disk_list:
        xi.child_add_string("disk-name", disk)

    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
예제 #15
0
def aggr_add(module):

  cluster = module.params['cluster']
  user_name = module.params['user_name']
  password = module.params['password']
  val_certs = module.params['val_certs']
  disk_type = module.params['disk_type']
  aggr = module.params['aggr']
  disk_count = module.params['disk_count']
  disk_size = module.params['disk_size']

  results = {}

  results['changed'] = False

  if not val_certs:
        try:
            _create_unverified_https_context = ssl._create_unverified_context
        
        except AttributeError:
        # Legacy Python that doesn't verify HTTPS certificates by default
            pass
        else:
        # Handle target environment that doesn't support HTTPS verification
            ssl._create_default_https_context = _create_unverified_https_context

  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-add")
  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)


  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 trigger_autosupport():
    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)

    api = NaElement("autosupport-invoke")
    api.child_add_string("message", "Possible NFSv4 lock bug discovered")
    api.child_add_string("node-name", "*")
    api.child_add_string("type", "all")

    s.invoke_elem(api)
예제 #17
0
def migrate_lifs(cluster, username, password, dest_node, dest_port, vserver, lif):
    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)

    api = NaElement("net-interface-migrate")

    api.child_add_string("destination-node", dest_node)
    api.child_add_string("destination-port", dest_port)
    api.child_add_string("lif", lif)
    api.child_add_string("vserver", vserver)
    s.invoke_elem(api)
예제 #18
0
def connect_to_api(module):
    cluster = module.params['cluster']
    user_name = module.params['user_name']
    password = module.params['password']
    val_certs = module.params['val_certs']

    if not val_certs:
        invoke_elem_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)
예제 #19
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")
예제 #20
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()
예제 #21
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()
예제 #23
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()
예제 #24
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()
예제 #25
0
파일: snapmirror.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 == "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()
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()
예제 #27
0
파일: qtree_quota.py 프로젝트: raykuan/docs
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")
예제 #28
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 == "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()
예제 #29
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()
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()
예제 #31
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()
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()
예제 #33
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()
예제 #34
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
예제 #35
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
예제 #36
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
예제 #37
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
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
예제 #39
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
예제 #40
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
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()
예제 #42
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
예제 #43
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()
예제 #44
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")
예제 #45
0
def main():
    # check for valid number of parameters
    s = NaServer (filer, 1, 3)

    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 == "cg-start"):
        cg_start(s)

    elif(command == "cg-commit"):
        cg_commit(s)

    else:
        print ("Invalid operation\n")
        print_usage()
예제 #46
0
    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)
예제 #47
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)
예제 #48
0
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
예제 #49
0
파일: apitest.py 프로젝트: raykuan/docs
# NaServer(hostname, major API version number, minor API version number)
#

if(dovfiler):
    s = NaServer(host, 1, 7)

else:
    s = NaServer(host, 1, 0)

if ( s == None ) :
    print ("Initializing server elements failed.\n")
    sys.exit (3)

if (dossl) :

    response = s.set_transport_type('HTTPS')

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

# Set the login and password used for authenticating when
# an ONTAPI API is invoked.
# When Host_equiv is  set,dont set username ,password

if(host_equiv != 1 and use_cba != 1):
    s.set_admin_user(user, password)


# Set the name of the vfiler on which the API
예제 #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
#!/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.
예제 #52
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 ''
예제 #53
0
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',
                                            )
예제 #54
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()
예제 #55
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)
예제 #56
0
    user = sys.argv[3]
    password = sys.argv[4] 
    arguments = sys.argv[5:]


# open server
server = NaServer(filer, 1, 7)

if(not server.set_vfiler(vfiler)):
    print ("Error: ONTAPI version must be at least 1.7 to send API to a vfiler\n")
    sys.exit (2)

server.set_admin_user(user, password)

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

if(len(arguments) > 0):
    # invoke the api with api name and any supplied key-value pairs
    x = NaElement(arguments[0])
    k = 0
    arguments.remove(arguments[0])
    length = len(arguments) - 1 
    if((length & 1) != 0):
        while(k <= length):
            key = arguments[k]
예제 #57
0
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    
예제 #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))
    options, argsleft = get_option_parser().parse_args()

    # 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: