def redistribute_routers(provider_id, users=[], redistribute=False): for provider in Provider.objects.filter(id=provider_id): router_map = provider.get_router_distribution() # Print 'before' instance_map = _get_instance_owner_map(provider, users=users) if redistribute: needs_router = provider.identity_set.all().order_by( 'created_by__username') router_map = {key: 0 for key in router_map.keys()} else: needs_router = provider.missing_routers() for identity in needs_router: identity_user = identity.created_by.username if users and identity_user not in users: print "Skipping user %s" % identity_user continue instances = instance_map.get(identity_user, []) if len(instances) > 0: print "Skipping user %s - Reason: User has running instances" % identity_user continue # Select next available router for the identity selected_router = provider.select_router(router_map) # Save happens here: Identity.update_credential(identity, 'router_name', selected_router, replace=True) router_map[selected_router] += 1 provider.get_router_distribution() # Print 'after' return
def redistribute_routers(provider_id, users=[], redistribute=False): for provider in Provider.objects.filter(id=provider_id): router_map = provider.get_router_distribution() # Print 'before' instance_map = _get_instance_owner_map(provider, users=users) if redistribute: needs_router = provider.identity_set.all( ).order_by('created_by__username') router_map = {key: 0 for key in router_map.keys()} else: needs_router = provider.missing_routers() for identity in needs_router: identity_user = identity.created_by.username if users and identity_user not in users: print "Skipping user %s" % identity_user continue instances = instance_map.get(identity_user, []) if len(instances) > 0: print "Skipping user %s - Reason: User has running instances" % identity_user continue # Select next available router for the identity selected_router = provider.select_router(router_map) # Save happens here: Identity.update_credential( identity, 'router_name', selected_router, replace=True ) router_map[selected_router] += 1 provider.get_router_distribution() # Print 'after' return
def create_accounts(acct_driver, provider, users, rebuild=False, admin=False): added = 0 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: if not rebuild: continue print "%s Exists -- Attempting an account rebuild" % user new_identity = acct_driver.create_account(user, max_quota=admin) # After identity is created, be sure to select one of the # `public_routers` in provider to be given # to the identity as a `router_name` selected_router = provider.select_router() Identity.update_credential(new_identity, 'router_name', selected_router, replace=True) added += 1 if admin: make_admin(user) print "%s added as admin." % (user) else: print "%s added." % (user) except Exception as e: logger.exception("Problem creating account") print "Problem adding %s." % (user) logger.exception(e) print e.message print "Total users added:%s" % (added)
def create_accounts(acct_driver, provider, users, rebuild=False, admin=False): added = 0 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: if not rebuild: continue print "%s Exists -- Attempting an account rebuild" % user new_identity = acct_driver.create_account(user, max_quota=admin) # After identity is created, be sure to select one of the # `public_routers` in provider to be given # to the identity as a `router_name` selected_router = provider.select_router() Identity.update_credential( new_identity, 'router_name', selected_router, replace=True) added += 1 if admin: make_admin(user) print "%s added as admin." % (user) else: print "%s added." % (user) except Exception as e: logger.exception("Problem creating account") print "Problem adding %s." % (user) logger.exception(e) print e.message print "Total users added:%s" % (added)
def main(args): provider_id = args.provider redistribute = args.redistribute for provider in Provider.objects.filter(id=provider_id): router_map = provider.get_router_distribution() # Print 'before' if redistribute: needs_router = provider.identity_set.all() router_map = {key: 0 for key in router_map.keys()} else: needs_router = provider.missing_routers() for identity in needs_router: # Select next available router for the identity selected_router = provider.select_router(router_map) # Save happens here: Identity.update_credential(identity, 'router_name', selected_router, replace=True) router_map[selected_router] += 1 provider.get_router_distribution() # Print 'after' return