コード例 #1
0
ファイル: api.py プロジェクト: globusonline/provision
    def run(self):
        self.parse_options()

        if len(self.args) >= 2:
            inst_ids = self.args[1:]
        else:
            inst_ids = None

        api = API(self.opt.dir)
        (status_code, message, topologies_json) = api.instance_list(inst_ids)

        if status_code != API.STATUS_SUCCESS:
            self._print_error("Unable to list instances.", message)
            return 1
        else:
            insts = json.loads(topologies_json)

            for inst in insts:
                if self.opt.verbose or self.opt.debug:
                    print json.dumps(inst, indent=2)
                else:
                    topology = Topology.from_json_dict(inst)

                    reset = Fore.RESET + Style.RESET_ALL
                    print Fore.WHITE + Style.BRIGHT + topology.id + reset + ": " + self._colorize_topology_state(
                        topology.state
                    )

            return 0
コード例 #2
0
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)
コード例 #3
0
ファイル: api.py プロジェクト: ajyounge/provision
 def run(self):    
     self.parse_options()
     
     if len(self.args) >= 2:
         inst_ids = self.args[1:]
     else:
         inst_ids = None
     
     api = API(self.opt.dir)
     insts = api.instance_list(inst_ids)
     
     for i in insts:
         t = i.topology
         print "%s\t%s" % (i.id, Topology.state_str[t.state])
         if self.opt.verbose:
             for node in t.get_nodes():
                 print "\t%s\t%s\t%s" % (node.id, node.hostname, node.ip)
                 if self.opt.debug:
                     print "\t%s" % node.deploy_data