Skip to content

Commit

Permalink
Merge pull request #310 from sig9org/declare_python_interpreter
Browse files Browse the repository at this point in the history
Add python interpreter declaration
  • Loading branch information
michsmit99 committed Jul 14, 2017
2 parents 486b133 + b9692ea commit 9f73f40
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 161 deletions.
40 changes: 6 additions & 34 deletions samples/aci-check-cluster.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
#!/usr/bin/env python
################################################################################
# _ ____ ___ _____ _ _ _ _ #
# / \ / ___|_ _| |_ _|__ ___ | | | _(_) |_ #
# / _ \| | | | | |/ _ \ / _ \| | |/ / | __| #
# / ___ \ |___ | | | | (_) | (_) | | <| | |_ #
# ____ /_/ \_\____|___|___|_|\___/ \___/|_|_|\_\_|\__| #
# / ___|___ __| | ___ / ___| __ _ _ __ ___ _ __ | | ___ ___ #
# | | / _ \ / _` |/ _ \ \___ \ / _` | '_ ` _ \| '_ \| |/ _ \/ __| #
# | |__| (_) | (_| | __/ ___) | (_| | | | | | | |_) | | __/\__ \ #
# \____\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|\___||___/ #
# |_| #
################################################################################
# #
# Copyright (c) 2015 Cisco Systems #
# All Rights Reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
# License for the specific language governing permissions and limitations #
# under the License. #
# #
################################################################################

"""
Simple application that shows all of the processes running on a switch
"""
Expand All @@ -49,20 +21,20 @@ def main():
session = Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
print('%% Could not login to APIC')
sys.exit(0)

cluster = Cluster.get(session)

if (cluster.config_size != cluster.cluster_size):
print("*******************************************************")
print ("WARNING, configured cluster size "), cluster.config_size
print (": not equal to the actual size "), cluster.cluster_size
print "WARNING, desired stats collection might be lost"
print("WARNING, configured cluster size "), cluster.config_size
print(": not equal to the actual size "), cluster.cluster_size
print("WARNING, desired stats collection might be lost")
print("*******************************************************")
print("APICs in the cluster"), cluster.name, (":")
for apic in cluster.apics:
print json.dumps(apic, indent=4, sort_keys=True)
print(json.dumps(apic, indent=4, sort_keys=True))
else:
print("PASS")

Expand Down
44 changes: 8 additions & 36 deletions samples/aci-epg-reports-in-yaml.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
#!/usr/bin/env python
################################################################################
# _ ____ ___ _____ _ _ _ _ #
# / \ / ___|_ _| |_ _|__ ___ | | | _(_) |_ #
# / _ \| | | | | |/ _ \ / _ \| | |/ / | __| #
# / ___ \ |___ | | | | (_) | (_) | | <| | |_ #
# ____ /_/ \_\____|___|___|_|\___/ \___/|_|_|\_\_|\__| #
# / ___|___ __| | ___ / ___| __ _ _ __ ___ _ __ | | ___ ___ #
# | | / _ \ / _` |/ _ \ \___ \ / _` | '_ ` _ \| '_ \| |/ _ \/ __| #
# | |__| (_) | (_| | __/ ___) | (_| | | | | | | |_) | | __/\__ \ #
# \____\___/ \__,_|\___| |____/ \__,_|_| |_| |_| .__/|_|\___||___/ #
# |_| #
################################################################################
# #
# Copyright (c) 2015 Cisco Systems #
# All Rights Reserved. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
# License for the specific language governing permissions and limitations #
# under the License. #
# #
################################################################################

