def manage_existing_users(new_policy_users)
      now = Time.now

      previous = {}
      if InstanceState.login_policy
        InstanceState.login_policy.users.each do |user|
          previous[user.uuid] = user
        end
      end

      current = {}
      new_policy_users.each do |user|
        current[user.uuid] = user
      end

      added   = current.keys - previous.keys
      removed = previous.keys - current.keys
      stayed  = current.keys & previous.keys

      removed.each do |k|
        begin
          user = current[k] || previous[k]
          LoginUserManager.manage_user(user.uuid, user.superuser, :disable => true)
        rescue Exception => e
          RightScale::Log.error("Failed to disable user '#{user.uuid}'", e) unless e.is_a?(ArgumentError)
        end
      end

      (added + stayed).each do |k|
        begin
          user = current[k] || previous[k]
          disable = !!(user.expires_at) && (now >= user.expires_at)
          LoginUserManager.manage_user(user.uuid, user.superuser, :disable => disable)
        rescue Exception => e
          RightScale::Log.error("Failed to manage existing user '#{user.uuid}'", e) unless e.is_a?(ArgumentError)
        end
      end
    rescue Exception => e
      RightScale::Log.error("Failed to manage existing users", e)
    end
def manage_existing_users(new_policy_users)
      now = Time.now

      previous = {}
      if InstanceState.login_policy
        InstanceState.login_policy.users.each do |user|
          previous[user.uuid] = user
        end
      end

      current = {}
      new_policy_users.each do |user|
        current[user.uuid] = user
      end

      added   = current.keys - previous.keys
      removed = previous.keys - current.keys
      stayed  = current.keys & previous.keys

      removed.each do |k|
        begin
          user = current[k] || previous[k]
          LoginUserManager.manage_user(user.uuid, user.superuser, :disable => true)
        rescue Exception => e
          RightScale::Log.error("Failed to disable user '#{user.uuid}'", e) unless e.is_a?(ArgumentError)
        end
      end

      (added + stayed).each do |k|
        begin
          user = current[k] || previous[k]
          disable = !!(user.expires_at) && (now >= user.expires_at)
          LoginUserManager.manage_user(user.uuid, user.superuser, :disable => disable)
        rescue Exception => e
          RightScale::Log.error("Failed to manage existing user '#{user.uuid}'", e) unless e.is_a?(ArgumentError)
        end
      end
    rescue Exception => e
      RightScale::Log.error("Failed to manage existing users", e)
    end
Schedules expiration of new users from policy and existing ones

 @param [Array<LoginUsers>] Array of updated users

 == Returns:
 @return [TrueClass] always returns true