foreman_virt_who_configure 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a6d5edff03f44341f5a5c589b370b07df3fc79be8da03cc15a8e510c3bbab25
4
- data.tar.gz: 14532602b8e22287a71eae220793f2865bed9265630b25ee326bb9b457cbabf2
3
+ metadata.gz: 4530753c078a8fb15731435042afcbc985207fe160b96d242e04ecfc9d2078f2
4
+ data.tar.gz: 8013fca41321555482fe77a5203d7558b7828cfe7989208c4121686aa8c5dc2f
5
5
  SHA512:
6
- metadata.gz: 70d8749e99f5ca805edda408c2fe9bb2013c6df149bcf403d79405c88363889e73170c6f3180f6b1b5ee0c42565649b5b4b68bbba86cd654af831a832de4ed1c
7
- data.tar.gz: d762a6229d23557e188accde65b70a32faec53d98f62b55914e9f380e18671feb401fc7df033fbe20e74527e1aa860f319c95923a39fa682c31c7d9cd7aeda90
6
+ metadata.gz: 45f214c29a0c4e76fb92834bb6f5a124fbac03788e5e235da28dfe798be08d7a36c121d50e7e135bc5fb78a93ba6616784965e76ec6a1ea46949207c0c99e706
7
+ data.tar.gz: 3f66cb56f3efa3e59c016e40d22ff0f9aeff357be3901f2c7937e3eeef98bfb802d7ae762ec83f40030dc4211b2f6c81c134127d548b9dc8162f9a50016e04bf
@@ -35,7 +35,13 @@ function virt_who_update_hypervisor_fields() {
35
35
  element.closest('.form-group').toggle(selected_type == 'kubevirt');
36
36
  var element = $('#foreman_virt_who_configure_config_hypervisor_server');
37
37
  element.closest('.form-group').toggle(selected_type != 'kubevirt');
38
+ var element = $('#foreman_virt_who_configure_config_ahv_update_interval');
39
+ element.closest('.form-group').toggle(selected_type == 'ahv');
40
+ var element = $('#foreman_virt_who_configure_config_ahv_internal_debug');
41
+ element.closest('.form-group').toggle(selected_type == 'ahv');
38
42
  virt_who_update_listing_mode();
43
+ var element = $('#foreman_virt_who_configure_config_prism_flavor');
44
+ element.closest('.form-group').toggle(selected_type == 'ahv');
39
45
  }
40
46
 
41
47
  function virt_who_update_credentials_help() {
@@ -53,9 +59,23 @@ function virt_who_update_credentials_help() {
53
59
  });
54
60
  }
55
61
 
