fog-kubevirt 0.3.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/lib/fog/bin/kubevirt.rb +2 -2
  4. data/lib/fog/kubevirt.rb +1 -4
  5. data/lib/fog/{compute/kubevirt.rb → kubevirt/compute/compute.rb} +35 -184
  6. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/node.rb +3 -3
  7. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/nodes.rb +4 -4
  8. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/template.rb +2 -2
  9. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/templates.rb +4 -4
  10. data/lib/fog/kubevirt/compute/models/vm.rb +71 -0
  11. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/vminstance.rb +4 -13
  12. data/lib/fog/{compute/kubevirt → kubevirt/compute}/models/vminstances.rb +4 -4
  13. data/lib/fog/kubevirt/compute/models/vms.rb +137 -0
  14. data/lib/fog/kubevirt/compute/models/volume.rb +9 -0
  15. data/lib/fog/kubevirt/compute/models/volumes.rb +12 -0
  16. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/create_pvc.rb +2 -2
  17. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/create_vm.rb +2 -3
  18. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/create_vminstance.rb +2 -2
  19. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/delete_vm.rb +3 -3
  20. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/delete_vminstance.rb +5 -5
  21. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/get_node.rb +2 -2
  22. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/get_template.rb +2 -2
  23. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/get_vm.rb +3 -3
  24. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/get_vminstance.rb +6 -6
  25. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/list_nodes.rb +2 -2
  26. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/list_templates.rb +2 -2
  27. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/list_vminstances.rb +2 -2
  28. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/list_vms.rb +6 -6
  29. data/lib/fog/{compute/kubevirt → kubevirt/compute}/requests/update_vm.rb +2 -2
  30. data/lib/fog/kubevirt/version.rb +1 -1
  31. metadata +39 -133
  32. data/lib/fog/compute/kubevirt/models/networkattachmentdef.rb +0 -25
  33. data/lib/fog/compute/kubevirt/models/networkattachmentdefs.rb +0 -59
  34. data/lib/fog/compute/kubevirt/models/persistentvolume.rb +0 -82
  35. data/lib/fog/compute/kubevirt/models/persistentvolumes.rb +0 -73
  36. data/lib/fog/compute/kubevirt/models/pvc.rb +0 -59
  37. data/lib/fog/compute/kubevirt/models/pvcs.rb +0 -76
  38. data/lib/fog/compute/kubevirt/models/server.rb +0 -44
  39. data/lib/fog/compute/kubevirt/models/servers.rb +0 -32
  40. data/lib/fog/compute/kubevirt/models/service.rb +0 -36
  41. data/lib/fog/compute/kubevirt/models/services.rb +0 -83
  42. data/lib/fog/compute/kubevirt/models/storageclass.rb +0 -33
  43. data/lib/fog/compute/kubevirt/models/storageclasses.rb +0 -61
  44. data/lib/fog/compute/kubevirt/models/vm.rb +0 -17
  45. data/lib/fog/compute/kubevirt/models/vm_base.rb +0 -86
  46. data/lib/fog/compute/kubevirt/models/vm_data.rb +0 -162
  47. data/lib/fog/compute/kubevirt/models/vms.rb +0 -206
  48. data/lib/fog/compute/kubevirt/models/volume.rb +0 -57
  49. data/lib/fog/compute/kubevirt/models/volumes.rb +0 -18
  50. data/lib/fog/compute/kubevirt/requests/create_networkattachmentdef.rb +0 -37
  51. data/lib/fog/compute/kubevirt/requests/create_persistentvolume.rb +0 -19
  52. data/lib/fog/compute/kubevirt/requests/create_service.rb +0 -18
  53. data/lib/fog/compute/kubevirt/requests/create_storageclass.rb +0 -18
  54. data/lib/fog/compute/kubevirt/requests/delete_networkattachmentdef.rb +0 -16
  55. data/lib/fog/compute/kubevirt/requests/delete_persistentvolume.rb +0 -16
  56. data/lib/fog/compute/kubevirt/requests/delete_pvc.rb +0 -16
  57. data/lib/fog/compute/kubevirt/requests/delete_service.rb +0 -16
  58. data/lib/fog/compute/kubevirt/requests/delete_storageclass.rb +0 -16
  59. data/lib/fog/compute/kubevirt/requests/get_networkattachmentdef.rb +0 -19
  60. data/lib/fog/compute/kubevirt/requests/get_persistentvolume.rb +0 -16
  61. data/lib/fog/compute/kubevirt/requests/get_pvc.rb +0 -16
  62. data/lib/fog/compute/kubevirt/requests/get_server.rb +0 -32
  63. data/lib/fog/compute/kubevirt/requests/get_service.rb +0 -16
  64. data/lib/fog/compute/kubevirt/requests/get_storageclass.rb +0 -16
  65. data/lib/fog/compute/kubevirt/requests/list_networkattachmentdefs.rb +0 -21
  66. data/lib/fog/compute/kubevirt/requests/list_persistentvolumes.rb +0 -22
  67. data/lib/fog/compute/kubevirt/requests/list_pvcs.rb +0 -22
  68. data/lib/fog/compute/kubevirt/requests/list_servers.rb +0 -25
  69. data/lib/fog/compute/kubevirt/requests/list_services.rb +0 -22
  70. data/lib/fog/compute/kubevirt/requests/list_storageclasses.rb +0 -22
  71. data/lib/fog/compute/kubevirt/requests/list_volumes.rb +0 -30
  72. data/spec/compute_v1alpha2_spec.rb +0 -30
  73. data/spec/create_vm_spec.rb +0 -101
  74. data/spec/fixtures/kubevirt/networkattachmentdefinition/networkattachmentdefinitions_crud.yml +0 -320
  75. data/spec/fixtures/kubevirt/persistentvolume/persistent_volumes_crud.yml +0 -316
  76. data/spec/fixtures/kubevirt/pvc/pvcs_crud.yml +0 -362
  77. data/spec/fixtures/kubevirt/service/services_crud.yml +0 -316
  78. data/spec/fixtures/kubevirt/storageclass/storageclasses_crud.yml +0 -400
  79. data/spec/fixtures/kubevirt/vm/vm_create_multi.yml +0 -459
  80. data/spec/fixtures/kubevirt/vm/vm_create_single.yml +0 -362
  81. data/spec/network_attachment_definition_v1alpha2_spec.rb +0 -28
  82. data/spec/persistent_volumes_v1alpha2_spec.rb +0 -45
  83. data/spec/pvcs_v1alpha2_spec.rb +0 -59
  84. data/spec/shared_context.rb +0 -54
  85. data/spec/spec_helper.rb +0 -10
  86. data/spec/storage_classes_v1_spec.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25a9419e80245eff2f02bac207711317b6503432
