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
@@ -0,0 +1,71 @@
1
+ module Fog
2
+ module Kubevirt
3
+ class Compute
4
+ class Vm < Fog::Model
5
+ include Shared
6
+
7
+ identity :name
8
+
9
+ attribute :namespace, :aliases => 'metadata_namespace'
10
+ attribute :resource_version, :aliases => 'metadata_resource_version'
11
+ attribute :uid, :aliases => 'metadata_uid'
12
+ attribute :labels, :aliases => 'metadata_labels'
13
+ attribute :owner_reference, :aliases => 'metadata_owner_reference'
14
+ attribute :annotations, :aliases => 'metadata_annotations'
15
+ attribute :cpu_cores, :aliases => 'spec_cpu_cores'
16
+ attribute :memory, :aliases => 'spec_memory'
17
+ attribute :disks, :aliases => 'spec_disks'
18
+ attribute :volumes, :aliases => 'spec_volumes'
19
+ attribute :status, :aliases => 'spec_running'
20
+
21
+
22
+ def start(options = {})
23
+ # Change the `running` attribute to `true` so that the virtual machine controller will take it and
24
+ # create the virtual machine instance.
25
+ vm = service.get_raw_vm(name)
26
+ vm = deep_merge!(vm,
27
+ :spec => {
28
+ :running => true
29
+ }
30
+ )
31
+ service.update_vm(vm)
32
+ end
33
+
34
+ def stop(options = {})
35
+ vm = service.get_raw_vm(name)
36
+ vm = deep_merge!(vm,
37
+ :spec => {
38
+ :running => false
39
+ }
40
+ )
41
+ service.update_vm(vm)
42
+ end
43
+
44
+ def self.parse(object)
45
+ metadata = object[:metadata]
46
+ spec = object[:spec][:template][:spec]
47
+ domain = spec[:domain]
48
+ owner = metadata[:ownerReferences]
49
+ annotations = metadata[:annotations]
50
+ cpu = domain[:cpu]
51
+ vm = {
52
+ :namespace => metadata[:namespace],
53
+ :name => metadata[:name],
54
+ :resource_version => metadata[:resourceVersion],
55
+ :uid => metadata[:uid],
56
+ :labels => metadata[:labels],
57
+ :memory => domain[:resources][:requests][:memory],
58
+ :disks => domain[:devices][:disks],
59
+ :volumes => spec[:volumes],
60
+ :status => object[:spec][:running].to_s == "true" ? "running" : "stopped"
61
+ }
62
+ vm[:owner_reference] = owner unless owner.nil?
63
+ vm[:annotations] = annotations unless annotations.nil?
64
+ vm[:cpu_cores] = cpu[:cores] unless cpu.nil?
65
+
66
+ vm
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,11 +1,7 @@
1
- require 'fog/compute/kubevirt/models/vm_data'
2
-
3
1
  module Fog
4
- module Compute
5
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
6
4
  class Vminstance < Fog::Model
7
- extend VmData
8
-
9
5
  identity :name
10
6
 
11
7
  attribute :namespace, :aliases => 'metadata_namespace'
@@ -18,8 +14,6 @@ module Fog
18
14
  attribute :disks, :aliases => 'spec_disks'
19
15
  attribute :volumes, :aliases => 'spec_volumes'
20
16
  attribute :ip_address, :aliases => 'status_interfaces_ip'
21
- attribute :interfaces, :aliases => 'spec_interfaces'
22
- attribute :networks, :aliases => 'spec_networks'
23
17
  attribute :node_name, :aliases => 'status_node_name'
24
18
  attribute :status, :aliases => 'status_phase'
25
19
 
@@ -28,7 +22,6 @@ module Fog
28
22
  status = object[:status]
29
23
  spec = object[:spec]
30
24
  domain = spec[:domain]
