Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
94db7365
Commit
94db7365
authored
Oct 03, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
__getattr__ to hide some of the attribute magic.
parent
a1751686
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
66 deletions
+78
-66
test/v2/playbook/test_task.py
+3
-3
v2/ansible/playbook/attribute.py
+4
-5
v2/ansible/playbook/base.py
+34
-17
v2/ansible/playbook/task.py
+37
-41
No files found.
test/v2/playbook/test_task.py
View file @
94db7365
...
...
@@ -31,9 +31,9 @@ class TestTask(unittest.TestCase):
def
test_can_load_simple_task
(
self
):
t
=
Task
.
load
(
basic_shell_task
)
assert
t
is
not
None
print
"
T.NAME =
%
s"
%
t
.
name
print
"
NAME=
%
s"
%
t
.
name
assert
t
.
name
==
basic_shell_task
[
'name'
]
assert
t
.
module
==
'shell'
assert
t
.
args
==
'echo hi'
#
assert t.module == 'shell'
#
assert t.args == 'echo hi'
v2/ansible/playbook/attribute.py
View file @
94db7365
...
...
@@ -18,14 +18,13 @@
#from ansible.common.errors import AnsibleError
class
Attribute
(
object
):
def
__init__
(
self
,
isa
=
None
,
validator
=
None
,
post_validator
=
None
):
def
__init__
(
self
,
isa
=
None
):
self
.
isa
=
isa
self
.
validator
=
validator
self
.
post_validator
=
post_validator
self
.
value
=
None
def
__call__
(
self
):
return
self
.
value
class
FieldAttribute
(
Attribute
):
pass
v2/ansible/playbook/base.py
View file @
94db7365
...
...
@@ -24,44 +24,61 @@ class Base(object):
def
__init__
(
self
):
self
.
_data
=
dict
()
self
.
_attributes
=
dict
()
for
name
in
self
.
__class__
.
__dict__
:
aname
=
name
[
1
:]
if
isinstance
(
aname
,
Attribute
)
and
not
isinstance
(
aname
,
FieldAttribute
):
self
.
_attributes
[
aname
]
=
None
def
load_data
(
self
,
ds
):
''' walk the input datastructure and assign any values '''
assert
ds
is
not
None
for
name
in
self
.
__class__
.
__dict__
:
print
"DEBUG: processing attribute:
%
s"
%
name
attribute
=
self
.
__class__
.
__dict__
[
name
]
for
(
name
,
attribute
)
in
self
.
__class__
.
__dict__
.
iteritems
():
aname
=
name
[
1
:]
# process Fields
if
isinstance
(
attribute
,
FieldAttribute
):
method
=
getattr
(
self
,
'_load_
%
s'
%
name
,
None
)
method
=
getattr
(
self
,
'_load_
%
s'
%
a
name
,
None
)
if
method
:
self
.
_attributes
[
name
]
=
method
(
self
,
attribute
)
self
.
_attributes
[
a
name
]
=
method
(
self
,
attribute
)
else
:
if
name
in
ds
:
self
.
_attributes
[
name
]
=
ds
[
name
]
if
a
name
in
ds
:
self
.
_attributes
[
aname
]
=
ds
[
a
name
]
# implement PluginAtrribute which allows "with_" and "action" aliases.
#
TODO:
implement PluginAtrribute which allows "with_" and "action" aliases.
return
self
def
attribute_value
(
self
,
name
):
return
self
.
_attributes
[
name
]
def
validate
(
self
):
# TODO: finish
for
name
in
self
.
__dict__
:
attribute
=
self
.
__dict__
[
name
]
aname
=
name
[
1
:]
attribute
=
self
.
__dict__
[
aname
]
if
instanceof
(
attribute
,
FieldAttribute
):
method
=
getattr
(
self
,
'_validate_
%
s'
%
(
prefix
,
name
),
None
)
method
=
getattr
(
self
,
'_validate_
%
s'
%
(
prefix
,
a
name
),
None
)
if
method
:
method
(
self
,
attribute
)
def
post_validate
(
self
,
runner_context
):
# TODO: finish
raise
exception
.
NotImplementedError
# TODO: __getattr__ that looks inside _attributes
def
__getattr__
(
self
,
needle
):
if
needle
in
self
.
_attributes
:
return
self
.
_attributes
[
needle
]
if
needle
in
self
.
__dict__
:
return
self
.
__dict__
[
needle
]
raise
AttributeError
#def __setattr__(self, needle, value):
# if needle in self._attributes:
# self._attributes[needle] = value
# if needle in self.__dict__:
# super(Base, self).__setattr__(needle, value)
# # self.__dict__[needle] = value
# raise AttributeError
v2/ansible/playbook/task.py
View file @
94db7365
...
...
@@ -43,45 +43,45 @@ class Task(Base):
# will be used if defined
# might be possible to define others
action
=
FieldAttribute
(
isa
=
'string'
)
always_run
=
FieldAttribute
(
isa
=
'bool'
)
any_errors_fatal
=
FieldAttribute
(
isa
=
'bool'
)
async
=
FieldAttribute
(
isa
=
'int'
)
connection
=
FieldAttribute
(
isa
=
'string'
)
delay
=
FieldAttribute
(
isa
=
'int'
)
delegate_to
=
FieldAttribute
(
isa
=
'string'
)
environment
=
FieldAttribute
(
isa
=
'dict'
)
first_available_file
=
FieldAttribute
(
isa
=
'list'
)
ignore_errors
=
FieldAttribute
(
isa
=
'bool'
)
_
action
=
FieldAttribute
(
isa
=
'string'
)
_
always_run
=
FieldAttribute
(
isa
=
'bool'
)
_
any_errors_fatal
=
FieldAttribute
(
isa
=
'bool'
)
_
async
=
FieldAttribute
(
isa
=
'int'
)
_
connection
=
FieldAttribute
(
isa
=
'string'
)
_
delay
=
FieldAttribute
(
isa
=
'int'
)
_
delegate_to
=
FieldAttribute
(
isa
=
'string'
)
_
environment
=
FieldAttribute
(
isa
=
'dict'
)
_
first_available_file
=
FieldAttribute
(
isa
=
'list'
)
_
ignore_errors
=
FieldAttribute
(
isa
=
'bool'
)
# FIXME: this should not be a Task
# include = FieldAttribute(isa='string')
local_action
=
FieldAttribute
(
isa
=
'string'
)
_
local_action
=
FieldAttribute
(
isa
=
'string'
)
# FIXME: this should not be a Task
meta
=
FieldAttribute
(
isa
=
'string'
)
name
=
FieldAttribute
(
isa
=
'string'
)
no_log
=
FieldAttribute
(
isa
=
'bool'
)
notify
=
FieldAttribute
(
isa
=
'list'
)
poll
=
FieldAttribute
(
isa
=
'integer'
)
register
=
FieldAttribute
(
isa
=
'string'
)
remote_user
=
FieldAttribute
(
isa
=
'string'
)
retries
=
FieldAttribute
(
isa
=
'integer'
)
run_once
=
FieldAttribute
(
isa
=
'bool'
)
su
=
FieldAttribute
(
isa
=
'bool'
)
su_pass
=
FieldAttribute
(
isa
=
'string'
)
su_user
=
FieldAttribute
(
isa
=
'string'
)
sudo
=
FieldAttribute
(
isa
=
'bool'
)
sudo_user
=
FieldAttribute
(
isa
=
'string'
)
sudo_pass
=
FieldAttribute
(
isa
=
'string'
)
transport
=
FieldAttribute
(
isa
=
'string'
)
until
=
FieldAttribute
(
isa
=
'list'
)
# ?
role
=
Attribute
()
block
=
Attribute
()
_
meta
=
FieldAttribute
(
isa
=
'string'
)
_
name
=
FieldAttribute
(
isa
=
'string'
)
_
no_log
=
FieldAttribute
(
isa
=
'bool'
)
_
notify
=
FieldAttribute
(
isa
=
'list'
)
_
poll
=
FieldAttribute
(
isa
=
'integer'
)
_
register
=
FieldAttribute
(
isa
=
'string'
)
_
remote_user
=
FieldAttribute
(
isa
=
'string'
)
_
retries
=
FieldAttribute
(
isa
=
'integer'
)
_
run_once
=
FieldAttribute
(
isa
=
'bool'
)
_
su
=
FieldAttribute
(
isa
=
'bool'
)
_
su_pass
=
FieldAttribute
(
isa
=
'string'
)
_
su_user
=
FieldAttribute
(
isa
=
'string'
)
_
sudo
=
FieldAttribute
(
isa
=
'bool'
)
_
sudo_user
=
FieldAttribute
(
isa
=
'string'
)
_
sudo_pass
=
FieldAttribute
(
isa
=
'string'
)
_
transport
=
FieldAttribute
(
isa
=
'string'
)
_
until
=
FieldAttribute
(
isa
=
'list'
)
# ?
_
role
=
Attribute
()
_
block
=
Attribute
()
def
__init__
(
self
,
block
=
None
,
role
=
None
):
''' constructors a task, without the Task.load classmethod, it will be pretty blank '''
...
...
@@ -92,17 +92,13 @@ class Task(Base):
def
get_name
(
self
):
''' return the name of the task '''
# FIXME: getattr magic in baseclass so this is not required:
original
=
self
.
attribute_value
(
'name'
)
role_value
=
self
.
attribute_value
(
'role'
)
if
role_value
:
return
"
%
s :
%
s"
%
(
role_value
.
get_name
(),
original
)
if
self
.
role
:
return
"
%
s :
%
s"
%
(
self
.
role
.
get_name
(),
self
.
name
)
else
:
return
original
return
self
.
name
@staticmethod
def
load
(
data
,
block
=
block
,
role
=
rol
e
):
def
load
(
data
,
block
=
None
,
role
=
Non
e
):
t
=
Task
(
block
=
block
,
role
=
role
)
return
t
.
load_data
(
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment