Skip to content

Commit

Permalink
Merge pull request #308 from sig9org/add_specific_tenant_option
Browse files Browse the repository at this point in the history
Add option to speficy tenant
  • Loading branch information
michsmit99 committed Jul 11, 2017
2 parents 560b60c + 474165d commit 866e917
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 234 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ Required

## Downloading

Option A:
### Option A:

If you have git installed, clone the repository

git clone https://github.com/datacenter/acitoolkit.git

Option B:
### Option B:

If you don't have git, [download a zip copy of the repository](https://github.com/datacenter/acitoolkit/archive/master.zip) and extract.

Option C:
### Option C:

The latest build of this project is also available as a Docker image from Docker Hub

Expand Down
3 changes: 2 additions & 1 deletion samples/aci-show-cdp.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 CDP neighbours,
and display in text table format
Expand All @@ -7,7 +9,6 @@
from acitoolkit.aciConcreteLib import ConcreteCdp
from tabulate import tabulate


def main():
"""
Main show Cdps routine
Expand Down
63 changes: 26 additions & 37 deletions samples/aci-show-contexts.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
#!/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
of the Contexts.
"""
import sys
import acitoolkit.acitoolkit as ACI


data = []
longest_names = {'Tenant': len('Tenant'),
'Context': len('Context')}
def main():
"""
Main execution routine
Expand All @@ -46,6 +20,7 @@ def main():
# Otherwise, take them from your environment variables file ~/.profile
description = 'Simple application that logs on to the APIC and displays all of the Contexts.'
creds = ACI.Credentials('apic', description)
creds.add_argument('--tenant', help='The name of Tenant')
args = creds.get()

# Login to APIC
Expand All @@ -57,21 +32,35 @@ def main():

# Download all of the contexts
# and store the data as tuples in a list
data = []
tenants = ACI.Tenant.get(session)
for tenant in tenants:
contexts = ACI.Context.get(session, tenant)
for context in contexts:
data.append((tenant.name, context.name))
check_longest_name(tenant.name, "Tenant")
if args.tenant is None:
get_context(session, tenant)
else:
if tenant.name == args.tenant:
get_context(session, tenant)

# IPython.embed()

# Display the data downloaded
template = '{0:19} {1:20}'
template = '{0:' + str(longest_names["Tenant"]) + '} ' \
'{1:' + str(longest_names["Context"]) + '}'
print(template.format("Tenant", "Context"))
print(template.format("------", "-------"))
for rec in data:
print(template.format('-' * longest_names["Tenant"],
'-' * longest_names["Context"]))
for rec in sorted(data):
print(template.format(*rec))

def get_context(session, tenant):
contexts = ACI.Context.get(session, tenant)
for context in contexts:
check_longest_name(context.name, "Context")
data.append((tenant.name, context.name))

def check_longest_name(item, title):
if len(item) > longest_names[title]:
longest_names[title] = len(item)

if __name__ == '__main__':
main()
65 changes: 27 additions & 38 deletions samples/aci-show-contracts.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
#!/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
of the Contracts.
"""
import sys
import acitoolkit.acitoolkit as aci


data = []
longest_names = {'Tenant': len('Tenant'),
'Contract': len('Contract')}
def main():
"""
Main show contracts routine
Expand All @@ -46,6 +20,7 @@ def main():
description = ('Simple application that logs on to the APIC'
'and displays all of the Contracts.')
creds = aci.Credentials('apic', description)
creds.add_argument('--tenant', help='The name of Tenant')
args = creds.get()

# Login to APIC
Expand All @@ -57,21 +32,35 @@ def main():

# 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))
check_longest_name(tenant.name, "Tenant")
if args.tenant is None:
get_contract(session, tenant)
else:
if tenant.name == args.tenant:
get_contract(session, tenant)

# IPython.embed()

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

def get_contract(session, tenant):
contracts = aci.Contract.get(session, tenant)
for contract in contracts:
check_longest_name(contract.name, "Contract")
data.append((tenant.name, contract.name))

def check_longest_name(item, title):
if len(item) > longest_names[title]:
longest_names[title] = len(item)

if __name__ == '__main__':
try:
Expand Down
33 changes: 2 additions & 31 deletions samples/aci-show-domains.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,12 @@
#!/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
of the Physical Domains, VMM Domains, and EPG associations.
"""
import sys
import acitoolkit.acitoolkit as aci


def main():
"""
Main Show Domains Routine
Expand Down Expand Up @@ -118,7 +89,7 @@ def main():
if len(domains) > 0:
template = '{0:20} {1:11} {2:26}'
print (template.format('Infra Domain Profile', 'Domain Type', 'TENANT:APP:EPG Association'))
print (template.format('--------------------', '-----------', '--------------------------'))
print(template.format("-" * 20, "-" * 11, "-" * 26))
for rec in output:
print (template.format(*rec))
print ('\n')
Expand Down
74 changes: 34 additions & 40 deletions samples/aci-show-epgs.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
#!/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.
"""
import acitoolkit.acitoolkit as aci


data = []
longest_names = {'Tenant': len('Tenant'),
'Application Profile': len('Application Profile'),
'EPG': len('EPG')}
def main():
"""
Main show EPGs routine
Expand All @@ -44,30 +19,49 @@ def main():
description = ('Simple application that logs on to the APIC'
' and displays all of the EPGs.')
creds = aci.Credentials('apic', description)
creds.add_argument('--tenant', help='The name of Tenant')
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')

# 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))
check_longest_name(tenant.name, "Tenant")
if args.tenant is None:
get_epg(session, tenant)
else:
if tenant.name == args.tenant:
get_epg(session, tenant)

# 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:
template = '{0:' + str(longest_names["Tenant"]) + '} ' \
'{1:' + str(longest_names["Application Profile"]) + '} ' \
'{2:' + str(longest_names["EPG"]) + '}'
print(template.format("Tenant", "Application Profile","EPG"))
print(template.format('-' * longest_names["Tenant"],
'-' * longest_names["Application Profile"],
'-' * longest_names["EPG"]))
for rec in sorted(data):
print(template.format(*rec))

def get_epg(session, tenant):
apps = aci.AppProfile.get(session, tenant)
for app in apps:
check_longest_name(app.name, "Application Profile")
epgs = aci.EPG.get(session, app, tenant)
for epg in epgs:
check_longest_name(epg.name, "EPG")
data.append((tenant.name, app.name, epg.name))

def check_longest_name(item, title):
if len(item) > longest_names[title]:
longest_names[title] = len(item)

if __name__ == '__main__':
try:
main()
Expand Down

0 comments on commit 866e917

Please sign in to comment.