Skip to content

Commit

Permalink
Merge pull request CiscoUcs#44 from vvb/misc_fix
Browse files Browse the repository at this point in the history
pep8 fixes
  • Loading branch information
vvb committed May 23, 2016
2 parents 6012f09 + c673d90 commit 671add1
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 107 deletions.
12 changes: 6 additions & 6 deletions ucsmsdk/ucscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def __init__(self, class_id, tag_name=None):
def to_xml(self, xml_doc=None, option=None, elem_name=None):
"""This method writes the xml representation of the Method object."""
xml_obj = self.elem_create(class_tag=self._tag_name,
xml_doc=xml_doc,
override_tag=elem_name)
xml_doc=xml_doc,
override_tag=elem_name)
for key in self.__dict__:
if key.startswith("_"):
continue
Expand All @@ -170,8 +170,8 @@ def __init__(self, class_id, tag_name=None):
def to_xml(self, xml_doc=None, option=None, elem_name=None):
"""This method writes the xml representation of the Method object."""
xml_obj = self.elem_create(class_tag=self._tag_name,
xml_doc=xml_doc,
override_tag=elem_name)
xml_doc=xml_doc,
override_tag=elem_name)
for key in self.__dict__:
if key.startswith("_"):
continue
Expand All @@ -188,8 +188,8 @@ def from_xml(self, elem, handle=None):
self._handle = handle
if elem.attrib:
for attr_name, attr_value in ucsgenutils.iteritems(elem.attrib):
self.attr_set(ucsgenutils.convert_to_python_var_name(attr_name)
, str(attr_value))
self.attr_set(ucsgenutils.convert_to_python_var_name(
attr_name), str(attr_value))

child_elems = elem.getchildren()
if child_elems:
Expand Down
13 changes: 7 additions & 6 deletions ucsmsdk/ucscoreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def get_ucs_obj(class_id, elem, mo_obj=None):
if 'topRoot' in mo_class.mo_meta.parents:
mo_obj = mo_class(from_xml_response=True, **mo_class_param_dict)
else:
mo_obj = mo_class(parent_mo_or_dn=p_dn, from_xml_response=True, **mo_class_param_dict)
mo_obj = mo_class(parent_mo_or_dn=p_dn,
from_xml_response=True, **mo_class_param_dict)
return mo_obj
elif class_id in OTHER_TYPE_CLASS_ID:
module_ = load_module(class_id)
Expand All @@ -85,7 +86,8 @@ def get_ucs_obj(class_id, elem, mo_obj=None):
elif mo_obj:
p_dn = mo_obj.dn

mo_obj = ucsmo.GenericMo(class_id=elem.tag, parent_mo_or_dn=p_dn, **elem.attrib)
mo_obj = ucsmo.GenericMo(
class_id=elem.tag, parent_mo_or_dn=p_dn, **elem.attrib)
return mo_obj


