| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame^] | 1 | """ |
| 2 | Distributed Cloud Emulator (dcemulator) |
| 3 | (c) 2015 by Manuel Peuster <manuel.peuster@upb.de> |
| 4 | """ |
| 5 | |
| 6 | import logging |
| 7 | import threading |
| 8 | import zerorpc |
| 9 | |
| 10 | logging.basicConfig(level=logging.DEBUG) |
| 11 | |
| 12 | |
| 13 | class ZeroRpcApiEndpoint(object): |
| 14 | |
| 15 | def __init__(self, listenip, port): |
| 16 | self.dcs = {} |
| 17 | self.ip = listenip |
| 18 | self.port = port |
| 19 | logging.debug("Created API endpoint %s(%s:%d)" % ( |
| 20 | self.__class__.__name__, self.ip, self.port)) |
| 21 | |
| 22 | def connectDatacenter(self, dc): |
| 23 | self.dcs[dc.name] = dc |
| 24 | logging.info("Connected DC(%s) to API endpoint %s(%s:%d)" % ( |
| 25 | dc.name, self.__class__.__name__, self.ip, self.port)) |
| 26 | |
| 27 | def start(self): |
| 28 | thread = threading.Thread(target=self._api_server_thread, args=()) |
| 29 | thread.daemon = True |
| 30 | thread.start() |
| 31 | logging.debug("Started API endpoint %s(%s:%d)" % ( |
| 32 | self.__class__.__name__, self.ip, self.port)) |
| 33 | |
| 34 | def _api_server_thread(self): |
| 35 | s = zerorpc.Server(MultiDatacenterApi(self.dcs)) |
| 36 | s.bind("tcp://%s:%d" % (self.ip, self.port)) |
| 37 | s.run() |
| 38 | |
| 39 | |
| 40 | class MultiDatacenterApi(object): |
| 41 | |
| 42 | def __init__(self, dcs): |
| 43 | self.dcs = dcs |
| 44 | |
| 45 | def compute_action_start(self, dc_name, compute_name): |
| 46 | # TODO return UUID / IP ? |
| 47 | logging.info("compute start") |
| 48 | |
| 49 | def compute_action_stop(self, dc_name, compute_name): |
| 50 | logging.info("compute stop") |
| 51 | |
| 52 | def compute_list(self): |
| 53 | pass |