b75b0435601ba07ef6b74fbf998eeda2657b25d8
[osm/vim-emu.git] / emuvim / cli / compute.py
1 """
2 son-emu compute CLI
3 """
4
5 import argparse
6 import pprint
7 import zerorpc
8
9
10 pp = pprint.PrettyPrinter(indent=4)
11
12
13 class ZeroRpcClient(object):
14
15 def __init__(self):
16 self.c = zerorpc.Client()
17 self.c.connect("tcp://127.0.0.1:4242") # yes, hard coded for now. we'll change this later
18 self.cmds = {}
19
20 def execute_command(self, args):
21 if getattr(self, args["command"]) is not None:
22 # call the local method with the same name as the command arg
23 getattr(self, args["command"])(args)
24 else:
25 print "Command not implemented."
26
27 def start(self, args):
28 r = self.c.compute_action_start(
29 args.get("datacenter"), args.get("name"))
30 pp.pprint(r)
31
32 def stop(self, args):
33 r = self.c.compute_action_stop(
34 args.get("datacenter"), args.get("name"))
35 pp.pprint(r)
36
37 def list(self, args):
38 print "TODO: Not implemented"
39
40 def status(self, args):
41 print "TODO: Not implemented"
42
43
44 parser = argparse.ArgumentParser(description='son-emu compute')
45 parser.add_argument("command", help="Action to be executed.")
46 parser.add_argument(
47 "--datacenter", "-d", dest="datacenter", help="Data center.")
48 parser.add_argument(
49 "--name", "-n", dest="name", help="Compute name.")
50 # TODO: IP, image, etc. pp.
51
52
53 def main(argv):
54 args = vars(parser.parse_args(argv))
55 c = ZeroRpcClient()
56 c.execute_command(args)