fog-kubevirt 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1de135b0b0723b41c540c9bc1247b67d1f8176ef
4
- data.tar.gz: 8845f174d0923e0224e0683c710d0a5219608c7b
3
+ metadata.gz: aa2d9409a7b3472593ad9f4851e75b1e702d6be9
4
+ data.tar.gz: bb3258447667e18c78273407587d4adbf25ff308
5
5
  SHA512:
6
- metadata.gz: ea3d49cf4931797629028d01cea8332d78f57c90b130e8d362e0bd1002d19e539ceee45280f2a6d16c2da45fa11e40da14da12cdb31a9bc2da2af6038bd3560f
7
- data.tar.gz: 06ad5911dc8b3c7f110f33992ee61e19403f4643b0d97607000dff270e20036ad6b2414f54b72a545f606c927d15c93237d25915aebcdf176fb5327c13549218
6
+ metadata.gz: a866f0a383c98f3f08e913374d9b0d4d7a57059423848ce96628119ff20bf122d2d459cb5ed5888793a11e4a6ff2044604ca7f531a1c004a28b167468c4b7b07
7
+ data.tar.gz: 4c972287cffa8afcc7b81730115daf8bbe5052124dda86d62c92fa95b3abfc04074812b9ce9bae29c863687712577a26bee539896c9757191a057b73b6890a36
@@ -7,8 +7,7 @@ require "fog/core"
7
7
  module Fog
8
8
  module Compute
9
9
  class Kubevirt < Fog::Service
10
- requires :kubevirt_token
11
- recognizes :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, \
10
+ recognizes :kubevirt_token, :kubevirt_hostname, :kubevirt_port, :kubevirt_namespace, \
12
11
  :kubevirt_log, :kubevirt_verify_ssl, :kubevirt_ca_cert
13
12
 
14
13
  model_path 'fog/compute/kubevirt/models'
@@ -278,7 +277,7 @@ module Fog
278
277
  populate_notice_attributes(vminstance, notice)
279
278
  vminstance
280
279
  end
281
- watch = kubevirt_client.watch_virtual_machines(opts)
280
+ watch = kubevirt_client.watch_virtual_machine_instances(opts)
282
281
 
283
282
  WatchWrapper.new(watch, mapper)
284
283
  end
@@ -352,9 +351,28 @@ module Fog
352
351
  :path => path
353
352
  )
354
353
 
354
+ if @kubevirt_token.to_s.empty?
355
+ create_client_from_config(path)
356
+ else
357
+ create_client_from_token(url)
358
+ end
359
+ end
360
+
361
+ def create_client_from_token(url)
362
+ # Prepare the TLS and authentication options that will be used for the standard Kubernetes API
363
+ # and also for the KubeVirt extension:
364
+ @opts = {
365
+ :ssl_options => {
366
+ :verify_ssl => OpenSSL::SSL::VERIFY_NONE,
367
+ },
368
+ :auth_options => {
369
+ :bearer_token => @kubevirt_token
370
+ }
371
+ }
355
372
  version = detect_version(url.to_s, @opts[:ssl_options])
356
- key = path + '/' + version
357
- client = @clients[key]
373
+ key = url.path + '/' + version
374
+
375
+ client = check_client(key)
358
376
  return client if client
359
377
 
360
378
  client = Kubeclient::Client.new(
@@ -362,10 +380,38 @@ module Fog
362
380
  version,
363
381
  @opts
364
382
  )
383
+
384
+ wrap_client(client, version, key)
385
+ end
386
+
387
+ def create_client_from_config(path)
388
+ config = Kubeclient::Config.read(ENV['KUBECONFIG'] || ENV['HOME']+'/.kube/config')
389
+ context = config.context
390
+ url = context.api_endpoint
391
+ version = detect_version(url + path, context.ssl_options)
392
+ key = path + '/' + version
393
+
394
+ client = check_client(key)
395
+ return client if client
396
+
397
+ client = Kubeclient::Client.new(
398
+ url + path,
399
+ version,
400
+ ssl_options: context.ssl_options,
401
+ auth_options: context.auth_options
402
+ )
403
+
404
+ wrap_client(client, version, key)
405
+ end
406
+
407
+ def check_client(key)
408
+ @clients[key]
409
+ end
410
+
411
+ def wrap_client(client, version, key)
365
412
  wrapped_client = ExceptionWrapper.new(client, version)
