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
8a617942
Commit
8a617942
authored
Apr 04, 2012
by
Seth Vidal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add idempotent and ='s separated parameters to virt module to make people happy
parent
415f4baa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
31 deletions
+43
-31
library/virt
+43
-31
No files found.
library/virt
View file @
8a617942
...
@@ -353,16 +353,11 @@ def main():
...
@@ -353,16 +353,11 @@ def main():
'shutdown'
,
'undefine'
,
'destroy'
,
'get_xml'
,
'autostart'
]
'shutdown'
,
'undefine'
,
'destroy'
,
'get_xml'
,
'autostart'
]
host_commands
=
[
'freemem'
,
'list_vms'
,
'info'
,
'nodeinfo'
,
'virttype'
]
host_commands
=
[
'freemem'
,
'list_vms'
,
'info'
,
'nodeinfo'
,
'virttype'
]
msg
=
"""
msg
=
"""
virtmodule arguments:
virtmodule arguments:
- queryvm guest <queryable item from libvirt domain api> <more of those>
state=[running|shutdown] guest=guestname
- guest commands: (all require a single guest name an argument)
command=some_virt_command [guest=guestname]
%
s
"""
- host commands:
%
s
"""
%
(
', '
.
join
(
sorted
(
vm_commands
)),
', '
.
join
(
sorted
(
host_commands
)))
if
len
(
sys
.
argv
)
==
1
:
if
len
(
sys
.
argv
)
==
1
:
return
VIRT_FAILED
,
msg
return
VIRT_FAILED
,
msg
...
@@ -378,38 +373,55 @@ def main():
...
@@ -378,38 +373,55 @@ def main():
if
not
len
(
items
):
if
not
len
(
items
):
return
VIRT_FAILED
,
msg
return
VIRT_FAILED
,
msg
basecmd
=
items
[
0
]
v
=
Virt
()
if
basecmd
in
(
'queryvm'
):
# vm=name state=[running|shutdown|destroyed|undefined]
if
len
(
items
)
<
3
:
# command=[some command] [vm=name]
msg
=
"queryvm requires at least 2 arguments: guest itemname [itemname]"
return
VIRT_FAILED
,
msg
params
=
{}
for
x
in
items
:
(
k
,
v
)
=
x
.
split
(
"="
)
params
[
k
]
=
v
guest
=
items
[
1
]
state
=
params
.
get
(
'state'
,
None
)
reqs
=
items
[
2
:]
guest
=
params
.
get
(
'guest'
,
None
)
command
=
params
.
get
(
'command'
,
None
)
options
=
params
.
get
(
'options'
,
[])
v
=
Virt
()
res
=
{}
res
=
{}
for
req
in
reqs
:
vm
=
v
.
get_vm
(
guest
)
if
hasattr
(
vm
,
req
):
data
=
getattr
(
vm
,
req
)()
res
[
req
]
=
data
return
rc
,
res
# any methods that require the guest/vmid as the argument must be listed here
if
state
:
elif
basecmd
in
vm_commands
:
if
not
guest
:
if
len
(
items
)
<
2
:
msg
=
"state change requires a guest specified"
msg
=
"
%
s requires 1 argument: guest"
%
basecmd
return
VIRT_FAILED
,
msg
return
VIRT_FAILED
,
msg
guest
=
items
[
1
]
res
[
'changed'
]
=
False
res
=
getattr
(
v
,
basecmd
)(
guest
)
if
state
==
'running'
:
if
v
.
status
(
guest
)
is
not
'running'
:
res
[
'changed'
]
=
True
res
[
'msg'
]
=
v
.
start
(
guest
)
elif
state
==
'shutdown'
:
if
v
.
status
(
guest
)
is
not
'shutdown'
:
res
[
'changed'
]
=
True
res
[
'msg'
]
=
v
.
shutdown
(
guest
)
return
VIRT_SUCCESS
,
res
if
command
:
if
command
in
vm_commands
:
if
not
guest
:
msg
=
"
%
s requires 1 argument: guest"
%
command
return
VIRT_FAILED
,
msg
res
=
getattr
(
v
,
command
)(
guest
)
if
type
(
res
)
!=
dict
:
if
type
(
res
)
!=
dict
:
res
=
{
basecm
d
:
res
}
res
=
{
comman
d
:
res
}
return
rc
,
res
return
rc
,
res
elif
hasattr
(
v
,
basecmd
):
elif
hasattr
(
v
,
command
):
res
=
getattr
(
v
,
basecmd
)()
res
=
getattr
(
v
,
command
)()
if
type
(
res
)
!=
dict
:
res
=
{
command
:
res
}
return
rc
,
res
return
rc
,
res
else
:
else
:
...
...
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