fog-kubevirt 0.1.4 → 0.1.5

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: 349189a4486be7bf7f5566e4f81ac6068a815b8e
4
- data.tar.gz: a5a758533671d33261309f766686c6625cf7220a
3
+ metadata.gz: 1c337ff2c2a840dbac40190eeb2f68142439c7ce
4
+ data.tar.gz: d1cf9a63c550417736ccccb088b2a3eab636808b
5
5
  SHA512:
6
- metadata.gz: 727d5527a879251aaff589d3f0b2b0932a3d44316252329dc165d8238465ac66d069734ff68cf4f264d149745ec549656eb42670ee2dd0a73ad7235f051dc726
7
- data.tar.gz: 4484d23a1894820fbaffe80b5b7d6cdf47575d23fae1852a3c9b7f6106cca6cd55006e214dfe30880af27c47ff679af5ccf534f86616cae5bc784bb5517ade45
6
+ metadata.gz: ad5568f12fd77a0301de97b524b3b427eb65c75bb5be393d238fd226c34b4014870236a09f985a707f4393b856d221e4b339cb33340756ae263c52bf1a06f120
7
+ data.tar.gz: b2101735200e5f5f2f4c69e490ed886f49d43b4723bec949e68088dc439c452cf451113c33d8a304136fe834378f47040e8d5541c4fbec85600c2b73f006257b
@@ -1,5 +1,4 @@
1
1
  require 'delegate'
2
- require 'logger'
3
2
 
4
3
  require "fog/core"
5
4
 
@@ -50,6 +49,30 @@ module Fog
50
49
  end
51
50
  end
52
51
 
52
+ class ExceptionWrapper
53
+ def initialize(client)
54
+ @client = client
55
+ end
56
+
57
+ def method_missing(symbol, *args)
58
+ super unless @client.respond_to?(symbol)
59
+
60
+ if block_given?
61
+ @client.__send__(symbol, *args) do |*block_args|
62
+ yield(*block_args)
63
+ end
64
+ else
65
+ @client.__send__(symbol, *args)
66
+ end
67
+ rescue KubeException => e
68
+ raise ::Fog::Kubevirt::Errors::ClientError, e
69
+ end
70
+
71
+ def respond_to_missing?(method_name, include_private = false)
72
+ @client.respond_to?(symbol, include_all) || super
73
+ end
74
+ end
75
+
53
76
  #
54
77
  # Label name which identifies operation system information
55
78
  #
@@ -118,7 +141,7 @@ module Fog
118
141
  @port = options[:kubevirt_port]
119
142
 
120
143
  @log = options[:kubevirt_log]
121
- @log ||= Logger::Logger.new(STDOUT)
144
+ @log ||= ::Logger.new(STDOUT)
122
145
 
123
146
  @namespace = options[:kubevirt_namespace] || 'default'
124
147
 
@@ -306,10 +329,11 @@ module Fog
306
329
  version,
307
330
  @opts
308
331
  )
309
- @clients[key] = client
332
+ wrapped_client = ExceptionWrapper.new(client)
333
+ @clients[key] = wrapped_client
310
334
 
311
335
  # Return the client:
312
- client
336
+ wrapped_client
313
337
  end
314
338
 
315
339
  def openshift_client
@@ -10,7 +10,12 @@ module Fog
10
10
  model Fog::Compute::Kubevirt::Template
11
11
 
12
12
  def all(filters = {})
13
- temps = service.list_templates(filters)
13
+ begin
14
+ temps = service.list_templates(filters)
15
+ rescue ::Fog::Kubevirt::Errors::ClientError
16
+ # we assume that we get 404
17
+ temps = []
18
+ end
14
19
  @kind = temps.kind
15
20
  @resource_version = temps.resource_version
16
21
  load temps
@@ -20,7 +20,6 @@ module Fog
20
20
  def self.parse(object)
21
21
  metadata = object[:metadata]
22
22
  status = object[:status]
23
- owner = metadata[:ownerReferences][0]
24
23
  spec = object[:spec]
25
24
  domain = spec[:domain]