"""
Simple application that logs on to the APIC and displays all
EPGs.
Expand Down Expand Up @@ -62,26 +34,26 @@ def main():
for tenant in tenants:
tenants_dict = {}
tenants_dict['name'] = tenant.name

if tenant.descr:
tenants_dict['description'] = tenant.descr

tenants_dict['app-profiles'] = []
for app in tenant.get_children(AppProfile):
app_profiles = {}
app_profiles['name'] =app.name
if app.descr:
app_profiles['description'] = app.descr
app_profiles['epgs'] = []


for epg in app.get_children(EPG):
epgs_info = {}
epgs_info['name'] = epg.name
if epg.descr:
epgs_info['description'] = epg.descr
epgs_info['endpoints'] = []

for endpoint in epg.get_children(Endpoint):
endpoint_info = {}
endpoint_info['name'] = endpoint.name
Expand All @@ -95,15 +67,15 @@ def main():
endpoint_info['hostname'] = hostname
if endpoint.descr:
endpoint_info['description'] = endpoint.descr

epgs_info['endpoints'].append(endpoint_info)
app_profiles['epgs'].append(epgs_info)
tenants_dict['app-profiles'].append(app_profiles)
tenants_list.append(tenants_dict)

tenants_info = {}
tenants_info['tenants'] = tenants_list
print yaml.safe_dump(tenants_info,sys.stdout, indent= 4,default_flow_style=False)
print(yaml.safe_dump(tenants_info,sys.stdout, indent= 4,default_flow_style=False))

if __name__ == '__main__':
try:
Expand Down
11 changes: 6 additions & 5 deletions samples/aci-find-ip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
Simple application that logs on to the APIC and displays all
networks that match the given IP
Expand All @@ -6,7 +8,6 @@
from ipaddr import IPNetwork
import acitoolkit.acitoolkit as aci


def main():
"""
Main routine
Expand All @@ -25,10 +26,10 @@ def main():
print('%% Could not login to APIC')

if not args.find_ip:
print "Error: -f|--find_ip <ip_address> argument required"
print("Error: -f|--find_ip <ip_address> argument required")
sys.exit(1)