Expand Down Expand Up @@ -379,7 +381,6 @@ def write_mo_tree(mo, level=0, break_level=None, show_level=[],
return tree_dict



def extract_mo_tree_from_config_method_response(method_response,
break_level=None,
show_level=[],
Expand Down Expand Up @@ -508,7 +509,7 @@ def __str__(self):
out_str = "\n"
out_str += str("ClassId").ljust(ts * 4) + str(self.class_id) + "\n"
out_str += ("-" * len("ClassId")).ljust(ts * 4) + "-" * len(
self.class_id)+"\n"
self.class_id) + "\n"
out_str += str("xml_attribute").ljust(ts * 4) + ':' + str(
self.xml_attribute) + "\n"
out_str += str("rn").ljust(ts * 4) + ':' + str(
Expand Down Expand Up @@ -558,7 +559,7 @@ def _show_tree(class_id, break_level=None, level=0, ancestor_str="",
_show_tree(child, break_level, level, ancestor_str_, ancestor,
total == count)

ancestor.pop(index-1)
ancestor.pop(index - 1)


def search_class_id(class_id):
Expand Down Expand Up @@ -591,7 +592,7 @@ def search_class_id(class_id):
log.info('"%s" did not match any available Class Ids.\n'
'Related Class Ids are:\n%s\n%s' %
(class_id,
"-"*len("Related Class Ids are:"),
"-" * len("Related Class Ids are:"),
"\n".join(class_ids)))
else:
log.info('"%s" did not match any available Class Ids.' % class_id)
Expand Down
1 change: 1 addition & 0 deletions ucsmsdk/ucsexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

log = logging.getLogger('ucs')


def UcsWarning(warn_str):
"""
Method to throw warnings.
Expand Down
11 changes: 9 additions & 2 deletions ucsmsdk/ucsfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ def parse_filter_obj(sstr, loc, toks):
# print prop_, value_, type_, flag_ #logger

if flag_ == "I":
value_ = re.sub(r"[a-zA-Z]", lambda x: "[" + x.group().upper() + x.group().lower() + "]", value_)
value_ = re.sub(
r"[a-zA-Z]",
lambda x: "[" +
x.group().upper() +
x.group().lower() +
"]",
value_)

if ParseFilter.is_meta_classid:
class_obj = ucscoreutils.load_class(ParseFilter.class_id)
Expand Down Expand Up @@ -116,7 +122,8 @@ def not_operator(str_, loc, toks):
return not_filter


prop = pp.WordStart(pp.alphas) + pp.Word(pp.alphanums+"_").setResultsName("prop")
prop = pp.WordStart(pp.alphas) + pp.Word(pp.alphanums +
"_").setResultsName("prop")
value = (pp.QuotedString("'") | pp.QuotedString('"') | pp.Word(
pp.printables, excludeChars=",")).setResultsName("value")
types_ = pp.oneOf("re eq ne gt ge lt le").setResultsName("types")
Expand Down
32 changes: 16 additions & 16 deletions ucsmsdk/ucshandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def query_dns(self, *dns):
dn_set.child_add(dn_obj)

elem = config_resolve_dns(cookie=self.cookie,
in_dns=dn_set)
in_dns=dn_set)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code, response.error_descr)
Expand Down Expand Up @@ -269,7 +269,7 @@ def query_classids(self, *class_ids):
class_id_set.child_add(class_id_obj)

elem = config_resolve_classes(cookie=self.cookie,
in_ids=class_id_set)
in_ids=class_id_set)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code, response.error_descr)
Expand Down Expand Up @@ -315,8 +315,8 @@ def query_dn(self, dn, hierarchy=False, need_response=False):
dn_set.child_add(dn_obj)

elem = config_resolve_dns(cookie=self.cookie,
in_dns=dn_set,
in_hierarchical=hierarchy)
in_dns=dn_set,
in_hierarchical=hierarchy)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code, response.error_descr)
Expand Down Expand Up @@ -387,7 +387,7 @@ def query_classid(self, class_id=None, filter_str=None, hierarchy=False,
raise ValueError("Provide Parameter class_id")

meta_class_id = ucscoreutils.find_class_id_in_mo_meta_ignore_case(
class_id)
class_id)
if meta_class_id:
is_meta_class_id = True
else:
Expand All @@ -401,9 +401,9 @@ def query_classid(self, class_id=None, filter_str=None, hierarchy=False,
in_filter = None

elem = config_resolve_class(cookie=self.cookie,
class_id=meta_class_id,
in_filter=in_filter,
in_hierarchical=hierarchy)
class_id=meta_class_id,
in_filter=in_filter,
in_hierarchical=hierarchy)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code, response.error_descr)
Expand All @@ -412,8 +412,8 @@ def query_classid(self, class_id=None, filter_str=None, hierarchy=False,
return response

out_mo_list = ucscoreutils.extract_molist_from_method_response(
response,
hierarchy)
response,
hierarchy)
return out_mo_list

def query_children(self, in_mo=None, in_dn=None, class_id=None,
Expand Down Expand Up @@ -488,7 +488,7 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,

if class_id:
meta_class_id = ucscoreutils.find_class_id_in_mo_meta_ignore_case(
class_id)
class_id)
if meta_class_id:
is_meta_class_id = True
else:
Expand All @@ -511,8 +511,8 @@ def query_children(self, in_mo=None, in_dn=None, class_id=None,
raise UcsException(response.error_code, response.error_descr)

out_mo_list = ucscoreutils.extract_molist_from_method_response(
response,
hierarchy)
response,
hierarchy)

return out_mo_list

Expand Down Expand Up @@ -636,7 +636,7 @@ def commit(self):
config_map.child_add(pair)

elem = config_conf_mos(self.cookie, config_map,
False)
False)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code, response.error_descr)
Expand All @@ -653,11 +653,11 @@ def commit(self):
dn_set.child_add(dn_obj)

elem = config_resolve_dns(cookie=self.cookie,
in_dns=dn_set)
in_dns=dn_set)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code,
response.error_descr)
response.error_descr)

for out_mo in response.out_configs.child:
out_mo.sync_mo(refresh_dict[out_mo.dn])
Expand Down
13 changes: 7 additions & 6 deletions ucsmsdk/ucsmethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"""

from __future__ import absolute_import
from .ucscore import UcsBase
from . import ucscoreutils
from . import ucsgenutils


try:
import xml.etree.cElementTree as ET
Expand All @@ -29,10 +33,6 @@
log = logging.getLogger('ucs')


from .ucscore import UcsBase
from . import ucscoreutils
from . import ucsgenutils

class ExternalMethod(UcsBase):
"""
This class represents the UCS Central Xml api's query/configuration
Expand Down Expand Up @@ -120,10 +120,11 @@ def to_xml(self, xml_doc=None, option=None, elem_name=None):
self.child_to_xml(xml_obj, option)
return xml_obj

def from_xml(self, elem, handle=None): # , handle, modify_self=False, mo=None):
# , handle, modify_self=False, mo=None):
def from_xml(self, elem, handle=None):
"""Method updates/fills the object from the xml representation
of the external method object. """

self._handle = handle
if elem.attrib:
for attr_name, attr_value in ucsgenutils.iteritems(elem.attrib):
Expand Down
25 changes: 16 additions & 9 deletions ucsmsdk/ucsmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class _GenericProp():
"""
Internal class to handle the unknown property.
"""

def __init__(self, name, value, is_dirty):
self.name = name
self.value = value
Expand All @@ -57,7 +58,12 @@ class ManagedObject(UcsBase):
__internal_prop = frozenset(
["_dirty_mask", "_class_id", "_child", "_handle", ''])

def __init__(self, class_id, parent_mo_or_dn=None, from_xml_response=False, **kwargs):
def __init__(
self,
class_id,
parent_mo_or_dn=None,
from_xml_response=False,
**kwargs):
self.__parent_mo = None
self.__status = None
self.__parent_dn = None
Expand Down Expand Up @@ -107,7 +113,6 @@ def _rn_set(self):
else:
self.rn = ""


def _dn_set(self):
"""
Internal method to set dn
Expand Down Expand Up @@ -171,8 +176,8 @@ def __set_prop(self, name, value, mark_dirty=True, forced=False):
prop_meta = self.prop_meta[name]
if prop_meta.access != ucscoremeta.MoPropertyMeta.READ_WRITE:
if getattr(self, name) is not None or \
prop_meta.access != \
ucscoremeta.MoPropertyMeta.CREATE_ONLY:
prop_meta.access != \
ucscoremeta.MoPropertyMeta.CREATE_ONLY:
raise ValueError("%s is not a read-write property." % name)
if not prop_meta.validate_property_value(value):
raise ValueError("Invalid Value Exception - "
Expand Down Expand Up @@ -296,8 +301,8 @@ def to_xml(self, xml_doc=None, option=None, elem_name=None):
if key != 'rn' and key in self.prop_meta:
mo_prop_meta = self.prop_meta[key]
if (option != WriteXmlOption.DIRTY or (
mo_prop_meta.mask is not None and
self._dirty_mask & mo_prop_meta.mask != 0)):
mo_prop_meta.mask is not None and
self._dirty_mask & mo_prop_meta.mask != 0)):
value = getattr(self, key)
if value is not None:
xml_obj.set(mo_prop_meta.xml_attribute, value)
Expand Down Expand Up @@ -332,7 +337,8 @@ def from_xml(self, elem, handle=None):
self._handle = handle
if elem.attrib:
if self.__class__.__name__ != "ManagedObject":
for attr_name, attr_value in ucsgenutils.iteritems(elem.attrib):
for attr_name, attr_value in ucsgenutils.iteritems(
elem.attrib):
if attr_name in self.prop_map:
attr_name = self.prop_map[attr_name]
else:
Expand All @@ -342,7 +348,8 @@ def from_xml(self, elem, handle=None):
False)
object.__setattr__(self, attr_name, attr_value)
else:
for attr_name, attr_value in ucsgenutils.iteritems(elem.attrib):
for attr_name, attr_value in ucsgenutils.iteritems(
elem.attrib):
object.__setattr__(self, attr_name, attr_value)

if hasattr(self, 'rn') and not hasattr(self, 'dn'):
Expand All @@ -358,7 +365,7 @@ def from_xml(self, elem, handle=None):
continue

if self.__class__.__name__ != "ManagedObject" and (
child_elem.tag in self.mo_meta.field_names):
child_elem.tag in self.mo_meta.field_names):
pass

