Class: Fog::Hyperv::Compute::HardDrive
- Defined in:
- lib/fog/hyperv/compute/models/hard_drive.rb
Overview
A hard drive attached to a VM
Instance Attribute Summary collapse
-
#computer_name ⇒ String
readonly
The name of the computer running the VM that this hard drive is attached to.
-
#controller_location ⇒ String
The controller location this hard drive is attached to.
-
#controller_number ⇒ Integer
The controller number this hard drive is attached to.
-
#controller_type ⇒ :IDE, :SCSI
readonly
The controller type this hard drive is attached to.
-
#disk ⇒ Object
The attached physical disk.
-
#id ⇒ String
readonly
The GUID of this hard drive.
-
#maximum_iops ⇒ Integer
The maximum number of IOPS allocated for this hard drive.
-
#minimum_iops ⇒ Integer
The minimum number of IOPS allocated for this hard drive.
-
#name ⇒ String
readonly
The name of this hard drive.
-
#path ⇒ String
The path to the VHD file for this hard drive.
-
#pool_name ⇒ String
The name of the pool storing this hard drive’s image.
-
#size_bytes ⇒ Integer?
readonly
The size of the underlying VHD if any.
-
#support_persistent_reservations ⇒ Boolean
If the underlying hard drive supports SCSI persistent reservations.
-
#vhd ⇒ Vhd?
The VHD that is attached to this hard drive.
-
#vm_id ⇒ String
readonly
The GUID of the VM this hard drive is attached to.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy(underlying: false) ⇒ Object
-
#initialize(attributes = {}) ⇒ HardDrive
constructor
A new instance of HardDrive.
- #reload ⇒ Object
- #update ⇒ Object
-
#vhd? ⇒ Boolean
Does the hard drive have a VHD attached?.
Methods inherited from Model
Methods included from ModelExtends
Methods included from ModelIncludes
#cluster, #computer, #dirty, #dirty?, #vm
Constructor Details
#initialize(attributes = {}) ⇒ HardDrive
Returns a new instance of HardDrive.
57 58 59 60 61 62 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 57 def initialize(attributes = {}) vhd = attributes[:vhd] attributes[:path] ||= vhd&.path super end |
Instance Attribute Details
#computer_name ⇒ String (readonly)
Returns the name of the computer running the VM that this hard drive is attached to.
14 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 14 attribute :computer_name |
#controller_location ⇒ String
Returns the controller location this hard drive is attached to.
21 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 21 attribute :controller_location |
#controller_number ⇒ Integer
Returns the controller number this hard drive is attached to.
24 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 24 attribute :controller_number, type: :integer |
#controller_type ⇒ :IDE, :SCSI (readonly)
Returns the controller type this hard drive is attached to.
27 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 27 attribute :controller_type, type: :hypervenum, values: %i[IDE SCSI] |
#disk ⇒ Object
Returns the attached physical disk.
30 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 30 attribute :disk |
#id ⇒ String (readonly)
Returns the GUID of this hard drive.
10 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 10 identity :id |
#maximum_iops ⇒ Integer
Returns the maximum number of IOPS allocated for this hard drive.
34 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 34 attribute :maximum_iops, type: :integer |
#minimum_iops ⇒ Integer
Returns the minimum number of IOPS allocated for this hard drive.
37 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 37 attribute :minimum_iops, type: :integer |
#name ⇒ String (readonly)
Returns the name of this hard drive.
40 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 40 attribute :name |
#path ⇒ String
Returns the path to the VHD file for this hard drive.
43 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 43 attribute :path |
#pool_name ⇒ String
Returns the name of the pool storing this hard drive’s image.
46 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 46 attribute :pool_name |
#size_bytes ⇒ Integer? (readonly)
Returns the size of the underlying VHD if any.
87 88 89 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 87 def size_bytes vhd&.size end |
#support_persistent_reservations ⇒ Boolean
Returns if the underlying hard drive supports SCSI persistent reservations. This should be set when multiple VMs share the same underlying disk.
50 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 50 attribute :support_persistent_reservations |
#vhd ⇒ Vhd?
Returns the VHD that is attached to this hard drive.
66 67 68 69 70 71 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 66 def vhd return associations[:vhd] if associations[:vhd] return unless path associations[:vhd] = service.vhds.get(path, computer_name:) end |
#vm_id ⇒ String (readonly)
Returns the GUID of the VM this hard drive is attached to.
17 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 17 attribute :vm_id |
Instance Method Details
#create ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 91 def create requires :vm_id requires_one :controller_location, :controller_number, :controller_type, :path if associations[:vhd] vhd.save if !vhd.persisted? || vhd.dirty? attributes[:path] ||= vhd.path end merge_attributes( service.add_vm_hard_disk_drive( computer_name:, vm_id:, allow_unverified_paths:, controller_location:, controller_number:, controller_type:, # disk_number: disk&.number, maximum_iops:, minimum_iops:, path:, resource_pool_name: pool_name, _return_fields: self.class.attributes - %i[allow_unverified_paths vhd] ) ) end |
#destroy(underlying: false) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 173 def destroy(underlying: false) return unless persisted? requires :id, :vm_id service.remove_vm_hard_disk_drive( computer_name:, vm_id:, id: ) vhd.destroy if && vhd? true end |
#reload ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 158 def reload requires :id, :vm_id data = service.get_vm_hard_disk_drive( computer_name:, vm_id:, id:, _return_fields: self.class.attributes - %i[allow_unverified_paths vhd] ) return unless data merge_attributes(data) end |
#update ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 120 def update requires :id, :vm_id changes = { maximum_iops: changed!(:maximum_iops), minimum_iops: changed!(:minimum_iops), 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) }.compact changes[:path] = path if changed?(:path) if changes.any? merge_attributes( service.set_vm_hard_disk_drive( computer_name: old.computer_name, vm_id: old.vm_id, id: old.id, **changes, allow_unverified_paths:, _always_include: changes.keys, _return_fields: self.class.attributes - %i[allow_unverified_paths vhd] ) ) end if associations[:vhd] vhd.save if !vhd.persisted? || vhd.dirty? associations[:vhd] = nil if changed?(:path) end self end |
#vhd? ⇒ Boolean
Returns does the hard drive have a VHD attached?.
81 82 83 |
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 81 def vhd? !vhd.nil? end |