1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import libvirt
17 from gofer.decorators import *
18 from gofer.agent.plugin import Plugin
19 from logging import getLogger
20
21 log = getLogger(__name__)
22 plugin = Plugin.find(__name__)
26
27 @classmethod
32
33 @remote
34 - def getDomainID(self, name):
35 """
36 Resolve a domain name to a domain ID.
37 @param name: A domain name.
38 @type name: str
39 @return: A domain ID.
40 @rtype: int
41 """
42 con = self.open()
43 try:
44 domain = con.lookupByName(name)
45 return domain.ID()
46 finally:
47 con.close()
48
49 @remote
50 - def listDomains(self):
51 """
52 Get a list of domains.
53 @return: List of dict: {id, name, active}
54 @rtype: list
55 """
56 con = self.open()
57 try:
58 domains = []
59 for id in con.listDomainsID():
60 domain = con.lookupByID(id)
61 d = dict(id=id,
62 name=domain.name(),
63 active=domain.isActive())
64 domains.append(d)
65 return domains
66 finally:
67 con.close()
68
69 @remote
71 """
72 Get whether a domain is alive (running).
73 @param id: A domain ID.
74 @type id: int
75 @return: True if alive.
76 @rtype: bool
77 """
78 con = self.open()
79 try:
80 domain = con.lookupByID(id)
81 return domain.isAlive()
82 finally:
83 con.close()
84
85 @remote
86 @pam(user='root')
88 """
89 Start (create) a domain.
90 @param id: A domain ID.
91 @type id: int
92 """
93 con = self.open()
94 try:
95 domain = con.lookupByID(id)
96 domain.create()
97 finally:
98 con.close()
99
100 @remote
101 @pam(user='root')
103 """
104 Shutdown a domain.
105 @param id: A domain ID.
106 @type id: int
107 """
108 con = self.open()
109 try:
110 domain = con.lookupByID(id)
111 domain.shutdown()
112 finally:
113 con.close()
114