Skip to content

Commit

Permalink
pylint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Smith committed Apr 1, 2015
1 parent c37acd1 commit 5f8012c
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 129 deletions.
54 changes: 32 additions & 22 deletions samples/aci-create-tenant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2014 Cisco Systems
# Copyright (c) 2014, 2015 Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -17,31 +17,41 @@
"""
It logs in to the APIC and will create the tenant.
"""
import acitoolkit.acitoolkit as ACI
import acitoolkit.acitoolkit as aci

# Define static values to pass (edit these if you wish to set differently)

DEFAULT_TENANT_NAME = 'tenant_kit'

# Get all the arguments
description = 'It logs in to the APIC and will create the tenant.'
creds = ACI.Credentials('apic', description)
creds.add_argument('-t', '--tenant', help='The name of tenant',
default=DEFAULT_TENANT_NAME)
args = creds.get()
def main():
"""
Main create tenant routine
:return: None
"""
# Get all the arguments
description = 'It logs in to the APIC and will create the tenant.'
creds = aci.Credentials('apic', description)
creds.add_argument('-t', '--tenant', help='The name of tenant',
default=DEFAULT_TENANT_NAME)
args = creds.get()

# Login to the APIC
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'

# Login to the APIC
session = ACI.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
# Create the Tenant, App Profile, and EPG
tenant = aci.Tenant(args.tenant)

# Create the Tenant, App Profile, and EPG
tenant = ACI.Tenant(args.tenant)
# Push it all to the APIC
resp = session.push_to_apic(tenant.get_url(),
tenant.get_json())
if not resp.ok:
print '%% Error: Could not push configuration to APIC'
print resp.text

# Push it all to the APIC
resp = session.push_to_apic(tenant.get_url(),
tenant.get_json())
if not resp.ok:
print '%% Error: Could not push configuration to APIC'
print resp.text
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
68 changes: 40 additions & 28 deletions samples/aci-show-contracts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2014 Cisco Systems
# Copyright (c) 2014, 2015 Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -19,35 +19,47 @@
of the Contracts.
"""
import sys
import acitoolkit.acitoolkit as ACI
import acitoolkit.acitoolkit as aci

# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = 'Simple application that logs on to the APIC and displays all of the Contracts.'
creds = ACI.Credentials('apic', description)
args = creds.get()
def main():
"""
Main show contracts routine
:return: None
"""
# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application that logs on to the APIC'
'and displays all of the Contracts.')
creds = aci.Credentials('apic', description)
args = creds.get()

# Login to APIC
session = ACI.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)
# Login to APIC
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)

# Download all of the contracts
# and store the data as tuples in a list
data = []
tenants = ACI.Tenant.get(session)
for tenant in tenants:
contracts = ACI.Contract.get(session, tenant)
for contract in contracts:
data.append((tenant.name, contract.name))
# Download all of the contracts
# and store the data as tuples in a list
data = []
tenants = aci.Tenant.get(session)
for tenant in tenants:
contracts = aci.Contract.get(session, tenant)
for contract in contracts:
data.append((tenant.name, contract.name))

# IPython.embed()
# IPython.embed()

# Display the data downloaded
template = '{0:19} {1:20}'
print template.format("Tenant", "Contract")
print template.format("------", "--------")
for rec in data:
print template.format(*rec)
# Display the data downloaded
template = '{0:19} {1:20}'
print template.format("Tenant", "Contract")
print template.format("------", "--------")
for rec in data:
print template.format(*rec)

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
78 changes: 49 additions & 29 deletions samples/aci-show-endpoints.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2014 Cisco Systems
# Copyright (c) 2014, 2015 Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -19,35 +19,55 @@
of the Endpoints.
"""
import sys
import acitoolkit.acitoolkit as ACI
import acitoolkit.acitoolkit as aci

# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application that logs on to the APIC'
' and displays all of the Endpoints.')
creds = ACI.Credentials('apic', description)
args = creds.get()

# Login to APIC
session = ACI.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)
def main():
"""
Main Show Endpoints Routine
:return: None
"""
# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application that logs on to the APIC'
' and displays all of the Endpoints.')
creds = aci.Credentials('apic', description)
args = creds.get()

# Download all of the interfaces
# and store the data as tuples in a list
data = []
endpoints = ACI.Endpoint.get(session)
for ep in endpoints:
epg = ep.get_parent()
app_profile = epg.get_parent()
tenant = app_profile.get_parent()
data.append((ep.mac, ep.ip, ep.if_name, ep.encap, tenant.name, app_profile.name, epg.name))
# Login to APIC
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)

