Class: Fog::Compute::Hyperv::HardDrive

Inherits:
Hyperv::Model show all
Defined in:
lib/fog/hyperv/models/compute/hard_drive.rb

Instance Method Summary collapse

Methods inherited from Hyperv::Model

#initialize

Methods included from Hyperv::ModelExtends

#lazy_attributes

Methods included from Hyperv::ModelIncludes

#cluster, #computer, #dirty?, #lazy_attributes, #parent, #vm

Constructor Details

This class inherits a constructor from Fog::Hyperv::Model

Instance Method Details

#destroyObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 95

def destroy
  return unless persisted?

  service.remove_vm_hard_disk_drive(
    computer_name: computer_name,
    vm_name: vm_name,

    controller_location: controller_location,
    controller_number: controller_number,
    controller_type: controller_type
  )
end

#reloadObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 81

def reload
  data = collection.get(
    computer_name: computer_name,
    vm_name: vm_name,
    controller_location: controller_location,
    controller_number: controller_number,
    controller_type: controller_type
  )

  merge_attributes(data.attributes)
  @old = data
  self
end

#saveObject



36
37
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
72
73
74
75
76
77
78
79
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 36

def save
  requires :computer_name, :vm_name

  if persisted?
    data = service.set_vm_hard_disk_drive(
      computer_name: old.computer_name,
      vm_name: old.vm_name,
      controller_location: old.controller_location,
      controller_number: old.controller_number,
      controller_type: old.controller_type,
      passthru: true,

      disk_number: changed?(:disk) && disk && disk.number,
      maximum_iops: changed!(:maximum_iops),
      minimum_iops: changed!(:minimum_iops),
      path: changed!(:path),
      resource_pool_name: changed!(:pool_name),
      support_persistent_reservations: changed!(:support_persistent_reservations),
      to_controller_location: changed!(:controller_location),
      to_controller_number: changed!(:controller_number),
      to_controller_type: changed!(:controller_type),

      _return_fields: self.class.attributes,
      _json_depth: 1
    )
    @vhd = nil if changed?(:path)
  else
    possible = %i[computer_name controller_location controller_number controller_type path vm_name].freeze
    data = service.add_vm_hard_disk_drive(
      attributes.select { |k, _v| possible.include? k }.merge(
        disk_number: disk && disk.number,
        resource_pool_name: pool_name,

        passthru: true,
        _return_fields: self.class.attributes,
        _json_depth: 1
      )
    )
  end

  merge_attributes(data)
  @old = dup
  self
end

#size_bytesObject



28
29
30
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 28

def size_bytes
  vhd && vhd.size_bytes || 0
end

#size_bytes=(bytes) ⇒ Object



32
33
34
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 32

def size_bytes=(bytes)
  vhd.size_bytes = bytes if vhd
end

#vhdObject

TODO? VM Snapshots?



23
24
25
26
# File 'lib/fog/hyperv/models/compute/hard_drive.rb', line 23

def vhd
  return nil unless path && computer_name
  @vhd ||= service.vhds.get(path, computer_name: computer_name)
end