本文整理汇总了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