Class: Fog::Kubevirt::Compute::Pvcs

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/kubevirt/compute/models/pvcs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



10
11
12
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 10

def kind
  @kind
end

#resource_versionObject (readonly)

Returns the value of attribute resource_version.



10
11
12
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 10

def resource_version
  @resource_version
end

Instance Method Details

#all(filters = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 14

def all(filters = {})
  pvcs = service.list_pvcs(filters)
  @kind = pvcs.kind
  @resource_version = pvcs.resource_version
  load pvcs
end

#create(args = {}) ⇒ Object

Creates a pvc using provided paramters: kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims :name [String] - name of a pvc :namespace [String] - the namespace of the PVC, should be the same as POD’s pvc :storage_class [String] - the storage class name of the pvc :volume_name [String] - The volume name to :volume_mode [String] - Filesystem or block device :accessModes [Arr] - the access modes for the volume, values are specified here: :requests [Hash] - the request for storage resource, i.e. { :storage => “20Gi” } :limits [Hash] - the maximum amount of storage to consume, i.e. { :storage => “20Gi” } :match_labels [Hash] - label query over volumes for binding :match_expressions [Hash] - list of label selector requirements

Parameters:

  • attributes (Hash)

    containing details about pvc to be created.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 38

def create(args = {})
  name = args[:name]

  pvc = {
    :apiVersion => "v1",
    :kind => "PersistentVolumeClaim",
    :metadata => {
      :name      => name,
      :namespace => args[:namespace]
    },
    :spec => {
      :storageClassName => args[:storage_class],
      :resources        => {}
    }
  }

  # requests is required
  check_size(args[:requests])
  pvc[:spec][:resources].merge!(:requests => args[:requests])
  check_size(args[:limits]) if args[:limits]
  pvc[:spec][:resources].merge!(:limits => args[:limits]) if args[:limits]

  if args[:match_labels] || args[:match_expressions]
    pvc[:spec][:selector] = {}
    pvc[:spec][:selector].merge!(:matchLabels => args[:match_labels]) if args[:match_labels]
    pvc[:spec][:selector].merge!(:matchExpressions => args[:match_expressions]) if args[:match_expressions]
  end

  # access mode is required
  pvc[:spec][:accessModes] = args[:access_modes]
  pvc[:spec][:volumeMode] = args[:volume_mode] if args[:volume_mode]
  pvc[:spec][:volumeName] = args[:volume_name] if args[:volume_name]
  service.create_pvc(pvc)
end

#delete(name) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 73

def delete(name)
  begin
    pvc = get(name)
  rescue ::Fog::Kubevirt::Errors::ClientError
    # the pvc doesn't exist
    pvc = nil
  end

  service.delete_pvc(name) unless pvc.nil?
end

#get(name) ⇒ Object



21
22
23
# File 'lib/fog/kubevirt/compute/models/pvcs.rb', line 21

def get(name)
  new service.get_pvc(name)
end