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


Python ConfigDict.getUser方法代码示例

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


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

示例1: add

# 需要导入模块: from cloudmesh_client.common.ConfigDict import ConfigDict [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.ConfigDict import getUser [as 别名]
    def add(cls, name=None, type="vm", id=None, category="kilo"):
        """
        Add an instance to a new group
            or add it to an existing one
        :param name:
        :param type:
        :param id:
        :param cloud:
        :return:
        """
        # user logged into cloudmesh
        user = ConfigDict.getUser(category) or cls.cm.user

        try:
            # See if group already exists. If yes, add id to the group
            query = {
                'name': name,
                'category': category
            }

            # Find an existing group with name
            existing_group = cls.cm.find("group", output="object",
                                         **query).first()

            # Existing group
            if existing_group is not None:
                id_str = str(existing_group.value)
                ids = id_str.split(',')

                # check if id is already in group
                if id in ids:
                    Console.error("ID [{}] is already part of Group [{}]"
                                  .format(id, name))
                else:
                    id_str += ',' + id  # add the id to the group
                    existing_group.value = id_str
                    cls.cm.save()
                    Console.ok("Added ID [{}] to Group [{}]"
                               .format(id, name))

            # Create a new group
            else:
                obj_d = cls.cm.db_obj_dict("group",
                                           name=name,
                                           value=id,
                                           type=type,
                                           category=category,
                                           user=user)
                cls.cm.add_obj(obj_d)
                cls.cm.save()

                """
                group_obj = model.GROUP(
                    name,
                    id,
                    type,
                    category=category,
                    user=user
                )
                cls.cm.add(group_obj)
                cls.cm.save()
                """
                Console.ok("Created a new group [{}] and added ID [{}] to it"
                           .format(name, id))

        except Exception as ex:
            Console.error(ex.message, ex)

        return
开发者ID:alistairking,项目名称:client,代码行数:71,代码来源:group.py


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