本文整理汇总了Python中service.accounts.openstack.AccountDriver.parse_identity方法的典型用法代码示例。如果您正苦于以下问题:Python AccountDriver.parse_identity方法的具体用法?Python AccountDriver.parse_identity怎么用?Python AccountDriver.parse_identity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.accounts.openstack.AccountDriver
的用法示例。
在下文中一共展示了AccountDriver.parse_identity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import parse_identity [as 别名]
def main():
"""
Using the keyname and public_key defined in settings
Ensure that the keypair has been distributed to every identity on the
provider.
It is essential that all users carry the same keypair to allow Deployment
access
"""
keyname = settings.ATMOSPHERE_KEYPAIR_NAME
with open(settings.ATMOSPHERE_KEYPAIR_FILE, 'r') as pub_key_file:
public_key = pub_key_file.read()
print "Adding keypair: %s Contents: %s" % (keyname, public_key)
os_providers = Provider.objects.filter(type__name="OpenStack")
for prov in os_providers:
count = 0
identities = Identity.objects.filter(provider=prov)
os_accounts = OSAccountDriver(prov)
for ident in identities:
creds = os_accounts.parse_identity(ident)
try:
(keypair, created) = os_accounts.get_or_create_keypair(
creds['username'], creds['password'], creds['tenant_name'],
keyname, public_key)
except Unauthorized, exc:
print "Could not create keypair for %s. Error message: %s"\
% (creds['username'], exc.message)
if created:
print "Created keypair %s for user %s"\
% (keypair, creds['username'])
count += 1
print 'Keypairs added for %s accounts on %s' % (count, prov)