62
+ function virt_who_update_ahv_debug() {
63
+ var element = $('#foreman_virt_who_configure_config_ahv_internal_debug');
64
+ var element_debug = $('#foreman_virt_who_configure_config_debug');
65
+
66
+ element.mouseenter(function(){
67
+ var inline_help_popover_ahv = element.parents('.form-group').find('.help-inline a[rel=popover]');
68
+ var inline_help_popover_global = element_debug.parents('.form-group').find('.help-inline a[rel=popover]');
69
+ inline_help_popover_ahv.popover('show');
70
+ inline_help_popover_global.popover('show');
71
+ });
72
+ }
73
+
56
74
  $(document).ready(function () {
57
75
  virt_who_update_listing_mode();
58
76
  virt_who_update_hypervisor_fields();
77
+ virt_who_update_ahv_debug();
78
+
59
79
  $('#foreman_virt_who_configure_config_listing_mode').change(virt_who_update_listing_mode);
60
80
  $('#foreman_virt_who_configure_config_hypervisor_type').change(virt_who_update_credentials_help);
61
81
  $('#foreman_virt_who_configure_config_hypervisor_type').change(virt_who_update_hypervisor_fields);
@@ -47,14 +47,18 @@ module ForemanVirtWhoConfigure
47
47
  param :exclude_host_parents, String, :desc => N_("Applicable only for esx provider type. Hosts which parent (usually ComputeResource) name is specified in comma-separated list in this option will <b>NOT</b> be reported. Wildcards and regular expressions are supported, multiple records must be separated by comma. Put the value into the double-quotes if it contains special characters like comma. All new line characters will be removed in resulting configuration file, white spaces are removed from beginning and end."), :required => false
48
48
  param :hypervisor_id, Config::HYPERVISOR_IDS, :desc => N_("Specifies how the hypervisor will be identified."), :required => true
49
49
  param :hypervisor_type, Config::HYPERVISOR_TYPES.keys, :desc => N_("Hypervisor type"), :required => true
50
- param :hypervisor_server, String, :desc => N_("Fully qualified host name or IP address of the hypervisor"), :required => true
51
- param :hypervisor_username, String, :desc => N_("Account name by which virt-who is to connect to the hypervisor."), :required => true
52
- param :hypervisor_password, String, :desc => N_("Hypervisor password, required for all hypervisor types except for libvirt"), :required => false
50
+ param :hypervisor_server, String, :desc => N_("Fully qualified host name or IP address of the hypervisor"), :required => false
51
+ param :hypervisor_username, String, :desc => N_("Account name by which virt-who is to connect to the hypervisor."), :required => false
52
+ param :hypervisor_password, String, :desc => N_("Hypervisor password, required for all hypervisor types except for libvirt/kubevirt."), :required => false
53
53
  param :satellite_url, String, :desc => N_("Foreman server FQDN"), :required => true
54
54
  param :debug, :bool, :desc => N_("Enable debugging output")
55
+ param :kubeconfig_path, String, :desc => N_('Configuration file containing details about how to connect to the cluster and authentication details.'), :required => false
55
56
  param :http_proxy_id, Integer, :desc => N_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers.')
56
57
  param :no_proxy, String, :desc => N_("Ignore proxy. A comma-separated list of hostnames or domains or ip addresses to ignore proxy settings for. Optionally this may be set to * to bypass proxy settings for all hostnames domains or ip addresses.")
57
58
  param :organization_id, Integer, :required => true, :desc => N_("Organization of the virt-who configuration") if ::SETTINGS[:organizations_enabled]
59
+ param :prism_flavor, Config::PRISM_FLAVORS.keys, :desc => N_("Select the Prism flavor you are connecting to"), :required => false
60
+ param :ahv_update_interval, Integer, :desc => N_("The frequency of VM-to-host mapping updates for AHV(in seconds)"), :required => false
61
+ param :ahv_internal_debug, :bool, :desc => N_("Option Enable debugging output is required to enable AHV internal debug. It provides extra AHV debug information when both options are enabled"), :required => false
58
62
  end
59
63
  end
60
64
 
@@ -5,7 +5,8 @@ module ForemanVirtWhoConfigure
5
5
  'esx' => _('VMware vCenter server’s fully qualified host name or IP address.'),
6
6
  'hyperv' => _('Microsoft Hyper-V fully qualified host name or IP address.'),
7
7
  'libvirt' => _('Libvirt server’s fully qualified host name or IP address. You can also specify preferred schema, for example: <code>qemu+ssh://libvirt.example.com/system</code>. If you use SSH, make sure you setup root\'s SSH key on target host for a user specified at hypervisor username field'),
8
- 'kubevirt' => _('Container-native virtualization’s fully qualified host name or IP address. In order to connect to the cluster it is required to provide path to kubeconfig which contains connection details and authentication token.')
8
+ 'kubevirt' => _('Container-native virtualization’s fully qualified host name or IP address. In order to connect to the cluster it is required to provide path to kubeconfig which contains connection details and authentication token.'),
9
+ 'ahv' => _('Nutanix AHV’s IP address.')
9
10
  }
10
11
  end
11
12
 
@@ -14,7 +15,8 @@ module ForemanVirtWhoConfigure
14
15
  'esx' => _('Account name by which virt-who is to connect to the hypervisor, in the format <code>domain_name\account_name</code>. Note that only a single backslash separates the values for domain_name and account_name. If you are using a domain account, and the global configuration file <code>/etc/virt-who.conf</code>, then <b>two</b> backslashes are required. For further details, see <a href="https://access.redhat.com/solutions/1270223">Red Hat Knowledgebase solution How to use a windows domain account with virt-who</a> for more information.'),
15
16
  'hyperv' => _('Account name by which virt-who is to connect to the hypervisor. By default this is <code>Administrator</code>. To use an alternate account, create a user account and assign that account to the following groups (Windows 2012 Server): Hyper-V Administrators and Remote Management Users.'),
16
17
  'libvirt' => _('Account name by which virt-who is to connect to the hypervisor. Virt-who does not support password based authentication, you must manually setup SSH key, see <a href="https://access.redhat.com/solutions/1515983">Red Hat Knowledgebase solution How to configure virt-who for a KVM host</a> for more information.'),
17
- 'kubevirt' => ''
18
+ 'kubevirt' => '',
19
+ 'ahv' => _('Account name by which virt-who is to connect to Nutanix AHV.')
18
20
  }
