Skip to content

Commit

Permalink
pylint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Smith committed Feb 15, 2015
1 parent 9ce088a commit 227a7cc
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 12 deletions.
140 changes: 128 additions & 12 deletions acitoolkit/acitoolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from acisession import Session
from acitoolkitlib import Credentials
# from aciphysobject import Linecard
import json
import logging
import re
import copy
Expand All @@ -34,12 +33,22 @@ class Tenant(BaseACIObject):
"""
@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvTenant')
return resp

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return None

def _get_instance_subscription_url(self):
Expand Down Expand Up @@ -74,9 +83,15 @@ def push_to_apic(self, session):
"""
resp = session.push_to_apic(self.get_url(),
self.get_json())
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {'fvAp': AppProfile,
'fvBD': BridgeDomain,
'fvCtx': Context,
Expand Down Expand Up @@ -164,16 +179,31 @@ def __init__(self, name, parent):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvAp')
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {'fvAEPg': EPG, }

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return Tenant

@staticmethod
Expand Down Expand Up @@ -438,17 +468,32 @@ def __init__(self, epg_name, parent=None):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvAEPg')
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {'fvCEp': Endpoint,
'fvStCEp': Endpoint, }

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return AppProfile

@staticmethod
Expand Down Expand Up @@ -1091,16 +1136,31 @@ def __init__(self, bd_name, parent=None):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvBD')
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {'fvSubnet': Subnet, }

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return Tenant

@staticmethod
Expand Down Expand Up @@ -1263,6 +1323,11 @@ def __init__(self, subnet_name, parent=None):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvSubnet')
return resp
Expand Down Expand Up @@ -1340,16 +1405,31 @@ def __init__(self, context_name, parent=None):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvCtx')
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {}

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return Tenant

@staticmethod
Expand Down Expand Up @@ -1415,12 +1495,16 @@ def get(cls, session, tenant):

class BaseContract(BaseACIObject):
""" BaseContract : Base class for Contracts and Taboos """
def __init__(self, contract_name, contract_type='vzBrCP', parent=None):
def __init__(self, contract_name, parent=None):
super(BaseContract, self).__init__(contract_name, parent)
self._scope = 'context'

@staticmethod
def _get_contract_code():
"""
Returns the APIC class name for this contract.
Meant to be overridden by inheriting classes.
"""
raise NotImplementedError

@staticmethod
Expand All @@ -1433,12 +1517,22 @@ def _get_subject_relation_code():

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append(cls._get_contract_code())
return resp

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return Tenant

def set_scope(self, scope):
Expand All @@ -1459,6 +1553,11 @@ def get_scope(self):

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {}

def get_json(self):
Expand Down Expand Up @@ -1498,10 +1597,15 @@ def get_json(self):
class Contract(BaseContract):
""" Contract : Class for Contracts """
def __init__(self, contract_name, parent=None):
super(Contract, self).__init__(contract_name, 'vzBrCP', parent)
super(Contract, self).__init__(contract_name, parent)

@staticmethod
def _get_contract_code():
"""
Returns the APIC class name for this type of contract.
:returns: String containing APIC class name for this type of contract.
"""
return 'vzBrCP'

@staticmethod
Expand Down Expand Up @@ -1561,11 +1665,15 @@ def get(cls, session, tenant):
class Taboo(BaseContract):
""" Taboo : Class for Taboos """
def __init__(self, contract_name, parent=None):
super(Taboo, self).__init__(contract_name, self._get_contract_code(),
parent)
super(Taboo, self).__init__(contract_name, parent)

@staticmethod
def _get_contract_code():
"""
Returns the APIC class name for this type of contract.
:returns: String containing APIC class name for this type of contract.
"""
return 'vzTaboo'

@staticmethod
Expand Down Expand Up @@ -1692,7 +1800,6 @@ def get(cls, session, parent=None, tenant=None):
dn = object_data['vzRsSubjFiltAtt']['attributes']['dn']
tDn = object_data['vzRsSubjFiltAtt']['attributes']['tDn']
tRn = object_data['vzRsSubjFiltAtt']['attributes']['tRn']
names = ()
if dn.split('/')[2][4:] == parent.name and dn.split('/')[4][len(apic_class)-1:] == dn.split('/')[3][5:] and dn.split('/')[3][5:] == tDn.split('/')[2][4:] and tDn.split('/')[2][4:] == tRn[4:]:
name = str(object_data[apic_class]['attributes']['tRn'][4:])
if name[:len(parent.name)] == parent.name and name[len(parent.name):] != '':
Expand Down Expand Up @@ -1741,7 +1848,6 @@ def get_deep(cls, session, parent=None, tenant=None):
dn = object_data['vzRsSubjFiltAtt']['attributes']['dn']
tDn = object_data['vzRsSubjFiltAtt']['attributes']['tDn']
tRn = object_data['vzRsSubjFiltAtt']['attributes']['tRn']
names = ()
if dn.split('/')[2][4:] == parent.name and dn.split('/')[4][len(apic_class)-1:] == dn.split('/')[3][5:] and dn.split('/')[3][5:] == tDn.split('/')[2][4:] and tDn.split('/')[2][4:] == tRn[4:]:
name = str(object_data[apic_class]['attributes']['tRn'][4:])
if name[:len(parent.name)] == parent.name and name[len(parent.name):] != '':
Expand Down Expand Up @@ -2302,7 +2408,6 @@ def get(self, session=None):

ret = session.get(mo_query_url)
data = ret.json()['imdata']
noCounts = False
if data:
if 'children' in data[0]['l1PhysIf']:
children = data[0]['l1PhysIf']['children']
Expand Down Expand Up @@ -2413,10 +2518,6 @@ def get(self, session=None):
result[countName][granularity][period]['intervalEnd'] = counterAttr.get('repIntvEnd')
result[countName][granularity][period]['intervalStart'] = counterAttr.get('repIntvStart')

else:
noCounts = True
else:
noCounts = True
# store the result to be accessed by the retrieve method
self.result = result
return result
Expand Down Expand Up @@ -2628,17 +2729,32 @@ def __init__(self, name, parent):

@classmethod
def _get_apic_classes(cls):
"""
Get the APIC classes used by this acitoolkit class.
:returns: list of strings containing APIC class names
"""
resp = []
resp.append('fvCEp')
resp.append('fvStCEp')
return resp

@classmethod
def _get_toolkit_to_apic_classmap(cls):
"""
Gets the APIC class to an acitoolkit class mapping dictionary
:returns: dict of APIC class names to acitoolkit classes
"""
return {}

@staticmethod
def _get_parent_class():
"""
Gets the class of the parent object
:returns: class of parent object
"""
return EPG

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/acitoolkit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from credentials import *
import sys
import time
import json

MAX_RANDOM_STRING_SIZE = 20

Expand All @@ -36,6 +37,7 @@ def random_string(size):
return ''.join(random.choice(string.ascii_uppercase +
string.digits) for _ in range(size))


def random_size_string():
"""
Generates a random string between 1 and MAX_RANDOM_STRING_SIZE
Expand Down

0 comments on commit 227a7cc

Please sign in to comment.