当前位置: 首页>>代码示例>>Python>>正文


Python Default.set方法代码示例

本文整理汇总了Python中cloudmesh_client.cloud.default.Default.set方法的典型用法代码示例。如果您正苦于以下问题:Python Default.set方法的具体用法?Python Default.set怎么用?Python Default.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudmesh_client.cloud.default.Default的用法示例。


在下文中一共展示了Default.set方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_007

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
 def test_007(self):
     """
     set default variable
     :return:
     """
     HEADING()
     name = "myvar"
     value = "myvalue"
     cloud = "mycloud"
     Default.set(name, value, cloud)
     assert Default.get(name, cloud) == value
     self._check(value)
开发者ID:atavism,项目名称:client,代码行数:14,代码来源:test_default.py

示例2: get

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    def get(prefix=None, idx=None, user=None):
        """Return a vm name to use next time. prefix or index can be
        given to update a vm name (optional)

        Args:
            prefix (str, optional): the name of prefix
            idx (int, str, optional): the index to increment. This can be a
            digit or arithmetic e.g. +5 or -3 can be used

        """
        user = user or getpass.getuser()
        prefix = prefix or user
        if type(idx) is not int:
            idx = int(idx)
        Default.set('index', idx)
        return "%{:}_%{:}".format()
开发者ID:atavism,项目名称:client,代码行数:18,代码来源:vmname.py

示例3: __init__

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    def __init__(self, context):
        cmd.Cmd.__init__(self)
        self.command_topics = {}
        self.register_topics()
        self.context = context
        if self.context.debug:
            print("init CloudmeshConsole")

        self.prompt = 'ghost> '

        self.banner = textwrap.dedent("""
            +==========================================================+
            .                          _   .-')       ('-.   .-') _    .
            .                         ( '.( OO )_   _(  OO) (  OO) )   .
            .     .-----.  .-'),-----. ,--.   ,--.)(,------./     '._  .
            .    '  .--./ ( OO'  .-.  '|   `.'   |  |  .---'|'--...__) .
            .    |  |('-. /   |  | |  ||         |  |  |    '--.  .--' .
            .   /_) |OO  )\_) |  |\|  ||  |'.'|  | (|  '--.    |  |    .
            .   ||  |`-'|   \ |  | |  ||  |   |  |  |  .--'    |  |    .
            .  (_'  '--'\    `'  '-'  '|  |   |  |  |  `---.   |  |    .
            .     `-----'      `-----' `--'   `--'  `------'   `--'    .
            +==========================================================+
                                  Comet Ghost Shell
            """)
        # KeyCommands.__init__(self, context)

        #
        # set default cloud and default group if they do not exist
        # use the first cloud in cloudmesh.yaml as default
        #
        value = Default.get('cloud', 'general')
        if value is None:
            filename = path_expand("~/.cloudmesh/cloudmesh.yaml")
            clouds = ConfigDict(filename=filename)["cloudmesh"]["clouds"]
            cloud = clouds.keys()[0]
            Default.set('cloud', cloud, 'general')

        value = Default.get('default', 'general')
        if value is None:
            Default.set('default', 'default', 'general')

        for c in CloudmeshConsole.__bases__[1:]:
            # noinspection PyArgumentList
            c.__init__(self, context)
开发者ID:rajaramcomputers,项目名称:client,代码行数:46,代码来源:ghost.py

示例4: __init__

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    def __init__(self, context):
        cmd.Cmd.__init__(self)
        self.command_topics = {}
        self.register_topics()
        self.context = context
        if self.context.debug:
            print("init CloudmeshConsole")

        self.prompt = 'cm> '

        self.banner = textwrap.dedent("""
            +=======================================================+
            .   ____ _                 _                     _      .
            .  / ___| | ___  _   _  __| |_ __ ___   ___  ___| |__   .
            . | |   | |/ _ \| | | |/ _` | '_ ` _ \ / _ \/ __| '_ \  .
            . | |___| | (_) | |_| | (_| | | | | | |  __/\__ \ | | | .
            .  \____|_|\___/ \__,_|\__,_|_| |_| |_|\___||___/_| |_| .
            +=======================================================+
                                 Cloudmesh Shell
            """)
        # KeyCommands.__init__(self, context)

        #
        # set default cloud and default group if they do not exist
        # use the first cloud in cloudmesh.yaml as default
        #

        filename = path_expand("~/.cloudmesh/cloudmesh.yaml")
        create_cloudmesh_yaml(filename)

        # sys,exit(1)

        value = Default.get('cloud', cloud='general')
        if value is None:
            clouds = ConfigDict(filename=filename)["cloudmesh"]["clouds"]
            cloud = clouds.keys()[0]
            Default.set('cloud', cloud, cloud='general')

        value = Default.get('default', cloud='general')
        if value is None:
            Default.set('default', 'default', cloud='general')

        cluster = 'india'  # hardcode a value if not defined
        value = Default.get('cluster', cloud='general')
        if value is None:
            try:
                hosts = ssh_config().names()
                if hosts is not None:
                    cluster = hosts[0]
            except:
                pass  # use the hardcoded cluster

        else:
            cluster = value
        Default.set('cluster', cluster, cloud='general')

        #
        # Read cloud details from yaml file
        #
        filename = 'cloudmesh.yaml'
        config = ConfigDict(filename=filename)["cloudmesh"]
        clouds = config["clouds"]

        defaults = {'clouds': {},
                    'key': {}}

        for cloud in clouds:
            if "default" in config['clouds'][cloud]:
                defaults['clouds'][cloud] = config["clouds"][cloud]['default']

        if "default" in config["keys"]:
            defaults["keys"] = config["keys"]["default"]
        else:
            defaults['key'] = None

        for cloud in defaults["clouds"]:
            for default, value in defaults["clouds"][cloud].iteritems():
                Default.set(default, value, cloud=cloud)

        for c in CloudmeshConsole.__bases__[1:]:
            # noinspection PyArgumentList
            c.__init__(self, context)
开发者ID:atavism,项目名称:client,代码行数:84,代码来源:cm.py

示例5: do_default

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    def do_default(self, args, arguments):
        """
        ::

          Usage:
              default list [--cloud=CLOUD] [--format=FORMAT] [--all]
              default delete KEY [--cloud=CLOUD]
              default KEY [--cloud=CLOUD]
              default KEY=VALUE [--cloud=CLOUD]

          Arguments:

            KEY    the name of the default
            VALUE  the value to set the key to

          Options:

             --cloud=CLOUD    the name of the cloud
             --format=FORMAT  the output format [default: table]
             --all            lists all the default values

        Description:


            Cloudmesh has the ability to manage easily multiple
            clouds. One of the key concepts to make the list of such
            clouds easier is the introduction of defaults for each
            cloud or globally. Hence it is possible to set default
            images, flavors for each cloud, and also the default
            cloud. The default command is used to set and list the
            default values. These defaults are used in other commands
            if they are not overwritten by a command parameter.


        The current default values can by listed with --all option:(
        if you have a default cloud specified. You can also add a
        cloud parameter to apply the command to a specific cloud)

               default list

            A default can be set with

                default KEY=VALUE

            To look up a default value you can say

                default KEY

            A default can be deleted with

                default delete KEY


        Examples:
            default list --all
            default list --cloud=general
            default image=xyz
            default image=abc --cloud=kilo
            default image
            default image --cloud=kilo
            default delete image
            default delete image --cloud=kilo
        """
        # pprint(arguments)

        """
        For these keys, the 'cloud' column in db
        will always be 'general'.
        """
        general_keys = ["cloud", "cluster", "queue"]

        """
        If the default cloud has been set (eg. default cloud=xxx),
        then subsequent defaults for any key (eg. default image=yyy),
        will have 'cloud' column in db as the default cloud that was set.
        (eg. image=yyy for cloud=xxx).
        """

        if arguments["KEY"] in general_keys:
            cloud = "general"
        else:
            cloud = arguments["--cloud"] or Default.get("cloud", "general") or "general"

        if arguments["list"]:
            output_format = arguments["--format"]

            if arguments['--all'] or arguments["--cloud"] is None:
                cloud = None
            result = Default.list(cloud=cloud, format=output_format)

            if result is None:
                Console.error("No default values found")
            else:
                print(result)
            return ""

        elif arguments["delete"]:

            key = arguments["KEY"]
            result = Default.delete(key, cloud)
#.........这里部分代码省略.........
开发者ID:atavism,项目名称:client,代码行数:103,代码来源:DefaultCommand.py

示例6: do_select

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    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)
#.........这里部分代码省略.........
开发者ID:rajaramcomputers,项目名称:client,代码行数:103,代码来源:SelectCommand.py

示例7: print

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
                print (e)
                print (keyname)
                print (filename)
                Console.error("Problem adding the key `{}` from file `{}`".format(keyname, filename))

        elif arguments['default']:

            # print("default")

            if arguments['KEYNAME']:
                keyname = None
                try:
                    keyname = arguments['KEYNAME']
                    sshdb = SSHKeyDBManager()
                    sshdb.set_default(keyname)
                    Default.set("key", keyname, "general")
                    print("Key {:} set as default".format(keyname))
                    msg = "info. OK."
                    Console.ok(msg)
                except Exception, e:
                    import traceback
                    print(traceback.format_exc())
                    print (e)
                    Console.error("Setting default for key {:} failed.".format(keyname))

            elif arguments['--select']:
                keyname = None
                try:
                    sshdb = SSHKeyDBManager()
                    select = sshdb.select()
                    if select != 'q':
开发者ID:atavism,项目名称:client,代码行数:33,代码来源:KeyCommand.py

示例8: do_select

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    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"]
        if arguments["image"]:
            pass
        elif arguments["flavor"]:
            pass
        elif arguments["cloud"]:

            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")

        elif arguments["key"]:

            db = SSHKeyDBManager()

            d = db.table_dict()

            try:
                element = dict_choice(d)

                keyname = element["name"]
                print("Set default key to ", keyname)
                db.set_default(keyname)
                Default.set("key", keyname, "general")

            except:
                print("ERROR: could not set key")

        return ""
开发者ID:atavism,项目名称:client,代码行数:65,代码来源:SelectCommand.py

示例9: do_default

# 需要导入模块: from cloudmesh_client.cloud.default import Default [as 别名]
# 或者: from cloudmesh_client.cloud.default.Default import set [as 别名]
    def do_default(self, args, arguments):
        """
        ::

          Usage:
              default
              default list [--cloud=CLOUD] [--format=FORMAT] [--all]
              default delete KEY [--cloud=CLOUD]
              default KEY [--cloud=CLOUD]
              default KEY=VALUE [--cloud=CLOUD]

          Arguments:
            KEY    the name of the default
            VALUE  the value to set the key to

          Options:
             --cloud=CLOUD    the name of the cloud
             --format=FORMAT  the output format. Values include
                              table, json, csv, yaml. [default: table]
             --all            lists all the default values

        Description:
            Cloudmesh has the ability to manage easily multiple
            clouds. One of the key concepts to manage multiple clouds
            is to use defaults for the cloud, the images, flavors,
            and other values. The default command is used to manage
            such default values. These defaults are used in other commands
            if they are not overwritten by a command parameter.

            The current default values can by listed with

                default list --all

            Via the default command you can list, set, get and delete
            default values. You can list the defaults with

               default list

            A default can be set with

                default KEY=VALUE

            To look up a default value you can say

                default KEY

            A default can be deleted with

                default delete KEY

            To be specific to a cloud you can specify the name of the
            cloud with the --cloud=CLOUD option. The list command can
            print the information in various formats iv specified.

        Examples:
            default
                lists the default for the current default cloud

            default list --all
                lists all default values

            default list --cloud=kilo
                lists the defaults for the cloud with the name kilo

            default image=xyz
                sets the default image for the default cloud to xyz

            default image=abc --cloud=kilo
                sets the default image for the cloud kilo to xyz

            default image
                list the default image of the default cloud

            default image --cloud=kilo
                list the default image of the cloud kilo

            default delete image
                deletes the value for the default image in the
                default cloud

            default delete image --cloud=kilo
                deletes the value for the default image in the
                cloud kilo

        """
        # pprint(arguments)

        """
        For these keys, the 'cloud' column in db
        will always be 'general'.
        """
        general_keys = ["cloud", "cluster", "queue"]

        """
        If the default cloud has been set (eg. default cloud=xxx),
        then subsequent defaults for any key (eg. default image=yyy),
        will have 'cloud' column in db as the default cloud that was set.
        (eg. image=yyy for cloud=xxx).
        """

#.........这里部分代码省略.........
开发者ID:rajaramcomputers,项目名称:client,代码行数:103,代码来源:DefaultCommand.py


注:本文中的cloudmesh_client.cloud.default.Default.set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。