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 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
예제 #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
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
예제 #6
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
예제 #7
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
예제 #9
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
예제 #10
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
예제 #11
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
예제 #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
예제 #14
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
예제 #15
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)
예제 #16
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)
예제 #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 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
예제 #19
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
예제 #20
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
예제 #21
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
예제 #22
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
예제 #23
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
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
예제 #25
0
def date_time(module):

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

    results = {}

    results['changed'] = False

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

    args = NaElement("args")

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

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

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

    else:
        results['changed'] = True

    return results
예제 #26
0
def nfs_service_create(module):

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

    results = {}

    results['changed'] = False

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

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

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

    else:
        results['changed'] = True

    return results
예제 #27
0
def asup_invoke(module):

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

  results = {}

  results['changed'] = False

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

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

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

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


  xo = s.invoke_elem(api)

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

  else:
    results['changed'] = True

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

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

    results = {}

    results['changed'] = False

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

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

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

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

    xo = s.invoke_elem(api)

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

    else:
        results['changed'] = True

    return results
예제 #31
0
def broadcast_domain_create(module):

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

    results = {}

    results['changed'] = False

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

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

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

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

    xo = s.invoke_elem(api)

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

    else:
        results['changed'] = True

    return results
예제 #32
0
def vlan_create(module):

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

    results = {}

    results['changed'] = False

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

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

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

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

    xo = s.invoke_elem(api)

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

    else:
        results['changed'] = True

    return results
예제 #33
0
def aggr_hybrid(module):

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

    results = {}

    results['changed'] = False

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

    args = NaElement("args")

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

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

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

    else:
        results['changed'] = True

    return results
예제 #34
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.
if __name__ == '__main__':
    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)
예제 #36
0
파일: apitest.py 프로젝트: raykuan/docs
    s.set_admin_user(user, password)


# Set the name of the vfiler on which the API
# commands need to be invoked.
#

if (dovfiler):
    s.set_vfiler(vfiler_name)

if (send_oid):
    s.set_originator_id(originator_id)

# Set the Type of API Server.
#
response = s.set_server_type(server_type)

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

if(set_timeout == 1) :

    if(timeout > 0) :
        s.set_timeout(timeout)
    
    else :
        print ("Invalid value for connection timeout." + " Connection timeout value should be greater than 0.\n") 
        sys.exit (2)
예제 #37
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
예제 #38
0
  sys.exit (1)

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))
예제 #39
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))
예제 #40
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())