本文整理匯總了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