fog-kubevirt 1.0.2 → 1.1.0

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/kubevirt/compute/compute.rb +28 -6
  3. data/lib/fog/kubevirt/compute/models/persistentvolume.rb +82 -0
  4. data/lib/fog/kubevirt/compute/models/persistentvolumes.rb +73 -0
  5. data/lib/fog/kubevirt/compute/models/storageclass.rb +33 -0
  6. data/lib/fog/kubevirt/compute/models/storageclasses.rb +61 -0
  7. data/lib/fog/kubevirt/compute/models/vm_base.rb +13 -2
  8. data/lib/fog/kubevirt/compute/models/vm_data.rb +11 -13
  9. data/lib/fog/kubevirt/compute/models/vminstance.rb +11 -2
  10. data/lib/fog/kubevirt/compute/models/vms.rb +48 -19
  11. data/lib/fog/kubevirt/compute/models/volume.rb +44 -69
  12. data/lib/fog/kubevirt/compute/models/volumes.rb +3 -58
  13. data/lib/fog/kubevirt/compute/requests/{create_volume.rb → create_persistentvolume.rb} +2 -2
  14. data/lib/fog/kubevirt/compute/requests/create_storageclass.rb +18 -0
  15. data/lib/fog/kubevirt/compute/requests/{delete_volume.rb → delete_persistentvolume.rb} +2 -2
  16. data/lib/fog/kubevirt/compute/requests/{get_volume.rb → delete_storageclass.rb} +3 -3
  17. data/lib/fog/kubevirt/compute/requests/delete_vm.rb +1 -1
  18. data/lib/fog/kubevirt/compute/requests/delete_vminstance.rb +3 -3
  19. data/lib/fog/kubevirt/compute/requests/get_persistentvolume.rb +16 -0
  20. data/lib/fog/kubevirt/compute/requests/get_storageclass.rb +16 -0
  21. data/lib/fog/kubevirt/compute/requests/list_persistentvolumes.rb +22 -0
  22. data/lib/fog/kubevirt/compute/requests/list_storageclasses.rb +22 -0
  23. data/lib/fog/kubevirt/compute/requests/list_volumes.rb +14 -6
  24. data/lib/fog/kubevirt/version.rb +1 -1
  25. data/spec/create_vm_spec.rb +101 -0
  26. data/spec/fixtures/kubevirt/{volume/volumes_crud.yml → persistentvolume/persistent_volumes_crud.yml} +0 -0
  27. data/spec/fixtures/kubevirt/pvc/pvcs_crud.yml +122 -76
  28. data/spec/fixtures/kubevirt/storageclass/storageclasses_crud.yml +400 -0
  29. data/spec/fixtures/kubevirt/vm/vm_create_multi.yml +459 -0
  30. data/spec/fixtures/kubevirt/vm/vm_create_single.yml +362 -0
  31. data/spec/{volumes_v1alpha2_spec.rb → persistent_volumes_v1alpha2_spec.rb} +11 -11
  32. data/spec/pvcs_v1alpha2_spec.rb +7 -0
  33. data/spec/storage_classes_v1_spec.rb +46 -0
  34. metadata +28 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d98797096ddd6d2f4464998bcdbf56dcac2e9ab
4
- data.tar.gz: eea11774097b4c70fe95ecbbef47847c454fa548
3
+ metadata.gz: ee0eacc3688d804fe65c3b1aad58a83598ea1464
4
+ data.tar.gz: 3bb93e156ebcfd91ab968472aa820bad4be79f24
5
5
  SHA512:
6
- metadata.gz: c2ea3b5710d1783c0e4710e625d2a8a8271afe322e196a52d59b27164dcf7f76a770fd95f5b77857a5447a6162a60bc96fbad78415d46c3511e005ce65a11aa0
7
- data.tar.gz: 57e59e0eeb42b6542735181069436c234ca1c236fe179b44c8a45eebab6b44e682c247b7d917eacc079aa43dce2b4c18285ae54094c338d775203a8fab747451
6
+ metadata.gz: b923222a67ec3decae7a438a62ddcaf47c6f2ea9b242479e0359398a253c715300aada3ea9024a97b2ed41a8df694ca304d019d1c1f7653e91cb84f8db57adae
7
+ data.tar.gz: d4fac11a34371874e4c2a59983cc1168c8ae5e3a09617a63cd74eb51553951beb0f9f0d38fae5c25f58f9ccba485facee7f21b8f88d2404a6787266e7a3a2096
@@ -18,12 +18,16 @@ module Fog
18
18
  collection :nodes
