Skip to content

Commit

Permalink
pep8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Edsall committed Apr 8, 2015
1 parent 510cca8 commit a917299
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions applications/reports/SwitchJson.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
################################################################################
# _ ____ ___ ____ _ #
# / \ / ___|_ _| | _ \ ___ _ __ ___ _ __| |_ ___ #
# / _ \| | | | | |_) / _ \ '_ \ / _ \| '__| __/ __| #
# / ___ \ |___ | | | _ < __/ |_) | (_) | | | |_\__ \ #
# _ ____ ___ ____ _ #
# / \ / ___|_ _| | _ \ ___ _ __ ___ _ __| |_ ___ #
# / _ \| | | | | |_) / _ \ '_ \ / _ \| '__| __/ __| #
# / ___ \ |___ | | | _ < __/ |_) | (_) | | | |_\__ \ #
# /_/ \_\____|___| |_| \_\___| .__/ \___/|_| \__|___/ #
# |_| #
# #
Expand All @@ -25,6 +25,8 @@
# under the License. #
# #
################################################################################


class SwitchJson(object):
"""
This class will hold the entire json tree
Expand All @@ -36,17 +38,18 @@ class SwitchJson(object):
It will allow an instance of a class to be retrieved returned
as a single object.
"""

def __init__(self, session, node_id):
self.session = session
self.node_id = node_id

self.by_class = {}
self.by_dn = {}

pod_id = '1'
self.top_dn = 'topology/pod-'+pod_id+'/node-'+self.node_id+'/sys'
query_url = ('/api/mo/'+self.top_dn+'.json?'
'query-target=self&rsp-subtree=full')
self.top_dn = 'topology/pod-' + pod_id + '/node-' + self.node_id + '/sys'
query_url = ('/api/mo/' + self.top_dn + '.json?'
'query-target=self&rsp-subtree=full')

ret = session.get(query_url)
data = ret.json()['imdata']
Expand Down Expand Up @@ -79,13 +82,13 @@ def _index_by_dn_class(self, branch):
"""
if branch:
for apic_class in branch:
self.by_dn[branch[apic_class]['attributes']['dn']] = {apic_class:branch[apic_class]}
if not apic_class in self.by_class:
self.by_dn[branch[apic_class]['attributes']['dn']] = {apic_class: branch[apic_class]}

if apic_class not in self.by_class:
self.by_class[apic_class] = []
self.by_class[apic_class].append({apic_class:branch[apic_class]})

self.by_class[apic_class].append({apic_class: branch[apic_class]})

if 'children' in branch[apic_class]:
for child in branch[apic_class]['children']:
self._index_by_dn_class(child)
Expand All @@ -96,15 +99,14 @@ def _index_recurse_dn(self, branch, dn_root):
"""
if branch:
for apic_class in branch:
if not 'dn' in branch[apic_class]['attributes']:
branch[apic_class]['attributes']['dn'] = dn_root+ \
'/'+branch[apic_class]['attributes']['rn']
if 'dn' not in branch[apic_class]['attributes']:
branch[apic_class]['attributes']['dn'] = dn_root + \
'/' + branch[apic_class]['attributes']['rn']
new_root_dn = branch[apic_class]['attributes']['dn']
if 'children' in branch[apic_class]:
for child in branch[apic_class]['children']:
self._index_recurse_dn(child, new_root_dn)


def get_class(self, class_name):
"""
returns all the objects of a given class
Expand Down Expand Up @@ -132,7 +134,6 @@ def get_subtree(self, class_name, dname):
result.append(class_record)
return result


def get_object(self, dname):
"""
Will return the object specified by dn.
Expand Down

0 comments on commit a917299

Please sign in to comment.