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 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)