mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Add autodetect to xm create for xml files
signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
1 parent
4d3817aae9
commit
dd6bd5adf4
3 files changed
+56
-24
No files matched your search
@@ -1098,6 +1098,8 @@ def parseCommandLine(argv):
|
||||
if not gopts.vals.xauthority:
|
||||
gopts.vals.xauthority = get_xauthority()
|
||||
|
||||
gopts.is_xml = False
|
||||
|
||||
# Process remaining args as config variables.
|
||||
for arg in args:
|
||||
if '=' in arg:
|
||||
@@ -1106,11 +1108,16 @@ def parseCommandLine(argv):
|
||||
if gopts.vals.config:
|
||||
config = gopts.vals.config
|
||||
else:
|
||||
gopts.load_defconfig()
|
||||
preprocess(gopts.vals)
|
||||
if not gopts.getopt('name') and gopts.getopt('defconfig'):
|
||||
gopts.setopt('name', os.path.basename(gopts.getopt('defconfig')))
|
||||
config = make_config(gopts.vals)
|
||||
try:
|
||||
gopts.load_defconfig()
|
||||
preprocess(gopts.vals)
|
||||
if not gopts.getopt('name') and gopts.getopt('defconfig'):
|
||||
gopts.setopt('name', os.path.basename(gopts.getopt('defconfig')))
|
||||
config = make_config(gopts.vals)
|
||||
except XMLFileError, ex:
|
||||
XMLFile = ex.getFile()
|
||||
gopts.is_xml = True
|
||||
config = ex.getFile()
|
||||
|
||||
return (gopts, config)
|
||||
|
||||
@@ -1233,6 +1240,8 @@ def help():
|
||||
return str(gopts)
|
||||
|
||||
def main(argv):
|
||||
is_xml = False
|
||||
|
||||
try:
|
||||
(opts, config) = parseCommandLine(argv)
|
||||
except StandardError, ex:
|
||||
@@ -1241,23 +1250,24 @@ def main(argv):
|
||||
if not opts:
|
||||
return
|
||||
|
||||
if type(config) == str:
|
||||
try:
|
||||
config = sxp.parse(file(config))[0]
|
||||
except IOError, exn:
|
||||
raise OptionError("Cannot read file %s: %s" % (config, exn[1]))
|
||||
if not opts.is_xml:
|
||||
if type(config) == str:
|
||||
try:
|
||||
config = sxp.parse(file(config))[0]
|
||||
except IOError, exn:
|
||||
raise OptionError("Cannot read file %s: %s" % (config, exn[1]))
|
||||
|
||||
if serverType == SERVER_XEN_API:
|
||||
from xen.xm.xenapi_create import sxp2xml
|
||||
sxp2xml_inst = sxp2xml()
|
||||
doc = sxp2xml_inst.convert_sxp_to_xml(config, transient=True)
|
||||
|
||||
if serverType == SERVER_XEN_API:
|
||||
from xen.xm.xenapi_create import sxp2xml
|
||||
sxp2xml_inst = sxp2xml()
|
||||
doc = sxp2xml_inst.convert_sxp_to_xml(config, transient=True)
|
||||
if opts.vals.dryrun and not opts.is_xml:
|
||||
SXPPrettyPrint.prettyprint(config)
|
||||
|
||||
if opts.vals.dryrun:
|
||||
SXPPrettyPrint.prettyprint(config)
|
||||
|
||||
if opts.vals.xmldryrun and serverType == SERVER_XEN_API:
|
||||
from xml.dom.ext import PrettyPrint as XMLPrettyPrint
|
||||
XMLPrettyPrint(doc)
|
||||
if opts.vals.xmldryrun and serverType == SERVER_XEN_API:
|
||||
from xml.dom.ext import PrettyPrint as XMLPrettyPrint
|
||||
XMLPrettyPrint(doc)
|
||||
|
||||
if opts.vals.dryrun or opts.vals.xmldryrun:
|
||||
return
|
||||
@@ -1268,10 +1278,13 @@ def main(argv):
|
||||
if serverType == SERVER_XEN_API:
|
||||
from xen.xm.xenapi_create import xenapi_create
|
||||
xenapi_create_inst = xenapi_create()
|
||||
vm_refs = xenapi_create_inst.create(document = doc)
|
||||
if opts.is_xml:
|
||||
vm_refs = xenapi_create_inst.create(filename = config)
|
||||
else:
|
||||
vm_refs = xenapi_create_inst.create(document = doc)
|
||||
|
||||
map(lambda vm_ref: server.xenapi.VM.start(vm_ref, 0), vm_refs)
|
||||
else:
|
||||
elif not opts.is_xml:
|
||||
if not create_security_check(config):
|
||||
raise security.ACMError(
|
||||
'Security Configuration prevents domain from starting')
|
||||
|
||||
@@ -24,6 +24,8 @@ import os.path
|
||||
import sys
|
||||
import types
|
||||
|
||||
|
||||
|
||||
def _line_wrap(text, width = 70):
|
||||
lines = []
|
||||
current_line = ''
|
||||
@@ -60,6 +62,15 @@ class OptionError(Exception):
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
class XMLFileError(Exception):
|
||||
"""Thrown is input is an XML File"""
|
||||
def __init__(self, XMLFile):
|
||||
self.XMLFile = XMLFile
|
||||
def __str__(self):
|
||||
return "XMLFileError: %s" % self.XMLFile
|
||||
def getFile(self):
|
||||
return self.XMLFile
|
||||
|
||||
class Opt:
|
||||
"""An individual option.
|
||||
"""
|
||||
@@ -492,6 +503,14 @@ class Opts:
|
||||
p = os.path.join(os.path.curdir, p)
|
||||
if os.path.exists(p):
|
||||
self.info('Using config file "%s".' % p)
|
||||
|
||||
f = open(p)
|
||||
is_xml = (f.read(1) == '<')
|
||||
f.close()
|
||||
|
||||
if is_xml:
|
||||
raise XMLFileError(p)
|
||||
|
||||
self.load(p, help)
|
||||
break
|
||||
else:
|
||||
|
||||
@@ -80,8 +80,8 @@ class xenapi_create:
|
||||
Create a domain from an XML file or DOM tree
|
||||
"""
|
||||
if filename is not None:
|
||||
self.check_dtd(file)
|
||||
document = parse(file)
|
||||
self.check_dtd(filename)
|
||||
document = parse(filename)
|
||||
elif document is not None:
|
||||
self.check_dom_against_dtd(document)
|
||||
|
||||
|
||||