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


Python AccountDriver.create_account方法代码示例

本文整理汇总了Python中service.accounts.openstack.AccountDriver.create_account方法的典型用法代码示例。如果您正苦于以下问题:Python AccountDriver.create_account方法的具体用法?Python AccountDriver.create_account怎么用?Python AccountDriver.create_account使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在service.accounts.openstack.AccountDriver的用法示例。


在下文中一共展示了AccountDriver.create_account方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    """
    TODO: Add argparse, --delete : Deletes existing users in eucalyptus (Never use in PROD)
    """
    euca = Provider.objects.get(location="Eucalyptus (retiring March 4)")
    euca_driver = EucaAccountDriver(euca)
    openstack = Provider.objects.get(location="iPlant Cloud - Tucson")
    os_driver = OSAccountDriver(openstack)
    all_users = euca_driver.list_users()
    # Sort by users
    all_values = sorted(all_users.values(), key=lambda user: user["username"])
    total = 0
    for user_dict in all_values:
        id_exists = Identity.objects.filter(created_by__username=user_dict["username"], provider=euca)
        if not id_exists:
            euca_driver.create_account(user_dict)
            total += 1
            print "Added to Eucalyptus: %s" % user_dict["username"]
    print "Total users added:%s" % total
    if include_openstack:
        print "Adding all eucalyptus users to openstack"
        total = 0
        for user_dict in all_values:
            id_exists = Identity.objects.filter(created_by__username=user_dict["username"], provider=openstack)
            if not id_exists:
                os_driver.create_account(user_dict["username"])
                total += 1
                print "Added to Openstack: %s" % user_dict["username"]
        print "Total users added to openstack:%s" % total
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:31,代码来源:import_users_from_euca.py

示例2: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--provider", type=int,
                        help="Atmosphere provider ID"
                        " to use when importing users.")
    parser.add_argument("--users",
                        help="LDAP usernames to import. (comma separated)")
    parser.add_argument("--admin", action="store_true",
                        help="Users addded as admin and staff users.")
    args = parser.parse_args()
    users = None
    added = 0
    if args.provider:
        provider = Provider.objects.get(id=args.provider)
    else:
        provider = Provider.objects.get(location='iPlant Cloud - Tucson')
    print "Using Provider: %s" % provider
    type_name = provider.type.name.lower()
    if type_name == 'openstack':
        acct_driver = OSAccountDriver(provider)
    elif type_name == 'eucalyptus':
        acct_driver = EucaAccountDriver(provider)
    else:
        raise Exception("Could not find an account driver for Provider with"
                        " type:%s" % type_name)
    if not args.users:
        print "Retrieving all 'atmo-user' members in LDAP."
        users = get_members('atmo-user')
    else:
        users = args.users.split(",")
    for user in users:
        # Then add the Openstack Identity
        try:
            id_exists = Identity.objects.filter(
                    created_by__username__iexact=user,
                    provider=provider)
            if id_exists:
                continue
            acct_driver.create_account(user, max_quota=args.admin)
            added += 1
            if args.admin:
                make_admin(user)
                print "%s added as admin." % (user)
            else:
                print "%s added." % (user)
        except Exception as e:
            print "Problem adding %s." % (user)
            print e.message
    print "Total users added:%s" % (added)
开发者ID:JScottWagner,项目名称:atmosphere,代码行数:51,代码来源:add_new_accounts.py

示例3: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [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)
开发者ID:EthanChen-Field,项目名称:atmosphere,代码行数:33,代码来源:import_users_from_openstack.py

示例4: setUp

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
    def setUp(self):
        #Initialize core DB
        #Ensure there is an account created/ready to go

        #self.euca_admin_id = create_euca_provider()
        #self.euca_provider = self.euca_admin_id.provider
        #euca_accounts = EucaAccounts(self.euca_provider)
        #euca_user = euca_accounts.get_user(settings.TEST_RUNNER_USER)
        #self.euca_id = euca_accounts.create_account(euca_user, max_quota=True)

        self.os_admin_id = create_os_provider()
        self.os_provider = self.os_admin_id.provider
        os_accounts = OSAccounts(self.os_provider)
        self.os_id = os_accounts.create_account(
                settings.TEST_RUNNER_USER,
                os_accounts.hashpass(settings.TEST_RUNNER_USER), max_quota=True)
        user = AtmosphereUser.objects.get(username=settings.TEST_RUNNER_USER)
        user.is_staff = True
        user.is_superuser = True
        user.save()
        #Initialize API
        self.api_client = TokenAPIClient()
        self.api_client.login(
                username=settings.TEST_RUNNER_USER,
                password=settings.TEST_RUNNER_PASS)
        reverse_link = reverse('api:v1:instance-list',
                               args=[self.os_id.provider.id,
                                     self.os_id.id])
        self.os_instance_url = urljoin(settings.SERVER_URL, reverse_link)
        reverse_link = reverse('api:v1:machine-request-list',
                               args=[self.os_id.provider.id,
                                     self.os_id.id])
        self.os_request_url = urljoin(settings.SERVER_URL, reverse_link)
