Skip to content

Commit

Permalink
Merge pull request #351 from lumean/master
Browse files Browse the repository at this point in the history
Python 3 signature authentication fix and general compatibility improvement
  • Loading branch information
Michael Smith committed Sep 25, 2019
2 parents 5faffd3 + e9de48f commit 24acd23
Show file tree
Hide file tree
Showing 39 changed files with 315 additions and 315 deletions.
2 changes: 1 addition & 1 deletion acitoolkit/acisession.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def _prep_x509_header(self, method, url, data=None):
payload += data

signature = base64.b64encode(sign(self._x509Key, payload, 'sha256'))
cookie = {'APIC-Request-Signature': signature,
cookie = {'APIC-Request-Signature': signature.decode('ascii'),
'APIC-Certificate-Algorithm': 'v1.0',
'APIC-Certificate-Fingerprint': 'fingerprint',
'APIC-Certificate-DN': cert_dn}
Expand Down
28 changes: 14 additions & 14 deletions applications/cableplan/cableplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def compare_cable_plans(session, file1, file2=None):
else:
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
print('%% Could not login to APIC')
sys.exit(1)
cp1 = CABLEPLAN.get(session)
source1 = 'APIC'
Expand All @@ -1097,38 +1097,38 @@ def compare_cable_plans(session, file1, file2=None):
extra_switches = cp2.difference_switch(cp1)

if missing_switches:
print '\nThe following switches are in', source1 + ', but not in', source2
print('\nThe following switches are in', source1 + ', but not in', source2)
for switch in missing_switches:
print ' ', switch.get_name()
print(' ', switch.get_name())

if extra_switches:
print '\nThe following switches are in', source2 + ', but not in', source1
print('\nThe following switches are in', source2 + ', but not in', source1)
for switch in missing_switches:
print ' ', switch.get_name()
print(' ', switch.get_name())

if missing_switches or extra_switches:
print 'Link comparisons skipped because the switches are miss-matched'
print('Link comparisons skipped because the switches are miss-matched')
else:
missing_links = cp1.difference_link(cp2)
extra_links = cp2.difference_link(cp1)

if missing_links:
print '\nThe following links in', source1, 'are not found in', source2
print('\nThe following links in', source1, 'are not found in', source2)
for link in missing_links:
print ' ', link.get_name()
print(' ', link.get_name())

if extra_links:
print '\nThe following links in', source2, 'are not found in', source1
print('\nThe following links in', source2, 'are not found in', source1)
for link in extra_links:
print ' ', link.get_name()
print(' ', link.get_name())
if not missing_links and not extra_links:
print source1, 'and', source2, 'are the same'


def export_to_file(session, file1=None):
resp = session.login()
if not resp.ok:
print '%% Could not login to APIC'
print('%% Could not login to APIC')
sys.exit(1)
cp = CABLEPLAN.get(session)

Expand Down Expand Up @@ -1168,17 +1168,17 @@ def main():

if args.export_file and (args.cableplan1 or args.cableplan2):
creds.print_help()
print '\nError: export and compare operations are mutually exclusive'
print('\nError: export and compare operations are mutually exclusive')
exit()

if args.cableplan2 and not args.cableplan1:
creds.print_help()
print '\nError: -c2 option only valid with -c1 option'
print('\nError: -c2 option only valid with -c1 option')
exit()

if not args.export_file and not args.cableplan1:
creds.print_help()
print '\nError: Either export (-e) or compare (-c1) is required'
print('\nError: Either export (-e) or compare (-c1) is required')
exit()

if args.export_file:
Expand Down
26 changes: 13 additions & 13 deletions applications/cableplan/docs/cable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Using the Cable Plan module

.. _tut-invoking:

Invoking
Invoking
========================

The Cable Plan module is imported from the :file:`cable.py`.::
Expand All @@ -27,15 +27,15 @@ The Cable Plan module is imported from the :file:`cable.py`.::

When you want to create a cable plan from the current running topology
of an ACI fabric, simply do the following::

cp = CABLEPLAN.get(session)

Where ``session`` is an ACI session object generated using the
``acitoolkit``. ``cp`` will be the cable plan object.

You can export that cable plan by opening a file and calling the
``export()`` method as follows::

cpFile = open('cableplan1.xml','w')
cp.export(cpFile)
cpFile.close()
Expand All @@ -61,13 +61,13 @@ read from the :file:`cableplan2.xml` does not have switch "Spine3"
and the first cable plan does have it. The following example will
print all of the switches in the first cable plan and not in the
second.::

missing_switches = cp1.difference_switch(cp2)
for switch in missing_switches :
print switch.get_name()

This will print the following::

Spine3

Similiarly, the following example will print all of the missing
Expand All @@ -79,13 +79,13 @@ links::

To understand all of the differences between two cable plans it is
necessary to compare them in both directions ::

missing_links = cp1.difference_link(cp2)
extra_links = cp2.difference_link(cp1)
print 'The following links are missing from the second cable plan'
print('The following links are missing from the second cable plan')
for link in missing_links :
print link.get_name()
print 'The following links are extra links in the second cable plan'
print('The following links are extra links in the second cable plan')
for link in extra_links:
print link.get_name()

Expand All @@ -94,10 +94,10 @@ maxPorts attributes (see Cable Plan XML Syntax below), it is possible
that a link object in the first cable plan is only partially met by
the link objects in the second cable plan. The ``remaining_need()``
method of the CpLink object.::

missing_links = cp1.difference_link(cp2)
for link in missing_links :
print 'Link',link.get_name(), 'still
print('Link',link.get_name(), 'still)
needs',link.remaining_need(),'links to satisfy its mimimum
requirement'

Expand All @@ -111,7 +111,7 @@ It might be necessary to compare cable plans when the names of the
switches are different, but the topologies are the same. This can
easily done by simply changing the names of the switches that are
different and then doing the comparisons.::

switch = cp1.get_switch('Spine1')
switch.set_name('Spine1_new_name')

Expand All @@ -122,7 +122,7 @@ file. Simply read it in, change the switch name, and export it out.
The following example will read in :file:`cable_plan2.xml`, change the
name of 'Leaf1' to 'Leaf35', and then export to the same file the
modified cable plan::

fileName = 'cable_plan2.xml'
cp2 = CABLEPLAN.get(fileName)
switch = cp2.get_switch('Leaf1')
Expand All @@ -131,7 +131,7 @@ modified cable plan::
cp2.export(f)
f.close()

Cable Plan XML Syntax
Cable Plan XML Syntax
========================
The cable plan XML looks like the following ::

Expand Down
12 changes: 6 additions & 6 deletions applications/configpush/apic_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ def main():

args = parser.parse_args()
if args.config is None:
print '%% No configuration file given'
print('%% No configuration file given')
return

# Load in the configuration
try:
with open(args.config) as config_file:
config = json.load(config_file)
except IOError:
print '%% Could not load configuration file'
print('%% Could not load configuration file')
return
except ValueError:
print 'Could not load improperly formatted configuration file'
print('Could not load improperly formatted configuration file')
return

if 'apic' not in config:
if args.url is None or args.login is None or args.password is None:
print 'APIC credentials not given'
print('APIC credentials not given')
return
elif args.url is not None and 'http://' in args.url:
ip_address = args.url.partition('http://')[-1]
Expand All @@ -74,7 +74,7 @@ def main():
ip_address = args.url.partition('https://')[-1]
use_https = True
else:
print 'Improperly formatted URL'
print('Improperly formatted URL')
return
config['apic'] = {'user_name': args.login,
'password': args.password,
Expand All @@ -85,7 +85,7 @@ def main():
resp = tool.add_config(config)
if resp == 'OK':
if not args.displayonly:
print 'Success'
print('Success')
else:
print resp

Expand Down
22 changes: 11 additions & 11 deletions applications/configpush/apicservice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
try:
from apicservice_test_credentials import (LOGIN, PASSWORD, IPADDR)
except ImportError:
print '''
print(''')
Please create a file called apicservice_test_credentials.py with the following:
IPADDR = ''
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_tenantname_in_configpush(self):
for tenant in tenants:
if tenant.name == tenant_name:
self.assertTrue(True, "tennat exists with name " + tenant_name)

def test_tenantname_for_invalidname_in_configpush(self):
"""
this should test the tenant name of tenant. the invalid characters in tenant name should be removed.
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_appProfilename_in_configpush(self):
app_profiles = tenant.get_children(AppProfile)
app = app_profiles[0]
self.assertEquals(app[0].name, app_name, "application profile with given name doesnot exist")

def test_appProfilename_for_invalidname_in_configpush(self):
"""
this should test the application Profile name of tenant. the invalid characters in application profile should be removed.
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_appProfilename_for_invalidname_in_configpush(self):
app_profiles = tenant.get_children(AppProfile)
app = app_profiles[0]
self.assertEquals(app[0].name, "app-test**-_.__", "application profile with given name doesnot exist")

def test_appProfilename_for_change_in_name_configpush(self):
"""
this should test the application Profile name of tenant.push the same json with diferent --app name for the second time.
Expand Down Expand Up @@ -640,7 +640,7 @@ def test_appProfilename_for_change_in_name_configpush(self):
self.assertEqual(len(app_profiles), 1, "len(app_profiles)!=1")
for app in app_profiles:
self.assertEquals(app.name, "app-test__-_.___changed", "application profile with name is not updated to the changed name")

app_name = 'app-test_second**-#.{}_changed'
load_config.load_configFile(config_file, is_file=False, tenant_name=tenant_name, app_name=app_name)
time.sleep(5)
Expand Down Expand Up @@ -742,7 +742,7 @@ def test_l3ext_name_in_configpush(self):
l3ext_name,
"External routed network with name doesnot exist" +
l3ext_name)

def test_l3ext_name_for_invalidname_in_configpush(self):
"""
this should test the external routed network name of tenant. the invalid characters in external routed network name should be removed.
Expand Down Expand Up @@ -834,11 +834,11 @@ def test_l3ext_name_for_invalidname_in_configpush(self):
l3ext_name,
"External routed network with name doesnot exist" +
l3ext_name)

def test_manglenames_in_configpush(self):
"""
this should test the mangle_names method defined in apicserive.py.
which will make sure the length of the names of EPGS,Filters, app_profiles, nodes, contracts not to exceed 64 characters
which will make sure the length of the names of EPGS,Filters, app_profiles, nodes, contracts not to exceed 64 characters
and also replaces the invalid characters
"""

Expand Down Expand Up @@ -948,10 +948,10 @@ def test_manglenames_in_configpush(self):
self.assertEqual(1, len(epgs), "num of epgs didnot match")
for epg in epgs:
self.assertEqual(epg.name, "Configpushtest2____..____-1", "epg name mangled successfully")

filters = tenant.get_children(Filter)
self.assertEqual(1, len(filters), "num of filters didnot match")

outsideL3s = tenant.get_children(OutsideL3)
self.assertEqual(1, len(outsideL3s), "num of outsideL3s didnot match")
for outsideL3 in outsideL3s:
Expand All @@ -964,7 +964,7 @@ def test_manglenames_in_configpush(self):
self.assertEqual(1, len(outsideNetworks), "num 0f outsideEpgs didnot match")
for outsideNetwork in outsideNetworks:
self.assertEqual(outsideNetwork.name, "240.0.0.0_24", "outsideNetwork name mangled successfully")

contracts = tenant.get_children(Contract)
self.assertEqual(1, len(contracts), "num of contracts didnot match")
for contract in contracts:
Expand Down
16 changes: 8 additions & 8 deletions applications/connection_search/aciConSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def search(self, flow_spec):
'contract': c_contract['contract']})

