本文整理汇总了Python中service.accounts.openstack.AccountDriver.get_or_create_keypair方法的典型用法代码示例。如果您正苦于以下问题:Python AccountDriver.get_or_create_keypair方法的具体用法?Python AccountDriver.get_or_create_keypair怎么用?Python AccountDriver.get_or_create_keypair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类service.accounts.openstack.AccountDriver
的用法示例。
在下文中一共展示了AccountDriver.get_or_create_keypair方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import get_or_create_keypair [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)
示例2: keypair_init
# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import get_or_create_keypair [as 别名]
def keypair_init(core_identity):
os_driver = OSAccountDriver(core_identity.provider)
creds = core_identity.get_credentials()
with open(settings.ATMOSPHERE_KEYPAIR_FILE, 'r') as pub_key_file:
public_key = pub_key_file.read()
keypair, created = os_driver.get_or_create_keypair(
creds['key'], creds['secret'], creds['ex_tenant_name'],
settings.ATMOSPHERE_KEYPAIR_NAME, public_key)
if created:
logger.info("Created keypair for %s" % creds['key'])
return keypair