コード例 #1
0
ファイル: ImageCommand.py プロジェクト: jemitchell/client
    def do_image(self, args, arguments):
        """
        ::

            Usage:
                image refresh [--cloud=CLOUD]
                image list [ID] [--cloud=CLOUD] [--format=FORMAT] [--refresh]

                This lists out the images present for a cloud

            Options:
               --format=FORMAT  the output format [default: table]
               --cloud=CLOUD    the cloud name
               --refresh        live data taken from the cloud

            Examples:
                cm image refresh
                cm image list
                cm image list --format=csv
                cm image list 58c9552c-8d93-42c0-9dea-5f48d90a3188 --refresh

        """
        cloud = arguments["--cloud"] or Default.cloud
        if cloud is None:
            Console.error("Default cloud doesn't exist")
            return

        if arguments["refresh"] or Default.refresh:
            msg = "Refresh image for cloud {:}.".format(cloud)
            if Image.refresh(cloud):
                Console.ok("{:} ok.".format(msg))
            else:
                Console.error("{:} failed.".format(msg))
                return ""

        if arguments["list"]:
            id = arguments['ID']
            live = arguments['--refresh']
            output_format = arguments["--format"]

            counter = 0

            result = None
            while counter < 2:
                if id is None:
                    result = Image.list(cloud, output_format)
                else:
                    result = Image.details(cloud, id, live, output_format)
                if counter == 0 and result is None:
                    if not Image.refresh(cloud):
                        msg = "Refresh image for cloud {:}.".format(cloud)
                        Console.error("{:} failed.".format(msg))
                counter += 1

            if result is None:
                Console.error("No image(s) found. Failed.")
            else:
                print(result)
            return ""
コード例 #2
0
ファイル: views.py プロジェクト: cloudmesh/portal
def cloudmesh_refresh_db(request, action=None, cloud=None):

    if action is None:
        action = ['image']
    else:
        action = [action]

    print("******DEBUG*********")
    print("ACTION IS:",action)
    print("******DEBUG*********")

    if cloud is None:
        cloud = Default.cloud
    # TODO: make the cloudname a parameter
    data = Image.refresh(cloud)

    print("REFRESH IMAGE DATA",data)

    data = Image.list(cloud, format='dict')
    print(json.dumps(data, indent=4))
    # TODO set proper columns
    order = [
        'cm_id',
        'name',
        'category',
        'minDisk',
        'minRam',
        'os_image_size',
        'progress',
        'project',
        'status',
    ]

    return (dict_table(request,
                       title="Cloudmesh Images {}".format(cloud),
                       data=data,
                       order=order))
コード例 #3
0
    def do_select(self, args, arguments):
        """
        ::

          Usage:
              select image [CLOUD] [--refresh]
              select flavor [CLOUD] [--refresh]
              select cloud [CLOUD]
              select key [CLOUD]

          selects interactively the default values

          Arguments:

            CLOUD    the name of the cloud

          Options:

            --refresh   refreshes the data before displaying it
                        from the cloud

        """
        # pprint(arguments)
        cloud = arguments["CLOUD"] or Default.cloud
        if arguments["image"]:
            try:
                refresh = arguments['--refresh'] or Default.refresh
                if refresh:
                    Image.refresh(cloud)

                image_dict = Image.list(cloud, format="dict")

                image_names = list()
                for image in list(image_dict.values()):
                    image_names.append(image["name"])

                number = menu_return_num(title="Select an Image",
                                         menu_list=image_names,
                                         tries=10,
                                         with_display=True)

                if number == "q":
                    pass
                else:
                    image = image_names[number]
                    print("Selected image " + image)
                    Default.set("image", image, category=cloud)
            except:
                print("ERROR: could not set image.")

        elif arguments["flavor"]:
            try:
                refresh = arguments['--refresh'] or Default.refresh
                if refresh:
                    Flavor.refresh(cloud)

                flavor_dict = Flavor.list(cloud, format="dict")

                flavor_names = list()
                for flavor in list(flavor_dict.values()):
                    flavor_names.append(flavor["name"])

                number = menu_return_num(title="Select a Flavor",
                                         menu_list=flavor_names,
                                         tries=10,
                                         with_display=True)

                if number == "q":
                    pass
                else:
                    flavor = flavor_names[number]
                    print("Selected flavor " + flavor)
                    Default.set("flavor", flavor, category=cloud)
            except:
                print("ERROR: could not set flavor.")

        elif arguments["cloud"]:
            try:
                config = ConfigDict("cloudmesh.yaml")
                clouds = config["cloudmesh"]["clouds"]

                for key in clouds:
                    Console.ok("  " + key)

                number = menu_return_num(title="Select a cloud",
                                         menu_list=list(clouds),
                                         tries=10,
                                         with_display=True)
                if number == "q":
                    pass
                else:
                    cloud = list(clouds)[number]
                    print("Selected cloud " + cloud)
                    Default.set("cloud", cloud, "general")
            except:
                print("ERROR: could not set cloud.")

        elif arguments["key"]:
            try:
                #db = SSHKeyDBManager()

                key_dict = Key.all(output='dict')

                key_names = list()
                for key in key_dict.values():
                    key_names.append(key["name"])

                number = menu_return_num(title="Select a Key",
                                         menu_list=key_names,
                                         tries=10,
                                         with_display=True)

                if number == "q":
                    pass
                else:
                    key = key_names[number]
                    print("Selected key " + key)

                    # TODO Fix default key setting in key DB
                    # db.set_default(key)

                    Default.set("key", key, category=cloud)
            except:
                print("ERROR: could not set key")

        return ""