31
- disks = parse_disks(domain[:devices][:disks])
32
25
  {
33
26
  :namespace => metadata[:namespace],
34
27
  :name => metadata[:name],
@@ -38,10 +31,8 @@ module Fog
38
31
  :owner_uid => metadata.dig(:ownerReferences, 0, :uid),
39
32
  :cpu_cores => domain.dig(:cpu, :cores),
40
33
  :memory => domain[:resources][:requests][:memory],
41
- :disks => disks,
42
- :volumes => parse_volumes(spec[:volumes], disks),
43
- :interfaces => parse_interfaces(domain[:devices][:interfaces]),
44
- :networks => parse_networks(spec[:networks]),
34
+ :disks => domain[:devices][:disks],
35
+ :volumes => spec[:volumes],
45
36
  :ip_address => status.dig(:interfaces, 0, :ipAddress),
46
37
  :node_name => status[:nodeName],
47
38
  :status => status[:phase]
@@ -1,13 +1,13 @@
1
1
  require 'fog/core/collection'
2
- require 'fog/compute/kubevirt/models/vminstance'
2
+ require 'fog/kubevirt/compute/models/vminstance'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Kubevirt
5
+ module Kubevirt
6
+ class Compute
7
7
  class Vminstances < Fog::Collection
8
8
  attr_reader :kind, :resource_version
9
9
 
10
- model Fog::Compute::Kubevirt::Vminstance
10
+ model Fog::Kubevirt::Compute::Vminstance
11
11
 
12
12
  def all(filters = {})
13
13
  begin
@@ -0,0 +1,137 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/kubevirt/compute/models/vm'
3
+
4
+ module Fog
5
+ module Kubevirt
6
+ class Compute
7
+ class Vms < Fog::Collection
8
+ include Shared
9
+
10
+ attr_reader :kind, :resource_version
11
+
12
+ model Fog::Kubevirt::Compute::Vm
13
+
14
+ def all(filters = {})
15
+ begin
16
+ vms = service.list_vms(filters)
17
+ rescue ::Fog::Kubevirt::Errors::ClientError
18
+ # we assume that we get 404
19
+ vms = []
20
+ end
21
+ @kind = vms.kind
22
+ @resource_version = vms.resource_version
23
+ load vms
24
+ end
25
+
26
+ def get(name)
27
+ new service.get_vm(name)
28
+ end
29
+
30
+
31
+ # Creates a virtual machine using provided paramters:
32
+ # :vm_name [String] - name of a vm
33
+ # :cpus [String] - number of cpus
34
+ # :memory_size [String] - amount of memory
35
+ # :image [String] - name of a registry disk
36
+ # :pvc [String] - name of a persistent volume claim
37
+ #
38
+ # One of :image or :pvc needs to be provided.
39
+ #
40
+ # @param [Hash] attributes containing details about vm about to be
41
+ # created.
42
+ def create(args = {})
43
+ vm_name = args.fetch(:vm_name)
44
+ cpus = args.fetch(:cpus, nil)
45
+ memory_size = args.fetch(:memory_size)
46
+ image = args.fetch(:image, nil)
47
+ pvc = args.fetch(:pvc, nil)
48
+
49
+ if image.nil? && pvc.nil?
50
+ raise ::Fog::Kubevirt::Errors::ValidationError
51
+ end
52
+
53
+ volume = {}
54
+
55
+ if !image.nil?
56
+ volume = {
57
+ :name => vm_name,
58
+ :registryDisk => {
59
+ :image => image
60
+ }
61
+ }
62
+ else
63
+ volume = {
64
+ :name => vm_name,
65
+ :persistentVolumeClaim => {
66
+ :claimName => pvc
67
+ }
68
+ }
69
+ end
70
+
71
+ vm = {
72
+ :apiVersion => service.class::KUBEVIRT_VERSION_LABEL,
73
+ :kind => "VirtualMachine",
74
+ :metadata => {
75
+ :labels => {
76
+ :"kubevirt.io/vm" => vm_name,
77
+ },
78
+ :name => vm_name,
79
+ :namespace => service.namespace,
80
+ },
81
+ :spec => {
82
+ :running => false,
83
+ :template => {
84
+ :metadata => {
85
+ :creationTimestamp => nil,
86
+ :labels => {
87
+ :"kubevirt.io/vm" => vm_name
88
+ }
89
+ },
90
+ :spec => {
91
+ :domain => {
92
+ :devices => {
93
+ :disks => [
94
+ {:disk => {
95
+ :bus => "virtio"
96
+ },
97
+ :name => vm_name,
98
+ :volumeName => vm_name
99
+ }
100
+ ]
101
+ },
102
+ :machine => {
103
+ :type => ""
104
+ },
105
+ :resources => {
106
+ :requests => {
107
+ :memory => "#{memory_size}M"
108
+ }
109
+ }
110
+ },
111
+ :terminationGracePeriodSeconds => 0,
112
+ :volumes => [volume]
113
+ }
114
+ }
115
+ }
116
+ }
117
+
118
+ vm = deep_merge!(vm,
119
+ :spec => {
120
+ :template => {
121
+ :spec => {
122
+ :domain => {
123
+ :cpu => {
124
+ :cores => cpus
125
+ }
126
+ }
127
+ }
128
+ }
129
+ }
130
+ ) unless cpus.nil?
131
+
132
+ service.create_vm(vm)
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,9 @@
1
+ module Fog
2
+ module Kubevirt
3
+ class Compute
4
+ class Volume < Fog::Model
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/kubevirt/compute/models/volume'
3
+
4
+ module Fog
5
+ module Kubevirt
6
+ class Compute
7
+ class Volumes < Fog::Collection
8
+ model Fog::Kubevirt::Compute::Volume
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def create_pvc(pvc)
6
6
  kube_client.create_persistent_volume_claim(pvc)
@@ -1,9 +1,8 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def create_vm(vm)
6
- vm[:apiVersion] = kubevirt_client.version
7
6
  kubevirt_client.create_virtual_machine(vm)
8
7
  rescue ::Fog::Kubevirt::Errors::ClientError => err
9
8
  log.warn(err)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
 
6
6
  def create_vminstance(vm)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def delete_vm(name, namespace)
6
6
  kubevirt_client.delete_virtual_machine(name, namespace)
@@ -8,7 +8,7 @@ module Fog
8
8
  end
9
9
 
10
10
  class Mock
11
- def delete_vm(name, namespace)
11
+ def delete_vm(name)
12
12
  end
13
13
  end
14
14
  end
@@ -1,14 +1,14 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
- def delete_vminstance(name)
6
- kubevirt_client.delete_virtual_machine_instance(name, @namespace)
5
+ def delete_vminstance(name, namespace)
6
+ kubevirt_client.delete_virtual_machine_instance(name, namespace)
7
7
  end
8
8
  end
9
9
 
10
10
  class Mock
11
- def delete_virtual_machine_instance(name)
11
+ def delete_virtual_machine_instance(name, namespace = nil)
12
12
  end
13
13
  end
14
14
  end
@@ -1,8 +1,8 @@
1
1
  require 'recursive_open_struct'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Kubevirt
4
+ module Kubevirt
5
+ class Compute
6
6
  class Real
7
7
  def get_node(name)
8
8
  Node.parse object_to_hash( kube_client.get_node(name) )
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def get_template(name)
6
6
  Template.parse object_to_hash( openshift_client.get_template(name, @namespace) )
@@ -1,13 +1,13 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def get_vm(name)
6
6
  Vm.parse get_raw_vm(name)
7
7
  end
8
8
 
9
9
  def get_raw_vm(name)
10
- object_to_hash(kubevirt_client.get_virtual_machine(name, @namespace))
10
+ object_to_hash( kubevirt_client.get_virtual_machine(name, @namespace) )
11
11
  end
12
12
  end
13
13
 
@@ -1,8 +1,8 @@
1
1
  require 'recursive_open_struct'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Kubevirt
4
+ module Kubevirt
5
+ class Compute
6
6
  class Real
7
7
  def get_vminstance(name)
8
8
  # namespace is defined on the Real object
@@ -30,8 +30,8 @@ module Fog
30
30
  },
