Commit ff87ac08 by Michael DeHaan

An attempt at modularization prior to moving things towards BaseObject and considering Attributes.

parent cae88ca1
Subproject commit db5668b84c3a19498b843d0bfe34574aef40c193 Subproject commit 9b35a391213fe87834af5ebc907109de2bc0005f
...@@ -21,43 +21,5 @@ from playbook.tag import Tag ...@@ -21,43 +21,5 @@ from playbook.tag import Tag
class Base(object): class Base(object):
def __init__(self): def __init__(self):
self._tags = Tag() pass
def _ensure_int(self, attr, default=0):
value = getattr(self, attr)
if value is None:
setattr(self, attr, default)
elif not isinstance(value, int):
try:
setattr(self, attr, int(value))
except ValueError:
raise AnsibleError("failed to set attr %s to an integer, got '%s' which is a %s" % (attr, value, type(value)))
def _ensure_bool(self, attr, default=False):
value = getattr(self, attr)
if value is None:
setattr(self, attr, default)
elif not isinstance(value, bool):
setattr(self, attr, utils.boolean(value))
def _ensure_basestring(self, attr, default=""):
value = getattr(self, attr)
if value is None:
setattr(self, attr, default)
elif not isinstance(value, basestring):
setattr(self, attr, "%s" % value)
def _ensure_list_of_strings(self, attr, default=[]):
value = getattr(self, attr)
if value is None:
setattr(self, attr, default)
elif not isinstance(value, list):
setattr(self, attr, [ str(value) ])
else:
changed = False
for idx,val in enumerate(value):
if not isinstance(val, basestring):
value[idx] = str(val)
changed = True
if changed:
setattr(self, attr, value)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment