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
7a6c60b4
Commit
7a6c60b4
authored
Mar 18, 2014
by
Joshua Conner
Committed by
Michael DeHaan
Mar 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docker: use type instead of manually casting strings to lists
parent
7bba2298
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
30 deletions
+16
-30
library/cloud/docker
+16
-30
No files found.
library/cloud/docker
View file @
7a6c60b4
...
...
@@ -345,7 +345,7 @@ class DockerManager:
if
self
.
module
.
params
.
get
(
'volumes'
):
self
.
binds
=
{}
self
.
volumes
=
{}
vols
=
self
.
parse_list_from_param
(
'volumes'
)
vols
=
self
.
module
.
params
.
get
(
'volumes'
)
for
vol
in
vols
:
parts
=
vol
.
split
(
":"
)
# host mount (e.g. /mnt:/tmp, bind mounts host's /tmp to /mnt in the container)
...
...
@@ -359,48 +359,32 @@ class DockerManager:
self
.
lxc_conf
=
None
if
self
.
module
.
params
.
get
(
'lxc_conf'
):
self
.
lxc_conf
=
[]
options
=
self
.
parse_list_from_param
(
'lxc_conf'
)
options
=
self
.
module
.
params
.
get
(
'lxc_conf'
)
for
option
in
options
:
parts
=
option
.
split
(
':'
)
self
.
lxc_conf
.
append
({
"Key"
:
parts
[
0
],
"Value"
:
parts
[
1
]})
self
.
exposed_ports
=
None
if
self
.
module
.
params
.
get
(
'expose'
):
expose
=
self
.
parse_list_from_param
(
'expose'
)
self
.
exposed_ports
=
self
.
get_exposed_ports
(
expose
)
self
.
exposed_ports
=
self
.
get_exposed_ports
(
self
.
module
.
params
.
get
(
'expose'
))
self
.
port_bindings
=
None
if
self
.
module
.
params
.
get
(
'ports'
):
ports
=
self
.
parse_list_from_param
(
'ports'
)
self
.
port_bindings
=
self
.
get_port_bindings
(
ports
)
self
.
port_bindings
=
self
.
get_port_bindings
(
self
.
module
.
params
.
get
(
'ports'
))
self
.
links
=
None
if
self
.
module
.
params
.
get
(
'links'
):
links
=
self
.
parse_list_from_param
(
'links'
)
self
.
links
=
dict
(
map
(
lambda
x
:
x
.
split
(
':'
),
links
))
self
.
links
=
dict
(
map
(
lambda
x
:
x
.
split
(
':'
),
self
.
module
.
params
.
get
(
'links'
)))
self
.
env
=
None
if
self
.
module
.
params
.
get
(
'env'
):
env
=
self
.
parse_list_from_param
(
'env'
)
self
.
env
=
dict
(
map
(
lambda
x
:
x
.
split
(
"="
),
env
))
self
.
env
=
dict
(
map
(
lambda
x
:
x
.
split
(
"="
),
self
.
module
.
params
.
get
(
'env'
)))
# connect to docker server
docker_url
=
urlparse
(
module
.
params
.
get
(
'docker_url'
))
self
.
client
=
docker
.
Client
(
base_url
=
docker_url
.
geturl
())
def
parse_list_from_param
(
self
,
param_name
,
delimiter
=
','
):
"""
Get a list from a module parameter, whether it's specified as a delimiter-separated string or is already in list form.
"""
param_list
=
self
.
module
.
params
.
get
(
param_name
)
if
not
isinstance
(
param_list
,
list
):
# if param_list is a number, like 3333, this will fail, so we coerce to a str first
param_list
=
str
(
param_list
)
.
split
(
delimiter
)
# whitespace in between commas will cause problems if we don't strip each param
return
[
param
.
strip
()
for
param
in
param_list
]
def
get_exposed_ports
(
self
,
expose_list
):
"""
Parse the ports and protocols (TCP/UDP) to expose in the docker-py `create_container` call from the docker CLI-style syntax.
...
...
@@ -425,7 +409,9 @@ class DockerManager:
"""
binds
=
{}
for
port
in
ports
:
parts
=
port
.
split
(
':'
)
# ports could potentially be an array like [80, 443], so we make sure they're strings
# before splitting
parts
=
str
(
port
)
.
split
(
':'
)
container_port
=
parts
[
-
1
]
if
'/'
not
in
container_port
:
container_port
=
int
(
parts
[
-
1
])
...
...
@@ -634,12 +620,12 @@ def main():
count
=
dict
(
default
=
1
),
image
=
dict
(
required
=
True
),
command
=
dict
(
required
=
False
,
default
=
None
),
expose
=
dict
(
required
=
False
,
default
=
None
),
ports
=
dict
(
required
=
False
,
default
=
None
),
expose
=
dict
(
required
=
False
,
default
=
None
,
type
=
'list'
),
ports
=
dict
(
required
=
False
,
default
=
None
,
type
=
'list'
),
publish_all_ports
=
dict
(
default
=
False
,
type
=
'bool'
),
volumes
=
dict
(
default
=
None
),
volumes
=
dict
(
default
=
None
,
type
=
'list'
),
volumes_from
=
dict
(
default
=
None
),
links
=
dict
(
default
=
None
),
links
=
dict
(
default
=
None
,
type
=
'list'
),
memory_limit
=
dict
(
default
=
0
),
memory_swap
=
dict
(
default
=
0
),
docker_url
=
dict
(
default
=
'unix://var/run/docker.sock'
),
...
...
@@ -647,16 +633,16 @@ def main():
password
=
dict
(),
email
=
dict
(),
hostname
=
dict
(
default
=
None
),
env
=
dict
(),
env
=
dict
(
type
=
'list'
),
dns
=
dict
(),
detach
=
dict
(
default
=
True
,
type
=
'bool'
),
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
,
'stopped'
,
'killed'
,
'restarted'
]),
debug
=
dict
(
default
=
False
,
type
=
'bool'
),
privileged
=
dict
(
default
=
False
,
type
=
'bool'
),
lxc_conf
=
dict
(
default
=
None
),
name
=
dict
(
default
=
None
),
stdin_open
=
dict
(
default
=
False
,
type
=
'bool'
),
tty
=
dict
(
default
=
False
,
type
=
'bool'
),
lxc_conf
=
dict
(
default
=
None
,
type
=
'list'
),
name
=
dict
(
default
=
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