Class: Fog::Hyperv::Compute::Vhd
- Defined in:
- lib/fog/hyperv/compute/models/vhd.rb
Overview
A VM hard drive - VHD - file
Constant Summary collapse
- VHD_TYPE_ENUM_VALUES =
Note:
Defined by Microsoft.Vhd.PowerShell.VhdType
VHD types
{ Unknown: 0, Fixed: 2, Dynamic: 3, Differencing: 4 }.freeze
- VHD_FORMAT_ENUM_VALUES =
Note:
Defined by Microsoft.Vhd.PowerShell.VhdFormat
VHD formats
{ Unknown: 0, VHD: 2, VHDX: 3, VHDSet: 4 }.freeze
Instance Attribute Summary collapse
-
#attached ⇒ Boolean
readonly
Is the VHD attached to something.
-
#basename ⇒ String
readonly
The basename of the VHD file, without extension.
-
#block_size ⇒ Integer
readonly
The block size of the VHD in bytes.
-
#computer_name ⇒ String
readonly
The name of the computer hosting this VHD.
-
#disk_identifier ⇒ String
readonly
The guid of this VHD.
-
#disk_number ⇒ Integer?
readonly
The disk number.
-
#file_size ⇒ Integer?
readonly
The size of the VHD file in bytes.
-
#logical_sector_size ⇒ 512, 4096
readonly
The logical sector size for the VHD in bytes.
-
#minimum_size ⇒ Integer?
readonly
The minimum possible size of the VHD in bytes, for shrinking purposes.
-
#parent_path ⇒ String?
readonly
The path to the parent VHD.
-
#path ⇒ String?
readonly
The path to the VHD on disk.
-
#physical_sector_size_bytes ⇒ 512, 4096
The physical sector size for the VHD in bytes.
-
#pool_name ⇒ String
readonly
The name of the pool storing this VHD.
-
#size ⇒ Integer?
The size of the VHD in bytes.
-
#unc_path ⇒ String
readonly
The UNC path to the VHD file in a cluster.
-
#vhd_format ⇒ :Unknown, ...
readonly
The format of the VHD.
-
#vhd_type ⇒ :Unknown, ...
readonly
The type of the VHD.
Instance Method Summary collapse
-
#create ⇒ Object
Save the VHD to Hyper-V.
-
#destroy ⇒ Object
Remove the VHD from disk.
-
#optimize(mode: nil) ⇒ Object
Optimizes the VHD on disk.
-
#reload ⇒ Object
Reload the VHD attributes from Hyper-V.
- #update ⇒ Object
Methods inherited from Model
Methods included from ModelExtends
Methods included from ModelIncludes
#cluster, #computer, #dirty, #dirty?, #vm
Constructor Details
This class inherits a constructor from Fog::Hyperv::Model
Instance Attribute Details
#attached ⇒ Boolean (readonly)
Returns is the VHD attached to something.
37 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 37 attribute :attached, type: :boolean |
#basename ⇒ String (readonly)
Returns the basename of the VHD file, without extension.
80 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 80 attribute :basename |
#block_size ⇒ Integer (readonly)
Returns the block size of the VHD in bytes.
40 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 40 attribute :block_size, type: :integer |
#computer_name ⇒ String (readonly)
Returns the name of the computer hosting this VHD.
33 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 33 attribute :computer_name |
#disk_identifier ⇒ String (readonly)
Returns the guid of this VHD.
29 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 29 identity :disk_identifier |
#disk_number ⇒ Integer? (readonly)
Returns the disk number.
43 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 43 attribute :disk_number |
#file_size ⇒ Integer? (readonly)
Returns the size of the VHD file in bytes.
46 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 46 attribute :file_size |
#logical_sector_size ⇒ 512, 4096 (readonly)
Returns the logical sector size for the VHD in bytes.
49 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 49 attribute :logical_sector_size, type: :integer |
#minimum_size ⇒ Integer? (readonly)
Returns the minimum possible size of the VHD in bytes, for shrinking purposes.
52 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 52 attribute :minimum_size |
#parent_path ⇒ String? (readonly)
Returns the path to the parent VHD.
55 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 55 attribute :parent_path |
#path ⇒ String? (readonly)
Returns the path to the VHD on disk.
58 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 58 attribute :path |
#physical_sector_size_bytes ⇒ 512, 4096
Returns the physical sector size for the VHD in bytes.
64 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 64 attribute :physical_sector_size, type: :integer |
#pool_name ⇒ String (readonly)
Returns the name of the pool storing this VHD.
61 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 61 attribute :pool_name |
#size ⇒ Integer?
Defaults to 32GB if not specified
Returns the size of the VHD in bytes.
68 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 68 attribute :size, default: 32 * 1024 * 1024 * 1024 |
#unc_path ⇒ String (readonly)
Returns the UNC path to the VHD file in a cluster.
84 85 86 87 88 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 84 def unc_path requires :path "\\\\#{computer_name || 'localhost'}\\#{path.tr ':', '$'}" end |
#vhd_format ⇒ :Unknown, ... (readonly)
Returns the format of the VHD.
72 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 72 attribute :vhd_format, type: :hypervenum, default: :VHDX, values: VHD_FORMAT_ENUM_VALUES |
#vhd_type ⇒ :Unknown, ... (readonly)
Returns the type of the VHD.
76 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 76 attribute :vhd_type, type: :hypervenum, default: :Dynamic, values: VHD_TYPE_ENUM_VALUES |
Instance Method Details
#create ⇒ Object
Save the VHD to Hyper-V
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 91 def create if basename requires :vm attributes[:path] ||= vm.build_vhd_path("#{basename}.#{vhd_ext}") end requires_one :path, :disk_number attrs = { source_disk: disk_number, logical_sector_size_bytes: logical_sector_size, physical_sector_size_bytes: physical_sector_size }.compact case vhd_type when :Dynamic attrs[:dynamic] = true requires :size unless disk_number when :Differencing requires :parent_path attrs[:differencing] = true attrs[:parent_path] = parent_path attrs.delete :source_disk attrs.delete :logical_sector_size_bytes when :Fixed attrs[:fixed] = true requires :size unless disk_number else raise "Invalid VHD type #{vhd_type.inspect}, must be :Dynamic, :Fixed, or :Differencing" end merge_attributes( service.new_vhd( computer_name:, path:, block_size_bytes: block_size, size_bytes: size, **attrs, _return_fields: self.class.attributes - %i[basename] ) ) end |
#destroy ⇒ Object
Remove the VHD from disk
169 170 171 172 173 174 175 176 177 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 169 def destroy requires :path service.remove_item( computer_name:, path: ) true end |
#optimize(mode: nil) ⇒ Object
Optimizes the VHD on disk
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 183 def optimize(mode: nil) requires :path service.optimize_vhd( computer_name:, path:, mode: ) true end |
#reload ⇒ Object
Reload the VHD attributes from Hyper-V
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 153 def reload requires_one :path, :disk_number data = service.get_vhd( computer_name:, path:, disk_number:, _return_fields: self.class.attributes - %i[basename] ) return unless data merge_attributes(data) end |
#update ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fog/hyperv/compute/models/vhd.rb', line 136 def update requires :path return self unless changed?(:size) service.resize_vhd( computer_name: old.computer_name, path: old.path, size_bytes: size ) @old.size = size self end |