fog-kubevirt 1.2.2 → 1.2.3

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: 445aff4c53478ed34bda932d25161a63a5c3626a
4
- data.tar.gz: e2ad2b37177c59c61f1d57b20c7294f028ccad28
3
+ metadata.gz: 4e1ad47434b4be227ffa7e32f9435021980784c0
4
+ data.tar.gz: 78189c5ee24ea2f3a3314c1c32e242a2dc66a764
5
5
  SHA512:
6
- metadata.gz: 7fb2a57dc4d902e140442981ff5aa1f3acd0e6fda538f615f6be12e890eb9b825ed6879a0b4d96abcf9a313ab418aec0396e10c032fc19ad34a5c12f6221c786
7
- data.tar.gz: 32866fcaea0020147cb2688993fb3b3050c9b4eebe97945c0aa6ae2683eec6a419543c80f216d7527bb9b7fa9396e0414aa04c85f8552847e4527eed9193e655
6
+ metadata.gz: 6d128816adb81bb5e438348537003b6893305cf3df4c9ebac3a611db2ebb974bfbfa360fb6937e0ccaff0292ca68d2f410107fd3d02b440842d61619d2a064d3
7
+ data.tar.gz: 34b7f11414b8dec2720386485e25e2d0746579566828d5e2cebf85f75d2d27de9b9dce2774122b4674f7e65c9319b4c135ca5ef3affebd7e8ac0ed3a4f15f06d
@@ -34,6 +34,7 @@ module Fog
34
34
  cpu = domain[:cpu]
35
35
  mem = domain.dig(:resources, :requests, :memory)
36
36
  disks = parse_disks(domain[:devices][:disks])
37
+ networks = parse_networks(spec[:networks])
37
38
  vm = {
38
39
  :namespace => metadata[:namespace],
39
40
  :name => metadata[:name],
@@ -43,8 +44,8 @@ module Fog
43
44
  :disks => disks,
44
45
  :volumes => parse_volumes(spec[:volumes], disks),
45
46
  :status => object[:spec][:running].to_s == "true" ? "running" : "stopped",
46
- :interfaces => parse_interfaces(domain[:devices][:interfaces], object[:status].nil? ? [] : object[:status][:interfaces]),
47
- :networks => parse_networks(spec[:networks]),
47
+ :interfaces => parse_interfaces(domain[:devices][:interfaces], object[:status].nil? ? [] : object[:status][:interfaces], networks),
48
+ :networks => networks,
48
49
  :machine_type => domain.dig(:machine, :type)
49
50
  }
50
51
  vm[:owner_reference] = owner unless owner.nil?
@@ -4,8 +4,9 @@ module Fog
4
4
  module VmData
5
5
 
6
6
  class VmNetwork
7
- attr_accessor :name,
8
- :type # values: multus, pod, genie
7
+ attr_accessor :name, # inner name used to map to interface
8
+ :type, # values: multus, pod, genie
9
+ :network_name # name of network attachment definition
9
10
  end
10
11
 
11
12
  class VmDisk
@@ -12,7 +12,7 @@ module Fog
12
12
  #
13
13
  # @param object [Hash] A hash with raw interfaces data.
14
14
  #
15
- def parse_interfaces(object, object_status)
15
+ def parse_interfaces(object, object_status, networks)
16
16
  return {} if object.nil?
17
17
  nics = []
18
18
  object.each do |iface|
@@ -23,6 +23,13 @@ module Fog
23
23
  nic.mac_address = !status_iface.nil? && status_iface.key?(:mac) ? status_iface[:mac] : iface[:macAddress]
24
24
  nic.type = 'bridge' if iface.keys.include?(:bridge)
25
25
  nic.type = 'slirp' if iface.keys.include?(:slirp)
26
+
27
+ net = networks.detect { |n| n.name == iface[:name] }
28
+ if net
29
+ nic.cni_provider = net.type
30
+ nic.network = net.network_name
31
+ end
32
+
26
33
  nics << nic
27
34
  end
28
35
 
@@ -41,7 +48,10 @@ module Fog
41
48
  network = VmData::VmNetwork.new
42
49
  network.name = net[:name]
43
50
  network.type = 'pod' if net.keys.include?(:pod)
44
- network.type = 'multus' if net.keys.include?(:multus)
51
+ if net.keys.include?(:multus)
52
+ network.type = 'multus'
53
+ network.network_name = net[:multus][:networkName]
54
+ end
45
55
  network.type = 'genie' if net.keys.include?(:genie)
46
56
  networks << network
47
57
  end
@@ -128,7 +138,7 @@ module Fog
128
138
  end
129
139
 
130
140
  volume.config = v[volume.type.to_sym]
131
- disk = disks.select { |d| d.name == volume.name }.first
141
+ disk = disks.detect { |d| d.name == volume.name }
132
142
  volume.boot_order = disk.boot_order
133
143
  volume.bus = disk.bus if disk.respond_to?(:bus)
134
144
 
@@ -29,6 +29,7 @@ module Fog
29
29
  spec = object[:spec]
30
30
  domain = spec[:domain]
31
31
  disks = parse_disks(domain[:devices][:disks])
32
+ networks = parse_networks(spec[:networks])
32
33
  {
33
34
  :namespace => metadata[:namespace],
34
35
  :name => metadata[:name],
@@ -40,8 +41,8 @@ module Fog
40
41
  :memory => domain[:resources][:requests][:memory],
41
42
  :disks => disks,
42
43
  :volumes => parse_volumes(spec[:volumes], disks),
43
- :interfaces => parse_interfaces(domain[:devices][:interfaces], status[:interfaces]),
44
- :networks => parse_networks(spec[:networks]),
44
+ :interfaces => parse_interfaces(domain[:devices][:interfaces], status[:interfaces], networks),
45
+ :networks => networks,
45
46
  :ip_address => status.dig(:interfaces, 0, :ipAddress),
46
47
  :node_name => status[:nodeName],
47
48
  :status => status[:phase]
@@ -9,6 +9,8 @@ module Fog
9
9
  attribute :model
10
10
  attribute :ports
11
11
  attribute :boot_order
12
+ attribute :network
13
+ attribute :cni_provider
12
14
  alias :mac :mac_address
13
15
 
14
16
  def persisted?
@@ -47,13 +47,15 @@ module Fog
47
47
  disk
48
48
  end
49
49
 
50
- def vm_nic(mac_address: "")
50
+ def vm_nic(mac_address: "", network: "ovs-foreman")
51
51
  vm_nic = Fog::Kubevirt::Compute::VmNic.new
52
52
  vm_nic.mac_address = mac_address
53
53
  vm_nic.type = "bridge"
54
+ vm_nic.network = network
54
55
  vm_nic.model = nil
55
56
  vm_nic.ports = nil
56
57
  vm_nic.boot_order = nil
58
+ vm_nic
57
59
  end
58
60
 
59
61
  def get_server(name)
@@ -69,6 +71,7 @@ module Fog
69
71
  vm_network = Fog::Kubevirt::Compute::VmData::VmNetwork.new
70
72
  vm_network.name="ovs-foreman"
71
73
  vm_network.type="multus"
74
+ vm_network.network_name="ovs-foreman"
72
75
 
73
76
  interfaces = name != 'no_interfaces' ? [vm_nic(mac_address: "a2:b4:a2:b6:a2:a8")] : nil
74
77
 
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Kubevirt
3
- VERSION = '1.2.2'
3
+ VERSION = '1.2.3'
4
4
  end
5
5
  end
@@ -58,7 +58,7 @@ describe Fog::Compute do
58
58
  assert_equal(volumes.count, 3)
59
59
 
60
60
  # verify first claim values
61
- volume = volumes.select { |v| v.name == 'test-disk-01' }.first
61
+ volume = volumes.detect { |v| v.name == 'test-disk-01' }
62
62
  refute_nil(volume)
63
63
  refute_nil(volume.pvc)
64
64
  assert_equal(volume.name, 'test-disk-01')
@@ -66,7 +66,7 @@ describe Fog::Compute do
66
66
  assert_equal(volume.type, 'persistentVolumeClaim')
67
67
 
68
68
  # verify second claim values
69
- volume = volumes.select { |v| v.name == 'test-disk-02' }.first
69
+ volume = volumes.detect { |v| v.name == 'test-disk-02' }
70
70
  refute_nil(volume)
71
71
  refute_nil(volume.pvc)
72
72
  assert_equal(volume.pvc.name, pvc2)
@@ -74,7 +74,7 @@ describe Fog::Compute do
74
74
  assert_equal(volume.type, 'persistentVolumeClaim')
75
75
 
76
76
  # verify third claim values
77
- volume = volumes.select { |v| v.name == 'test-disk-03' }.first
77
+ volume = volumes.detect { |v| v.name == 'test-disk-03' }
78
78
  refute_nil(volume)
79
79
  assert_equal(volume.name, 'test-disk-03')
80
80
  assert_equal(volume.type, 'hostDisk')
@@ -49,7 +49,7 @@ require 'spec_helper'
49
49
 
50
50
  # test all volumes based on PVCs
51
51
  volumes = @service.volumes.all
52
- volume = volumes.select { |v| v.name == name }.first
52
+ volume = volumes.detect { |v| v.name == name }
53
53
  refute_nil(volume)
54
54
  assert_equal(volume.name, 'my-local-storage-pvc')
55
55
  assert_equal(volume.type, 'persistentVolumeClaim')
@@ -90,7 +90,7 @@ require 'spec_helper'
90
90
 
91
91
  # test all volumes based on PVCs
92
92
  volumes = @service.volumes.all
93
- volume = volumes.select { |v| v.name == name }.first
93
+ volume = volumes.detect { |v| v.name == name }
94
94
  refute_nil(volume)
95
95
  assert_equal(volume.name, 'my-local-storage-pvc')
96
96
  assert_equal(volume.type, 'persistentVolumeClaim')
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fog::Kubevirt::Compute do
4
+ it 'parses vm' do
5
+ Fog.mock!
6
+ mock = Fog::Kubevirt::Compute.new
7
+ vm = mock.get_vm('test')
8
+
9
+ assert_nil(vm[:interfaces][0].mac_address)
10
+ assert_nil(vm[:interfaces][1].mac_address)
11
+ Fog.unmock!
12
+ end
13
+
14
+ it 'parses vmi' do
15
+ Fog.mock!
16
+ mock = Fog::Kubevirt::Compute.new
17
+ vm = mock.get_vminstance('test')
18
+
19
+ assert_equal(vm[:interfaces][0].mac_address, '0e:fc:6c:c3:20:ec')
20
+ assert_equal(vm[:interfaces][1].mac_address, '4a:90:1c:2e:fe:d7')
21
+ Fog.unmock!
22
+ end
23
+
24
+ it 'parses not ready server' do
25
+ Fog.mock!
26
+ mock = Fog::Kubevirt::Compute.new
27
+ server = mock.get_server('no_interfaces')
28
+
29
+ assert_nil(server[:interfaces])
30
+ Fog.unmock!
31
+ end
32
+
33
+ it 'parses vm interface of pod network' do
34
+ Fog.mock!
35
+ mock = Fog::Kubevirt::Compute.new
36
+ vm = mock.get_vm('robin-rykert.example.com')
37
+
38
+ assert_nil(vm[:interfaces][0].network)
39
+ assert_equal(vm[:interfaces][0].cni_provider, "pod")
40
+
41
+ assert_equal(vm[:interfaces][1].network, "ptp-conf")
42
+ assert_equal(vm[:interfaces][1].cni_provider, "multus")
43
+ Fog.unmock!
44
+ end
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-kubevirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kliczewski
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2019-04-12 00:00:00.000000000 Z
17
+ date: 2019-04-15 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: minitest
@@ -226,7 +226,7 @@ files:
226
226
  - spec/shared_context.rb
227
227
  - spec/spec_helper.rb
228
228
  - spec/storage_classes_v1_spec.rb
229
- - spec/vm_parse.rb
229
+ - spec/vm_parse_spec.rb
230
230
  homepage: https://github.com/pkliczewski/fog-kubevirt
231
231
  licenses:
232
232
  - Apache-2.0
@@ -268,4 +268,4 @@ test_files:
268
268
  - spec/shared_context.rb
269
269
  - spec/spec_helper.rb
270
270
  - spec/storage_classes_v1_spec.rb
271
- - spec/vm_parse.rb
271
+ - spec/vm_parse_spec.rb
@@ -1,24 +0,0 @@
1
- describe Fog::Kubevirt::Compute do
2
- it 'parses vm' do
3
- mock = Fog::Kubevirt::Compute::Mock.new
4
- vm = mock.get_vm('test')
5
-
6
- assert_nil(vm[:interfaces][0].mac_address)
7
- assert_nil(vm[:interfaces][1].mac_address)
8
- end
9
-
10
- it 'parses vmi' do
11
- mock = Fog::Kubevirt::Compute::Mock.new
12
- vm = mock.get_vminstance('test')
13
-
14
- assert_equal(vm[:interfaces][0].mac_address, '0e:fc:6c:c3:20:ec')
15
- assert_equal(vm[:interfaces][1].mac_address, '4a:90:1c:2e:fe:d7')
16
- end
17
-
18
- it 'parses not ready server' do
19
- mock = Fog::Kubevirt::Compute::Mock.new
20
- server = mock.get_server('no_interfaces')
21
-
22
- assert_nil(server[:interfaces])
23
- end
24
- end