Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
jiffybox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansible
Plugins
jiffybox
Commits
dda36d95
Commit
dda36d95
authored
7 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
New option "group" which can be used instead of "target" to move to any host within the same group
parent
2637c4e9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
action_plugins/jiffybox.py
+24
-8
24 additions, 8 deletions
action_plugins/jiffybox.py
with
24 additions
and
8 deletions
action_plugins/jiffybox.py
+
24
−
8
View file @
dda36d95
import
json
import
json
import
requests
from
ansible.errors
import
AnsibleError
as
ae
from
ansible.errors
import
AnsibleError
as
ae
from
ansible.plugins.action
import
ActionBase
from
ansible.plugins.action
import
ActionBase
import
requests
try
:
try
:
from
__main__
import
display
from
__main__
import
display
except
ImportError
:
except
ImportError
:
...
@@ -131,6 +132,12 @@ class ActionModule(ActionBase):
...
@@ -131,6 +132,12 @@ class ActionModule(ActionBase):
return
self
.
devices
[
block
]
return
self
.
devices
[
block
]
return
False
return
False
def
find_host_in_group
(
self
,
group
,
excluded
):
for
name
in
group
:
if
name
!=
excluded
:
return
self
.
find_host
(
name
)
return
False
def
find_ip
(
self
,
address
):
def
find_ip
(
self
,
address
):
self
.
load_ips
()
self
.
load_ips
()
for
block
in
self
.
ips
:
for
block
in
self
.
ips
:
...
@@ -194,12 +201,15 @@ class ActionModule(ActionBase):
...
@@ -194,12 +201,15 @@ class ActionModule(ActionBase):
def
move_ip
(
self
):
def
move_ip
(
self
):
display
.
vv
(
"
Moving IP ...
"
)
display
.
vv
(
"
Moving IP ...
"
)
target
=
self
.
_task
.
args
.
get
(
'
target
'
,
False
)
target
=
self
.
_task
.
args
.
get
(
'
target
'
,
False
)
if
not
target
:
group
=
self
.
_task
.
args
.
get
(
'
group
'
,
False
)
if
not
target
and
not
group
:
raise
ae
(
"'
target
'
is a required argument.
"
)
raise
ae
(
"'
target
'
is a required argument.
"
)
targethost
=
self
.
find_host
(
target
)
if
target
:
if
not
targethost
:
targethost
=
self
.
find_host
(
target
)
raise
ae
(
"
Target host %s unknown in this JiffyBox account.
"
%
target
)
if
not
targethost
:
display
.
vv
(
"
- target host: %s
"
%
target
)
raise
ae
(
"
Target host %s unknown in this JiffyBox account.
"
%
target
)
else
:
targethost
=
False
ips
=
self
.
find_floating_ip
()
ips
=
self
.
find_floating_ip
()
for
ip
in
ips
:
for
ip
in
ips
:
...
@@ -213,8 +223,14 @@ class ActionModule(ActionBase):
...
@@ -213,8 +223,14 @@ class ActionModule(ActionBase):
else
:
else
:
display
.
vv
(
"
- source host: %s
"
%
sourcehost
.
get
(
'
name
'
))
display
.
vv
(
"
- source host: %s
"
%
sourcehost
.
get
(
'
name
'
))
if
sourcehost
.
get
(
'
id
'
)
==
targethost
.
get
(
'
id
'
):
if
not
target
:
targethost
=
self
.
find_host_in_group
(
group
,
sourcehost
.
get
(
'
name
'
))
if
not
targethost
:
pass
elif
sourcehost
.
get
(
'
id
'
)
==
targethost
.
get
(
'
id
'
):
display
.
vv
(
'
- cancelled as source and target are the same
'
)
display
.
vv
(
'
- cancelled as source and target are the same
'
)
else
:
else
:
display
.
vv
(
"
- target host: %s
"
%
targethost
.
get
(
'
name
'
))
path
=
'
ips/
'
+
str
(
sourcehost
.
get
(
'
id
'
))
+
'
/
'
+
str
(
ip
.
get
(
'
id
'
))
+
'
/move
'
path
=
'
ips/
'
+
str
(
sourcehost
.
get
(
'
id
'
))
+
'
/
'
+
str
(
ip
.
get
(
'
id
'
))
+
'
/move
'
self
.
_request
(
path
,
{
'
targetid
'
:
targethost
.
get
(
'
id
'
)})
self
.
_request
(
path
,
{
'
targetid
'
:
targethost
.
get
(
'
id
'
)})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment