mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
bitkeeper revision 1.1062.3.7 (40f2c856i0jGNAZ3xZZ9fZILH7YDhw)
Fix sxpr conversion for forms. Fix args for restore.
This commit is contained in:
1 parent
2ca5e83aa7
commit
0c373adfd4
3 files changed
+38
-26
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import types
|
||||
import StringIO
|
||||
|
||||
import sxp
|
||||
|
||||
class ArgError(StandardError):
|
||||
@@ -50,39 +52,48 @@ class Args:
|
||||
def get_form_args(self, f, xargs=None):
|
||||
d = {}
|
||||
for (k, v) in f.items():
|
||||
n = len(v)
|
||||
if ((k not in self.arg_dict) and
|
||||
(k not in self.key_dict)):
|
||||
continue
|
||||
if n == 0:
|
||||
continue
|
||||
elif n == 1:
|
||||
d[k] = v[0]
|
||||
if isinstance(v, types.ListType):
|
||||
n = len(v)
|
||||
if n == 0:
|
||||
continue
|
||||
elif n == 1:
|
||||
val = v[0]
|
||||
else:
|
||||
raise ArgError('Too many values for %s' % k)
|
||||
else:
|
||||
raise ArgError('Too many values for %s' % k)
|
||||
val = v
|
||||
d[k] = val
|
||||
return self.get_args(d, xargs=xargs)
|
||||
|
||||
def coerce(self, type, v):
|
||||
try:
|
||||
if type == 'int':
|
||||
return int(v)
|
||||
if type == 'str':
|
||||
return str(v)
|
||||
if type == 'sxpr':
|
||||
return self.sxpr(v)
|
||||
val = int(v)
|
||||
elif type == 'str':
|
||||
val = str(v)
|
||||
elif type == 'sxpr':
|
||||
val = self.sxpr(v)
|
||||
else:
|
||||
raise ArgError('invalid type:' + str(type))
|
||||
return val
|
||||
except ArgError:
|
||||
raise
|
||||
except StandardError, ex:
|
||||
raise ArgError(str(ex))
|
||||
|
||||
def sxpr(self, v):
|
||||
if instanceof(v, types.ListType):
|
||||
return v
|
||||
if instanceof(v, types.File) or hasattr(v, 'readline'):
|
||||
return sxpr_file(v)
|
||||
if instanceof(v, types.StringType):
|
||||
return sxpr_file(StringIO(v))
|
||||
return str(v)
|
||||
if isinstance(v, types.ListType):
|
||||
val = v
|
||||
elif isinstance(v, types.FileType) or hasattr(v, 'readline'):
|
||||
val = self.sxpr_file(v)
|
||||
elif isinstance(v, types.StringType):
|
||||
val = self.sxpr_file(StringIO.StringIO(v))
|
||||
else:
|
||||
val = str(v)
|
||||
return val
|
||||
|
||||
def sxpr_file(self, fin):
|
||||
try:
|
||||
|
||||
@@ -222,14 +222,19 @@ class Xend:
|
||||
{'op' : 'create',
|
||||
'config' : fileof(conf) })
|
||||
|
||||
def xend_domain(self, id):
|
||||
return xend_get(self.domainurl(id))
|
||||
def xend_domain_restore(self, filename):
|
||||
return xend_call(self.domainurl(),
|
||||
{'op' : 'restore',
|
||||
'file' : filename })
|
||||
|
||||
def xend_domain_configure(self, id, config):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'configure',
|
||||
'config' : fileof(conf) })
|
||||
|
||||
def xend_domain(self, id):
|
||||
return xend_get(self.domainurl(id))
|
||||
|
||||
def xend_domain_unpause(self, id):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'unpause'})
|
||||
@@ -252,11 +257,6 @@ class Xend:
|
||||
{'op' : 'save',
|
||||
'file' : filename})
|
||||
|
||||
def xend_domain_restore(self, id, filename):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'restore',
|
||||
'file' : filename })
|
||||
|
||||
def xend_domain_migrate(self, id, dst):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'migrate',
|
||||
|
||||
@@ -19,9 +19,10 @@ class SrvDomain(SrvDir):
|
||||
self.xconsole = XendConsole.instance()
|
||||
|
||||
def op_configure(self, op, req):
|
||||
print 'op_configure>', op, req.args
|
||||
fn = FormFn(self.xd.domain_configure,
|
||||
[['dom', 'int'],
|
||||
['config', 'sxp']])
|
||||
['config', 'sxpr']])
|
||||
val = fn(req.args, {'dom': self.dom.id})
|
||||
#todo: may need to add ok and err callbacks.
|
||||
return val
|
||||
|
||||