开发者ID:miquelcie,项目名称:atmosphere,代码行数:35,代码来源:test_machine_imaging.py

示例5: setUp

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
 def setUp(self):
     #Initialize core DB
     self.euca_admin_id = create_euca_provider()
     self.euca_provider = self.euca_admin_id.provider
     self.os_admin_id = create_os_provider()
     self.os_provider = self.os_admin_id.provider
     #Ensure there is an account created/ready to go
     euca_accounts = EucaAccounts(self.euca_provider)
     euca_user = euca_accounts.get_user(settings.TEST_RUNNER_USER)
     self.euca_id = euca_accounts.create_account(euca_user)
     os_accounts = OSAccounts(self.os_provider)
     self.os_id = os_accounts.create_account(
             settings.TEST_RUNNER_USER, 
             os_accounts.hashpass(settings.TEST_RUNNER_USER))
     #Initialize API
     self.api_client = TokenAPIClient()
     self.api_client.login(
             username=settings.TEST_RUNNER_USER,
             password=settings.TEST_RUNNER_PASS)
     reverse_link = reverse('api:public_apis:machine-list',
                            args=[self.os_id.provider.id,
                                  self.os_id.id])
     self.os_machine_url = urljoin(settings.SERVER_URL, reverse_link)
     reverse_link = reverse('api:public_apis:machine-list',
                           args=[self.euca_id.provider.id,
                                 self.euca_id.id])
     self.euca_machine_url = urljoin(settings.SERVER_URL, reverse_link)
开发者ID:420reich,项目名称:atmosphere,代码行数:29,代码来源:test_machine.py

示例6: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    """
    TODO: Add argparse, --delete : Deletes existing users in openstack
          (Never use in PROD)
    """
    euca_driver = EucaAccountDriver(
        Provider.objects.get(location='EUCALYPTUS'))
    os_driver = OSAccountDriver(Provider.objects.get(location='OpenStack-Tucson (BETA)'))
    found = 0
    create = 0
    core_services = ['estevetest03', ]  # get_core_services()
    for user in core_services:
        euca_driver.create_account(user, max_quota=True)
        # Then add the Openstack Identity
        os_driver.create_account(user, max_quota=True)
        make_admin(user)
    print "Total core-service/admins added:%s" % len(core_services)
开发者ID:nickeddy,项目名称:atmosphere,代码行数:19,代码来源:import_core_services.py

示例7: setUp

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
    def setUp(self):
        #Initialize core DB
        self.euca_admin_id = create_euca_provider()
        self.euca_provider = self.euca_admin_id.provider
        self.os_admin_id = create_os_provider()
        self.os_provider = self.os_admin_id.provider
        #Ensure there is an account created/ready to go
        euca_accounts = EucaAccounts(self.euca_provider)
        euca_user = euca_accounts.get_user(settings.TEST_RUNNER_USER)
        self.euca_id = euca_accounts.create_account(euca_user, max_quota=True)
        os_accounts = OSAccounts(self.os_provider)
        self.os_id = os_accounts.create_account(
                settings.TEST_RUNNER_USER, 
                os_accounts.hashpass(settings.TEST_RUNNER_USER), max_quota=True)
        #user = AtmosphereUser.objects.get(username=settings.TEST_RUNNER_USER)
        #user.is_staff = True
        #user.is_superuser = True
        #user.save()
        #Initialize API
        self.api_client = TokenAPIClient()
        self.api_client.login(
                username=settings.TEST_RUNNER_USER,
                password=settings.TEST_RUNNER_PASS)
        reverse_link = reverse('api:public_apis:instance-list',
                              args=[self.os_id.provider.id,
                                    self.os_id.id])
        self.os_instance_url = urljoin(settings.SERVER_URL, reverse_link)
        reverse_link = reverse('api:public_apis:volume-list',
                               args=[self.os_id.provider.id,
                                     self.os_id.id])
        #Prepare Openstack
        self.os_volume_url = urljoin(settings.SERVER_URL, reverse_link)
        instance_data = {
                "size_alias":"2",
                "machine_alias":"0f539197-3718-40bc-8a29-c22e0841684f",
                "name":"test volume attachment",
                "delete_before":False
            }
        (self.os_instance_id, self.os_instance_ip) = standup_instance(
                self, self.os_instance_url, **instance_data)

        #Prepare Eucalyptus
        reverse_link = reverse('api:public_apis:volume-list',
                              args=[self.euca_id.provider.id,
                                    self.euca_id.id])
        self.euca_volume_url = urljoin(settings.SERVER_URL, reverse_link)
        reverse_link = reverse('api:public_apis:instance-list',
                              args=[self.euca_id.provider.id,
                                    self.euca_id.id])
        self.euca_instance_url = urljoin(settings.SERVER_URL, reverse_link)
        instance_data = {
                "size_alias":"m1.small",
                "machine_alias":"emi-E7F8300F",
                "name":"test volume attachment",
                "delete_before":False
            }
        (self.euca_instance_id, self.euca_instance_ip) = standup_instance(
                self, self.euca_instance_url, **instance_data)
