Beispiel #1
0
    def enable_root(self):
        """Enable the root user global access and/or reset the root password"""
        user = models.MySQLUser()
        user.name = "root"
        user.host = "%"
        user.password = generate_random_password()
        with LocalSqlClient(get_engine()) as client:
            try:
                cu = query.CreateUser(user.name, host=user.host)
                t = text(str(cu))
                client.execute(t, **cu.keyArgs)
            except exc.OperationalError as err:
                # Ignore, user is already created, just reset the password
                # TODO(rnirmal): More fine grained error checking later on
                LOG.debug(err)
        with LocalSqlClient(get_engine()) as client:
            uu = query.UpdateUser(user.name,
                                  host=user.host,
                                  clear=user.password)
            t = text(str(uu))
            client.execute(t)

            LOG.debug("CONF.root_grant: %s CONF.root_grant_option: %s" %
                      (CONF.root_grant, CONF.root_grant_option))

            g = query.Grant(permissions=CONF.root_grant,
                            user=user.name,
                            host=user.host,
                            grant_option=CONF.root_grant_option,
                            clear=user.password)

            t = text(str(g))
            client.execute(t)
            return user.serialize()
Beispiel #2
0
 def _generate_root_password(client):
     """ Generate and set a random root password and forget about it. """
     localhost = "localhost"
     uu = query.UpdateUser("root",
                           host=localhost,
                           clear=generate_random_password())
     t = text(str(uu))
     client.execute(t)
Beispiel #3
0
 def _create_admin_user(self, client, password):
     """
     Create a os_admin user with a random password
     with all privileges similar to the root user
     """
     localhost = "localhost"
     cu = query.CreateUser(ADMIN_USER_NAME, host=localhost)
     t = text(str(cu))
     client.execute(t, **cu.keyArgs)
     uu = query.UpdateUser(ADMIN_USER_NAME, host=localhost, clear=password)
     t = text(str(uu))
     client.execute(t)
     g = query.Grant(permissions='ALL',
                     user=ADMIN_USER_NAME,
                     host=localhost,
                     grant_option=True,
                     clear=password)
     t = text(str(g))
     client.execute(t)
Beispiel #4
0
 def change_passwords(self, users):
     """Change the passwords of one or more existing users."""
     LOG.debug("Changing the password of some users." "")
     LOG.debug("Users is %s" % users)
     with LocalSqlClient(get_engine()) as client:
         for item in users:
             LOG.debug("\tUser: %s" % item)
             user_dict = {
                 '_name': item['name'],
                 '_host': item['host'],
                 '_password': item['password'],
             }
             user = models.MySQLUser()
             user.deserialize(user_dict)
             LOG.debug("\tDeserialized: %s" % user.__dict__)
             uu = query.UpdateUser(user.name,
                                   host=user.host,
                                   clear=user.password)
             t = text(str(uu))
             client.execute(t)