Sha256: 3692a4c24a7f7a8ff37442941c8f261f57150d81ee05ac08deb13ef93389903f

Contents?: true

Size: 1.73 KB

Versions: 6

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

# Copyright 2018 Tristan Robert

# This file is part of ForemanFogProxmox.

# ForemanFogProxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# ForemanFogProxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.

module ProxmoxComputeResourcesHelper
  def user_token_expiration_date(compute_resource)
    expire = compute_resource.current_user_token_expire
  rescue ::Foreman::Exception => e
    return 'Has already expired. Please edit the compute resource to set a new valid one.' if e.message == 'User token expired'
  rescue StandardError => e
    logger.warn(format(_('failed to get identity client version: %<e>s'), e: e))
    raise e
  else
    return 'Never' if expire == 0

    Time.at(expire).utc
  end

  def cluster_nodes(compute_resource)
    nodes = compute_resource.nodes ? compute_resource.nodes.collect(&:node) : []
  rescue ::Foreman::Exception => e
    return [] if e.message == 'User token expired'
  rescue StandardError => e
    logger.warn(format(_('failed to get cluster nodes: %<e>s'), e: e))
    raise e
  else
    nodes
  end

  def proxmox_auth_methods_map
    [OpenStruct.new(id: 'access_ticket', name: '(Default) Access ticket'),
     OpenStruct.new(id: 'user_token', name: 'User token')]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_fog_proxmox-0.14.0 app/helpers/proxmox_compute_resources_helper.rb
foreman_fog_proxmox-0.13.4 app/helpers/proxmox_compute_resources_helper.rb
foreman_fog_proxmox-0.13.3 app/helpers/proxmox_compute_resources_helper.rb
foreman_fog_proxmox-0.13.2 app/helpers/proxmox_compute_resources_helper.rb
foreman_fog_proxmox-0.13.1 app/helpers/proxmox_compute_resources_helper.rb
foreman_fog_proxmox-0.13.0 app/helpers/proxmox_compute_resources_helper.rb