Exemple #1
0
    def update_attributes(cls, context, instance_id, username, hostname,
                          user_attrs):
        load_and_verify(context, instance_id)
        client = create_guest_client(context, instance_id)

        user_changed = user_attrs.get('name')
        host_changed = user_attrs.get('host')

        validate = guest_models.MySQLUser()
        if host_changed:
            validate.host = host_changed
        if user_changed:
            validate.name = user_changed

        user = user_changed or username
        host = host_changed or hostname
        userhost = "%s@%s" % (user, host)
        if user_changed or host_changed:
            existing_users, _nadda = Users.load_with_client(
                client,
                limit=1,
                marker=userhost,
                include_marker=True)
            if (len(existing_users) > 0 and
                    existing_users[0].name == user and
                    existing_users[0].host == host):
                raise exception.UserAlreadyExists(name=user,
                                                  host=host)
        client.update_attributes(username, hostname, user_attrs)
Exemple #2
0
    def update_attributes(cls, context, instance_id, username, hostname,
                          user_attrs):
        load_and_verify(context, instance_id)
        client = create_guest_client(context, instance_id)

        user_changed = user_attrs.get('name')
        host_changed = user_attrs.get('host')

        user = user_changed or username
        host = host_changed or hostname

        validate = guest_models.MySQLUser(name=user, host=host)
        validate.check_reserved()

        userhost = "%s@%s" % (user, host)
        if user_changed or host_changed:
            existing_users, _nadda = Users.load_with_client(
                client,
                limit=1,
                marker=userhost,
                include_marker=True)
            if (len(existing_users) > 0 and
                    existing_users[0].name == user and
                    existing_users[0].host == host):
                raise exception.UserAlreadyExists(name=user,
                                                  host=host)
        client.update_attributes(username, hostname, user_attrs)
Exemple #3
0
    def find(cls, context, instance_id, schema_id):
        load_and_verify(context, instance_id)
        client = create_guest_client(context, instance_id)
        model_schemas, _ = cls.load_with_client(client, 1, schema_id, True)
        if model_schemas and model_schemas[0].name == schema_id:
            return model_schemas[0]

        return None
Exemple #4
0
def load_via_context(cls, context, instance_id):
    """Creates guest and fetches pagination arguments from the context."""
    load_and_verify(context, instance_id)
    limit = utils.pagination_limit(context.limit, cls.DEFAULT_LIMIT)
    client = create_guest_client(context, instance_id)
    # The REST API standard dictates that we *NEVER* include the marker.
    return cls.load_with_client(client=client, limit=limit,
                                marker=context.marker, include_marker=False)
Exemple #5
0
def load_via_context(cls, context, instance_id):
    """Creates guest and fetches pagination arguments from the context."""
    load_and_verify(context, instance_id)
    limit = utils.pagination_limit(context.limit, cls.DEFAULT_LIMIT)
    client = create_guest_client(context, instance_id)
    # The REST API standard dictates that we *NEVER* include the marker.
    return cls.load_with_client(client=client, limit=limit,
                                marker=context.marker, include_marker=False)