19
19
  model :vm
20
20
  collection :vms
21
+ model :persistentvolume
22
+ collection :persistentvolumes
21
23
  model :pvc
22
24
  collection :pvcs
23
25
  model :server
24
26
  collection :servers
25
27
  model :service
26
28
  collection :services
29
+ model :storageclass
30
+ collection :storageclasses
27
31
  model :template
28
32
  collection :templates
29
33
  model :volume
@@ -33,33 +37,38 @@ module Fog
33
37
  request :create_networkattachmentdef
34
38
  request :create_vm
35
39
  request :create_vminstance
40
+ request :create_persistentvolume
36
41
  request :create_pvc
37
42
  request :create_service
38
- request :create_volume
43
+ request :create_storageclass
39
44
  request :delete_networkattachmentdef
45
+ request :delete_persistentvolume
40
46
  request :delete_pvc
41
47
  request :delete_service
48
+ request :delete_storageclass
42
49
  request :delete_vminstance
43
50
  request :delete_vm
44
- request :delete_volume
45
51
  request :get_vminstance
46
52
  request :get_networkattachmentdef
47
53
  request :get_node
54
+ request :get_persistentvolume
48
55
  request :get_pvc
49
56
  request :get_vm
50
- request :get_volume
51
57
  request :get_server
52
58
  request :get_service
59
+ request :get_storageclass
53
60
  request :get_template
54
61
  request :list_vminstances
55
62
  request :list_nodes
56
63
  request :list_networkattachmentdefs
57
64
  request :list_vms
65
+ request :list_persistentvolumes
58
66
  request :list_pvcs
59
- request :list_volumes
60
67
  request :list_servers
61
68
  request :list_services
69
+ request :list_storageclasses
62
70
  request :list_templates
71
+ request :list_volumes
63
72
  request :update_vm
64
73
 
65
74
  module Shared
@@ -166,6 +175,11 @@ module Fog
166
175
  #
167
176
  NETWORK_GROUP = 'k8s.cni.cncf.io'.freeze
168
177
 
178
+ #
179
+ # The API group of the Kubernetes network extention:
180
+ #
181
+ STORAGE_GROUP = 'storage.k8s.io'.freeze
182
+
169
183
  def initialize(options={})
170
184
  require 'kubeclient'
171
185
 
@@ -416,12 +430,16 @@ module Fog
416
430
  ssl_client_key: ssl_options[:client_key],
417
431
  }
418
432
 
419
- response = ::JSON.parse(RestClient::Resource.new(url, options).get)
433
+ begin
434
+ response = ::JSON.parse(RestClient::Resource.new(url, options).get)
435
+ rescue => e
436
+ raise ::Fog::Kubevirt::Errors::ClientError, e
437
+ end
420
438
 
421
439
  # version detected based on
422
440
  # https://github.com/kubernetes-incubator/apiserver-builder/blob/master/docs/concepts/aggregation.md#viewing-discovery-information
423
441
  preferredVersion = response["preferredVersion"]
424
- return preferredVersion["version"] if preferredVersion
442
+ return preferredVersion["version"] if preferredVersion
425
443
  response["versions"][0]
426
444
  end
427
445
 
@@ -441,6 +459,10 @@ module Fog
441
459
  create_client('/apis/' + NETWORK_GROUP)
442
460
  end
443
461
 
462
+ def kube_storage_client
463
+ create_client('/apis/' + STORAGE_GROUP)
464
+ end
465
+
444
466
  def log
445
467
  @log
446
468
  end