# Display the data downloaded
template = "{0:19} {1:17} {2:15} {3:10} {4:10} {5:15} {6:15}"
print template.format("MACADDRESS", "IPADDRESS", "INTERFACE", "ENCAP", "TENANT", "APP PROFILE", "EPG")
print template.format("-----------------", "---------------", "--------------", "----------", "------", "-----------", "---")
for rec in data:
print template.format(*rec)
# Download all of the interfaces
# and store the data as tuples in a list
data = []
endpoints = aci.Endpoint.get(session)
for ep in endpoints:
epg = ep.get_parent()
app_profile = epg.get_parent()
tenant = app_profile.get_parent()
data.append((ep.mac, ep.ip, ep.if_name, ep.encap,
tenant.name, app_profile.name, epg.name))

# Display the data downloaded
col_widths = [19, 17, 15, 10, 15, 15, 15]
template = ''
for idx, width in enumerate(col_widths):
template += '{%s:%s} ' % (idx, width)
print template.format("MACADDRESS", "IPADDRESS", "INTERFACE",
"ENCAP", "TENANT", "APP PROFILE", "EPG")
fmt_string = []
for i in range(0, len(col_widths)):
fmt_string.append('-' * (col_widths[i] - 2))
print template.format(*fmt_string)
for rec in data:
print template.format(*rec)

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
64 changes: 39 additions & 25 deletions samples/aci-show-epgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,46 @@
#
"""
Simple application that logs on to the APIC and displays all
EPGs. Before running, please make sure that the credentials.py
file has the URL, LOGIN, and PASSWORD set for your APIC environment.
EPGs.
"""
import acitoolkit.acitoolkit as ACI
import credentials
import acitoolkit.acitoolkit as aci

# Login to APIC
session = ACI.Session(credentials.URL, credentials.LOGIN, credentials.PASSWORD)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'

# Download all of the tenants, app profiles, and EPGs
# and store the names as tuples in a list
data = []
tenants = ACI.Tenant.get(session)
for tenant in tenants:
apps = ACI.AppProfile.get(session, tenant)
for app in apps:
epgs = ACI.EPG.get(session, app, tenant)
for epg in epgs:
data.append((tenant.name, app.name, epg.name))
def main():
"""
Main show EPGs routine
:return: None
"""
# Login to APIC
description = ('Simple application that logs on to the APIC'
' and displays all of the EPGs.')
creds = aci.Credentials('apic', description)
args = creds.get()
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'

# Display the data downloaded
template = "{0:19} {1:20} {2:15}"
print template.format("TENANT", "APP_PROFILE", "EPG")
print template.format("------", "-----------", "---")
for rec in data:
print template.format(*rec)
# Download all of the tenants, app profiles, and EPGs
# and store the names as tuples in a list
data = []
tenants = aci.Tenant.get(session)
for tenant in tenants:
apps = aci.AppProfile.get(session, tenant)
for app in apps:
epgs = aci.EPG.get(session, app, tenant)
for epg in epgs:
data.append((tenant.name, app.name, epg.name))

# Display the data downloaded
template = "{0:19} {1:20} {2:15}"
print template.format("TENANT", "APP_PROFILE", "EPG")
print template.format("------", "-----------", "---")
for rec in data:
print template.format(*rec)

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
63 changes: 38 additions & 25 deletions samples/aci-subscribe-tenants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2014 Cisco Systems
# Copyright (c) 2014, 2015 Cisco Systems, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -22,31 +22,44 @@
deleted.
"""
import sys
import acitoolkit.acitoolkit as ACI
import acitoolkit.acitoolkit as aci

# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application using event subscription for the Tenant'
' class. When run, this application will log into the APIC '
'and subscribe to events on the Tenant class. If a new tenant'
' is created, the event will be printed on the screen. '
'Likewise, if an existing tenant is deleted.')
creds = ACI.Credentials('apic', description)
args = creds.get()

# Login to APIC
session = ACI.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)
def main():
"""
Main subscribe tenants routine
:return: None
"""
# Take login credentials from the command line if provided
# Otherwise, take them from your environment variables file ~/.profile
description = ('Simple application using event subscription for the'
'Tenant class. When run, this application will log '
'into the APIC and subscribe to events on the Tenant '
'class. If a new tenant is created, the event will be'
'printed on the screen. Likewise, if an existing tenant'
'is deleted.')
creds = aci.Credentials('apic', description)
args = creds.get()

ACI.Tenant.subscribe(session)
# Login to APIC
session = aci.Session(args.url, args.login, args.password)
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
sys.exit(0)

while True:
if ACI.Tenant.has_events(session):
tenant = ACI.Tenant.get_event(session)
if tenant.is_deleted():
print 'Tenant', tenant.name, 'has been deleted.'
else:
print 'Tenant', tenant.name, 'has been created or modified.'
aci.Tenant.subscribe(session)

while True:
if aci.Tenant.has_events(session):
tenant = aci.Tenant.get_event(session)
if tenant.is_deleted():
print 'Tenant', tenant.name, 'has been deleted.'
else:
print 'Tenant', tenant.name, 'has been created or modified.'

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass

0 comments on commit 5f8012c

Please sign in to comment.