fog-kubevirt 1.1.0 → 1.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: ee0eacc3688d804fe65c3b1aad58a83598ea1464
4
- data.tar.gz: 3bb93e156ebcfd91ab968472aa820bad4be79f24
3
+ metadata.gz: '0943d37da16b3d47be971ecd55a253508275a834'
4
+ data.tar.gz: f8b23b0d7c2ef8ef6769e5f9318b4efc8b80c07a
5
5
  SHA512:
6
- metadata.gz: b923222a67ec3decae7a438a62ddcaf47c6f2ea9b242479e0359398a253c715300aada3ea9024a97b2ed41a8df694ca304d019d1c1f7653e91cb84f8db57adae
7
- data.tar.gz: d4fac11a34371874e4c2a59983cc1168c8ae5e3a09617a63cd74eb51553951beb0f9f0d38fae5c25f58f9ccba485facee7f21b8f88d2404a6787266e7a3a2096
6
+ metadata.gz: 2fbdd1c0d3aaccba43a1f3270dc0fe2eeadb0b90f3dfe30df2442b16866bc2211913096b0b52d1d5022905362cb2e80cd79b2ff4f431817d2fa201eafbf9ad8e
7
+ data.tar.gz: 50a64408a54c66330c31e6c9b74db16eb70c16dbaf3bd45496e8fd705d85079267c7171a1370f1deeed169f3cd511ab7197aa5afb7cb370c6c12b1df0c3a28f8
@@ -7,7 +7,8 @@ require "fog/core"
7
7
  module Fog
8
8
  module Kubevirt
9
9
  class Compute < Fog::Service
10
- recognizes :kubevirt_token, :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, :kubevirt_log
10
+ recognizes :kubevirt_token, :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, \
11
+ :kubevirt_log, :kubevirt_verify_ssl, :kubevirt_ca_cert
11
12
 
12
13
  model_path 'fog/kubevirt/compute/models'
13
14
  model :vminstance
@@ -191,6 +192,12 @@ module Fog
191
192
  @log ||= ::Logger.new(STDOUT)
192
193
 
193
194
  @namespace = options[:kubevirt_namespace] || 'default'
195
+ @opts = {
196
+ :ssl_options => obtain_ssl_options(options),
197
+ :auth_options => {
198
+ :bearer_token => @kubevirt_token
199
+ }
200
+ }
194
201
 
195
202
  # Kubeclient needs different client objects for different API groups. We will keep in this hash the
196
203
  # client objects, indexed by API path/version.
@@ -211,6 +218,13 @@ module Fog
211
218
  end
212
219
 
213
220
  def valid?
221
+ begin
222
+ kube_client.get_namespace(namespace)
223
+ rescue => err
224
+ @log.warn("The namespace [#{namespace}] does not exist on the kubernetes cluster: #{err.message}")
225
+ raise "The namespace '#{namespace}' does not exist on the kubernetes cluster"
226
+ end
227
+
214
228
  kube_client.api_valid?
215
229
  end
216
230
 
@@ -466,6 +480,41 @@ module Fog
466
480
  def log
467
481
  @log
468
482
  end
483
+
484
+ #
485
+ # Prepare the TLS and authentication options that will be used for the
486
+ # standard Kubernetes API and also for the KubeVirt extension
487
+ #
488
+ # @param options [Hash] a hash with connection options
489
+ #
490
+ def obtain_ssl_options(options)
491
+ verify_ssl = options[:kubevirt_verify_ssl]
492
+ if verify_ssl == true
493
+ ca = options[:kubevirt_ca_cert] || ""
494
+ ca = IO.read(ca) if File.file?(ca)
495
+ certs = ca.split(/(?=-----BEGIN)/).reject(&:empty?).collect do |pem|
496
+ OpenSSL::X509::Certificate.new(pem)
497
+ end
498
+
499
+ cert_store = OpenSSL::X509::Store.new
500
+ certs.each do |cert|
501
+ cert_store.add_cert(cert)
502
+ end
503
+
504
+ ssl_options = {
505
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
506
+ :cert_store => cert_store
507
+ }
508
+ elsif verify_ssl == false || verify_ssl.to_s.empty?
509
+ ssl_options = {
510
+ :verify_ssl => OpenSSL::SSL::VERIFY_NONE
511
+ }
512
+ else
513
+ ssl_options = {
514
+ :verify_ssl => verify_ssl
515
+ }
516
+ end
517
+ end
469
518
  end
470
519
 
471
520
  class Mock
@@ -134,14 +134,19 @@ module Fog
134
134
  volumes
135
135
  end
136
136
 
137
- class VmNic
138
- attr_accessor :name,
139
- :mac_address,
140
- :type, # values: bridge, slirp
141
- :model,
142
- :ports,
143
- :boot_order
137
+ class VmNic < Fog::Model
138
+ attr_accessor :name
139
+
140
+ attribute :mac_address
141
+ attribute :type # values: bridge, slirp
142
+ attribute :model
143
+ attribute :ports
144
+ attribute :boot_order
144
145
  alias :mac :mac_address