366
413
  @clients[key] = wrapped_client
367
414
 
368
- # Return the client:
369
415
  wrapped_client
370
416
  end
371
417
 
@@ -27,7 +27,7 @@ module Fog
27
27
 
28
28
  def self.parse(object)
29
29
  server = parse_object(object)
30
- server[:status] = object[:phase]
30
+ server[:state] = object[:phase]
31
31
  server[:node_name] = object[:node_name]
32
32
  server[:ip_address] = object[:ip_address]
33
33
  server
@@ -43,7 +43,7 @@ module Fog
43
43
  :volumes => parse_volumes(spec[:volumes]),
44
44
  :interfaces => parse_interfaces(domain[:devices][:interfaces]),
45
45
  :networks => parse_networks(spec[:networks]),
46
- :state => object[:spec][:running].to_s == "true" ? "running" : "stopped",
46
+ :status => object[:spec][:running].to_s == "true" ? "running" : "stopped",
47
47
  :machine_type => domain.dig(:machine, :type)
48
48
  }
49
49
  vm[:owner_reference] = owner unless owner.nil?
@@ -56,6 +56,8 @@ module Fog
56
56
  end
57
57
 
58
58
  module VmAction
59
+ include Shared
60
+
59
61
  def start(options = {})
60
62
  # Change the `running` attribute to `true` so that the virtual machine controller will take it and
61
63
  # create the virtual machine instance.
@@ -150,13 +150,19 @@ module Fog
150
150
  :readonly
151
151
  end
152
152
 
153
- class VmVolume
154
- attr_accessor :name,
155
- # values: containerDisk, persistentVolumeClaim, emptyDisk,
156
- # ephemeral, cloudInitNoCloud, hostDisk, secret,
157
- # dataVolume, serviceAccount, configMap
158
- :type,
159
- :info # specific piece of information per volume type
153
+ class VmVolume < Fog::Model
154
+ identity :name
155
+ attribute :id
156
+ # values: containerDisk, persistentVolumeClaim, emptyDisk,
157
+ # ephemeral, cloudInitNoCloud, hostDisk, secret,
158
+ # dataVolume, serviceAccount, configMap
159
+ attribute :type
160
+
161
+ attribute :info # specific piece of information per volume type
162
+
163
+ def persisted?
164
+ !name.nil?
165
+ end
160
166
  end
161
167
  end
162
168
  end
@@ -59,8 +59,8 @@ module Fog
59
59
  image = args.fetch(:image, nil)
60
60
  pvc = args.fetch(:pvc, nil)
61
61
  init = args.fetch(:cloudinit, {})
62
- networks = args.fetch(:networks)
63
- interfaces = args.fetch(:interfaces)
62
+ networks = args.fetch(:networks, nil)
63
+ interfaces = args.fetch(:interfaces, nil)
64
64
 
65
65
  if image.nil? && pvc.nil?
66
66
  raise ::Fog::Kubevirt::Errors::ValidationError
@@ -103,7 +103,7 @@ module Fog
103
103
  {:disk => {
104
104
  :bus => "virtio"
105
105
  },
106
- :name => vm_name,
106
+ :name => volume_name,
107
107
  }
108
108
  ]
109
109
  },
@@ -141,8 +141,7 @@ module Fog
141
141
  :disk => {
142
142
  :bus => "virtio"
143
143
  },
144
- :name => "cloudinitdisk",
145
- :volumeName => "cloudinitvolume"
144
+ :name => "cloudinitvolume",
146
145
  ) unless init.empty?
147
146
 
148
147
  vm = deep_merge!(vm,
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Kubevirt
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.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: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kliczewski
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2019-01-23 00:00:00.000000000 Z
15
+ date: 2019-02-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: minitest