19
21
  end
20
22
 
@@ -6,7 +6,8 @@ module ForemanVirtWhoConfigure
6
6
  :satellite_url, :http_proxy_id, :no_proxy, :name,
7
7
  # API parameter filtering_mode gets translated to listing_mode in the controller
8
8
  # We keep both params permitted for compatibility with 1.11
9
- :listing_mode, :filtering_mode, :filter_host_parents, :exclude_host_parents, :kubeconfig_path
9
+ :listing_mode, :filtering_mode, :filter_host_parents, :exclude_host_parents, :kubeconfig_path,
10
+ :prism_flavor, :ahv_update_interval, :ahv_internal_debug
10
11
  ]
11
12
  audited :except => [ :hypervisor_password, :last_report_at, :out_of_date_at ], :associations => []
12
13
  include Authorizable
@@ -33,7 +34,8 @@ module ForemanVirtWhoConfigure
33
34
  'esx' => 'VMware vSphere / vCenter (esx)',
34
35
  'hyperv' => 'Microsoft Hyper-V (hyperv)',
35
36
  'libvirt' => 'libvirt',
36
- 'kubevirt' => 'Container-native virtualization'
37
+ 'kubevirt' => 'Container-native virtualization',
38
+ 'ahv' => 'Nutanix AHV (ahv)'
37
39
  }
38
40
 
39
41
  HYPERVISOR_DEFAULT_TYPE = 'esx'
@@ -65,6 +67,15 @@ module ForemanVirtWhoConfigure
65
67
  }
66
68
  )
67
69
 
70
+ PRISM_FLAVORS = {
71
+ 'central' => N_('Prism Central'),
72
+ 'element' => N_('Prism Element')
73
+ }
74
+
75
+ AHV_VALID_OPTIONS = %w(prism_flavor ahv_update_interval ahv_internal_debug)
76
+ KUBEVIRT_VALID_OPTIONS = %w(kubeconfig_path)
77
+ KUBEVIRT_INVALID_OPTIONS = %w(hypervisor_server hypervisor_username)
78
+
68
79
  include Encryptable
69
80
  encrypts :hypervisor_password
70
81
 
@@ -97,11 +108,16 @@ module ForemanVirtWhoConfigure
97
108
  validates :hypervisor_password, :presence => true, :if => Proc.new { |c| c.hypervisor_type != 'libvirt' && c.hypervisor_type != 'kubevirt' }
98
109
  validates :hypervisor_username, :presence => true, :if => Proc.new { |c| c.hypervisor_type != 'kubevirt' }
99
110
  validates :hypervisor_server, :presence => true, :if => Proc.new { |c| c.hypervisor_type != 'kubevirt' }
111
+ validates :kubeconfig_path, :presence => true, :if => Proc.new { |c| c.hypervisor_type == 'kubevirt' }
100
112
  validates :hypervisor_type, :inclusion => HYPERVISOR_TYPES.keys