146
+
147
+ def persisted?
148
+ !name.nil?
149
+ end
145
150
  end
146
151
 
147
152
  class VmNetwork
@@ -46,7 +46,6 @@ module Fog
46
46
  end
47
47
 
48
48
  def self.parse(object, disk)
49
- byebug
50
49
  volume = parse_object(object)
51
50
  volume[:boot_order] = object[:bootOrder]
52
51
  volume
@@ -12,11 +12,94 @@ module Fog
12
12
  end
13
13
 
14
14
  class Mock
15
- # TODO provide implementation
16
15
  def get_vm(name)
16
+ Vm.parse get_raw_vm(name)
17
17
  end
18
18
 
19
19
  def get_raw_vm(name)
20
+ {
21
+ :apiVersion=>"kubevirt.io/v1alpha3",
22
+ :kind=>"VirtualMachine",
23
+ :metadata=>{
24
+ :creationTimestamp=>"2019-04-02T13:28:47Z",
25
+ :generation=>1,
26
+ :labels=>{
27
+ :special=>"vm-multus-multiple-net"
28
+ },
29
+ :name=>"vm-multus-multiple-net",
30
+ :namespace=>"default",
31
+ :resourceVersion=>"24453",
32
+ :selfLink=>"/apis/kubevirt.io/v1alpha3/namespaces/default/virtualmachines/vm-multus-multiple-net",
33
+ :uid=>"3e959de9-554b-11e9-a3d6-525500d15501"
34
+ },
35
+ :spec=>{
36
+ :running=>false,
37
+ :template=>{
38
+ :metadata=>{
39
+ :labels=>{
40
+ :"kubevirt.io/vm"=>"vm-multus-multiple-net"
41
+ }
42
+ },
43
+ :spec=>{
44
+ :domain=>{
45
+ :devices=>{
46
+ :disks=>[
47
+ {
48
+ :disk=>{:bus=>"virtio"},
49
+ :name=>"containerdisk"
50
+ },
51
+ {
52
+ :disk=>{:bus=>"virtio"},
53
+ :name=>"cloudinitdisk"
54
+ }
55
+ ],
56
+ :interfaces=>[
57
+ {
58
+ :bridge=>{},
59
+ :name=>"default"
60
+ },
61
+ {
62
+ :bridge=>{},
63
+ :name=>"ptp"
64
+ }
65
+ ]
66
+ },
67
+ :machine=>{
68
+ :type=>""
69
+ },
70
+ :resources=>{
71
+ :requests=>{
72
+ :memory=>"1024M"
73
+ }
74
+ }
75
+ },
76
+ :networks=>[
77
+ {
78
+ :name=>"default",
79
+ :pod=>{}
80
+ },
81
+ {
82
+ :multus=>{
83
+ :networkName=>"ptp-conf"
84
+ },
85
+ :name=>"ptp"
86
+ }
87
+ ],
88
+ :terminationGracePeriodSeconds=>0,
89
+ :volumes=>[
90
+ {
91
+ :containerDisk=>{:image=>"registry:5000/kubevirt/fedora-cloud-container-disk-demo:devel"},
92
+ :name=>"containerdisk"
93
+ },
94
+ {
95
+ :cloudInitNoCloud=>{:userData=>"#!/bin/bash\necho \"fedora\" |passwd fedora --stdin\ndhclient eth1\n"},
96
+ :name=>"cloudinitdisk"
97
+ }
98
+ ]
99
+ }
100
+ }
101
+ }
102
+ }
20
103
  end
21
104
  end
22
105
  end
@@ -12,47 +12,112 @@ module Fog
12
12
 
13
13
  class Mock
14
14
  def get_vminstance(name)
15
- vm = { :apiVersion => "kubevirt.io/v1alpha2",
16
- :kind => "VirtualMachineInstance",
17
- :metadata => { :clusterName => "",
18
- :creationTimestamp => "2018-02-23T10:12:47Z",
19
- :name => "demo",
20
- :namespace => "default",
21
- :ownerReferences => [{ :apiVersion => "kubevirt.io/v1alpha2",
22
- :kind => "VirtualMachine",
23
- :name => "demo",
24
- :uid => "57e279c1-17ee-11e8-a9f9-525400a7f647"
25
- }
26
- ],
27
- :resourceVersion => "84873",
28
- :selfLink => "/apis/kubevirt.io/v1alpha2/namespaces/default/virtualmachineinstances/demo",
29
- :uid => "1906421f-1882-11e8-b539-525400a7f647"
30
- },
31
- :spec => { :domain => { :cpu => { :cores => "4" },
32
- :devices => { :disks => [{ :disk => { :dev => "vda" },
33
- :name => "containerDisk",
34
- :volumeName => "containervolume"
35
- },
36
- { :disk => { :dev => "vdb" },
37
- :name => "cloudinitdisk",
38
- :volumeName => "cloudinitvolume"
39
- }
40
- ]
41
- },
42
- :machine => { :type => "q35" },
43
- :resources => { :requests => { :memory => "512Mi" }}
44
- },
45
- :volumes => [ { :name => "containervolume",
46
- :containerDisk => { :image => "kubevirt/fedora-cloud-registry-disk-demo:latest" }
47
- },
48
- { :cloudInitNoCloud => { :userDataBase64 => "I2Nsb3VkLWNvbmZpZwpwYXNzd29yZDogYXRvbWljCnNzaF9wd2F1dGg6IFRydWUKY2hwYXNzd2Q6IHsgZXhwaXJlOiBGYWxzZSB9Cg==" },
49
- :name => "cloudinitvolume"
50
- }
51
- ]
52
- }
53
- }
54
- object = RecursiveOpenStruct.new(vm, recurse_over_arrays: true)
55
- Vminstance.parse object_to_hash(object)
15
+ vm = {
16
+ :apiVersion=>"kubevirt.io/v1alpha3",
17
+ :kind=>"VirtualMachineInstance",
18
+ :metadata=>{
19
+ :creationTimestamp=>"2019-04-02T13:46:08Z",
20
+ :finalizers=>["foregroundDeleteVirtualMachine"],
21
+ :generation=>7,
22
+ :labels=>{
23
+ :"kubevirt.io/nodeName"=>"node02",
24
+ :special=>"vmi-multus-multiple-net"
25
+ },
26
+ :name=>"vmi-multus-multiple-net",
27
+ :namespace=>"default",
28
+ :resourceVersion=>"27047",
29
+ :selfLink=>"/apis/kubevirt.io/v1alpha3/namespaces/default/virtualmachineinstances/vmi-multus-multiple-net",
30
+ :uid=>"ab5e450c-554d-11e9-a3d6-525500d15501"
31
+ },
32
+ :spec=>{
33
+ :domain=>{
34
+ :devices=>{
35
+ :disks=>[
36
+ {
37
+ :disk=>{:bus=>"virtio"},
38
+ :name=>"containerdisk"
39
+ },
40
+ {
41
+ :disk=>{:bus=>"virtio"},
42
+ :name=>"cloudinitdisk"
43
+ }
44
+ ],
45
+ :interfaces=>[
46
+ {
47
+ :bridge=>{},
48
+ :name=>"default"
49
+ },
50
+ {
51
+ :bridge=>{},
52
+ :name=>"ptp"
53
+ }
54
+ ]
55
+ },
56
+ :features=>{
57
+ :acpi=>{:enabled=>true}
58
+ },
59
+ :firmware=>{:uuid=>"ff1ff019-c799-400f-9be1-375c3cee8b59"},
60
+ :machine=>{:type=>"q35"},
61
+ :resources=>{
62
+ :requests=>{
63
+ :memory=>"1024M"
64
+ }
65
+ }
66
+ },
67
+ :networks=>[
68
+ {
69
+ :name=>"default",
70
+ :pod=>{}
71
+ },
72
+ {
73
+ :multus=>{:networkName=>"ptp-conf"},
74
+ :name=>"ptp"
75
+ }
76
+ ],
77
+ :terminationGracePeriodSeconds=>0,
78
+ :volumes=>[
79
+ {
80
+ :containerDisk=>{:image=>"registry:5000/kubevirt/fedora-cloud-container-disk-demo:devel"},
81
+ :name=>"containerdisk"
82
+ },
83
+ {
84
+ :cloudInitNoCloud=>{:userData=>"#!/bin/bash\necho \"fedora\" |passwd fedora --stdin\ndhclient eth1\n"},
85
+ :name=>"cloudinitdisk"
86
+ }
87
+ ]
88
+ },
89
+ :status=>{
90
+ :conditions=>[
91
+ {
92
+ :lastProbeTime=>nil,
93
+ :lastTransitionTime=>nil,
94
+ :status=>"True",
95
+ :type=>"LiveMigratable"
96
+ },
97
+ {
98
+ :lastProbeTime=>nil,
99
+ :lastTransitionTime=>"2019-04-02T13:46:24Z",
100
+ :status=>"True",
101
+ :type=>"Ready"
102
+ }
103
+ ],
104
+ :interfaces=>[
105
+ {
106
+ :ipAddress=>"10.244.1.14",
107
+ :mac=>"0e:fc:6c:c3:20:ec",
108
+ :name=>"default"
109
+ },
110
+ {
111
+ :mac=>"4a:90:1c:2e:fe:d7",
112
+ :name=>"ptp"
113
+ }
114
+ ],
115
+ :migrationMethod=>"BlockMigration",
116
+ :nodeName=>"node02",
117
+ :phase=>"Running"
118
+ }
119
+ }
120
+ Vminstance.parse object_to_hash(vm)
56
121
  end
57
122
  end
58
123
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Kubevirt
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
5
5
  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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kliczewski
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2019-04-01 00:00:00.000000000 Z
16
+ date: 2019-04-04 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: minitest