mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-27 16:15:23 +00:00
cebeba7bd7
* Makefile.am: Add examples/dominfo examples/domsuspend examples/python as SUBDIRS * configure.in: Update AC_OUTPUT for new/old Makefiles * docs/Makefile.am: Remove examples from SUBDIRS * docs/examples/info1.c: Move to examples/dominfo/info1.c * docs/examples/suspend.c: Move to examples/domsuspend/suspend.c * docs/examples: Remove all remaining files * docs/examples/python: Moved to examples/python/ * examples/dominfo/Makefile.am, examples/domsuspend/Makefile.am: New build files * libvirt.spec.in: Update to take account of moved examples
51 lines
1.3 KiB
Python
Executable File
51 lines
1.3 KiB
Python
Executable File
#! /usr/bin/python
|
|
# domstart - make sure a given domU is running, if not start it
|
|
|
|
import libvirt
|
|
import sys
|
|
import os
|
|
import libxml2
|
|
import pdb
|
|
|
|
# Parse the XML description of domU from FNAME
|
|
# and return a tuple (name, xmldesc) where NAME
|
|
# is the name of the domain, and xmldesc is the contetn of FNAME
|
|
def read_domain(fname):
|
|
fp = open(fname, "r")
|
|
xmldesc = fp.read()
|
|
fp.close()
|
|
|
|
doc = libxml2.parseDoc(xmldesc)
|
|
name = doc.xpathNewContext().xpathEval("/domain/name")[0].content
|
|
return (name, xmldesc)
|
|
|
|
def usage():
|
|
print 'Usage: %s domain.xml' % sys.argv[0]
|
|
print ' Check that the domain described by DOMAIN.XML is running'
|
|
print ' If the domain is not running, create it'
|
|
print ' DOMAIN.XML must be a XML description of the domain'
|
|
print ' in libvirt\'s XML format'
|
|
|
|
if len(sys.argv) != 2:
|
|
usage()
|
|
sys.exit(2)
|
|
|
|
(name, xmldesc) = read_domain(sys.argv[1])
|
|
|
|
conn = libvirt.open(None)
|
|
if conn == None:
|
|
print 'Failed to open connection to the hypervisor'
|
|
sys.exit(1)
|
|
|
|
try:
|
|
dom = conn.lookupByName(name)
|
|
except libvirt.libvirtError:
|
|
print "Starting domain %s ... " % name,
|
|
sys.stdout.flush()
|
|
dom = conn.createLinux(xmldesc, 0)
|
|
if dom == None:
|
|
print "failed"
|
|
sys.exit(1)
|
|
else:
|
|
print "done"
|