4
- data.tar.gz: 530e0f33df50161f668f78bc57d25b00c1b10951
3
+ metadata.gz: ef12aa5c8c8f76da4468c2addf70d01f798fca2e
4
+ data.tar.gz: 59e0ce857ec78e72f2f47fce4b59b4789aee9bfe
5
5
  SHA512:
6
- metadata.gz: f5c986661f483f6c05e9b20f4b8d7ce2b04fa4e079d6b0e228d6fe69698e9ed9197c072a1e49661b87cff6d76a8782cdaf9e46fe30d54053dd0ddf3db95cfe4c
7
- data.tar.gz: 807de8ea60c22dde2538805218be5eb80105b081701cb65ad470636a9f01012d4d3c209b860092ba9ecc1e96c3f5c715690d7e679298a7ab7d7cd0eb86123b87
6
+ metadata.gz: b715da932cbe7359039d796391e3fa1b149c7abafbd918d1c828bd761e026c3d5049d672fb11f0ff822c9faa86240b47e1536c7aa664c16d87df3be618be5482
7
+ data.tar.gz: f1d024c7a07089912a574cc0336475818ea71c284ff814a25bcc9edf4cf7047f0df2a114d54b82aa09af990b575a9aa73423a28defaeda70f5f24327e06b8719
data/README.md CHANGED
@@ -22,14 +22,13 @@ Or install it yourself as:
22
22
 
23
23
  Require the gem:
24
24
  ```ruby
25
- require 'fog/kubevirt'
25
+ require 'fog/kubevirt'
26
26
  ```
27
27
 
28
28
  Connect to kubevirt instance:
29
29
  ```ruby
30
30
 
31
- compute = Fog::Compute.new(
32
- :provider => "kubevirt",
31
+ compute = Fog::Kubevirt::Compute.new
33
32
  :kubevirt_token => token,
34
33
  :kubevirt_server => server,
35
34
  :kubevirt_port => port
@@ -3,7 +3,7 @@ class Kubevirt < Fog::Bin
3
3
  def class_for(key)
4
4
  case key
5
5
  when :compute
6
- Fog::Compute::Kubevirt
6
+ Fog::Kubevirt::Compute
7
7
  else
8
8
  raise ArgumentError, "Unrecognized service: #{key}"
9
9
  end
@@ -13,7 +13,7 @@ class Kubevirt < Fog::Bin
13
13
  @@connections ||= Hash.new do |hash, key|
14
14
  hash[key] = case key
15
15
  when :compute
16
- Fog::Compute.new(:provider => 'Kubevirt')
16
+ Fog::Kubevirt::Compute.new
17
17
  else
18
18
  raise ArgumentError, "Unrecognized service: #{key.inspect}"
19
19
  end
data/lib/fog/kubevirt.rb CHANGED
@@ -1,11 +1,8 @@
1
1
  require 'fog/core'
2
2
 
3
3
  module Fog
4
- module Compute
5
- autoload :Kubevirt, File.expand_path('../compute/kubevirt', __FILE__)
6
- end
7
-
8
4
  module Kubevirt
5
+ autoload :Compute, 'fog/kubevirt/compute/compute'
9
6
  extend Fog::Provider
10
7
 
11
8
  module Errors
@@ -1,75 +1,40 @@
1
1
  require 'delegate'
2
- require 'json'
3
- require 'rest-client'
4
2
 
5
3
  require "fog/core"
6
4
 
7
5
  module Fog
8
- module Compute
9
- class Kubevirt < Fog::Service
10
- recognizes :kubevirt_token, :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, \
11
- :kubevirt_log, :kubevirt_verify_ssl, :kubevirt_ca_cert
6
+ module Kubevirt
7
+ class Compute < Fog::Service
8
+ requires :kubevirt_token
9
+ recognizes :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, :kubevirt_log
12
10
 
13
- model_path 'fog/compute/kubevirt/models'
11
+ model_path 'fog/kubevirt/compute/models'
14
12
  model :vminstance
15
13
  collection :vminstances
16
- model :networkattachmentdef
17
- collection :networkattachmentdefs
18
14
  model :node
19
15
  collection :nodes
20
16
  model :vm
21
17
  collection :vms
22
- model :persistentvolume
23
- collection :persistentvolumes
24
- model :pvc
25
- collection :pvcs
26
- model :server
27
- collection :servers
28
- model :service
29
- collection :services
30
- model :storageclass
31
- collection :storageclasses
32
18
  model :template
33
19
  collection :templates
34
20
  model :volume
35
21
  collection :volumes
36
22
 
37
- request_path 'fog/compute/kubevirt/requests'
38
- request :create_networkattachmentdef
23
+ request_path 'fog/kubevirt/compute/requests'
24
+
39
25
  request :create_vm
40
26
  request :create_vminstance
41
- request :create_persistentvolume
42
27
  request :create_pvc
43
- request :create_service
44
- request :create_storageclass
45
- request :delete_networkattachmentdef
46
- request :delete_persistentvolume
47
- request :delete_pvc
48
- request :delete_service
49
- request :delete_storageclass
50
28
  request :delete_vminstance
51
29
  request :delete_vm
52
30
  request :get_vminstance
53
- request :get_networkattachmentdef
54
31
  request :get_node
55
- request :get_persistentvolume
56
- request :get_pvc
57
32
  request :get_vm
58
- request :get_server
59
- request :get_service
60
- request :get_storageclass
61
33
  request :get_template
62
34
  request :list_vminstances
63
35
  request :list_nodes
64
- request :list_networkattachmentdefs
65
36
  request :list_vms
66
- request :list_persistentvolumes
67
- request :list_pvcs
68
- request :list_servers
69
- request :list_services
70
- request :list_storageclasses
71
37
  request :list_templates
72
- request :list_volumes
73
38
  request :update_vm
74
39
 
75
40
  module Shared
@@ -85,9 +50,8 @@ module Fog
85
50
  end
86
51
 
87
52
  class ExceptionWrapper
88
- def initialize(client, version)
53
+ def initialize(client)
89
54
  @client = client
90
- @version = version
91
55
  end
92
56
 
93
57
  def method_missing(symbol, *args)
@@ -107,10 +71,6 @@ module Fog
107
71
  def respond_to_missing?(method_name, include_private = false)
108
72
  @client.respond_to?(symbol, include_all) || super
109
73
  end
110
-
111
- def version
112
- @version
113
- end
114
74
  end
115
75
 
116
76
  #
@@ -162,24 +122,17 @@ module Fog
162
122
  include Shared
163
123
 
164
124
  #
165
- # The API group of KubeVirt:
166
- #
167
- KUBEVIRT_GROUP = 'kubevirt.io'.freeze
168
-
169
- #
170
- # The API group of the Kubernetes core:
125
+ # The API version and group of the Kubernetes core:
171
126
  #
172
127
  CORE_GROUP = ''.freeze
128
+ CORE_VERSION = 'v1'.freeze
173
129
 
174
130
  #
175
- # The API group of the Kubernetes network extention:
176
- #
177
- NETWORK_GROUP = 'k8s.cni.cncf.io'.freeze
178
-
179
- #
180
- # The API group of the Kubernetes network extention:
131
+ # The API version and group of KubeVirt:
181
132
  #
182
- STORAGE_GROUP = 'storage.k8s.io'.freeze
133
+ KUBEVIRT_GROUP = 'kubevirt.io'.freeze
134
+ KUBEVIRT_VERSION = 'v1alpha2'.freeze
135
+ KUBEVIRT_VERSION_LABEL = KUBEVIRT_GROUP + '/' + KUBEVIRT_VERSION
183
136
 
184
137
  def initialize(options={})
185
138
  require 'kubeclient'
@@ -192,8 +145,13 @@ module Fog
192
145
  @log ||= ::Logger.new(STDOUT)
193
146
 
194
147
  @namespace = options[:kubevirt_namespace] || 'default'
148
+
149
+ # Prepare the TLS and authentication options that will be used for the standard Kubernetes API
150
+ # and also for the KubeVirt extension:
195
151
  @opts = {
196
- :ssl_options => obtain_ssl_options(options),
152
+ :ssl_options => {
153
+ :verify_ssl => OpenSSL::SSL::VERIFY_NONE,
154
+ },
197
155
  :auth_options => {
198
156
  :bearer_token => @kubevirt_token
199
157
  }
@@ -291,7 +249,7 @@ module Fog
291
249
  populate_notice_attributes(vminstance, notice)
292
250
  vminstance
293
251
  end
294
- watch = kubevirt_client.watch_virtual_machine_instances(opts)
252
+ watch = kubevirt_client.watch_virtual_machines(opts)
295
253
 
296
254
  WatchWrapper.new(watch, mapper)
297
255
  end
@@ -338,6 +296,7 @@ module Fog
338
296
 
339
297
  private
340
298
 
299
+
341
300
  #
342
301
  # Populates required notice attributes
343
302
  #
@@ -351,12 +310,18 @@ module Fog
351
310
  end
352
311
 
353
312
  #
354
- # Lazily creates the a client for the given Kubernetes API path.
313
+ # Lazily creates the a client for the given Kubernetes API path and version.
355
314
  #
356
315
  # @param path [String] The Kubernetes API path.
316
+ # @param version [String] The Kubernetes API version.
357
317
  # @return [Kubeclient::Client] The client for the given path and version.
358
318
  #
359
- def create_client(path)
319
+ def create_client(path, version)
320
+ # Return the client immediately if it has been created before:
321
+ key = path + '/' + version
322
+ client = @clients[key]
323
+ return client if client
324
+
360
325
  # Create the client and save it:
361
326
  url = URI::Generic.build(
362
327
  :scheme => 'https',
@@ -364,147 +329,33 @@ module Fog
364
329
  :port => @port,
365
330
  :path => path
366
331
  )
367
-
368
- if @kubevirt_token.to_s.empty?
369
- create_client_from_config(path)
370
- else
371
- create_client_from_token(url)
372
- end
373
- end
374
-
375
- def create_client_from_token(url)
376
- # Prepare the TLS and authentication options that will be used for the standard Kubernetes API
377
- # and also for the KubeVirt extension:
378
- @opts = {
379
- :ssl_options => {
380
- :verify_ssl => OpenSSL::SSL::VERIFY_NONE,
381
- },
382
- :auth_options => {
383
- :bearer_token => @kubevirt_token
384
- }
385
- }
386
- version = detect_version(url.to_s, @opts[:ssl_options])
387
- key = url.path + '/' + version
388
-
389
- client = check_client(key)
390
- return client if client
391
-
392
332
  client = Kubeclient::Client.new(
393
333
  url.to_s,
394
334
  version,
395
335
  @opts
396
336
  )
397
-
398
- wrap_client(client, version, key)
399
- end
400
-
401
- def create_client_from_config(path)
402
- config = Kubeclient::Config.read(ENV['KUBECONFIG'] || ENV['HOME']+'/.kube/config')
403
- context = config.context
404
- url = context.api_endpoint
405
- version = detect_version(url + path, context.ssl_options)
406
- key = path + '/' + version
407
-
408
- client = check_client(key)
409
- return client if client
410
-
411
- client = Kubeclient::Client.new(
412
- url + path,
413
- version,
414
- ssl_options: context.ssl_options,
415
- auth_options: context.auth_options
416
- )
417
-
418
- wrap_client(client, version, key)
419
- end
420
-
421
- def check_client(key)
422
- @clients[key]
423
- end
424
-
425
- def wrap_client(client, version, key)
426
- wrapped_client = ExceptionWrapper.new(client, version)
337
+ wrapped_client = ExceptionWrapper.new(client)
427
338
  @clients[key] = wrapped_client
428
339
 
340
+ # Return the client:
429
341
  wrapped_client
430
342
  end
431
343
 
432
- def detect_version(url, ssl_options)
433
- options = {
434
- ssl_ca_file: ssl_options[:ca_file],
435
- ssl_cert_store: ssl_options[:cert_store],
436
- verify_ssl: ssl_options[:verify_ssl],
437
- ssl_client_cert: ssl_options[:client_cert],
438
- ssl_client_key: ssl_options[:client_key],
439
- }
440
-
441
- response = ::JSON.parse(RestClient::Resource.new(url, options).get)
442
-
443
- # version detected based on
444
- # https://github.com/kubernetes-incubator/apiserver-builder/blob/master/docs/concepts/aggregation.md#viewing-discovery-information
445
- preferredVersion = response["preferredVersion"]
446
- return preferredVersion["version"] if preferredVersion
447
- response["versions"][0]
448
- end
449
-
450
344
  def openshift_client
451
- create_client('/oapi')
345
+ create_client('/oapi', CORE_VERSION)
452
346
  end
453
347
 
454
348
  def kube_client
455
- create_client('/api')
349
+ create_client('/api', CORE_VERSION)
456
350
  end
457
351
 
458
352
  def kubevirt_client
459
- create_client('/apis/' + KUBEVIRT_GROUP)
460
- end
461
-
462
- def kube_net_client
463
- create_client('/apis/' + NETWORK_GROUP)
464
- end
465
-
466
- def kube_storage_client
467
- create_client('/apis/' + STORAGE_GROUP)
353
+ create_client('/apis/' + KUBEVIRT_GROUP, KUBEVIRT_VERSION)
468
354
  end
469
355
 
470
356
  def log
471
357
  @log
472
358
  end
473
-
474
- #
475
- # Prepare the TLS and authentication options that will be used for the
476
- # standard Kubernetes API and also for the KubeVirt extension
477
- #
478
- # @param options [Hash] a hash with connection options
479
- #
480
- def obtain_ssl_options(options)
481
- verify_ssl = options[:kubevirt_verify_ssl]
482
- if verify_ssl == true
483
- ca = options[:kubevirt_ca_cert] || ""
484
- ca = IO.read(ca) if File.file?(ca)
485
- certs = ca.split(/(?=-----BEGIN)/).reject(&:empty?).collect do |pem|
486
- OpenSSL::X509::Certificate.new(pem)
487
- end
488
-
489
- cert_store = OpenSSL::X509::Store.new
490
- certs.each do |cert|
491
- cert_store.add_cert(cert)
492
- end
493
-
494
- ssl_options = {
495
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER,
496
- :cert_store => cert_store
497
- }
498
- elsif verify_ssl == false || verify_ssl.to_s.empty?
499
- ssl_options = {
500
- :verify_ssl => OpenSSL::SSL::VERIFY_NONE
501
- }
502
- else
503
- ssl_options = {
504
- :verify_ssl => verify_ssl
505
- }
506
- end
507
- end
508
359
  end
509
360
 
510
361
  class Mock
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Node < Fog::Model
5
5
  identity :name
6
6
 
@@ -36,4 +36,4 @@ module Fog
36
36
  end
37
37
  end
38
38
  end
39
- end
39
+ end
@@ -1,13 +1,13 @@
1
1
  require 'fog/core/collection'
2
- require 'fog/compute/kubevirt/models/node'
2
+ require 'fog/kubevirt/compute/models/node'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Kubevirt
5
+ module Kubevirt
6
+ class Compute
7
7
  class Nodes < Fog::Collection
8
8
  attr_reader :kind, :resource_version
9
9
 
10
- model Fog::Compute::Kubevirt::Node
10
+ model Fog::Kubevirt::Compute::Node
11
11
 
12
12
  def all(filters = {})
13
13
  nodes = service.list_nodes(filters)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Template < Fog::Model
5
5
  include Shared
6
6
  identity :name, :aliases => 'metadata_name'
@@ -1,13 +1,13 @@
1
1
  require 'fog/core/collection'
2
- require 'fog/compute/kubevirt/models/template'
2
+ require 'fog/kubevirt/compute/models/template'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Kubevirt
5
+ module Kubevirt
6
+ class Compute
7
7
  class Templates < Fog::Collection
8
8
  attr_reader :kind, :resource_version
9
9
 
10
- model Fog::Compute::Kubevirt::Template
10
+ model Fog::Kubevirt::Compute::Template
11
11
 
12
12
  def all(filters = {})
13
13
  begin