本文整理汇总了Python中NaServer.invoke_elem方法的典型用法代码示例。如果您正苦于以下问题:Python NaServer.invoke_elem方法的具体用法?Python NaServer.invoke_elem怎么用?Python NaServer.invoke_elem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NaServer
的用法示例。
在下文中一共展示了NaServer.invoke_elem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
def main():
module = AnsibleModule(
argument_spec=dict(
storage=dict(default=None, required=True),
user=dict(default='admin', required=False),
password=dict(default='[email protected]', 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)
示例2: main
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
def main():
module = AnsibleModule(
argument_spec=dict(
storage=dict(default=None, required=True),
user=dict(default='admin', required=False),
password=dict(default='[email protected]', 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)
示例3: NaServer
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
"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)
for snapStat in result:
示例4: raw_input
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
filerIP = raw_input("filer IP: ")
myPass = raw_input("filer password: ")
dir = raw_input("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.
api.child_add_string('path',dir)
xo = s.invoke_elem(api)
if (xo.results_status() == 'failed'):
示例5: readable_size
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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)
if tag:
list_in.child_add_string('tag', tag)
#cmd = filer.invoke_elem(list_in)
next_tag = cmd.child_get_string('next-tag')
attrib_info = cmd.child_get('attributes-list')
result = attrib_info.children_get()
for attrib_list in result:
attrib_name = attrib_list.child_get_string('volume')
vol_meta = readable_size(int(attrib_list.child_get_string('flexvol-metadata-footprint')))
print("Volume: " + attrib_name +"\nMeta Footprint: " + vol_meta + "\n")
if not tag:
break
示例6: len
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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)
tag = "tag"
while True:
naelement=NaElement('vserver-get-iter')
out=filer.invoke_elem(naelement)
if tag:
naelement.child_add_string('tag', tag)
#out=filer.invoke_elem(naelement)
tag=out.child_get_string('next-tag')
vserver_list=out.child_get('attributes-list').children_get()
for v in vserver_list:
name=v.child_get_string('vserver-name');
print name
#if not name in self.vserver:
# self.vserver[name]=dict()
示例7: raw_input
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
filer = raw_input("Filername: ")
# password prompt (echo disabled)
pw = getpass.getpass(prompt="Filer password: ")
# Setup the session with the filer
s = NaServer(filer, 1, 19)
s.set_server_type("FILER")
s.set_transport_type("HTTPS")
s.set_port(443)
s.set_style("LOGIN")
s.set_admin_user(user, pw)
# Obtain the Data ONTAP version.
api_sys_ver = NaElement("system-get-version")
out = s.invoke_elem(api_sys_ver)
if out.results_status() == "failed":
print ("Error:\n")
print (out.sprintf())
sys.exit(1)
print ("\nResults:\n")
print "Filer version:", out.child_get_string("version"), "\n"
api_ifconfig_get = NaElement("net-ifconfig-get")
# This is the name of the interface to display. If not provided, all interfaces will be displayed.
# api_ifconfig_get.child_add_string("interface-name","<name>")
out = s.invoke_elem(api_ifconfig_get)
if out.results_status() == "failed":
print ("Error:\n")
print (out.sprintf())
示例8: print
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
if (inputxml > 0) :
try :
minidom.parseString(api)
except:
print("\nParse Error\n")
sys.exit(1)
rxi = s.parse_raw_xml(api)
if (showxml == 1) :
print ("INPUT:\n" + rxi.sprintf() + "\n")
rxo = s.invoke_elem(rxi)
print ("\nOUTPUT: \n" + rxo.sprintf())
sys.exit (5)
# Create a XML element to print
if (showxml == 1) :
x = NaElement(api)
length = args-i
if((length & 1) != 0):
while(i <= args):
key = sys.argv[i]
i = i + 1
value = sys.argv[i]
示例9: __init__
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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']
#.........这里部分代码省略.........
示例10: __init__
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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']
#.........这里部分代码省略.........
示例11: len
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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)
tag = ""
while True:
api = NaElement('volume-footprint-get-iter')
if tag:
api.child_add_string('tag', tag)
run = filer.invoke_elem(api)
tag = run.child_get_string('next-tag')
attribinfo = run.child_get('attributes-list')
result = attribinfo.children_get()
for output in result:
volname = output.child_get_string('volume')
print volname
#if tag is None:
if not tag:
break
示例12: NaServer
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
#!/usr/bin/env python
import sys
sys.path.append("NMSDKpy")
from NaServer import *
cluster = "svlngen4-c01-trad-gen001"
transport = "HTTPS"
port = 443
style = "CERTIFICATE"
cert = "devops_cert.pem"
key = "devops_cert.key"
s = NaServer(cluster, 1, 30)
s.set_transport_type(transport)
s.set_port(port)
s.set_style(style)
s.set_server_cert_verification(0)
s.set_client_cert_and_key(cert, key)
api = NaElement("system-get-version")
output = s.invoke_elem(api)
if (output.results_status() == "failed"):
r = output.results_reason()
print("Failed: " + str(r))
sys.exit(2)
ontap_version = output.child_get_string("version")
print ("V: " + ontap_version)
示例13: NaElement
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
# invoke the api with api name and any supplied key-value pairs
x = NaElement(arguments[0])
k = 0
arguments.remove(arguments[0])
length = len(arguments) - 1
if((length & 1) != 0):
while(k <= length):
key = arguments[k]
k = k + 1
value = arguments[k]
k = k + 1
x.child_add(NaElement(key,value))
else:
print("Invalid number of parameters")
print_usage()
xo = server.invoke_elem(x)
else:
print_usage()
if ( xo == None ) :
print ("invoke_api failed to filer as user:password.\n")
sys.exit (3)
# format the output
print ("Output: \n" + xo.sprintf() + "\n" )
示例14: netapp_info
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
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')
#.........这里部分代码省略.........
示例15: get_metrics
# 需要导入模块: import NaServer [as 别名]
# 或者: from NaServer import invoke_elem [as 别名]
def get_metrics(name):
global FASMETRICS, LAST_FASMETRICS, FASMETRICS_CACHE_MAX, params
max_records = 10
metrics = {}
if (time.time() - FASMETRICS['time']) > FASMETRICS_CACHE_MAX:
for filer in filerdict.keys():
s = NaServer(filerdict[filer]['ipaddr'], 1, 3)
out = s.set_transport_type('HTTPS')
if (out and out.results_errno() != 0) :
r = out.results_reason()
print ("Connection to filer failed: " + r + "\n")
sys.exit(2)
out = s.set_style('LOGIN')
if (out and out.results_errno() != 0) :
r = out.results_reason()
print ("Connection to filer failed: " + r + "\n")
sys.exit(2)
out = s.set_admin_user(filerdict[filer]['user'], filerdict[filer]['password'])
perf_in = NaElement("perf-object-get-instances-iter-start")
#Hard coding volume object for testing
obj_name = "volume"
perf_in.child_add_string("objectname", obj_name)
#Create object of type counters
counters = NaElement("counters")
#Add counter names to the object
counters.child_add_string("counter", "total_ops")
counters.child_add_string("counter", "avg_latency")
counters.child_add_string("counter", "read_ops")
counters.child_add_string("counter", "read_latency")
counters.child_add_string("counter", "write_ops")
counters.child_add_string("counter", "write_latency")
perf_in.child_add(counters)
#Invoke API
out = s.invoke_elem(perf_in)
if(out.results_status() == "failed"):
print(out.results_reason() + "\n")
sys.exit(2)
iter_tag = out.child_get_string("tag")
num_records = 1
filername = filerdict[filer]['name']
while(int(num_records) != 0):
perf_in = NaElement("perf-object-get-instances-iter-next")
perf_in.child_add_string("tag", iter_tag)
perf_in.child_add_string("maximum", max_records)
out = s.invoke_elem(perf_in)
if(out.results_status() == "failed"):
print(out.results_reason() + "\n")
sys.exit(2)
num_records = out.child_get_int("records")
if(num_records > 0) :
instances_list = out.child_get("instances")
instances = instances_list.children_get()
for inst in instances:
inst_name = unicodedata.normalize('NFKD',inst.child_get_string("name")).encode('ascii','ignore')
counters_list = inst.child_get("counters")
counters = counters_list.children_get()
for counter in counters:
counter_name = unicodedata.normalize('NFKD',counter.child_get_string("name")).encode('ascii','ignore')
counter_value = counter.child_get_string("value")
counter_unit = counter.child_get_string("unit")
metrics[filername + '_vol_' + inst_name + '_' + counter_name] = float(counter_value)
# update cache
LAST_FASMETRICS = dict(FASMETRICS)
FASMETRICS = {
'time': time.time(),
'data': metrics
}
else:
metrics = FASMETRICS['data']
#print name
#calculate change in values and return
if 'total_ops' in name:
try:
delta = float(FASMETRICS['data'][name] - LAST_FASMETRICS['data'][name])/(FASMETRICS['time'] - LAST_FASMETRICS['time'])
if delta < 0:
print "Less than 0"
delta = 0
except StandardError:
delta = 0
#This is the Operations per second
return delta
elif 'avg_latency' in name:
try:
#T1 and T2
#.........这里部分代码省略.........