コード例 #1
0
            server_response.text)
    except Exception as ex:
        print(ex)
        return -1, 0, cluster_url


if __name__ == "__main__":
    try:
        if (len(sys.argv) != 2):
            PrintUsage()
            sys.exit(1)

        vm_name = sys.argv[1]

        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        mycluster = C.my_api(C.src_cluster_ip, C.src_cluster_admin,
                             C.src_cluster_pwd)
        status, cluster = mycluster.get_cluster_information()
        if (status != 200):
            print("Cannot connect to ", cluster)
            print("Did you remember to update the config file?")
            sys.exit(1)

        # Get information about all VMs in the cluster.
        status, all_vms = mycluster.get_all_vm_info()
        all_vms_list = all_vms["entities"]
        # pprint(all_vms_list)
        for vm_dict in all_vms_list:
            # If you were looking for a VM with a particular UUID, you would be matching for it here.
            if (vm_name == vm_dict["name"]):
                vm_uuid = vm_dict["uuid"]
                break
コード例 #2
0
if __name__ == "__main__":
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument(
            "--upload",
            action='store_true',
            help=
            "Upload vdisks. (default is no, we assume they are already there)")
        parser.add_argument("csvfile", type=str, help="CSV File with VM names")
        args = parser.parse_args()

        csvfile = args.csvfile

        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        mycluster = C.my_api(C.dst_cluster_ip, C.dst_cluster_admin,
                             C.dst_cluster_pwd)
        print("hello world!")
        status, cluster = mycluster.get_cluster_information()
        if (status != 200):
            print("Cannot connect to %s" % cluster)
            print("Did you remember to update the config file?")
            sys.exit(1)

        # Displays cluster authentication response and information.
        # print("Status code: %s" % status)
        # print("Text: ")
        # print(json.dumps(cluster,indent=2))
        # print("=")

        # Get specific cluster elements.
        print("Name: %s." % cluster["name"])