本文整理汇总了Python中service.accounts.openstack.AccountDriver.list_usergroup_names方法的典型用法代码示例。如果您正苦于以下问题:Python AccountDriver.list_usergroup_names方法的具体用法?Python AccountDriver.list_usergroup_names怎么用?Python AccountDriver.list_usergroup_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.accounts.openstack.AccountDriver
的用法示例。
在下文中一共展示了AccountDriver.list_usergroup_names方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import list_usergroup_names [as 别名]
def main():
"""
TODO: Add argparse, --delete : Deletes existing users in openstack (Never use in PROD)
"""
openstack = Provider.objects.filter(
type__name__iexact="openstack").order_by("id")
if not openstack:
raise Provider.DoesNotExist("No OpenStack Provider Found")
openstack = openstack[0]
os_driver = OSAccountDriver(openstack)
found = 0
create = 0
usernames = os_driver.list_usergroup_names()
quota_dict = {
'cpu': 10,
'memory': 20,
'storage': 10,
'storage_count': 10
}
higher_quota = Quota.objects.get_or_create(**quota_dict)[0]
for user in usernames:
# Openstack account exists, but we need the identity.
ident = os_driver.create_account(user)
if is_staff(ident):
im = ident.identity_membership.all()[0]
# Disable time allocation
im.allocation = None
# Raise everybody's quota
im.quota = higher_quota
im.save()
print "Total users added to atmosphere:%s" % len(usernames)
示例2: main
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import list_usergroup_names [as 别名]
def main():
"""
TODO: Add argparse, --delete : Deletes existing users in openstack (Never use in PROD)
"""
openstack = Provider.objects.get(location='iPlant Cloud - Tucson')
os_driver = OSAccountDriver(openstack)
found = 0
create = 0
quota_dict = {
'cpu':16,
'memory': 128,
'storage': 10,
'storage_count': 10
}
higher_quota = Quota.objects.get_or_create(**quota_dict)[0]
usernames = os_driver.list_usergroup_names()
staff = get_staff_users()
staff_users = sorted(list(set(staff) & set(usernames)))
non_staff = sorted(list(set(usernames) - set(staff)))
for user in non_staff:
#Raise everybody's quota
#try:
im_list = IdentityMembership.objects.filter(identity__created_by__username=user, identity__provider=openstack)
if not im_list:
print "Missing user:%s" % user
continue
im = im_list[0]
if not im.allocation:
print "User missing Allocation: %s" % user
im.allocation = Allocation.default_allocation()
im.save()
#Ignore the quota set if you are above it..
if im.quota.cpu >= quota_dict["cpu"] \
or im.quota.memory >= quota_dict["memory"]:
continue
print "Existing Quota CPU:%s should be %s" % (im.quota.cpu, quota_dict["cpu"])
im.quota = higher_quota
im.save()
print 'Found non-staff user:%s -- Update quota and add allocation' % user
#for user in staff_users:
# # Openstack account exists, but we need the identity.
# im = IdentityMembership.objects.filter(identity__created_by__username=user, identity__provider=openstack)
# if not im:
# print "Missing user:%s" % user
# continue
# im = im[0]
# if im.quota.cpu == quota_dict["cpu"]:
# continue
# #Disable time allocation
# im.allocation = None
# im.quota = higher_quota
# im.save()
# print 'Found staff user:%s -- Update quota and no allocation' % user
print "Total users added to atmosphere:%s" % len(usernames)