def build_account(
        cls,
        account_user,
        group_name,
        username,
        provider_location,
        quota=None,
        allocation=None,
        is_leader=False,
        max_quota=False,
        account_admin=False,
        **kwarg_creds
    ):
        """
        DEPRECATED: POST to v2/identities API to create an identity.
        """
        # Do not move up. ImportError.
        from core.models import Group, Quota, Provider, AccountProvider

        provider = Provider.objects.get(location__iexact=provider_location)
        credentials = cls._kwargs_to_credentials(kwarg_creds)

        if not quota:
            quota = Quota.default_quota()
        #DEV NOTE: 'New' identities are expected to have a router name directly assigned
        # upon creation. If the value is not passed in, we can ask the provider to select
        # the router with the least 'usage' to ensure an "eventually consistent" distribution
        # of users->routers.
        topologyClsName = provider.get_config(
            'network', 'topology', raise_exc=False
        )
        if topologyClsName == 'External Router Topology' and 'router_name' not in credentials:
            credentials['router_name'] = provider.select_router()

        (user,
         group) = Group.create_usergroup(account_user, group_name, is_leader)

        identity = cls._get_identity(user, group, provider, quota, credentials)
        # NOTE: This specific query will need to be modified if we want
        # 2+ Identities on a single provider

        id_membership = identity.share(group, allocation=allocation)
        # ID_Membership exists.

        # 3. Assign admin account, if requested
        if account_admin:
            AccountProvider.objects.get_or_create(
                provider=id_membership.identity.provider,
                identity=id_membership.identity
            )[0]

        # 4. Save the user to activate profile on first-time use
        # FIXME: only call .save() if 'no profile' test is True.
        # TODO: write a 'no profile' test f()
        user.save()

        # Return the identity
        return identity
Beispiel #2
0
    def build_account(cls,
                      account_user,
                      group_name,
                      username,
                      provider_location,
                      quota=None,
                      allocation=None,
                      is_leader=False,
                      max_quota=False,
                      account_admin=False,
                      **kwarg_creds):
        """
        DEPRECATED: POST to v2/identities API to create an identity.
        """
        # Do not move up. ImportError.
        from core.models import Group, Quota,\
            Provider, AccountProvider, Allocation,\
            IdentityMembership

        provider = Provider.objects.get(location__iexact=provider_location)
        credentials = cls._kwargs_to_credentials(kwarg_creds)

        if not quota:
            quota = Quota.default_quota()
        #DEV NOTE: 'New' identities are expected to have a router name directly assigned
        # upon creation. If the value is not passed in, we can ask the provider to select
        # the router with the least 'usage' to ensure an "eventually consistent" distribution
        # of users->routers.
        topologyClsName = provider.get_config('network',
                                              'topology',
                                              raise_exc=False)
        if topologyClsName == 'External Router Topology' and 'router_name' not in credentials:
            credentials['router_name'] = provider.select_router()

        (user, group) = Group.create_usergroup(account_user, group_name,
                                               is_leader)

        identity = cls._get_identity(user, group, provider, quota, credentials)
        # NOTE: This specific query will need to be modified if we want
        # 2+ Identities on a single provider

        id_membership = identity.share(group, allocation=allocation)
        # ID_Membership exists.

        # 3. Assign admin account, if requested
        if account_admin:
            AccountProvider.objects.get_or_create(
                provider=id_membership.identity.provider,
                identity=id_membership.identity)[0]

        # 4. Save the user to activate profile on first-time use
        # FIXME: only call .save() if 'no profile' test is True.
        # TODO: write a 'no profile' test f()
        user.save()

        # Return the identity
        return identity
 def _create_identity(cls, user, group, provider, quota, credentials):
     # FIXME: we shouldn't have to create the uuid.. default should do this?
     new_uuid = uuid4()
     if not quota:
         quota = Quota.default_quota()
     identity = Identity.objects.create(
         created_by=user, provider=provider, quota=quota, uuid=str(new_uuid)
     )
     for (c_key, c_value) in credentials.items():
         Identity.update_credential(identity, c_key, c_value)
     return identity
Beispiel #4
0
 def _create_identity(cls, user, group, provider, quota, credentials):
     # FIXME: we shouldn't have to create the uuid.. default should do this?
     new_uuid = uuid4()
     if not quota:
         quota = Quota.default_quota()
     identity = Identity.objects.create(created_by=user,
                                        provider=provider,
                                        quota=quota,
                                        uuid=str(new_uuid))
     for (c_key, c_value) in credentials.items():
         Identity.update_credential(identity, c_key, c_value)
     return identity