101
113
  validates :hypervisor_id, :inclusion => HYPERVISOR_IDS
102
114
  validates :interval, :inclusion => AVAILABLE_INTERVALS.keys.map(&:to_i)
103
115
  validates :listing_mode, :inclusion => FILTERING_MODES.keys.map(&:to_i)
116
+ validates :ahv_update_interval, numericality: { only_integer: true, allow_nil: true, greater_than: 0 }, :if => Proc.new { |c| c.hypervisor_type == 'ahv' }
117
+ validates :prism_flavor, :inclusion => {:in => PRISM_FLAVORS.keys, :message => "should be either central or element"}, :if => Proc.new { |c| c.hypervisor_type == 'ahv' }
104
118
  validate :validates_whitelist_blacklist
119
+ validate :validates_debug_settings, :if => Proc.new { |c| c.hypervisor_type == 'ahv' }
120
+ validate :validates_hypervisor_options
105
121
 
106
122
  def validates_whitelist_blacklist
107
123
  case listing_mode.to_i
@@ -116,6 +132,18 @@ module ForemanVirtWhoConfigure
116
132
  end
117
133
  end
118
134
 
135
+ def validates_debug_settings
136
+ if ahv_internal_debug && !debug
137
+ errors.add(:ahv_internal_debug, "Enable debugging output is required for Enable AHV debug")
138
+ end
139
+ end
140
+
141
+ def validates_hypervisor_options
142
+ invalid = hypervisor_type == 'kubevirt' ? KUBEVIRT_INVALID_OPTIONS : KUBEVIRT_VALID_OPTIONS
143
+ invalid.concat(AHV_VALID_OPTIONS) unless hypervisor_type == 'ahv'
144
+ invalid.each { |f| errors.add(f, "Invalid option for hypervisor [#{hypervisor_type}]") if eval(f).present? }
145
+ end
146
+
119
147
  validates_lengths_from_database
120
148
 
121
149
  before_validation :remove_whitespaces
@@ -120,7 +120,7 @@ env=Library#{connection_details}#{filtering}
120
120
  rhsm_hostname=#{satellite_url}
121
121
  rhsm_username=#{service_user_username}
122
122
  rhsm_encrypted_password=$user_password
123
- rhsm_prefix=/rhsm#{kubeconfig}
123
+ rhsm_prefix=/rhsm#{kubeconfig}#{ahv_config_options}
124
124
  EOF
