[haizea-commit] r460 - trunk/src/haizea/cli
haizea-commit at mailman.cs.uchicago.edu
haizea-commit at mailman.cs.uchicago.edu
Mon Aug 4 10:24:57 CDT 2008
Author: borja
Date: 2008-08-04 10:24:57 -0500 (Mon, 04 Aug 2008)
New Revision: 460
Added:
trunk/src/haizea/cli/optionparser.py
trunk/src/haizea/cli/rpc_commands.py
Log:
- Factor out optparse code
- Added commands that invoke RPC interface
- "haizea" command now interacts with daemon
Added: trunk/src/haizea/cli/optionparser.py
===================================================================
--- trunk/src/haizea/cli/optionparser.py (rev 0)
+++ trunk/src/haizea/cli/optionparser.py 2008-08-04 15:24:57 UTC (rev 460)
@@ -0,0 +1,47 @@
+# -------------------------------------------------------------------------- #
+# Copyright 2006-2008, University of Chicago #
+# Copyright 2008, Distributed Systems Architecture Group, Universidad #
+# Complutense de Madrid (dsa-research.org) #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); you may #
+# not use this file except in compliance with the License. You may obtain #
+# a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+# -------------------------------------------------------------------------- #
+import optparse as py_optparse
+
+class OptionParser (py_optparse.OptionParser):
+ def _init_parsing_state (self):
+ py_optparse.OptionParser._init_parsing_state(self)
+ self.option_seen = {}
+
+ def check_values (self, values, args):
+ for option in self.option_list:
+ if (isinstance(option, Option) and
+ option.required and
+ not self.option_seen.has_key(option)):
+ self.error("%s not supplied" % option)
+ return (values, args)
+
+class Option (py_optparse.Option):
+ ATTRS = py_optparse.Option.ATTRS + ['required']
+
+ def _check_required (self):
+ if self.required and not self.takes_value():
+ raise py_optparse.OptionError(
+ "required flag set for option that doesn't take a value",
+ self)
+
+ # Make sure _check_required() is called from the constructor!
+ CHECK_METHODS = py_optparse.Option.CHECK_METHODS + [_check_required]
+
+ def process (self, opt, value, values, parser):
+ py_optparse.Option.process(self, opt, value, values, parser)
+ parser.option_seen[self] = 1
\ No newline at end of file
Added: trunk/src/haizea/cli/rpc_commands.py
===================================================================
--- trunk/src/haizea/cli/rpc_commands.py (rev 0)
+++ trunk/src/haizea/cli/rpc_commands.py 2008-08-04 15:24:57 UTC (rev 460)
@@ -0,0 +1,57 @@
+# -------------------------------------------------------------------------- #
+# Copyright 2006-2008, University of Chicago #
+# Copyright 2008, Distributed Systems Architecture Group, Universidad #
+# Complutense de Madrid (dsa-research.org) #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); you may #
+# not use this file except in compliance with the License. You may obtain #
+# a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+# -------------------------------------------------------------------------- #
+from haizea.cli.optionparser import OptionParser, Option
+import xmlrpclib
+import sys
+
+def add_rpc_options(op):
+ op.add_option(Option("-s", "--server", action="store", type="string", dest="server", default="http://localhost:42493"))
+
+def create_rpc_proxy(server):
+ return xmlrpclib.ServerProxy(server)
+
+def haizea_request_lease(argv):
+ p = OptionParser()
+ add_rpc_options(p)
+
+ p.add_option(Option("-t", "--start", action="store", type="string", dest="start"))
+ p.add_option(Option("-d", "--duration", action="store", type="string", dest="duration"))
+ p.add_option(Option("-n", "--numnodes", action="store", type="int", dest="numnodes"))
+ p.add_option(Option("--preemptible", action="store_true", dest="preemptible"))
+ p.add_option(Option("--non-preemptible", action="store_false", dest="preemptible"))
+ p.add_option(Option("-c", "--cpu", action="store", type="float", dest="cpu"))
+ p.add_option(Option("-m", "--mem", action="store", type="int", dest="mem"))
+ p.add_option(Option("-i", "--vmimage", action="store", type="string", dest="vmimage"))
+ p.add_option(Option("-z", "--vmimagesize", action="store", type="int", dest="vmimagesize"))
+
+ opt, args = p.parse_args(argv)
+
+ if opt.preemptible == None:
+ preemptible = False
+ else:
+ preemptible = opt.preemptible
+
+ server = create_rpc_proxy(opt.server)
+
+ try:
+ lease_id = server.create_lease(opt.start, opt.duration, preemptible, opt.numnodes,
+ opt.cpu, opt.mem, opt.vmimage, opt.vmimagesize)
+ print "Lease submitted correctly."
+ print "Lease ID: %i" % lease_id
+ except Exception, msg:
+ print >> sys.stderr, "Error: %s" % msg
More information about the Haizea-commit
mailing list