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
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: logger.exception("Problem creating account") print "Problem adding %s." % (user) print e.message print "Total users added:%s" % (added)
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)
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)
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)
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))