125
125
  if [ $? -ne 0 ]; then result_code=$(($result_code|#{error_code(:virt_who_config_file_issue)})); fi
126
126
 
@@ -165,6 +165,18 @@ encrypted_password=$cr_password"
165
165
  end
166
166
  end
167
167
 
168
+ def ahv_config_options
169
+ if config.hypervisor_type == 'ahv'
170
+ prism_central = config.prism_flavor == "central"
171
+ update_interval = config.ahv_update_interval.present? ? "\nupdate_interval=#{config.ahv_update_interval}" : nil
172
+ internal_debug = config.ahv_internal_debug.present? ? "\ninternal_debug=#{config.ahv_internal_debug}" : nil
173
+
174
+ "\nprism_central=#{prism_central}#{internal_debug}#{update_interval}"
175
+ else
176
+ ""
177
+ end
178
+ end
179
+
168
180
  def error_handling
169
181
  CONFIGURATION_RESULTS.map do |result|
170
182
  "[ $(($result_code&#{result.code})) -ge 1 ] && echo '#{result.message}'"
@@ -9,7 +9,8 @@ end
9
9
  attributes :name, :interval, :organization_id, :whitelist, :blacklist, :hypervisor_id,
10
10
  :hypervisor_type, :hypervisor_server, :hypervisor_username, :debug,
11
11
  :satellite_url, :proxy, :no_proxy, :status, :last_report_at, :out_of_date_at,
12
- :filter_host_parents, :exclude_host_parents, :kubeconfig_path
12
+ :filter_host_parents, :exclude_host_parents, :kubeconfig_path,
13
+ :prism_flavor, :ahv_update_interval, :ahv_internal_debug
13
14
 
14
15
  child :http_proxy do
15
16
  attributes :id, :name, :url
@@ -52,6 +52,9 @@
52
52
  <%= config_attribute :http_proxy_id, @config.http_proxy.full_url, _('HTTP Proxy') if @config.http_proxy.present? %>
53
53
  <%= config_attribute :no_proxy, @config.no_proxy, _('Ignore Proxy') if @config.no_proxy.present? %>
54
54
  <%= config_attribute :kubeconfig_path, @config.kubeconfig_path if @config.hypervisor_type == 'kubevirt' %>
55
+ <%= config_attribute :prism_flavor, @config.prism_flavor if @config.hypervisor_type == 'ahv' %>
56
+ <%= config_attribute :ahv_update_interval, @config.ahv_update_interval if @config.hypervisor_type == 'ahv' %>
57
+ <%= config_attribute :ahv_internal_debug, checked_icon(@config.ahv_internal_debug) if @config.hypervisor_type == 'ahv' %>
55
58
  </div>
56
59
  </div>
57
60
  </div>
@@ -22,4 +22,10 @@
22
22
  inline_help_popover(_('HTTP proxy that should be used for communication between the server on which virt-who is running and the hypervisors and virtualization managers. Leave this blank if no proxy is used.').html_safe)) %>
23
23
  <%= text_f f, :no_proxy, inline_help_popover(_('A comma-separated list of hostnames or domains or ip addresses to ignore proxy settings for. Optionally this may be set to <code>*</code> to bypass proxy settings for all hostnames domains or ip addresses.')).merge(:label => _('Ignore proxy')) %>
24
24
  <%= text_f f, :kubeconfig_path, inline_help_popover(_('Configuration file containing details about how to connect to the cluster and authentication details')).merge(:label => _('Path to kubeconfig file')) %>
25
+
26
+ <%= selectable_f f, :prism_flavor, {'' => 'Nothing selected'}.merge(ForemanVirtWhoConfigure::Config::PRISM_FLAVORS).map { |k,v| [_(v), k] },
27
+ {}, { label: _('Prism Flavor'), :required => true }.merge(
28
+ inline_help_popover(_("Select the Prism flavor you are connecting to"))) %>
29
+ <%= text_f f, :ahv_update_interval, inline_help_popover(_('The frequency of VM-to-host mapping updates for AHV(in seconds)')).merge(:label => _('AHV update interval')) %>
30
+ <%= checkbox_f f, :ahv_internal_debug, inline_help_popover(_('Option Enable debugging output is required to enable AHV internal debug. It provides extra AHV debug information when both options are enabled ')).merge(:label => _('Enable AHV debug')) %>
25
31
  </div>
@@ -0,0 +1,7 @@
1
+ class AddAhvToConfig < ActiveRecord::Migration[6.0]
2
+ def change
3
+ add_column :foreman_virt_who_configure_configs, :prism_flavor, :string, :null => true
4
+ add_column :foreman_virt_who_configure_configs, :ahv_update_interval, :integer, :null => true
5
+ add_column :foreman_virt_who_configure_configs, :ahv_internal_debug, :boolean, :null => true
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanVirtWhoConfigure
2
- VERSION = '0.5.7'.freeze
2
+ VERSION = '0.5.8'.freeze
3
3
  end
@@ -17,7 +17,6 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
17
17
  :http_proxy_id => @http_proxy.id,
18
18
  :no_proxy => nil
19
19
  )
20
-
21
20
  @out_of_date_config = FactoryBot.create(:virt_who_config, :out_of_date)
22
21
  @ok_config = FactoryBot.create(:virt_who_config, :ok)
23
22
  end
@@ -128,6 +127,45 @@ class ForemanVirtWhoConfigure::Api::V2::ConfigsControllerTest < ActionController
128
127
  assert_equal @out_of_date_config.virt_who_config_script(:bash_script), response
