Esempio n. 1
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")
Esempio n. 2
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()
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
0
def create_qtree_quota():
    
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

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

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

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

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

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

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

    print ("Created new qtree\n")
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()
Esempio n. 7
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()
Esempio n. 8
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
Esempio n. 9
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 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
Esempio n. 11
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
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()
Esempio n. 13
0
def main():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')
    
    if (response and response.results_errno() != 0) :
        r = response.results_reason()
        print ("Unable to set authentication style " + r + "\n")
        sys.exit (2)
        
    s.set_admin_user(user, pw)
    response = s.set_transport_type('HTTP')

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

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

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

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

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

    else:
        print ("Invalid operation\n")
        print_usage()
Esempio n. 14
0
File: snmp.py Progetto: 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()
Esempio n. 15
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
Esempio n. 16
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 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
def main():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

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

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

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

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

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

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

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

    else:
        print("Invalid operation\n")
        print_usage()
def 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
Esempio n. 20
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
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
Esempio n. 22
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
Esempio n. 23
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
Esempio n. 24
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
Esempio n. 25
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
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
Esempio n. 27
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
Esempio n. 28
0
def get_volume_info():


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

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

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

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

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

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

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

    for vol in result:
        vol_name = vol.child_get_string("name")
        print ("Volume name :" + vol_name + "\n")
        size_total = vol.child_get_int("size-total")
        print ("Total size: " + str(size_total) + " bytes \n")
        size_used = vol.child_get_int("size-used")
        print ("Used Size : " + str(size_used) + " bytes\n")
        print ("-------------------------------------------\n")
Esempio n. 29
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
Esempio n. 30
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)
Esempio n. 31
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)
Esempio n. 32
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)
Esempio n. 33
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()
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()
Esempio n. 35
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
Esempio n. 36
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
Esempio n. 37
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
Esempio n. 38
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
Esempio n. 39
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
Esempio n. 40
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
Esempio n. 41
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
Esempio n. 42
0
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()
Esempio n. 43
0
def get_quota_info():
    s = NaServer(filer, 1, 3)
    response = s.set_style('LOGIN')

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

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

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

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

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

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

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

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

        print ("-----------------------------------------------------\n")
Esempio n. 44
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()
Esempio n. 45
0
def get_volume_info():
    s = NaServer (filer, 1, 3)
    response = s.set_style('LOGIN')

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

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

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

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

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

        global total_volume_size
        global used_volume_size
        global percent_space_avail

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

            if (percent_space_avail < threshold):
                send_mail(volume)
Esempio n. 46
0
def main():
	
	module = AnsibleModule(
   		argument_spec=dict(
        		storage=dict(default=None, required=True),
			user=dict(default='admin', required=False),
			password=dict(default='P@ssw0rd', required=False),
			vserver_name=dict(default=None, required=True),
			volume_name=dict(default=None, required=True),
			security_style=dict(default='unix', required=False),
			guarantee=dict(default='volume', required=False),
			aggr_name=dict(default=None, required=True),
		),
	)
	
	storage        = module.params['storage']
	user           = module.params['user']
	password       = module.params['password']
	vserver_name   = module.params['vserver_name']
	volume_name    = module.params['volume_name']
	security_style = module.params['security_style']
	guarantee      = module.params['guarantee']
	aggr_name      = module.params['aggr_name']

	s = NaServer(storage, 1, 20)
	s.set_admin_user(user, password)
	s.set_vserver(vserver_name)

	api = NaElement('volume-create')
	api.child_add_string('volume', volume_name)
	api.child_add_string('space-reserve', guarantee)
	api.child_add_string('containing-aggr-name', aggr_name)

	output = s.invoke_elem(api)
	#print(output.results_status())
	#print(output.sprintf())

	module.exit_json(changed=True)
Esempio n. 47
0
def main():

        module = AnsibleModule(
                argument_spec=dict(
                        storage=dict(default=None, required=True),
                        user=dict(default='admin', required=False),
                        password=dict(default='P@ssw0rd', required=False),
                        vserver_name=dict(default=None, required=True),
			root_volume=dict(default='svm_root', required=False),
			root_volume_aggregate=dict(default=None, required=True),
			root_volume_security_style=dict(default='unix', required=False),
                ),
        )

        storage        = module.params['storage']
        user           = module.params['user']
        password       = module.params['password']
        vserver_name   = module.params['vserver_name']
	root_volume    = module.params['root_volume']
	root_volume_aggregate      = module.params['root_volume_aggregate']
	root_volume_security_style = module.params['root_volume_security_style']

	s = NaServer(storage, 1, 20)
	s.set_admin_user(user, password)

	api = NaElement('vserver-create')
	api.child_add_string('language','C');
	ns_switch = NaElement('name-server-switch');
	api.child_add(ns_switch)

	ns_switch.child_add_string('nsswitch','file')
	api.child_add_string('root-volume', root_volume)
	api.child_add_string('root-volume-aggregate', root_volume_aggregate)
	api.child_add_string('root-volume-security-style', root_volume_security_style)
	api.child_add_string('vserver-name', vserver_name);

	output = s.invoke_elem(api)
	module.exit_json(changed=True)