31
31
  :spec => { :domain => { :cpu => { :cores => "4" },
32
32
  :devices => { :disks => [{ :disk => { :dev => "vda" },
33
- :name => "containerDisk",
34
- :volumeName => "containervolume"
33
+ :name => "registrydisk",
34
+ :volumeName => "registryvolume"
35
35
  },
36
36
  { :disk => { :dev => "vdb" },
37
37
  :name => "cloudinitdisk",
@@ -42,8 +42,8 @@ module Fog
42
42
  :machine => { :type => "q35" },
43
43
  :resources => { :requests => { :memory => "512Mi" }}
44
44
  },
45
- :volumes => [ { :name => "containervolume",
46
- :containerDisk => { :image => "kubevirt/fedora-cloud-registry-disk-demo:latest" }
45
+ :volumes => [ { :name => "registryvolume",
46
+ :registryDisk => { :image => "kubevirt/fedora-cloud-registry-disk-demo:latest" }
47
47
  },
48
48
  { :cloudInitNoCloud => { :userDataBase64 => "I2Nsb3VkLWNvbmZpZwpwYXNzd29yZDogYXRvbWljCnNzaF9wd2F1dGg6IFRydWUKY2hwYXNzd2Q6IHsgZXhwaXJlOiBGYWxzZSB9Cg==" },
49
49
  :name => "cloudinitvolume"
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Kubevirt
2
+ module Kubevirt
3
+ class Compute
4
4
  class Real
5
5
  def list_nodes(_filters = {})
6
6
  nodes = kube_client.get_nodes