Skip to content

Commit

Permalink
Merge pull request #307 from sig9org/json_output_option
Browse files Browse the repository at this point in the history
Add json output option
  • Loading branch information
michsmit99 committed Jul 11, 2017
2 parents 866e917 + a1b4421 commit 91067ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
16 changes: 10 additions & 6 deletions samples/aci-create-bd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def main():
creds.add_argument('--bd', help='The name of BridgeDomain')
creds.add_argument('--address', help='Subnet IPv4 Address')
creds.add_argument('--scope', help='The scope of subnet ("public", "private", "shared", "public,shared", "private,shared", "shared,public", "shared,private")')
creds.add_argument('--json', const='false', nargs='?', help='Json output only')

args = creds.get()
session = Session(args.url, args.login, args.password)
Expand All @@ -42,12 +43,15 @@ def main():
else:
subnet.set_scope(args.scope)

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 args.json:
print(tenant.get_json())
else:
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__':
main()
17 changes: 10 additions & 7 deletions samples/aci-create-epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def main():
creds.add_argument('--app', help='The name of ApplicationProfile')
creds.add_argument('--bd', help='The name of BridgeDomain')
creds.add_argument('--epg', help='The name of EPG')
creds.add_argument('--json', const='false', nargs='?', help='Json output only')

args = creds.get()
session = Session(args.url, args.login, args.password)
Expand All @@ -27,13 +28,15 @@ def main():
epg = EPG(args.epg, app)
epg.add_bd(bd)

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 args.json:
print(tenant.get_json())
else:
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__':
main()

0 comments on commit 91067ce

Please sign in to comment.