def main() :
    SevenMode = Get7ModeSystems()

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

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

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

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

        out = s.set_admin_user(user, pw)

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

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

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

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


        else:
            print ("Invalid operation\n")
            print_usage()
    def 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)
Esempio n. 50
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))
    # Credentials db must be initialized using the cred_mgmt.py file
    cdb = script_db.CredDB(options.work_dir + r'\cred_db')
	
    # Initialize the script database
    sdb = script_db.ScriptDB(options.work_dir + r'\script_db')
    sdb.setup()

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

    if options.operation == 'HELLO':
        check_lun(conn, options.serial)
    elif options.operation == 'CREATE_SNAP':   
        create_snap(cdb, sdb, conn, options.serial, options.snap_name, 
                    options.access_group, options.proxy_host,
					options.category, options.protect_category)
    elif options.operation == 'REMOVE_SNAP':
        remove_snap(cdb, sdb, conn, options.serial,
		            options.snap_name, options.proxy_host)
    else:
        print ('Invalid operation: %s' % str(options.operation))
        cdb.close()
        sdb.close()
        sys.exit(errno.EINVAL)
Esempio n. 52
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())
Esempio n. 53
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.
Esempio n. 54
0
    print("           -d <filer> <user> <pw> <vol> <snapshotname>\n")
    sys.exit(1)


args = len(sys.argv) - 1

if(args < 5):
    print_usage()
    
opt = sys.argv[1]
filer = sys.argv[2]
user = sys.argv[3]
pw = sys.argv[4]
vol = sys.argv[5]
s = NaServer(filer, 1, 1)
s.set_admin_user(user, pw)

#
# snapshot-get-schedule
#
if (opt == "-g") :
    output = s.invoke("snapshot-get-schedule", "volume", vol)

    if (output.results_errno() != 0) :
        r = output.results_reason()
        print ("snapshot-get-schedule failed:" + r + "\n")

    minutes = output.child_get_int("minutes")
    hours =   output.child_get_int("hours")
    days =    output.child_get_int("days")
    weeks =   output.child_get_int("weeks")
Esempio n. 55
0
args = len(sys.argv) - 1

if(args < 3):
  print_usage()

filer = sys.argv[1]
user = sys.argv[2]
password = sys.argv[3]

aggr_name = "cinder_aggr"
vol_name = "cinder"

s = NaServer(filer, 1, 1)
s.set_server_type("Filer")
s.set_admin_user(user, password)
s.set_transport_type("HTTP")

# Get the sysid of "this" controller
system = s.invoke("system-get-info")
sysinfo = system.child_get("system-info")
sysid = sysinfo.child_get_string("system-id")

# get the disks that this controller owns
output = s.invoke("disk-sanown-list-info")

if(output.results_errno() != 0):
   r = output.results_reason()
   print("Failed: \n" + str(r))

else :
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',
                                            )
filer_list = ( "filer101",
	       "filer102",
	       "filer103",
	       "filer104",
	       "filer105",
	       "filer106",
	       "filer107",
	       "filer108",
	       "filer109",
	       "filer110",
	       "filer111")

for filer_name in filer_list:
	print "============ %s ============ " % filer_name
	filer = NaServer(filer_name,1,6)
	filer.set_admin_user('root', 'password')
	cmd = NaElement("snapmirror-get-status")
	ret = filer.invoke_elem(cmd)

	if(ret.results_status() == "failed"):
		print "%s failed." % filer_name
		print(ret.results_reason() + "\n")
		sys.exit(2)
	
	status = ret.child_get("snapmirror-status")

	if(not(status == None)):
		result = status.children_get()
	else:
		print "status_children_get was empty\n"
		sys.exit(2)
Esempio n. 58
0
# [email protected]
##

import sys, getpass

sys.path.append("/home/alvinch/netapp-manageability-sdk-5.2/lib/python/NetApp")

from NaServer import *

help = "script filer_username filer volume"
args = len(sys.argv)
user_name = sys.argv[1]
password = getpass.getpass()
filer_name = sys.argv[2]
filer = NaServer(filer_name,1,6)
filer.set_admin_user(user_name, password)

def readable_size(size):
        for unit in ['bytes', 'KB', 'MB', 'GB', 'TB']:
                if size < 1000.0 and size > -1000.0:
                        return "%3.2f %s" % (size, unit)
                size /= 1024.0
        return "%3.2f %s" % (size, 'PB')

#list_in = NaElement('volume-footprint-get-iter')
#cmd = filer.invoke_elem(list_in)
tag = "tag"

while True:
        list_in = NaElement('volume-footprint-get-iter')
        cmd = filer.invoke_elem(list_in)
Esempio n. 59
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 == "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()