# t2 = datetime.datetime.now()
# print 'connections done', t2-t1
# print('connections done', t2-t1)
# t1=t2
for connection in connections:
if connection['source_tenant'] in self.valid_tenants or connection['dest_tenant'] in self.valid_tenants:
Expand All @@ -1625,7 +1625,7 @@ def search(self, flow_spec):
if len(matching_filters) > 0:
result.append(self._build_result_flow_spec(connection, matching_filters))
# t2 = datetime.datetime.now()
# print 'search result done', t2-t1
# print('search result done', t2-t1)
# t1=t2

# for flow_spec in result:
Expand Down Expand Up @@ -1696,7 +1696,7 @@ def find_contracts(self, subflow_spec, pro_con):
self.valid_tenants.add(tenant_name)

# t2 = datetime.datetime.now()
# print 'tenants done', t2-t1
# print('tenants done', t2-t1)
# t1=t2

# if 'common' not in tenants:
Expand All @@ -1718,7 +1718,7 @@ def find_contracts(self, subflow_spec, pro_con):
nodes = set()

# t2 = datetime.datetime.now()
# print 'contexts done', t2-t1
# print('contexts done', t2-t1)
# t1=t2
for context in contexts:
if context in self.context_radix:
Expand All @@ -1742,7 +1742,7 @@ def find_contracts(self, subflow_spec, pro_con):
nodes.add(node2)

# t2 = datetime.datetime.now()
# print 'nodes done', t2-t1
# print('nodes done', t2-t1)
# t1=t2
# now have all the nodes
if nodes is not None:
Expand All @@ -1761,7 +1761,7 @@ def find_contracts(self, subflow_spec, pro_con):
pass

# t2 = datetime.datetime.now()
# print 'overlap done', t2-t1
# print('overlap done', t2-t1)
# t1=t2
result = []
for epg in epgs_prefix:
Expand All @@ -1781,7 +1781,7 @@ def find_contracts(self, subflow_spec, pro_con):
'tenant': epg.get_parent().get_parent().name})

# t2 = datetime.datetime.now()
# print 'result done', t2-t1
# print('result done', t2-t1)
# t1=t2

return result
Expand Down Expand Up @@ -1863,7 +1863,7 @@ 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)

sdb = SearchDb(session)
Expand Down

0 comments on commit 24acd23

Please sign in to comment.