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
d97b38ba
Commit
d97b38ba
authored
Oct 06, 2014
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attribute defaults and optional accessors.
parent
e66a0096
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
12 deletions
+49
-12
test/v2/playbook/test_task.py
+15
-0
v2/ansible/playbook/attribute.py
+4
-1
v2/ansible/playbook/base.py
+13
-5
v2/ansible/playbook/task.py
+17
-6
No files found.
test/v2/playbook/test_task.py
View file @
d97b38ba
...
...
@@ -8,6 +8,10 @@ basic_shell_task = dict(
shell
=
'echo hi'
)
kv_shell_task
=
dict
(
action
=
'shell echo hi'
)
class
TestTask
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -36,6 +40,17 @@ class TestTask(unittest.TestCase):
assert
t
.
args
==
'echo hi'
def
test_can_load_action_kv_form
(
self
):
t
=
Task
.
load
(
kv_shell_task
)
assert
t
.
action
==
'shell'
assert
t
.
args
==
'echo hi'
def
test_can_auto_name
(
self
):
assert
'name'
not
in
kv_shell_task
t
=
Task
.
load
(
kv_shell_task
)
print
"GOT NAME=(
%
s)"
%
t
.
name
assert
t
.
name
==
'shell echo hi'
def
test_can_auto_name_with_role
(
self
):
pass
def
test_can_load_action_complex_form
(
self
):
...
...
v2/ansible/playbook/attribute.py
View file @
d97b38ba
...
...
@@ -18,10 +18,13 @@
#from ansible.common.errors import AnsibleError
class
Attribute
(
object
):
def
__init__
(
self
,
isa
=
None
,
private
=
False
):
def
__init__
(
self
,
isa
=
None
,
private
=
False
,
default
=
None
):
self
.
isa
=
isa
self
.
private
=
private
self
.
value
=
None
self
.
default
=
default
def
__call__
(
self
):
return
self
.
value
...
...
v2/ansible/playbook/base.py
View file @
d97b38ba
...
...
@@ -23,10 +23,11 @@ class Base(object):
# each class knows attributes set upon it, see Task.py for example
self
.
_attributes
=
dict
()
for
name
in
self
.
__class__
.
__dict__
:
for
(
name
,
value
)
in
self
.
__class__
.
__dict__
.
iteritems
():
aname
=
name
[
1
:]
if
isinstance
(
aname
,
Attribute
)
and
not
isinstance
(
aname
,
Field
Attribute
):
self
.
_attributes
[
aname
]
=
None
if
isinstance
(
value
,
Attribute
):
self
.
_attributes
[
aname
]
=
value
.
default
def
munge
(
self
,
ds
):
''' infrequently used method to do some pre-processing of legacy terms '''
...
...
@@ -94,9 +95,16 @@ class Base(object):
def
__getattr__
(
self
,
needle
):
# return any attribute names as if they were real.
# access them like obj.attrname()
# return any attribute names as if they were real
# optionally allowing masking by accessors
if
not
needle
.
startswith
(
"_"
):
method
=
"get_
%
s"
%
needle
if
method
in
self
.
__dict__
:
return
method
(
self
)
if
needle
in
self
.
_attributes
:
return
self
.
_attributes
[
needle
]
raise
AttributeError
(
"attribute not found:
%
s"
%
needle
)
v2/ansible/playbook/task.py
View file @
d97b38ba
...
...
@@ -87,9 +87,6 @@ class Task(Base):
_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 '''
self
.
_block
=
block
...
...
@@ -99,10 +96,24 @@ class Task(Base):
def
get_name
(
self
):
''' return the name of the task '''
if
self
.
rol
e
:
return
"
%
s :
%
s"
%
(
self
.
role
.
get_name
()
,
self
.
name
)
el
s
e
:
if
self
.
_role
and
self
.
nam
e
:
return
"
%
s :
%
s"
%
(
self
.
_role
.
name
,
self
.
name
)
el
if
self
.
nam
e
:
return
self
.
name
else
:
return
"
%
s
%
s"
%
(
self
.
action
,
self
.
_merge_kv
(
self
.
args
))
def
_merge_kv
(
self
,
ds
):
if
ds
is
None
:
return
""
elif
isinstance
(
ds
,
basestring
):
return
ds
elif
instance
(
ds
,
dict
):
buf
=
""
for
(
k
,
v
)
in
ds
.
iteritems
():
buf
=
buf
+
"
%
s=
%
s "
%
(
k
,
v
)
buf
=
buf
.
strip
()
return
buf
@staticmethod
def
load
(
data
,
block
=
None
,
role
=
None
):
...
...
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