@@ -0,0 +1,82 @@
1
+ module Fog
2
+ module Kubevirt
3
+ class Compute
4
+ class Persistentvolume < Fog::Model
5
+ identity :name
6
+
7
+ attribute :resource_version, :aliases => 'metadata_resource_version'
8
+ attribute :uid, :aliases => 'metadata_uid'
9
+ attribute :annotations, :aliases => 'metadata_annotations'
10
+ attribute :labels, :aliases => 'metadata_labels'
11
+ attribute :access_modes, :aliases => 'spec_access_modes'
12
+ attribute :mount_options, :aliases => 'spec_mount_options'
13
+ attribute :reclaim_policy, :aliases => 'spec_reclaim_policy'
14
+ attribute :storage_class, :aliases => 'spec_storage_class'
15
+ attribute :capacity, :aliases => 'spec_capacity'
16
+ attribute :claim_ref, :aliases => 'spec_claim_ref'
17
+ attribute :type, :aliases => 'spec_type'
18
+ attribute :config, :aliases => 'spec_config'
19
+ attribute :phase, :aliases => 'status_phase'
20
+ attribute :reason, :aliases => 'status_reason'
21
+ attribute :message, :aliases => 'status_message'
22
+
23
+ def self.parse(object)
24
+ metadata = object[:metadata]
25
+ spec = object[:spec]
26
+ status = object[:status]
27
+ type = detect_type(spec)
28
+
29
+ {
30
+ :name => metadata[:name],
31
+ :resource_version => metadata[:resourceVersion],
32
+ :uid => metadata[:uid],
33
+ :annotations => metadata[:annotations],
34
+ :labels => metadata[:labels],
35
+ :access_modes => spec[:accessModes],
36
+ :mount_options => spec[:mountOptions],
37
+ :reclaim_policy => spec[:persistentVolumeReclaimPolicy],
38
+ :storage_class => spec[:storageClassName],
39
+ :capacity => spec.dig(:capacity, :storage),
40
+ :claim_ref => spec[:claimRef],
41
+ :type => type,
42
+ :config => spec[type&.to_sym],
43
+ :phase => status[:phase],
44
+ :reason => status[:reason],
45
+ :message => status[:message]
46
+ }
47
+ end
48
+
49
+ def self.detect_type(spec)
50
+ type = ''
51
+ type = 'awsElasticBlockStore' if spec.keys.include?(:awsElasticBlockStore)
52
+ type = 'azureDisk' if spec.keys.include?(:azureDisk)
53
+ type = 'azureFile' if spec.keys.include?(:azureFile)
54
+ type = 'cephfs' if spec.keys.include?(:cephfs)
55
+ type = 'configMap' if spec.keys.include?(:configMap)
56
+ type = 'csi' if spec.keys.include?(:csi)
57
+ type = 'downwardAPI' if spec.keys.include?(:downwardAPI)
58
+ type = 'emptyDir' if spec.keys.include?(:emptyDir)
59
+ type = 'fc' if spec.keys.include?(:fc)
60
+ type = 'flexVolume' if spec.keys.include?(:flexVolume)
61
+ type = 'flocker' if spec.keys.include?(:flocker)
62
+ type = 'gcePersistentDisk' if spec.keys.include?(:gcePersistentDisk)
63
+ type = 'glusterfs' if spec.keys.include?(:glusterfs)
64
+ type = 'hostPath' if spec.keys.include?(:hostPath)
65
+ type = 'iscsi' if spec.keys.include?(:iscsi)
66
+ type = 'local' if spec.keys.include?(:local)
67
+ type = 'nfs' if spec.keys.include?(:nfs)
68
+ type = 'persistentVolumeClaim' if spec.keys.include?(:persistentVolumeClaim)
69
+ type = 'projected' if spec.keys.include?(:projected)
70
+ type = 'portworxVolume' if spec.keys.include?(:portworxVolume)
71
+ type = 'quobyte' if spec.keys.include?(:quobyte)
72
+ type = 'rbd' if spec.keys.include?(:rbd)
73
+ type = 'scaleIO' if spec.keys.include?(:scaleIO)
74
+ type = 'secret' if spec.keys.include?(:secret)
75
+ type = 'storageos' if spec.keys.include?(:storageos)
76
+ type = 'vsphereVolume' if spec.keys.include?(:vsphereVolume)
77
+ type
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,73 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/kubevirt/compute/models/persistentvolume'
3
+
4
+ module Fog
5
+ module Kubevirt
6
+ class Compute
7
+ class Persistentvolumes < Fog::Collection
8
+ attr_reader :kind, :resource_version
9
+
10
+ model Fog::Kubevirt::Compute::Persistentvolume
11
+
12
+ def all(filters = {})
13
+ volumes = service.list_persistentvolumes(filters)
14
+ @kind = volumes.kind
15
+ @resource_version = volumes.resource_version
16
+ load volumes
17
+ end
18
+
19
+ def get(name)
20
+ new service.get_persistentvolume(name)
21
+ end
22
+
23
+ # Creates a volume using provided paramters:
24
+ # :name [String] - name of a volume
25
+ # :labels [Hash] - a hash of key,values representing the labels
26
+ # :storage_class [String] - the storage class name of the volume
27
+ # :capacity [String] - The capacity of the storage if applied
28
+ # :accessModes [Arr] - the access modes for the volume, values are specified here:
29
+ # https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
30
+ # :type [String] - the type of the storage
31
+ # :config [Hash] - storage specific configuration to be applied for the volume
32
+ # correlated to the args[:type]
33
+ # @param [Hash] attributes containing details about volume to be created.
34
+ def create(args = {})
35
+ name = args[:name]
36
+ labels = args[:labels]
37
+
38
+ volume = {
39
+ :apiVersion => "v1",
40
+ :kind => "PersistentVolume",
41
+ :metadata => {
42
+ :name => name
43
+ },
44
+ :spec => {
45
+ :storageClassName => args[:storage_class]
46
+ }
47
+ }
48
+
49
+ volume[:metadata][:labels] = labels if labels
50
+ volume[:spec][:capacity] = {
51
+ :storage => args[:capacity]
52
+ } if args[:capacity]
53
+
54
+ volume[:spec][:accessModes] = args[:access_modes] if args[:access_modes]
55
+ volume[:spec][args[:type].to_sym] = args[:config] if args[:type]
56
+
57
+ service.create_persistentvolume(volume)
58
+ end
59
+
60
+ def delete(name)
61
+ begin
62
+ volume = get(name)
63
+ rescue ::Fog::Kubevirt::Errors::ClientError
64
+ # the volume doesn't exist
65
+ volume = nil
66
+ end
67
+
68
+ service.delete_persistentvolume(name) unless volume.nil?
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Kubevirt
3
+ class Compute
4
+ class Storageclass < Fog::Model
5
+ # Metadata
6
+ identity :name
7
+ attribute :resource_version, :aliases => 'metadata_resource_version'
8
+ attribute :uid, :aliases => 'metadata_uid'
9
+
10
+ attribute :mount_options
11
+ attribute :parameters
12
+ attribute :provisioner
13
+ attribute :reclaim_policy
14
+ attribute :volume_binding_mode
15
+
16
+ def self.parse(object)
17
+ metadata = object[:metadata]
18
+ {
19
+ :name => metadata[:name],
20
+ :resource_version => metadata[:resourceVersion],
21
+ :uid => metadata[:uid],
22
+
23
+ :parameters => object[:parameters],
24
+ :mount_options => object[:mountOptions],
25
+ :provisioner => object[:provisioner],
26
+ :reclaim_policy => object[:reclaimPolicy],
27
+ :volume_binding_mode => object[:volumeBindingMode]
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,61 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/kubevirt/compute/models/storageclass'
3
+
4
+ module Fog
5
+ module Kubevirt
6
+ class Compute
7
+ class Storageclasses < Fog::Collection
8
+ attr_reader :kind, :resource_version
9
+
10
+ model Fog::Kubevirt::Compute::Storageclass
11
+
12
+ def all(filters = {})
13
+ storageclasses = service.list_storageclasses(filters)
14
+ @kind = storageclasses.kind
15
+ @resource_version = storageclasses.resource_version
16
+ load storageclasses
17
+ end
18
+
19
+ def get(name)
20
+ new service.get_storageclass(name)
21
+ end
22
+
23
+ # Creates a storage class using provided paramters:
24
+ # https://kubernetes.io/docs/concepts/storage/storage-classes
25
+ # :name [String] - name of a storage class
26
+ # :parameters [Object] - parameters for the provisioner that should create volumes of this storage class
27
+ # :mount_options [Arr] - mount options for the dynamically provisioned PersistentVolumes of this storage class.
28
+ # :provisioner [String] - the type of the provisioner
29
+ # :volume_binding_mode [String] - indicates how PersistentVolumeClaims should be provisioned and bound
30
+ # :reclaim_policy [String] - the reclaim policy of the created PVs (Defaults to Delete).
31
+ def create(args = {})
32
+ storageclass = {
33
+ :apiVersion => "storage.k8s.io/v1",
34
+ :kind => "StorageClass",
35
+ :metadata => {
36
+ :name => args[:name],
37
+ },
38
+ :parameters => args[:parameters],
39
+ :mount_options => args[:mount_options],
40
+ :provisioner => args[:provisioner],
41
+ :volume_binding_mode => args[:volume_binding_mode],
42
+ :reclaim_policy => args[:reclaim_policy]
43
+ }
44
+
45
+ service.create_storageclass(storageclass)
46
+ end
47
+
48
+ def delete(name)
49
+ begin
50
+ storageclass = get(name)
51
+ rescue ::Fog::Kubevirt::Errors::ClientError
52
+ # the storageclass doesn't exist
53
+ storageclass = nil
54
+ end
55
+
56
+ service.delete_storageclass(name) unless storageclass.nil?
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,7 +1,11 @@
1
+ require 'fog/kubevirt/compute/models/vm_data'
2
+
1
3
  module Fog
2
4
  module Kubevirt
3
5
  class Compute
4
6
  module VmBase
7
+ include VmData
8
+
5
9
  def define_properties
6
10
  identity :name
7
11
 
@@ -16,6 +20,9 @@ module Fog
16
20
  attribute :disks, :aliases => 'spec_disks'
17
21
  attribute :volumes, :aliases => 'spec_volumes'
18
22
  attribute :status, :aliases => 'spec_running'
23
+ attribute :interfaces, :aliases => 'spec_interfaces'
24
+ attribute :networks, :aliases => 'spec_networks'
25
+ attribute :machine_type, :aliases => 'spec_machine_type'
19
26
  end
20
27
 
21
28
  def parse_object(object)
@@ -26,15 +33,19 @@ module Fog
26
33
  annotations = metadata[:annotations]
27
34
  cpu = domain[:cpu]
28
35
  mem = domain.dig(:resources, :requests, :memory)
36
+ disks = parse_disks(domain[:devices][:disks])
29
37
  vm = {
30
38
  :namespace => metadata[:namespace],
31
39
  :name => metadata[:name],
32
40
  :resource_version => metadata[:resourceVersion],
33
41
  :uid => metadata[:uid],
34
42
  :labels => metadata[:labels],
35
- :disks => domain[:devices][:disks],
36
- :volumes => spec[:volumes],
43
+ :disks => disks,
44
+ :volumes => parse_volumes(spec[:volumes], disks),
37
45
  :status => object[:spec][:running].to_s == "true" ? "running" : "stopped",
46
+ :interfaces => parse_interfaces(domain[:devices][:interfaces]),
47
+ :networks => parse_networks(spec[:networks]),
48
+ :machine_type => domain.dig(:machine, :type)
38
49
  }
39
50
  vm[:owner_reference] = owner unless owner.nil?
40
51
  vm[:annotations] = annotations unless annotations.nil?
@@ -1,3 +1,5 @@
1
+ require 'fog/kubevirt/compute/models/volume'
2
+
1
3
  module Fog
2
4
  module Kubevirt
3
5
  class Compute
@@ -55,7 +57,6 @@ module Fog
55
57
  disk = VmDisk.new
56
58
  disk.name = d[:name]
57
59
  disk.boot_order = d[:bootOrder]
58
- disk.volume_name = d[:volumeName]
59
60
 
60
61
  if d.keys.include?(:cdrom)
61
62
  disk.type = 'cdrom'
@@ -82,12 +83,13 @@ module Fog
82
83
  # Returns an array of parsed volumes
83
84
  #
84
85
  # @param object [Hash] A hash with raw volumes data.
86
+ # @param disks [Array] the disks of the vm associated to the volumes
85
87
  #
86
- def parse_volumes(object)
88
+ def parse_volumes(object, disks)
87
89
  return {} if object.nil?
88
90
  volumes = []
89
91
  object.each do |v|
90
- volume = VmVolume.new
92
+ volume = Volume.new
91
93
  volume.name = v[:name]
92
94
  if v.keys.include?(:containerDisk)
93
95
  volume.type = 'containerDisk'
@@ -120,6 +122,12 @@ module Fog
120
122
  volume.type = 'configMap'
121
123
  volume.info = v.dig(:configMap, :name)
122
124
  end
125
+
126
+ volume.config = v[volume.type.to_sym]
127
+ disk = disks.select { |d| d.name == volume.name }.first
128
+ volume.boot_order = disk.boot_order
129
+ volume.bus = disk.bus if disk.respond_to?(:bus)
130
+
123
131
  volumes << volume
124
132
  end
125
133
 
@@ -143,21 +151,11 @@ module Fog
143
151
 
144
152
  class VmDisk
145
153
  attr_accessor :name,
146
- :volume_name,
147
154
  :boot_order,
148
155
  :type, # values: cdrom, disk, floppy, lun
149
156
  :bus,
150
157
  :readonly
151
158
  end
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
160
- end
161
159
  end
162
160
  end
163
161
  end