class_id = ucsgenutils.word_u(child_elem.tag)
Expand Down
10 changes: 5 additions & 5 deletions ucsmsdk/ucssession.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ def _refresh(self, auto_relogin=False):
self.__stop_refresh_timer()

elem = aaa_refresh(self.__cookie,
self.__username,
self.__password)
self.__username,
self.__password)
response = self.post_elem(elem)
if response.error_code != 0:
self.__cookie = None
Expand Down Expand Up @@ -428,7 +428,7 @@ def __validate_connection(self):
if not self.__force:
top_system = TopSystem()
elem = config_resolve_dn(cookie=self.__cookie,
dn=top_system.dn)
dn=top_system.dn)
response = self.post_elem(elem)
if response.error_code != 0:
return False
Expand Down Expand Up @@ -464,7 +464,7 @@ def _login(self, auto_refresh=False, force=False):
return True

elem = aaa_login(in_name=self.__username,
in_password=self.__password)
in_password=self.__password)
response = self.post_elem(elem)
if response.error_code != 0:
self.__clear()
Expand All @@ -480,7 +480,7 @@ def _login(self, auto_refresh=False, force=False):
firmware = FirmwareRunning(top_system,
FirmwareRunningConsts.DEPLOYMENT_SYSTEM)
elem = config_resolve_dn(cookie=self.__cookie,
dn=firmware.dn)
dn=firmware.dn)
response = self.post_elem(elem)
if response.error_code != 0:
raise UcsException(response.error_code,
Expand Down
1 change: 1 addition & 0 deletions ucsmsdk/utils/ccoimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

log = logging.getLogger('ucs')


class _UcsCcoImageList:
"""enum for cco image attributes"""
IDAC_TAG_VERSION = "version"
Expand Down
Loading

0 comments on commit 671add1

Please sign in to comment.