print "searching for " + args.find_ip
print("searching for " + args.find_ip)
# Download all of the tenants, app profiles, and Subnets
# and store the names as tuples in two lists
priv = []
Expand Down Expand Up @@ -70,7 +71,7 @@ def main():
# Display
template = "{0:20} {1:20} {2:20} {3:18} {4:15}"
if len(priv):
print ""
print("")
print(template.format("Tenant",
"App",
"Bridge Domain",
Expand All @@ -84,7 +85,7 @@ def main():
for rec in priv:
print(template.format(*rec))
if len(publ):
print ""
print("")
print(template.format("Tenant",
"OutsideL3",
"OutsideEPG",
Expand Down
64 changes: 33 additions & 31 deletions samples/aci-get-interface-stats-from-nodes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import sys
import locale
from time import localtime, strftime
Expand All @@ -18,7 +20,7 @@ def __init__(self, session, txtformat='text', verbose=0):
:param txtformat: Output format, 'text' or 'csv'
:param verbose: Verbosity level of debug output
"""
print 'Getting inital info from APIC....'
print('Getting inital info from APIC....')
self.session = session
self.nodes = Node.get_deep(session)
self.txtformat = txtformat
Expand Down Expand Up @@ -51,25 +53,25 @@ def get_int_traffic(self, node_type, interval, threshold):
"""
if self.txtformat == 'csv':
csv = True
print "'Node Name','Interface','Epoch','Ingress bit rate'," \
"'Egress bit rate'"
print("'Node Name','Interface','Epoch','Ingress bit rate'," \
"'Egress bit rate'")
else:
csv = False
print "Report generated on {}.".format(
strftime("%Y-%b-%d %H:%M:%S %Z", localtime()))
print "Using reporting threshold of {:d}%.".format(threshold)
print("Report generated on {}.".format(
strftime("%Y-%b-%d %H:%M:%S %Z", localtime())))
print("Using reporting threshold of {:d}%.".format(threshold))

max_in_per = max_out_per = 0
for node in sorted(self.nodes, key=attrgetter('name')):
if node.role in node_type:
if not csv:
print " Node =", node.name
print(" Node =", node.name)
if self.verbose > 0:
print >> sys.stderr, " Node =", node.name
for lc in sorted(node.get_children(Linecard),
key=attrgetter('name')):
if not csv:
print " Linecard =", lc.name
print(" Linecard =", lc.name)
if self.verbose > 0:
print >> sys.stderr, " Linecard =", lc.name
for intf in sorted(Interface.get(self.session, lc),
Expand Down Expand Up @@ -109,9 +111,9 @@ def get_int_traffic(self, node_type, interval, threshold):
interval, epoch,
'intervalStart')
if csv:
print "'{}','{}',{},{},{}".format(
print("'{}','{}',{},{},{}".format(
node.name, intf.name, value_time,
value_in, value_out)
value_in, value_out))
else:
interval_count += 1
value_in_per = (value_in / intf_speed) * 100
Expand All @@ -133,28 +135,28 @@ def get_int_traffic(self, node_type, interval, threshold):
max_value_time = value_time

if excess_interval_count and not csv:
print " Interface =", intf.name
print " Interface Speed = {}({})".format(
print(" Interface =", intf.name)
print(" Interface Speed = {}({})".format(
info_dict['attributes']['operSpeed'],
locale.format('%d', intf_speed, True))
print " Highest usage interval with " \
locale.format('%d', intf_speed, True)))
print(" Highest usage interval with " \
" utilization exceeding {}% for {}.".format(
threshold, interval)
print " Interval time: {}".format(
max_value_time)
print " Ingress bps: {}".format(
locale.format('%d', max_value_in, True))
print " Egress bps: {}".format(
locale.format('%d', max_value_out, True))
print " {} of {} intervals over {}%" \
threshold, interval))
print(" Interval time: {}".format(
max_value_time))
print(" Ingress bps: {}".format(
locale.format('%d', max_value_in, True)))
print(" Egress bps: {}".format(
locale.format('%d', max_value_out, True)))
print(" {} of {} intervals over {}%" \
" utilization".format(excess_interval_count,
interval_count,
threshold)
threshold))

if not csv:
print "Max input usage found is {:d}%".format(int(max_in_per))
print "Max output usage found is {:d}%".format(int(max_out_per))
print("Max input usage found is {:d}%".format(int(max_in_per)))
print("Max output usage found is {:d}%".format(int(max_out_per)))


def get_interface_stats_from_nodes():
"""
Expand Down Expand Up @@ -206,12 +208,12 @@ def get_interface_stats_from_nodes():
session = Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
print('%% Could not login to APIC')
sys.exit(0)

statistics = Stats(session, args.format, args.verbose)
statistics.get_int_traffic(node_type, args.interval, threshold)


if __name__ == "__main__":
get_interface_stats_from_nodes()
get_interface_stats_from_nodes()
6 changes: 4 additions & 2 deletions samples/aci-get-tenantObject-from-json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
Simple application that takes a tenant json from a file and returns a tenant object
"""
Expand All @@ -20,9 +22,9 @@ def main():

tenantObject = None
if args.tenantconfigfile:
with open(args.tenantconfigfile) as data_file:
with open(args.tenantconfigfile) as data_file:
tenant_json = json.load(data_file)

tenant = ACI.Tenant(args.tenantname)
ACI.Tenant.get_from_json(tenant,tenant_json,parent=tenant)
print(tenant.get_json())
Expand Down
4 changes: 3 additions & 1 deletion samples/aci-raw-class-query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
Simple application that logs on to the APIC and displays all
the response of an API query given the class name and scope
Expand Down Expand Up @@ -28,7 +30,7 @@ def main():
sys.exit(0)

class_url = '/api/node/class/'+args.class_name+'.json?query-target='+args.query_target
print "class_url is "+class_url
print("class_url is "+class_url)
ret = session.get(class_url)
response = ret.json()
imdata = response['imdata']
Expand Down
18 changes: 10 additions & 8 deletions samples/aci-show-faults-by-domain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
simple application that logs on to apic and displays all the faults.
if a particular tenant is given shows faults of that tenant
Expand Down Expand Up @@ -50,16 +52,16 @@ def main():
if faults is not None:
for fault in faults:
if fault is not None:
print "---------------"
print("---------------")
if fault.descr is not None:
print " descr : " + fault.descr
print(" descr : " + fault.descr)
else:
print " descr : " + " "
print " dn : " + fault.dn
print " rule : " + fault.rule
print " severity : " + fault.severity
print " type : " + fault.type
print " domain : " + fault.domain
print(" descr : " + " ")
print(" dn : " + fault.dn)
print(" rule : " + fault.rule)
print(" severity : " + fault.severity)
print(" type : " + fault.type)
print(" domain : " + fault.domain)


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions samples/aci-show-lldp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

"""
Simple application that logs on to the APIC, pull all LLDP neighbours,
and display in text table format
Expand Down Expand Up @@ -40,12 +42,12 @@ def main():
for table_data in table.data:
if table_data not in output_list:
output_list.append(table_data)
print tabulate(output_list, headers=["Node-ID",
print(tabulate(output_list, headers=["Node-ID",
"Ip",
"Name",
"Chassis_id_t",
"Neighbour Platform",
"Neighbour Interface"])
"Neighbour Interface"]))

if __name__ == '__main__':
main()

0 comments on commit 9f73f40

Please sign in to comment.