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)
conf = SimpleTopologyConfig(topology_file) topology = conf.to_topology() topology_json = topology.to_json_string() except ConfigException, cfge: self._print_error("Error in topology configuration file.", cfge) exit(1) else: self._print_error("Unrecognized topology file format.", "File must be either a JSON (.json) or configuration (.conf) file.") exit(1) configf = open(self.opt.conf) config_txt = configf.read() configf.close() api = API(self.opt.dir) (status_code, message, inst_id) = api.instance_create(topology_json, config_txt) if status_code != API.STATUS_SUCCESS: self._print_error("Could not create instance.", message) exit(1) else: print "Created new instance:", print Fore.WHITE + Style.BRIGHT + inst_id def gp_describe_instance_func(): return gp_describe_instance(sys.argv).run() class gp_describe_instance(Command): """ Describes a Globus Provision instance, providing information on the state of the instance,