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
5cac2a76
Commit
5cac2a76
authored
Apr 08, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2616 from victorcoder/devel
Enable virt module to work with different libvirt connection uris.
parents
917704ee
c5c942c6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
library/virt
+17
-5
No files found.
library/virt
View file @
5cac2a76
...
...
@@ -25,7 +25,8 @@ version_added: "0.2"
options:
name:
description:
- name of the guest VM being managed
- name of the guest VM being managed. Note that VM must be previously
defined with xml.
required: true
default: null
aliases: []
...
...
@@ -44,6 +45,11 @@ options:
choices: ["create","status", "start", "stop", "pause", "unpause",
"shutdown", "undefine", "destroy", "get_xml", "autostart",
"freemem", "list_vms", "info", "nodeinfo", "virttype"]
uri:
description:
- libvirt connection uri
required: false
defaults: qemu:///
examples:
- code: "virt: name=alpha state=running"
description: "Example from Ansible Playbooks"
...
...
@@ -51,6 +57,7 @@ examples:
description: "Example guest management with C(/usr/bin/ansible)"
- code: ansible host -m virt -a "name=alpha command=get_xml"
description: "Use C(/usr/bin/ansible) to get the xml of the guest machine alpha"
- code: ansible host -m virt -a "name=alpha command=create uri=lxc:///"
requirements: [ "libvirt" ]
author: Michael DeHaan, Seth Vidal
'''
...
...
@@ -86,7 +93,7 @@ VIRT_STATE_NAME_MAP = {
class
LibvirtConnection
(
object
):
def
__init__
(
self
):
def
__init__
(
self
,
uri
):
cmd
=
subprocess
.
Popen
(
"uname -r"
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
close_fds
=
True
)
...
...
@@ -95,7 +102,7 @@ class LibvirtConnection(object):
if
output
.
find
(
"xen"
)
!=
-
1
:
conn
=
libvirt
.
open
(
None
)
else
:
conn
=
libvirt
.
open
(
"qemu:///system"
)
conn
=
libvirt
.
open
(
uri
)
if
not
conn
:
raise
Exception
(
"hypervisor connection failure"
)
...
...
@@ -192,8 +199,11 @@ class LibvirtConnection(object):
class
Virt
(
object
):
def
__init__
(
self
,
uri
):
self
.
uri
=
uri
def
__get_conn
(
self
):
self
.
conn
=
LibvirtConnection
()
self
.
conn
=
LibvirtConnection
(
self
.
uri
)
return
self
.
conn
def
get_vm
(
self
,
vmid
):
...
...
@@ -352,8 +362,9 @@ def core(module):
state
=
module
.
params
.
get
(
'state'
,
None
)
guest
=
module
.
params
.
get
(
'name'
,
None
)
command
=
module
.
params
.
get
(
'command'
,
None
)
uri
=
module
.
params
.
get
(
'uri'
,
None
)
v
=
Virt
()
v
=
Virt
(
uri
)
res
=
{}
...
...
@@ -401,6 +412,7 @@ def main():
name
=
dict
(
aliases
=
[
'guest'
]),
state
=
dict
(
choices
=
[
'running'
,
'shutdown'
]),
command
=
dict
(
choices
=
ALL_COMMANDS
),
uri
=
dict
(
default
=
'qemu:///system'
),
))
rc
=
VIRT_SUCCESS
...
...
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