def create_user(username, uuid, superuser)
      uid = LoginUserManager.uuid_to_uid(uuid)

      if uid_exists?(uid, ['rightscale'])
        username = uid_to_username(uid)
      elsif !uid_exists?(uid)
        username  = pick_username(username)
        yield(username) if block_given?
        add_user(username, uid)
        modify_group('rightscale', :add, username)

        # NB it is SUPER IMPORTANT to pass :force=>true here. Due to an oddity in Ruby's Etc
        # extension, a user who has recently been added, won't seem to be a member of
        # any groups until the SECOND time we enumerate his group membership.
        manage_user(uuid, superuser, :force=>true)
      else
        raise RightScale::LoginManager::SystemConflict, "A user with UID #{uid} already exists and is " +
                                                        "not managed by RightScale"
      end

      username
    end
def create_user(username, uuid, superuser)
      uid = LoginUserManager.uuid_to_uid(uuid)

      if uid_exists?(uid, ['rightscale'])
        username = uid_to_username(uid)
      elsif !uid_exists?(uid)
        username  = pick_username(username)
        yield(username) if block_given?
        add_user(username, uid)
        modify_group('rightscale', :add, username)

        # NB it is SUPER IMPORTANT to pass :force=>true here. Due to an oddity in Ruby's Etc
        # extension, a user who has recently been added, won't seem to be a member of
        # any groups until the SECOND time we enumerate his group membership.
        manage_user(uuid, superuser, :force=>true)
      else
        raise RightScale::LoginManager::SystemConflict, "A user with UID #{uid} already exists and is " +
                                                        "not managed by RightScale"
      end

      username
    end
Ensure that a given user exists and that his group membership is correct.

 === Parameters
 username(String):: preferred username of RightScale user
 uuid(String):: RightScale user's UUID
 superuser(Boolean):: whether the user should have sudo privileges

 === Block
 If a block is given AND the user needs to be created, yields to the block
 with the to-be-created account's username, before creating it. This gives
 the caller a chance to provide interactive feedback to the user.

 === Return
 username(String):: user's actual username (may vary from preferred username)

 === Raise
 (LoginManager::SystemConflict):: if an existing non-RightScale-managed UID prevents us from creating a user