开发者ID:420reich,项目名称:atmosphere,代码行数:60,代码来源:test_volume.py

示例8: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    """
    TODO: Add argparse, --delete : Deletes existing users in openstack
          (Never use in PROD)
    """
    euca_driver = EucaAccountDriver(
        Provider.objects.get(location='EUCALYPTUS'))
    os_driver = OSAccountDriver(Provider.objects.get(location='iPlant Cloud - Tucson'))
    found = 0
    create = 0
    raise Exception("Must manually set core_services!! See Line 30.")
    core_services = ['jchansen', ] # get_core_services() # ['estevetest03', ]
    for user in core_services:
        euca_driver.create_account(user, max_quota=True)
        # Then add the Openstack Identity
        os_driver.create_account(user, max_quota=True)
        make_admin(user)
    print "Total core-service/admins added:%s" % len(core_services)
开发者ID:consueloau,项目名称:atmosphere,代码行数:20,代码来源:import_core_services.py

示例9: setUp_openstack

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def setUp_openstack():
    # Initialize core DB
    global os_base_instance_url
    os_admin_id = create_os_provider()
    os_provider = os_admin_id.provider
    os_accounts = OSAccounts(os_provider)
    os_id = os_accounts.create_account(
        settings.TEST_RUNNER_USER, os_accounts.hashpass(settings.TEST_RUNNER_USER), max_quota=True
    )
    reverse_link = reverse("instance-list", args=[os_id.provider.id, os_id.id])
    os_base_instance_url = urljoin(settings.SERVER_URL, reverse_link)
开发者ID:nickeddy,项目名称:atmosphere,代码行数:13,代码来源:test_instance.py

示例10: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--provider", type=int,
                        help="Atmosphere provider ID"
                        " to use when importing users.")
    parser.add_argument("users",
                        help="LDAP usernames to import. (comma separated)")
    parser.add_argument("--admin", action="store_true",
                        help="Users addded as admin and staff users.")
    args = parser.parse_args()
    users = None
    added = 0
    if args.provider:
        os_driver = OSAccountDriver(Provider.objects.get(id=args.provider))
    else:
        os_driver = OSAccountDriver(
            Provider.objects.get(location='iPlant Workshop Cloud - Tucson'))
    users = args.users.split(",")
    for user in users:
        # Then add the Openstack Identity
        try:
            if is_atmo_user(user):
                os_driver.create_account(user, max_quota=args.admin)
                added += 1
            else:
                print "%s is not in the ldap atmosphere group (atmo-user)." % (user)
                continue
            if args.admin:
                make_admin(user)
                print "%s added as admin." % (user)
            else:
                print "%s added." % (user)
        except Exception as e:
            print "Problem adding %s." % (user)
            print e.message
    print "Total users added:%s" % (added)
开发者ID:Spencerx,项目名称:atmosphere,代码行数:38,代码来源:import_ldap.users.py

示例11: main

# 需要导入模块: from service.accounts.openstack import AccountDriver [as 别名]
# 或者: from service.accounts.openstack.AccountDriver import create_account [as 别名]
def main():
    """
    Add a user to openstack.
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('users', type=str, nargs='+')
    args = parser.parse_args()
    openstack_prov = Provider.objects.get(location='iPlant Cloud - Tucson')
    driver = AccountDriver(openstack_prov)
    success = 0
    for username in args.users:
        print "Adding username... %s" % username
        try:
            if not is_atmo_user(username):
                print "User is not in the atmo-user group.\n"\
                    + "User does not exist in Atmosphere."
                raise Exception("User does not exist in Atmosphere.")
            user = driver.get_user(username)
            if not user:
                identity = driver.create_account(username)
                credentials = identity.credential_set.all()
                print 'New OStack User - Credentials: %s ' % (credentials)
                send_new_provider_email(username, "Openstack")
            else:
                password = driver.hashpass(username)
                identity = driver.create_identity(user.name,
                                               password,
                                               project_name=username)
                credentials = identity.credential_set.all()
                print 'Found OStack User - Credentials: %s' % (credentials)
            #ASSERT: User exists on openstack, create an identity for them.
            success += 1
            print 'New OStack Identity - %s:%s' % (identity.id, identity)
        except Exception as e:
            print "Problem adding username: %s" % username
            print e
            raise

    print "Total users created:%s/%s" % (success, len(args.users))
开发者ID:Angelfirenze,项目名称:atmosphere,代码行数:41,代码来源:add_openstack_user.py


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