2 # domstart - make sure a given domU is running, if not start it
10 # Parse the XML description of domU from FNAME
11 # and return a tuple (name, xmldesc) where NAME
12 # is the name of the domain, and xmldesc is the contetn of FNAME
13 def read_domain(fname
):
18 doc
= libxml2
.parseDoc(xmldesc
)
19 name
= doc
.xpathNewContext().xpathEval("/domain/name")[0].content
20 return (name
, xmldesc
)
23 print('Usage: %s domain.xml' % sys
.argv
[0])
24 print(' Check that the domain described by DOMAIN.XML is running')
25 print(' If the domain is not running, create it')
26 print(' DOMAIN.XML must be a XML description of the domain')
27 print(' in libvirt\'s XML format')
29 if len(sys
.argv
) != 2:
33 (name
, xmldesc
) = read_domain(sys
.argv
[1])
35 conn
= libvirt
.open(None)
37 print('Failed to open connection to the hypervisor')
41 dom
= conn
.lookupByName(name
)
42 except libvirt
.libvirtError
:
43 print("Starting domain %s ... " % name
)
44 dom
= conn
.createLinux(xmldesc
, 0)