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():
    """
    Using the keyname and public_key defined in settings
    Ensure that the keypair has been distributed to every identity on the
    provider.
    It is essential that all users carry the same keypair to allow Deployment
    access
    """
    keyname = settings.ATMOSPHERE_KEYPAIR_NAME
    with open(settings.ATMOSPHERE_KEYPAIR_FILE, "r") as pub_key_file:
        public_key = pub_key_file.read()
    print "Adding keypair: %s Contents: %s" % (keyname, public_key)
    os_providers = Provider.objects.filter(type__name="OpenStack")
    for prov in os_providers:
        count = 0
        identities = Identity.objects.filter(provider=prov)
        os_accounts = OSAccountDriver(prov)
        for ident in identities:
            creds = os_accounts.parse_identity(ident)
            try:
                (keypair, created) = os_accounts.get_or_create_keypair(
                    creds["username"], creds["password"], creds["tenant_name"], keyname, public_key
                )
            except KeystoneUnauthorized as exc:
                print "Could not create keypair for %s. Error message: %s" % (creds["username"], exc.message)
            if created:
                print "Created keypair %s for user %s" % (keypair, creds["username"])
                count += 1
        print "Keypairs added for %s accounts on %s" % (count, prov)
Exemple #3
0
def main():
    """
    Using the keyname and public_key defined in settings
    Ensure that the keypair has been distributed to every identity on the
    provider.
    It is essential that all users carry the same keypair to allow Deployment
    access
    """
    keyname = settings.ATMOSPHERE_KEYPAIR_NAME
    with open(settings.ATMOSPHERE_KEYPAIR_FILE, 'r') as pub_key_file:
        public_key = pub_key_file.read()
    print "Adding keypair: %s Contents: %s" % (keyname, public_key)
    os_providers = Provider.objects.filter(type__name="OpenStack")
    for prov in os_providers:
        count = 0
        identities = Identity.objects.filter(provider=prov)
        os_accounts = OSAccountDriver(prov)
        for ident in identities:
            creds = os_accounts.parse_identity(ident)
            try:
                (keypair, created) = os_accounts.get_or_create_keypair(
                    creds['username'], creds['password'], creds['tenant_name'],
                    keyname, public_key)
            except KeystoneUnauthorized as exc:
                print "Could not create keypair for %s. Error message: %s"\
                    % (creds['username'], exc.message)
            if created:
                print "Created keypair %s for user %s"\
                    % (keypair, creds['username'])
                count += 1
        print 'Keypairs added 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 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)