Skip to content

Commit

Permalink
Fixed bug in aci-show-physical-inventory; pep8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Smith committed Apr 7, 2015
1 parent 70e1ddf commit 0ab5b40
Showing 1 changed file with 61 additions and 55 deletions.
116 changes: 61 additions & 55 deletions acitoolkit/aciphysobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def get(cls, session, parent=None):
:returns: list of fantrays
"""
fans = cls.get_obj(session, 'eqptFt', parent)
for fan in fans :
for fan in fans:
fan._add_additional_attributes(session)
return fans

Expand All @@ -664,7 +664,7 @@ def _populate_from_attributes(self, attributes):
self.descr = str(attributes['descr'])
self.oper_st = str(attributes['operSt'])
self.type = 'fantray'
self.name = str(attributes.get('fanName','None'))
self.name = str(attributes.get('fanName', 'None'))
self.status = str(attributes['status'])

@staticmethod
Expand All @@ -689,7 +689,8 @@ def populate_children(self, deep=False):
child.populate_children(deep=True)

return None



class Fan(BaseACIPhysModule):
"""Class for the fan of a fan tray"""
def __init__(self, id=None, parent=None):
Expand All @@ -705,6 +706,7 @@ def __init__(self, id=None, parent=None):
self.speed = None
self.id = id
self._parent = parent
self._children = []

@classmethod
def get(cls, session, parent=None):
Expand All @@ -726,12 +728,13 @@ def get(cls, session, parent=None):

if parent:
if not isinstance(parent, Fantray):
raise TypeError('When a parent is specified, it must be of type Fantray class')
raise TypeError(('When a parent is specified, it must be of'
'type Fantray class'))

fans = []

# get the total number of ports = number of power supply slots
if parent :
if parent:
mo_query_url = '/api/mo/' + parent.dn + '.json?query-target=subtree&target-subtree-class=eqptFan'
else:
mo_query_url = ('/api/node/class/eqptFan.json?'
Expand All @@ -740,8 +743,8 @@ def get(cls, session, parent=None):

ret = session.get(mo_query_url)
node_data = ret.json()['imdata']
if node_data :
for fan_obj in node_data :
if node_data:
for fan_obj in node_data:
fan = Fan()
fan.dn = str(fan_obj['eqptFan']['attributes']['dn'])
fan.id = str(fan_obj['eqptFan']['attributes']['id'])
Expand All @@ -756,18 +759,17 @@ def get(cls, session, parent=None):
ret = session.get(mo_query_url)
stat_data = ret.json()['imdata']
fan.speed = 'unknown'
if stat_data :
if stat_data:
if 'eqptFan' in stat_data[0]:
if 'children' in stat_data[0]['eqptFan']:
if stat_data[0]['eqptFan']['children']:
if 'eqptFanStats5min' in stat_data[0]['eqptFan']['children'][0]:
fan.speed = stat_data[0]['eqptFan']['children'][0]['eqptFanStats5min']['attributes']['speedLast']

if parent :
if parent:
fan._parent = parent
parent.add_child(fan)
fans.append(fan)

return fans

def __eq__(self, other):
Expand Down Expand Up @@ -870,7 +872,7 @@ def __init__(self, pod_id, attributes=None, parent=None):
if isinstance(parent, str):
raise TypeError("Parent object can't be a string")

if attributes :
if attributes:
if not isinstance(attributes, dict):
raise TypeError("Attributes must be a dictionary")

Expand Down Expand Up @@ -1070,13 +1072,13 @@ def get(session, parent=None, node_id=None):
if not isinstance(session, Session):
raise TypeError('An instance of Session class is required')

if node_id :
if node_id:
# this can be enhanced to get a specific node
node_dn = 'topology/pod-{0}/node-{1}'.format(pod_id, node_id)
node_query_url = '/api/mo/'+node_dn+ '.json?query-target=self'
# node_query_url = ('/api/node/class/fabricNode.json?'
# 'query-target=self')
else :
else:
node_query_url = ('/api/node/class/fabricNode.json?'
'query-target=self')

Expand All @@ -1097,29 +1099,28 @@ def get(session, parent=None, node_id=None):
# check for pod match if specified
pod_match = False
if parent:
if isinstance(parent, Pod) :
if node.pod == parent.pod :
if isinstance(parent, Pod):
if node.pod == parent.pod:
pod_match = True
parent.add_child(node)
node._parent = parent
else :
else:
# pod is a number string
if node.pod == parent :
if node.pod == parent:
pod_match = True
else :
else:
pod_match = True

# check for node match if specified
node_match = False
if node_id :
if node_id == node.node :
if node_id:
if node_id == node.node:
node_match = True
else :
else:
node_match = True

if node_match and pod_match :

if node.role == 'leaf' :
if node_match and pod_match:
if node.role == 'leaf':
node._add_vpc_info()
node.get_health()
node.get_firmware()
Expand All @@ -1136,19 +1137,19 @@ def get_firmware(self):
query_url = '/api/mo/'+dn+'.json?&query-target=self'
ret = self._session.get(query_url)
data = ret.json()['imdata']
if data :
if data:
self.firmware = data[0]['firmwareCardRunning']['attributes']['version']


def get_health(self):
"""
This will get the health of the switch node
"""
if self.role != 'controller' :
if self.role != 'controller':
mo_query_url = '/api/mo/'+self.dn+ '/sys.json?&rsp-subtree-include=stats&rsp-subtree-class=fabricNodeHealth5min'
ret = self._session.get(mo_query_url)
data = ret.json()['imdata']
if data :
if data:
self.health = data[0]['topSystem']['children'][0]['fabricNodeHealth5min']['attributes']['healthLast']

def _add_vpc_info(self):
Expand Down Expand Up @@ -1187,8 +1188,8 @@ def _add_vpc_info(self):
data = ret.json()['imdata'][0]

vpc_admin_state = data['vpcInst']['attributes']['adminSt']
result = {'admin_state':vpc_admin_state}
if vpc_admin_state=='enabled' :
result = {'admin_state': vpc_admin_state}
if vpc_admin_state=='enabled':
mo_query_url = '/api/mo/'+partial_dn + '.json?query-target=subtree&target-subtree-class=vpcDom'
ret = self._session.get(mo_query_url)
data = ret.json()['imdata']
Expand All @@ -1208,9 +1209,8 @@ def _add_vpc_info(self):
result['oper_role'] = vpcDom['operRole']
else:
result['oper_state'] = 'inactive'
else :
else:
result['oper_state'] = 'inactive'

self.vpc_info = result


Expand Down Expand Up @@ -1272,9 +1272,9 @@ def _get_topsystem_info(self):
node_data = ret.json()['imdata']
self.num_fan_slots = len(node_data)
self.num_fan_modules = 0
if node_data :
for slot in node_data :
if slot['eqptFtSlot']['attributes']['operSt']=='inserted' :
if node_data:
for slot in node_data:
if slot['eqptFtSlot']['attributes']['operSt']=='inserted':
self.num_fan_modules +=1

# get the total number of ports = number of linecard slots
Expand All @@ -1283,9 +1283,9 @@ def _get_topsystem_info(self):
node_data = ret.json()['imdata']
self.num_lc_slots = len(node_data)
self.num_lc_modules = 0
if node_data :
for slot in node_data :
if slot['eqptLCSlot']['attributes']['operSt']=='inserted' :
if node_data:
for slot in node_data:
if slot['eqptLCSlot']['attributes']['operSt']=='inserted':
self.num_lc_modules +=1

# get the total number of ports = number of power supply slots
Expand All @@ -1294,9 +1294,9 @@ def _get_topsystem_info(self):
node_data = ret.json()['imdata']
self.num_ps_slots = len(node_data)
self.num_ps_modules = 0
if node_data :
for slot in node_data :
if slot['eqptPsuSlot']['attributes']['operSt']=='inserted' :
if node_data:
for slot in node_data:
if slot['eqptPsuSlot']['attributes']['operSt']=='inserted':
self.num_ps_modules +=1

# get the total number of ports = number of supervisor slots
Expand All @@ -1305,9 +1305,9 @@ def _get_topsystem_info(self):
node_data = ret.json()['imdata']
self.num_sup_slots = len(node_data)
self.num_sup_modules = 0
if node_data :
for slot in node_data :
if slot['eqptSupCSlot']['attributes']['operSt']=='inserted' :
if node_data:
for slot in node_data:
if slot['eqptSupCSlot']['attributes']['operSt']=='inserted':
self.num_sup_modules +=1

# get dynamic load balancing config
Expand Down Expand Up @@ -1607,7 +1607,7 @@ def _get_system_info(session, dn):
lldp_dn = lldp_dn + port + ']/adj-1'

lldp_data = ENode._get_dn(session, lldp_dn)
if len(lldp_data) > 0 :
if len(lldp_data) > 0:
attrib['ipAddress'] = str(lldp_data[0]['lldpAdjEp']['attributes']['mgmtIp'])
attrib['name'] = str(lldp_data[0]['lldpAdjEp']['attributes']['sysName'])

Expand Down Expand Up @@ -1906,6 +1906,7 @@ def _parse_dn(dn):

return pod, link


class AccessPolicyConcrete(BaseACIObject):
"""
Access policy in the switch
Expand All @@ -1919,6 +1920,7 @@ def __init__(self):
self.filter_id = None
self.mask_dscp = None


