def update_password_for(prov, identities, dry_run=False, rebuild=False): count = 0 accounts = OSAccountDriver(prov) for ident in identities: creds = accounts.parse_identity(ident) username = creds['username'] password = creds['password'] # Represents the *SAVED* password. new_password = accounts.hashpass(username, strategy='salt_hashpass') if skip_change_password(accounts, username, password, new_password, dry_run=dry_run, rebuild=rebuild): print "Skipping user %s" % (username, ) continue # ASSERT: Saved Password is 'old' print "Changing password: %s (OLD:%s -> NEW:%s)" \ % (username, password, new_password), if dry_run: print "OK" count += 1 continue kwargs = {} if rebuild: old_password = get_old_password(accounts, username) kwargs.update({'old_password': old_password}) success = accounts.change_password(ident, new_password, **kwargs) if success: print "OK" count += 1 else: print "FAILED" print 'Changed passwords for %s accounts on %s' % (count, prov)
def update_password_for(prov, identities, dry_run=False, rebuild=False): count = 0 accounts = OSAccountDriver(prov) for ident in identities: creds = accounts.parse_identity(ident) username = creds["username"] password = creds["password"] # Represents the *SAVED* password. new_password = accounts.hashpass(username, strategy="salt_hashpass") if skip_change_password(accounts, username, password, new_password, dry_run=dry_run, rebuild=rebuild): print "Skipping user %s" % (username,) continue # ASSERT: Saved Password is 'old' print "Changing password: %s (OLD:%s -> NEW:%s)" % (username, password, new_password), if dry_run: print "OK" count += 1 continue kwargs = {} if rebuild: old_password = get_old_password(accounts, username) kwargs.update({"old_password": old_password}) success = accounts.change_password(ident, new_password, **kwargs) if success: print "OK" count += 1 else: print "FAILED" print "Changed passwords for %s accounts on %s" % (count, prov)
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))
def main(): """ Generate openstack users then add them to the DB """ driver = AccountDriver(secrets.OPENSTACK_ARGS) # Build the admin driver for openstack first. driver.create_identity( secrets.OPENSTACK_ADMIN_KEY, secrets.OPENSTACK_ADMIN_SECRET, secrets.OPENSTACK_ADMIN_TENANT, True) success = 1 # Add the others # 'sgregory', 'jmatt', 'edwins', 'cjlarose','mlent'] core_services = ['atmo_test'] for username in core_services: try: password = driver.hashpass(username) user = driver.get_user(username) if not user: user = driver.create_user(username, usergroup=True) print 'New OStack User - %s Pass - %s' % (user.name, password) else: print 'Found OStack User - %s Pass - %s' % (user.name, password) # ASSERT: User exists on openstack, create an identity for them. ident = driver.create_identity( user.name, password, project_name=username) success += 1 print 'New OStack Identity - %s:%s' % (ident.id, ident) except Exception as e: print "Problem adding username: %s" % username print e raise print "Total users created:%s/%s" % (success, len(core_services))
def update_password_for(prov, identities, rebuild=False): count = 0 accounts = OSAccountDriver(prov) for ident in identities: creds = accounts.parse_identity(ident) username = creds['username'] password = creds['password'] # Represents the *SAVED* password. new_password = accounts.hashpass(username) if skip_change_password( username, password, new_password, rebuild=rebuild): print "Skipping user %s" % (username,) continue # ASSERT: Saved Password is 'old' print "Changing password: %s (OLD:%s -> NEW:%s)" \ % (username, password, new_password) kwargs = {} if rebuild: old_password = get_old_password(username) kwargs.update({'old_password': old_password}) success = accounts.change_password( ident, new_password, **kwargs) if success: count += 1 print 'Changed passwords for %s accounts on %s' % (count, prov)