def check_sample_api(s): instances_dir = create_instances_dir() config_txt, topology_json = load_config_file(s, dummy = True) api = API(instances_dir) (status_code, message, inst_id) = api.instance_create(topology_json, config_txt) assert status_code == API.STATUS_SUCCESS check_instance_state(api, inst_id, Topology.STATE_NEW) (status_code, message, topologies_json) = api.instance_list(None) assert status_code == API.STATUS_SUCCESS insts = json.loads(topologies_json) assert len(insts) == 1 assert insts[0]["id"] == inst_id (status_code, message, topologies_json) = api.instance_list([inst_id]) assert status_code == API.STATUS_SUCCESS, message insts = json.loads(topologies_json) assert len(insts) == 1 assert insts[0]["id"] == inst_id (status_code, message) = api.instance_start(inst_id, [], []) assert status_code == API.STATUS_SUCCESS, message check_instance_state(api, inst_id, Topology.STATE_RUNNING) (status_code, message) = api.instance_stop(inst_id) assert status_code == API.STATUS_SUCCESS, message check_instance_state(api, inst_id, Topology.STATE_STOPPED) (status_code, message) = api.instance_start(inst_id, [], []) assert status_code == API.STATUS_SUCCESS, message check_instance_state(api, inst_id, Topology.STATE_RUNNING) (status_code, message) = api.instance_update(inst_id, None, [], []) assert status_code == API.STATUS_SUCCESS, message check_instance_state(api, inst_id, Topology.STATE_RUNNING) (status_code, message) = api.instance_terminate(inst_id) assert status_code == API.STATUS_SUCCESS, message check_instance_state(api, inst_id, Topology.STATE_TERMINATED) remove_instances_dir(instances_dir)
def run(self): SIGINTWatcher(self.cleanup_after_kill) self.parse_options() if len(self.args) != 2: print "You must specify an instance id." print "For example: %s [options] gpi-37a8bf17" % self.name exit(1) inst_id = self.args[1] print "Stopping instance", print Fore.WHITE + Style.BRIGHT + inst_id + Fore.RESET + Style.RESET_ALL + "...", api = API(self.opt.dir) status_code, message = api.instance_stop(inst_id) if status_code == API.STATUS_SUCCESS: print Fore.GREEN + Style.BRIGHT + "done!" elif status_code == API.STATUS_FAIL: self._print_error("Could not stop instance.", message) print exit(1)
def run(self): self.parse_options() if len(self.args) != 2: print "You must specify an instance id." print "For example: %s [options] gpi-37a8bf17" % self.name return 1 inst_id = self.args[1] print "Stopping instance", print Fore.WHITE + Style.BRIGHT + inst_id + Fore.RESET + Style.RESET_ALL + "...", api = API(self.opt.dir) status_code, message = api.instance_stop(inst_id) if status_code == API.STATUS_SUCCESS: print Fore.GREEN + Style.BRIGHT + "done!" self._set_last_gpi(inst_id) return 0 elif status_code == API.STATUS_FAIL: self._print_error("Could not stop instance.", message) print return 1