129
128
  end
130
129
 
130
+ test 'should fail without kubeconfig_path in kubeconfig config' do
131
+ org = FactoryBot.create(:organization)
132
+ post :create, :params => { :foreman_virt_who_configure_config => { :name => 'my new config',
133
+ :filtering_mode => ForemanVirtWhoConfigure::Config::UNLIMITED,
134
+ :hypervisor_id => 'uuid',
135
+ :hypervisor_type => 'kubevirt',
136
+ :satellite_url => "foreman.example.com",
137
+ :organization_id => org.id }
138
+ }, :session => set_session_user
139
+
140
+ assert_response :unprocessable_entity
141
+
142
+ response = ActiveSupport::JSON.decode(@response.body)
143
+ assert_equal "Kubeconfig path can't be blank", response['error']['full_messages'].join('')
144
+ end
145
+
146
+ test 'should not accept kubeconfig for other hypervisor types' do
147
+ org = FactoryBot.create(:organization)
148
+ post :create, :params => { :foreman_virt_who_configure_config => { :name => 'my new config',
149
+ :interval => 240,
150
+ :filtering_mode => ForemanVirtWhoConfigure::Config::BLACKLIST,
151
+ :blacklist => ' a,b ',
152
+ :hypervisor_id => 'uuid',
153
+ :hypervisor_type => 'esx',
154
+ :hypervisor_server => "vmware.example.com",
155
+ :hypervisor_username => "root",
156
+ :hypervisor_password => "password",
157
+ :debug => true,
158
+ :satellite_url => "foreman.example.com",
159
+ :kubeconfig_path => '/tmp/food',
160
+ :organization_id => org.id }
161
+ }, :session => set_session_user
162
+
163
+ assert_response :unprocessable_entity
164
+
165
+ response = ActiveSupport::JSON.decode(@response.body)
166
+ assert_equal "Kubeconfig path Invalid option for hypervisor [esx]", response['error']['full_messages'].join('')
167
+ end
168
+
131
169
  test "should create the config" do
132
170
  org = FactoryBot.create(:organization)
133
171
  post :create, :params => { :foreman_virt_who_configure_config => { :name => 'my new config',
@@ -128,5 +128,29 @@ module ForemanVirtWhoConfigure
128
128
  assert_includes bash_script_output, 'step 1 "Installing virt-who"'
129
129
  end
130
130
  end
131
+
132
+ describe 'nutanix ahv' do
133
+ test 'options specific to ahv are all set' do
134
+ config.hypervisor_type = 'ahv'
135
+ config.prism_flavor = 'central'
136
+ config.ahv_update_interval = 100
137
+ config.ahv_internal_debug = true
138
+
139
+ assert_includes output, 'type=ahv'
140
+ assert_includes output, 'prism_central=true'
141
+ assert_includes output, 'update_interval=100'
142
+ assert_includes output, 'internal_debug=true'
143
+ end
144
+
145
+ test 'options specific to ahv are not all set' do
146
+ config.hypervisor_type = 'ahv'
147
+ config.prism_flavor = 'central'
148
+
149
+ assert_includes output, 'type=ahv'
150
+ assert_includes output, 'prism_central=true'
151
+ assert_not_includes output, 'update_interval='
152
+ assert_not_includes output, 'update_interval='
153
+ end
154
+ end
131
155
  end
132
156
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_virt_who_configure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman virt-who-configure team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-28 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: katello
@@ -111,6 +111,7 @@ files:
111
111
  - db/migrate/20201211160234_add_foreign_key_proxy_id.rb
112
112
  - db/migrate/20210413165147_delete_xen_profiles.rb
113
113
  - db/migrate/20210608100743_delete_rhevm_profiles.rb
114
+ - db/migrate/20210910184516_add_ahv_to_config.rb
114
115
  - lib/foreman_virt_who_configure.rb
115
116
  - lib/foreman_virt_who_configure/engine.rb
116
117
  - lib/foreman_virt_who_configure/version.rb