Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
222962dc
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
222962dc
编写于
6月 03, 2014
作者:
R
Rudá Moura
提交者:
Rudá Moura
6月 03, 2014
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #83 from ruda/master
avocado.utils.virt: Improve implementation.
上级
1d4bd66d
1c20abbb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
98 addition
and
20 deletion
+98
-20
avocado/utils/virt.py
avocado/utils/virt.py
+98
-20
未找到文件。
avocado/utils/virt.py
浏览文件 @
222962dc
...
...
@@ -13,7 +13,7 @@
# Author: Ruda Moura <rmoura@redhat.com>
"""
Module to provide classes for
virtualization
.
Module to provide classes for
Virtual Machines
.
"""
import
libvirt
...
...
@@ -37,14 +37,19 @@ class Hypervisor(object):
self
.
uri
=
uri
self
.
connection
=
None
self
.
connected
=
False
self
.
domains
=
[]
def
__str__
(
self
):
return
"%s(%s)"
%
(
self
.
__class__
.
__name__
,
self
.
uri
)
def
_get_domains
(
self
):
self
.
domains
=
self
.
connection
.
listAllDomains
()
@
property
def
domains
(
self
):
"""
Property to get the list of all domains.
:return: a list of instances of :class:`libvirt.virDomain`.
"""
return
self
.
connection
.
listAllDomains
()
def
connect
(
self
):
"""
...
...
@@ -58,7 +63,6 @@ class Hypervisor(object):
return
None
else
:
self
.
connected
=
True
self
.
_get_domains
()
return
self
.
connection
def
find_domain_by_name
(
self
,
name
):
...
...
@@ -68,15 +72,15 @@ class Hypervisor(object):
:param domain: the domain name.
:return: an instance of :class:`libvirt.virDomain`.
"""
self
.
_get_domains
()
for
domain
in
self
.
domains
:
if
name
==
domain
.
name
():
return
domain
return
None
def
start_domain
(
self
,
xml
):
def
start_domain
_with_xml
(
self
,
xml
):
"""
Start domain.
Start/create domain with XML description.
:param xml: the XML description.
:return: an instance of :class:`libvirt.virDomain`.
"""
...
...
@@ -111,21 +115,91 @@ class VM(object):
self
.
hypervisor
.
uri
,
self
.
domain
.
name
())
@
property
def
is_active
(
self
):
"""
Property to check if VM is active.
:return: if VM is active.
:rtype: Boolean
"""
return
bool
(
self
.
domain
.
isActive
())
@
property
def
name
(
self
):
"""
Property with the name of VM.
:return: the name of VM.
"""
return
self
.
domain
.
name
()
@
property
def
state
(
self
):
"""
Property with the state of VM.
:return: current state name.
"""
states
=
[
'No state'
,
'Running'
,
'Blocked'
,
'Paused'
,
'Shutting down'
,
'Shutoff'
,
'Crashed'
]
return
states
[
self
.
domain
.
info
()[
0
]]
def
start
(
self
):
"""
Start VM.
"""
if
self
.
domain
.
isActive
():
return
True
xml
=
self
.
domain
.
XMLDesc
()
dom
=
self
.
hypervisor
.
start_domain
(
xml
)
if
dom
:
self
.
domain
=
dom
return
True
else
:
return
False
if
self
.
is_active
is
False
:
self
.
domain
.
create
()
def
suspend
(
self
):
"""
Suspend VM.
"""
if
self
.
is_active
:
self
.
domain
.
suspend
()
def
resume
(
self
):
"""
Resume VM.
"""
if
self
.
is_active
:
self
.
domain
.
resume
()
def
reboot
(
self
):
"""
Reboot VM.
"""
if
self
.
is_active
:
self
.
domain
.
reboot
()
def
shutdown
(
self
):
"""
Shutdown VM.
"""
if
self
.
is_active
:
self
.
domain
.
shutdown
()
def
reset
(
self
):
"""
Reset VM.
"""
if
self
.
is_active
:
self
.
domain
.
reset
()
def
_create_snapshot_xml
(
self
,
name
=
None
,
description
=
None
):
def
stop
(
self
):
"""
Stop VM.
"""
if
self
.
is_active
:
self
.
domain
.
destroy
()
def
_system_checkpoint_xml
(
self
,
name
=
None
,
description
=
None
):
def
create_element
(
doc
,
tag
,
text
):
el
=
doc
.
createElement
(
tag
)
txt
=
doc
.
createTextNode
(
text
)
...
...
@@ -141,11 +215,15 @@ class VM(object):
root
.
appendChild
(
create_element
(
doc
,
'description'
,
description
))
return
doc
.
toxml
()
@
property
def
snapshots
(
self
):
return
self
.
domain
.
snapshotListNames
()
def
create_snapshot
(
self
,
name
=
None
):
"""
Create
a snapshot point
.
Create
s a snapshot of kind 'system checkpoint'
.
"""
xml
=
self
.
_
create_snapsho
t_xml
(
name
)
xml
=
self
.
_
system_checkpoin
t_xml
(
name
)
self
.
snapshot
=
self
.
domain
.
snapshotCreateXML
(
xml
)
return
self
.
snapshot
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录