class BaseInterface(BaseACIObject):
"""Abstract class used to provide base functionality to other Interface
classes.
Expand Down Expand Up @@ -1963,6 +1965,7 @@ def get_port_selector_json(self):
def get_port_channel_selector_json(self, port_name):
return self._get_port_selector_json('accbundle', port_name)


class Interface(BaseInterface):
"""This class defines a physical interface.
"""
Expand Down Expand Up @@ -2327,9 +2330,8 @@ def get(session, pod_parent=None, node=None, module=None, port=None):
:returns: list of Interface instances
"""

if port:
if not isinstance(port, str) :
if not isinstance(port, str):
raise TypeError('When specifying a specific port, the port'
' must be a identified by a string')
if not isinstance(module, str):
Expand All @@ -2342,10 +2344,11 @@ def get(session, pod_parent=None, node=None, module=None, port=None):
raise TypeError(('When specifying a specific port, the pod '
'must be identified by a string'))
parent = None
else :
if pod_parent :
if not isinstance(pod_parent, Linecard) :
raise TypeError('Interface parent must be a linecard object')
else:
if pod_parent:
if not isinstance(pod_parent, Linecard):
raise TypeError(('Interface parent must be a linecard'
'object'))

parent = pod_parent

Expand Down Expand Up @@ -2406,7 +2409,9 @@ def get(session, pod_parent=None, node=None, module=None, port=None):
attributes['module'] = module
attributes['port'] = port
attributes['operSt'] = ethDataDict[dist_name + '/phys']['operSt']
interface_obj = Interface(interface_type, pod, node, module, port, parent=None, session=session, attributes=attributes)
interface_obj = Interface(interface_type, pod, node, module, port,
parent=None, session=session,
attributes=attributes)
interface_obj.porttype = porttype
interface_obj.adminstatus = adminstatus
interface_obj.speed = speed
Expand Down Expand Up @@ -2442,7 +2447,8 @@ def __eq__(self, other):

return True
return False
def get_adjacent_port(self) :

def get_adjacent_port(self):
"""
This will return the port ID of the port at the other end of the link.
Expand All @@ -2456,8 +2462,8 @@ def get_adjacent_port(self) :
"""
result = None

links = Link.get(self._session,'1',self.attributes['node'])
for link in links :
if link.port1==self.attributes['port'] :
links = Link.get(self._session, '1', self.attributes['node'])
for link in links:
if link.port1 == self.attributes['port']:
return link.get_port_id2()
return result

0 comments on commit 0ab5b40

Please sign in to comment.