26
25
  {
@@ -28,9 +27,9 @@ module Fog
28
27
  :name => metadata[:name],
29
28
  :resource_version => metadata[:resourceVersion],
30
29
  :uid => metadata[:uid],
31
- :owner_name => owner[:name],
32
- :owner_uid => owner[:uid],
33
- :cpu_cores => domain[:cpu][:cores],
30
+ :owner_name => metadata.dig(:ownerReferences, 0, :name),
31
+ :owner_uid => metadata.dig(:ownerReferences, 0, :uid),
32
+ :cpu_cores => domain.dig(:cpu, :cores),
34
33
  :memory => domain[:resources][:requests][:memory],
35
34
  :disks => domain[:devices][:disks],
36
35
  :volumes => spec[:volumes],
@@ -10,7 +10,12 @@ module Fog
10
10
  model Fog::Compute::Kubevirt::Vminstance
11
11
 
12
12
  def all(filters = {})
13
- vms = service.list_vminstances(filters)
13
+ begin
14
+ vms = service.list_vminstances(filters)
15
+ rescue ::Fog::Kubevirt::Errors::ClientError
16
+ # we assume that we get 404
17
+ vms = []
18
+ end
14
19
  @kind = vms.kind
15
20
  @resource_version = vms.resource_version
16
21
  load vms
@@ -23,7 +28,7 @@ module Fog
23
28
  def destroy(name, namespace)
24
29
  begin
25
30
  vm_instance = get(name)
26
- rescue Kubeclient::HttpError
31
+ rescue ::Fog::Kubevirt::Errors::ClientError
27
32
  # the virtual machine instance doesn't exist
28
33
  vm_instance = nil
29
34
  end
@@ -10,7 +10,12 @@ module Fog
10
10
  model Fog::Compute::Kubevirt::Vm
11
11
 
12
12
  def all(filters = {})
13
- vms = service.list_vms(filters)
13
+ begin
14
+ vms = service.list_vms(filters)
15
+ rescue ::Fog::Kubevirt::Errors::ClientError
16
+ # we assume that we get 404
17
+ vms = []
18
+ end
14
19
  @kind = vms.kind
15
20
  @resource_version = vms.resource_version
16
21
  load vms
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def create_pvc(pvc)
6
6
  kube_client.create_persistent_volume_claim(pvc)
7
- rescue Kubeclient::HttpError
7
+ rescue ::Fog::Kubevirt::Errors::ClientError => err
8
8
  log.warn(err)
9
9
  raise ::Fog::Kubevirt::Errors::AlreadyExistsError
10
10
  end
@@ -4,7 +4,7 @@ module Fog
4
4
  class Real
5
5
  def create_vm(vm)
6
6
  kubevirt_client.create_virtual_machine(vm)
7
- rescue Kubeclient::HttpError => err
7
+ rescue ::Fog::Kubevirt::Errors::ClientError => err
8
8
  log.warn(err)
9
9
  raise ::Fog::Kubevirt::Errors::AlreadyExistsError
10
10
  end
@@ -2,9 +2,10 @@ module Fog
2
2
  module Compute
3
3
  class Kubevirt
4
4
  class Real
5
+
5
6
  def create_vminstance(vm)
6
7
  kubevirt_client.create_virtual_machine_instance(vm)
7
- rescue Kubeclient::HttpError => err
8
+ rescue ::Fog::Kubevirt::Errors::ClientError => err
8
9
  log.warn(err)
9
10
  raise ::Fog::Kubevirt::Errors::AlreadyExistsError
10
11
  end
data/lib/fog/kubevirt.rb CHANGED
@@ -11,6 +11,7 @@ module Fog
11
11
  module Errors
12
12
  class ServiceError < Fog::Errors::Error; end
13
13
  class AlreadyExistsError < Fog::Errors::Error; end
14
+ class ClientError < Fog::Errors::Error; end
14
15
  end
15
16
 
16
17
  service(:compute, 'Compute')
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Kubevirt
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.5'
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kliczewski
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-06-25 00:00:00.000000000 Z
14
+ date: 2018-07-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler