Ejemplo n.º 1
0
    def do_flavor(self, args, arguments):
        """
        ::

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

                This lists out the flavors present for a cloud

            Options:
               --format=FORMAT  the output format [default: table]
               --cloud=CLOUD    the cloud name
               --refresh        refreshes the data before displaying it
                                from the cloud

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

        """

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

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

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

            if cluster_id is None:
                result = Flavor.list(cloud, output_format)
            else:
                result = Flavor.details(cloud, cluster_id, refresh, output_format)

            if result is None:
                #
                # outo refresh
                #
                Console.error("No flavor(s) found. Failed")
                # Flavor.refresh(cloud)
                # Console.ok("Refreshing flavor(s). ok.")

            else:

                print(result)
            return ""
Ejemplo n.º 2
0
def cloudmesh_flavors(request, cloud=None):
    if cloud is None:
        cloud = Default.get_cloud()
    data = Flavor.list(cloud, format='dict')
    print json.dumps(data, indent=4)

    order = [
        'id',
        'name',
        'cloud',
        'disk',
        'os_flavor_acces',
        'os_flv_disabled',
        'os_flv_ext_data',
        'project',
        'ram',
        'rxtx_factor',
        'swap',
        'vcpus',
    ]
    return dict_table(request,
                      title="Cloudmesh Flavors {}".format(cloud),
                      data=data, order=order)
Ejemplo n.º 3
0
def cloudmesh_flavors(request, cloud=None):
    if cloud is None:
        cloud = Default.get_cloud()
    data = Flavor.list(cloud, format='dict')
    print json.dumps(data, indent=4)

    order = [
        'id',
        'name',
        'cloud',
        'disk',
        'os_flavor_acces',
        'os_flv_disabled',
        'os_flv_ext_data',
        'project',
        'ram',
        'rxtx_factor',
        'swap',
        'vcpus',
    ]
    return dict_table(request,
                      title="Cloudmesh Flavors {}".format(cloud),
                      data=data,
                      order=order)
Ejemplo n.º 4
0
    def do_flavor(self, args, arguments):
        """
        ::

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

                This lists out the flavors present for a cloud

            Options:
               --format=FORMAT  the output format [default: table]
               --cloud=CLOUD    the cloud name
               --refresh        refreshes the data before displaying it
                                from the cloud

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

        """

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

        if arguments["-v"]:
            print("Cloud: {}".format(cloud))

        if arguments["refresh"] or Default.refresh():
            msg = "Refresh flavor for cloud {:}.".format(cloud)
            if Flavor.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 = Flavor.list(cloud, output_format)
                else:
                    result = Flavor.details(cloud, id, live, output_format)
                if counter == 0 and result is None:
                    if not Flavor.refresh(cloud):
                        msg = "Refresh flavor 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 ""
