foreman_kubevirt 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 0b699e5fa9739119a5e81d95db30e4f714136e5c
4
- data.tar.gz: 32ed36107c6cf8b3c96d9052c7a7359de84e8405
3
+ metadata.gz: eb14b9910b51e87d3bd699260b39936ecf751d2e
4
+ data.tar.gz: a2ff30c7286f23678e50f1bcafc77b27abe47ab4
5
5
  SHA512:
6
- metadata.gz: 39b465a6119bb777977a49a82cf0e2d9570ab46433a4d9ef46b323b386954a42b348b7d9e1ddaf09c57355f3a5bf61e9982c13b8b1642c29b5c430624c55abf6
7
- data.tar.gz: bd8db338ef655d007f0589cc34c9d3514768222413460d0fd45a4697af73020f100e2917f35271bda8672ba62b691a9c6cb0bd9d409d6f183dce59e4a78dcb18
6
+ metadata.gz: 406d06d9e17c37437d133513d44e89e6c006b99510a96145895e6584080dcc7bd3ea2f7e25d024b12351bfece8d51e2b08e6253cf52e96f9c128bc4bc54d696f
7
+ data.tar.gz: d16ddc90d2ad8652a71e05840fdbe605bc9ed20dccf38242bc5d767e03c814d7ba748eece054f09dbb084e2b51624b94e9a1dc95e0d1d465d3ce8a1cad35f64d
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  The ```foreman_kubevirt ``` plugin enables managing of [KubeVirt](https://kubevirt.io) as a Compute Resource in Foreman.
5
5
 
6
6
  * Website: [TheForeman.org](http://theforeman.org)
7
- * Wiki: [Foreman wiki](http://projects.theforeman.org/projects/foreman/wiki/About)
7
+ * Issues: [foreman Redmine](http://projects.theforeman.org/projects/kubevirt/issues/)
8
8
  * Community and support: #theforeman for general support, #theforeman-dev for development chat in [Freenode](irc.freenode.net)
9
9
  * Mailing lists:
10
10
  * [foreman-users](https://groups.google.com/forum/?fromgroups#!forum/foreman-users)
@@ -19,7 +19,7 @@ Please see the Foreman manual for appropriate instructions:
19
19
 
20
20
 
21
21
  ### Building the plugin from source
22
- # git clone https://github.com/masayag/foreman_kubevirt.git
22
+ # git clone https://github.com/theforeman/foreman_kubevirt
23
23
  # cd foreman_kubevirt
24
24
  # gem build foreman_kubevirt.gemspec # the output will be gem named foreman_kubevirt-x.y.z.gem, where x.y.z should be replaced with the actual version
25
25
 
@@ -123,6 +123,10 @@ Or by retrieving from the secret of service account *my-account* under the *defa
123
123
  # kubectl get secret $KUBE_SECRET -n default -o jsonpath='{.data.ca\.crt}' | base64 -d
124
124
  ```
125
125
 
126
+ ## Documentation
127
+
128
+ See the [Foreman Kubevirt manuals](https://theforeman.org/plugins/foreman_kubevirt/) on the Foreman web site.
129
+
126
130
  ## Tests
127
131
 
128
132
  Tests should be invoked from the *foreman* directory by:
@@ -11,21 +11,24 @@ bootableRadio = function (item) {
11
11
 
12
12
  cniProviderSelected = function (item) {
13
13
  const selected = $(item).val().toLowerCase();
14
- podSelected = selected == "pod";
15
- changeNetworkElementVisibility(!podSelected);
16
- }
14
+ const networks = $(item).parentsUntil('.fields').parent().find('#networks');
17
15
 
18
- function changeNetworkElementVisibility(toggle) {
19
- if (toggle) {
20
- $('.kubevirt-network').parents('.form-group').css('display', '');
16
+ if (selected == "pod") {
17
+ disableDropdown(networks);
21
18
  } else {
22
- $('.kubevirt-network').parents('.form-group').css('display', 'none');
19
+ enableDropdown(networks);
23
20
  }
24
21
  }
25
22
 
26
- function changeNetworkElementVisibilityOnLoad() {
27
- selected = $('select.kubevirt-cni-provider').val().toLowerCase();
28
- changeNetworkElementVisibility(selected != "pod");
23
+ function disableDropdown(item) {
24
+ item.hide();
25
+ item.attr('disabled', true);
26
+ $(item).closest('.removable-item').find('.kubevirt-network').prop('disabled', true);
29
27
  }
30
28
 
31
- $(document).ready(changeNetworkElementVisibilityOnLoad);
29
+ function enableDropdown(item) {
30
+ $(item).closest('.removable-item').find('.kubevirt-network').prop('disabled', false);
31
+ item.attr('disabled', false);
32
+ item.find(':input').attr('disabled', false);
33
+ item.show();
34
+ }
@@ -2,18 +2,6 @@ module FogExtensions
2
2
  module Kubevirt
3
3
  module Volume
4
4
  extend ActiveSupport::Concern
5
-
6
- attr_writer :storage_class
7
- attr_writer :capacity
8
-
9
- def capacity
10
- pvc.requests[:storage] unless pvc.nil?
11
- end
12
-
13
- def storage_class
14
- pvc&.storage_class
15
- end
16
-
17
5
  def bootable
18
6
  boot_order == 1
19
7
  end
@@ -83,12 +83,14 @@ module ForemanKubevirt
83
83
  def new_volume(attr = {})
84
84
  return unless new_volume_errors.empty?
85
85
 
86
- Fog::Kubevirt::Compute::Volume.new(attr)
86
+ vol = Fog::Kubevirt::Compute::Volume.new(attr)
87
+ vol.boot_order = 1 if attr[:bootable] == "on" || attr[:bootable] == "true"
88
+ vol
87
89
  end
88
90
 
89
91
  def new_volume_errors
90
92
  errors = []
91
- errors.push _('no Persistent Volumes available on provider') if storage_classes.empty?
93
+ errors.push _('no Storage Classes available on provider') if storage_classes.empty?
92
94
  errors
93
95
  end
94
96
 
@@ -128,6 +130,12 @@ module ForemanKubevirt
128
130
  # "capacity"=>"2"
129
131
  # }
130
132
  # }
133
+
134
+ def verify_booting_from_image_is_possible(volumes)
135
+ raise ::Foreman::Exception.new N_('It is not possible to set a bootable volume and image based provisioning.') if
136
+ volumes.any? { |_, v| v["bootable"] == "true" }
137
+ end
138
+
131
139
  def create_vm(args = {})
132
140
  options = vm_instance_defaults.merge(args.to_hash.deep_symbolize_keys)
133
141
  logger.debug("creating VM with the following options: #{options.inspect}")
@@ -135,13 +143,14 @@ module ForemanKubevirt
135
143
 
136
144
  image = args["image_id"]
137
145
  volumes_attributes = args["volumes_attributes"]
138
- raise "VM should be created based on Persistent Volume Claim or Image" unless (volumes_attributes.present? || image)
146
+ raise ::Foreman::Exception.new N_('VM should be created based on Persistent Volume Claim or Image') unless (volumes_attributes.present? || image)
139
147
 
140
148
  # Add image as volume to the virtual machine
141
149
  image_provision = args["provision_method"] == "image"
142
150
  if image_provision
151
+ verify_booting_from_image_is_possible(volumes_attributes)
143
152
  volume = Fog::Kubevirt::Compute::Volume.new
144
- raise "VM should be created based on an image" unless image
153
+ raise ::Foreman::Exception.new N_('VM should be created based on an image') unless image
145
154
 
146
155
  volume.info = image
147
156
  volume.boot_order = 1
@@ -149,6 +158,7 @@ module ForemanKubevirt
149
158
  volumes << volume
150
159
  end
151
160
 
161
+ volumes_attributes.each { |_, v| raise ::Foreman::Exception.new N_('Capacity was not found') if v["capacity"].empty? }
152
162
  volumes_attributes&.each_with_index do |(_, v), index|
153
163
  # Add PVC as volumes to the virtual machine
154
164
  pvc_name = options[:name].gsub(/[._]+/, '-') + "-claim-" + (index + 1).to_s
@@ -316,6 +326,15 @@ module ForemanKubevirt
316
326
  vm_attrs
317
327
  end
318
328
 
329
+ def new_vm(attr = {})
330
+ vm = super
331
+ interfaces = nested_attributes_for :interfaces, attr[:interfaces_attributes]
332
+ interfaces.map { |i| vm.interfaces << new_interface(i) }
333
+ volumes = nested_attributes_for :volumes, attr[:volumes_attributes]
334
+ volumes.map { |v| vm.volumes << new_volume(v) }
335
+ vm
336
+ end
337
+
319
338
  def associated_host(vm)
320
339
  associate_by("mac", vm.mac)
321
340
  end
@@ -4,7 +4,8 @@
4
4
  <%= password_f f, :password, :label => _("Token"), :required => true,
5
5
  :keep_value => true, :unset => unset_password?,
6
6
  :help_block => _("e.g. eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9..."),
7
- :help_inline => documentation_button('5.2.10PasswordEncryption') %>
7
+ :help_inline => documentation_button('/foreman_kubevirt/0.x/index.html#4.1SettingComputeResourceTokenandX509CAvalues',
8
+ root_url: 'https://theforeman.org/plugins') %>
8
9
 
9
10
  <%= textarea_f f, :ca_cert, :label => _("X509 Certification Authorities"),
10
11
  :placeholder => _("Optionally provide a CA, or a correctly ordered CA chain or a path to a file. If left blank - insecure.") %>
@@ -5,11 +5,16 @@
5
5
  :label_size => "col-md-3",
6
6
  :onchange => "cniProviderSelected(this)" %>
7
7
 
8
- <%= select_f f, :network, compute_resource.networks,
8
+ <% pod = f.object.cni_provider == 'pod' %>
9
+
10
+ <div id='networks' class='<%= 'hide' if pod %>'>
11
+ <%= select_f f, :network,
12
+ compute_resource.networks,
9
13
  :id,
10
14
  :name,
11
15
  {},
12
- :disabled => !new_vm || f.object.cni_provider == 'pod',
16
+ :disabled => !new_vm || pod,
13
17
  :class => "col-md-3 kubevirt-network",
14
18
  :label => _('Network'),
15
19
  :label_size => "col-md-3" %>
20
+ </div>
@@ -15,7 +15,7 @@
15
15
 
16
16
  <% bootable = f.object.boot_order.nil? ? false : f.object.bootable %>
17
17
  <%= field(f, :bootable, :label => _('Bootable'), :label_size => "col-md-2") do
18
- radio_button_f f, :bootable, {:disabled => !new_vm, :checked => bootable, :onclick => 'bootableRadio(this)',
18
+ radio_button_f f, :bootable, {:disabled => !new_vm, :value=> 'true', :checked => bootable, :onclick => 'bootableRadio(this)',
19
19
  :text => _('Only one volume can be bootable')}
20
20
  end %>
21
21
  <% end %>
@@ -1,3 +1,3 @@
1
1
  module ForemanKubevirt
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -32,7 +32,7 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
32
32
  end
33
33
 
34
34
  test "create_vm image based" do
35
- vm_args = { "cpu_cores" => "1", "memory" => "1073741824", "start" => "1", "volumes_attributes" => { "1554649143334" => { "_delete" => "", "storage_class" => "local-storage", "capacity" => "1", "bootable" => "true" } }, "image_id" => "kubevirt/fedora-cloud-registry-disk-demo", "name" => "olive-kempter.example.com", "provision_method" => "image", "firmware_type" => :bios, "interfaces_attributes" => { "0" => { "cni_provider" => "multus", "network" => "ovs-foreman", "ip" => "192.168.111.184", "mac" => "a2:a4:a2:b2:a2:b6", "provision" => true } } }
35
+ vm_args = { "cpu_cores" => "1", "memory" => "1073741824", "start" => "1", "volumes_attributes" => { "1554649143334" => { "_delete" => "", "storage_class" => "local-storage", "capacity" => "1", "bootable" => "false" } }, "image_id" => "kubevirt/fedora-cloud-registry-disk-demo", "name" => "olive-kempter.example.com", "provision_method" => "image", "firmware_type" => :bios, "interfaces_attributes" => { "0" => { "cni_provider" => "multus", "network" => "ovs-foreman", "ip" => "192.168.111.184", "mac" => "a2:a4:a2:b2:a2:b6", "provision" => true } } }
36
36
  Fog.mock!
37
37
  compute_resource = new_kubevirt_vcr
38
38
  server = compute_resource.create_vm(vm_args)
@@ -42,4 +42,31 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
42
42
  assert_equal 2, server.disks.count
43
43
  assert_equal 1, server.interfaces.count
44
44
  end
45
+
46
+ test "should fail when creating a VM with_bootable flag and image based" do
47
+ vm_args = { "cpu_cores" => "1", "memory" => "1073741824", "start" => "1", "volumes_attributes" => { "1554649143334" => { "_delete" => "", "storage_class" => "local-storage", "capacity" => "1", "bootable" => "true" } }, "image_id" => "kubevirt/fedora-cloud-registry-disk-demo", "name" => "olive-kempter.example.com", "provision_method" => "image", "firmware_type" => :bios, "interfaces_attributes" => { "0" => { "cni_provider" => "multus", "network" => "ovs-foreman", "ip" => "192.168.111.184", "mac" => "a2:a4:a2:b2:a2:b6", "provision" => true } } }
48
+ Fog.mock!
49
+ compute_resource = new_kubevirt_vcr
50
+ assert_raise(Foreman::Exception) do
51
+ compute_resource.create_vm(vm_args)
52
+ end
53
+ end
54
+
55
+ test "should fail when creating a VM without an image or pvc " do
56
+ vm_args = { "cpu_cores" => "1", "memory" => "1073741824", "start" => "1", "volumes_attributes" => {}, "name" => "olive-kempter.example.com", "provision_method" => "image", "firmware_type" => :bios, "interfaces_attributes" => { "0" => { "cni_provider" => "multus", "network" => "ovs-foreman", "ip" => "192.168.111.184", "mac" => "a2:a4:a2:b2:a2:b6", "provision" => true } } }
57
+ Fog.mock!
58
+ compute_resource = new_kubevirt_vcr
59
+ assert_raise(Foreman::Exception) do
60
+ compute_resource.create_vm(vm_args)
61
+ end
62
+ end
63
+
64
+ test "should fail when creating a VM with PVC and not providing a capacity" do
65
+ vm_args = { "cpu_cores" => "1", "memory" => "1073741824", "start" => "1", "volumes_attributes" => { "1554649143334" => { "_delete" => "", "storage_class" => "local-storage", "bootable" => "false" } }, "image_id" => "kubevirt/fedora-cloud-registry-disk-demo", "name" => "olive-kempter.example.com", "provision_method" => "image", "firmware_type" => :bios, "interfaces_attributes" => { "0" => { "cni_provider" => "multus", "network" => "ovs-foreman", "ip" => "192.168.111.184", "mac" => "a2:a4:a2:b2:a2:b6", "provision" => true } } }
66
+ Fog.mock!
67
+ compute_resource = new_kubevirt_vcr
68
+ assert_raise(Foreman::Exception) do
69
+ compute_resource.create_vm(vm_args)
70
+ end
71
+ end
45
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_kubevirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moti Asayag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -94,9 +94,9 @@ files:
94
94
  - test/models/compute_resources/kubevirt_test.rb
95
95
  - test/test_plugin_helper.rb
96
96
  - test/unit/foreman_kubevirt_test.rb
97
- homepage: https://github.com/masayag/foreman_kubevirt
97
+ homepage: https://github.com/theforeman/foreman_kubevirt
98
98
  licenses:
99
- - GPL-3.0
99
+ - GPLv3
100
100
  metadata: {}
101
101
  post_install_message:
102
102
  rdoc_options: []