当前位置: 首页>>代码示例>>Python>>正文


Python AccountDriver.get_or_create_keypair方法代码示例

本文整理汇总了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)
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:33,代码来源:update_keypairs.py

示例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
开发者ID:xingningdu,项目名称:atmosphere,代码行数:13,代码来源:instance.py


注:本文中的service.accounts.openstack.AccountDriver.get_or_create_keypair方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。