Exemple #6
0
 def access(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     databases = client.list_access(username, hostname)
     dbs = []
     for db in databases:
         dbs.append(Schema(name=db['_name'],
                           collate=db['_collate'],
                           character_set=db['_character_set']))
     return UserAccess(dbs)
Exemple #7
0
 def access(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     databases = client.list_access(username, hostname)
     dbs = []
     for db in databases:
         dbs.append(Schema(name=db['_name'],
                           collate=db['_collate'],
                           character_set=db['_character_set']))
     return UserAccess(dbs)
Exemple #8
0
 def change_password(cls, context, instance_id, users):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     change_users = []
     for user in users:
         change_user = {'name': user.name,
                        'host': user.host,
                        'password': user.password,
                        }
         change_users.append(change_user)
     client.change_passwords(change_users)
Exemple #9
0
 def change_password(cls, context, instance_id, users):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     change_users = []
     for user in users:
         change_user = {'name': user.name,
                        'host': user.host,
                        'password': user.password,
                        }
         change_users.append(change_user)
     client.change_passwords(change_users)
Exemple #10
0
 def create(cls, context, instance_id, schemas):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for schema in schemas:
         schema_name = schema['_name']
         existing_schema, _nadda = Schemas.load_with_client(
             client, limit=1, marker=schema_name, include_marker=True)
         if (len(existing_schema) > 0
                 and str(existing_schema[0].name) == str(schema_name)):
             raise exception.DatabaseAlreadyExists(name=schema_name)
     return client.create_database(schemas)
Exemple #11
0
 def load(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     validate = guest_models.MySQLUser()
     validate.name = username
     validate.host = hostname
     client = create_guest_client(context, instance_id)
     found_user = client.get_user(username=username, hostname=hostname)
     if not found_user:
         return None
     database_names = [{
         'name': db['_name']
     } for db in found_user['_databases']]
     return cls(found_user['_name'], found_user['_host'],
                found_user['_password'], database_names)
Exemple #12
0
 def create(cls, context, instance_id, schemas):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for schema in schemas:
         schema_name = schema['_name']
         existing_schema, _nadda = Schemas.load_with_client(
             client,
             limit=1,
             marker=schema_name,
             include_marker=True)
         if (len(existing_schema) > 0 and
                 str(existing_schema[0].name) == str(schema_name)):
             raise exception.DatabaseAlreadyExists(name=schema_name)
     return client.create_database(schemas)
Exemple #13
0
 def load(cls, context, instance_id, username, hostname):
     load_and_verify(context, instance_id)
     validate = guest_models.MySQLUser()
     validate.name = username
     validate.host = hostname
     client = create_guest_client(context, instance_id)
     found_user = client.get_user(username=username, hostname=hostname)
     if not found_user:
         return None
     database_names = [{'name': db['_name']}
                       for db in found_user['_databases']]
     return cls(found_user['_name'],
                found_user['_host'],
                found_user['_password'],
                database_names)
Exemple #14
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for user in users:
         user_name = user['_name']
         host_name = user['_host']
         userhost = "%s@%s" % (user_name, host_name)
         existing_users, _nadda = Users.load_with_client(
             client, limit=1, marker=userhost, include_marker=True)
         if (len(existing_users) > 0
                 and str(existing_users[0].name) == str(user_name)
                 and str(existing_users[0].host) == str(host_name)):
             raise exception.UserAlreadyExists(name=user_name,
                                               host=host_name)
     return client.create_user(users)
Exemple #15
0
 def create(cls, context, instance_id, users):
     # Load InstanceServiceStatus to verify if it's running
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     for user in users:
         user_name = user['_name']
         host_name = user['_host']
         userhost = "%s@%s" % (user_name, host_name)
         existing_users, _nadda = Users.load_with_client(
             client,
             limit=1,
             marker=userhost,
             include_marker=True)
         if (len(existing_users) > 0 and
                 str(existing_users[0].name) == str(user_name) and
                 str(existing_users[0].host) == str(host_name)):
             raise exception.UserAlreadyExists(name=user_name,
                                               host=host_name)
     return client.create_user(users)
Exemple #16
0
 def delete(cls, context, instance_id, schema):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_database(schema)
Exemple #17
0
 def revoke(cls, context, instance_id, username, hostname, database):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.revoke_access(username, hostname, database)
Exemple #18
0
 def grant(cls, context, instance_id, username, hostname, databases):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.grant_access(username, hostname, databases)
Exemple #19
0
 def create_guest_client(self, context, instance_id):
     common_utils.load_and_verify(context, instance_id)
     return remote.create_guest_client(context, instance_id)
Exemple #20
0
    def delete(cls, context, instance_id, user):
        load_and_verify(context, instance_id)

        with StartNotification(context, instance_id=instance_id,
                               username=user):
            create_guest_client(context, instance_id).delete_user(user)
Exemple #21
0
 def delete(cls, context, instance_id, schema):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_database(schema)
Exemple #22
0
 def get_auth_password(cls, context, instance_id):
     load_and_verify(context, instance_id)
     password = create_guest_client(context,
                                    instance_id).get_root_password()
     return password
Exemple #23
0
 def delete(cls, context, instance_id, user):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_user(user)
Exemple #24
0
 def revoke(cls, context, instance_id, username, hostname, database):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.revoke_access(username, hostname, database)
Exemple #25
0
 def grant(cls, context, instance_id, username, hostname, databases):
     load_and_verify(context, instance_id)
     client = create_guest_client(context, instance_id)
     client.grant_access(username, hostname, databases)
Exemple #26
0
 def delete(cls, context, instance_id, user):
     load_and_verify(context, instance_id)
     create_guest_client(context, instance_id).delete_user(user)
Exemple #27
0
    def delete(cls, context, instance_id, user):
        load_and_verify(context, instance_id)

        with StartNotification(context, instance_id=instance_id,
                               username=user):
            create_guest_client(context, instance_id).delete_user(user)