Ejemplo n.º 5
0
    def do_list(self, args, arguments):
        """
        ::

            Usage:
                list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] default
                list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] vm
                list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] flavor
                list [--cloud=CLOUD] [--format=FORMAT] [--user=USER] [--tenant=TENANT] image

            List the items stored in the database

            Options:
                --cloud=CLOUD    the name of the cloud
                --format=FORMAT  the output format
                --tenant=TENANT     Name of the tenant, e.g. fg82.

            Description:
                List command prints the values stored in the database
                for [default/vm/flavor/image].
                Result can be filtered based on the cloud, user & tenant arguments.
                If these arguments are not specified, it reads the default

            Examples:
                $ list --cloud india default
                $ list --cloud india --format table flavor
                $ list --cloud india --user albert --tenant fg82 flavor
        """

        # pprint(arguments)

        # Method to get the kind from args
        #
        # TODO: the kind are defined in the provider,
        # TODO: keep the kind lower case
        # why is there a reason to make the gind upper case
        def get_kind():
            for k in ["vm", "image", "flavor", "default"]:
                if arguments[k]:
                    # kinds are all uppercase in model.py
                    return k.upper()
            return "help"

        # Read commandline arguments
        output_format = arguments['--format']
        cloud = arguments['--cloud'] or Default.cloud
        user = arguments['--user']
        tenant = arguments['--tenant']

        # If format is not specified, read default
        if output_format is None:
            output_format = Default.get(name="format") or "table"

        # If cloud is not specified, get default
        if cloud is None:
            cloud = Default.get(name="cloud") or ConfigDict(
                filename="cloudmesh.yaml")["cloudmesh"]["active"][0]

        # If user is not specified, get default
        if user is None:
            user = Default.get(name="user")

        # If tenant is not specified, get default
        if tenant is None:
            tenant = Default.get(name="tenant")

        # Get the kind
        kind = get_kind()
        header = None
        order = None

        # print help message
        if kind == 'help':
            Console.ok("Print help!")
            return ""

        # Prepare the order & header based on kind
        # TODO: use lower case so we have a convention thats easy to follow
        # TODO: add quota
        # TODO: add limits
        # TODO: add usage

        #
        # TODO: BUG: use the get attribute from the provider.
        # TODO:: call the cm xyz list functions and do not
        # reimplement this here
        # possibly introduce List.py

        result = None
        if kind == 'FLAVOR':
            result = Flavor.list(cloud, format=output_format)
        elif kind == 'DEFAULT':
            result = Default.list(order=order, output=output_format)
        elif kind == 'IMAGE':
            result = Image.list(cloud, format=output_format)
        elif kind == 'VM':
            result = Vm.list(cloud=cloud, output_format=output_format)

        if result:
            print(result)
        else:
            Console.error("No {}s found in the database.".format(kind.lower()))

        return ""
Ejemplo n.º 6
0
    def do_select(self, args, arguments):
        """
        ::

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

          selects interactively the default values

          Arguments:

            CLOUD    the name of the cloud

          Options:

        """
        # pprint(arguments)
        cloud = arguments["CLOUD"] or Default.get_cloud()
        if arguments["image"]:
            try:
                image_dict = Image.list(cloud, format="dict")

                image_names = list()
                for image in 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, cloud=cloud)
            except:
                print("ERROR: could not set image.")

        elif arguments["flavor"]:
            try:
                flavor_dict = Flavor.list(cloud, format="dict")

                flavor_names = list()
                for flavor in 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, cloud=cloud)
            except:
                print("ERROR: could not set flavor.")

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

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

                number = menu_return_num(title="Select a cloud",
                                         menu_list=clouds.keys(),
                                         tries=10,
                                         with_display=True)
                if number == "q":
                    pass
                else:
                    cloud = clouds.keys()[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 = db.table_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, cloud=cloud)
            except:
                print("ERROR: could not set key")

        return ""
Ejemplo n.º 7
0
    def do_flavor(self, args, arguments):
        """
        ::

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

                This lists out the flavors present for a cloud

            Options:
               --format=FORMAT  the output format [default: table]
               --cloud=CLOUD    the cloud name
               --refresh        refreshes the data before displaying it
                                from the cloud

            Examples:
                cm flavor refresh
                cm flavor list
                cm flavor list --format=csv
                cm flavor show 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["-v"]:
            print("Cloud: {}".format(cloud))

        if arguments["refresh"] or Default.refresh:
            msg = "Refresh flavor for cloud {:}.".format(cloud)
            if Flavor.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 = Flavor.list(cloud, output_format)
                else:
                    result = Flavor.details(cloud, id, live, output_format)
                if counter == 0 and result is None:
                    if not Flavor.refresh(cloud):
                        msg = "Refresh flavor for cloud {:}.".format(cloud)
                        Console.error("{:} failed.".format(msg))
                counter += 1

            if result is None:
                Console.error("No flavor(s) found. Failed.")
            else:
                print(result)
            return ""
Ejemplo n.º 8
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 ""