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

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

Overview

A hard drive attached to a VM

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#merge_attributes

Methods included from ModelExtends

#collection

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_nameString (readonly)

Returns the name of the computer running the VM that this hard drive is attached to.

Returns:

  • (String)

    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_locationString

Returns the controller location this hard drive is attached to.

Returns:

  • (String)

    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_numberInteger

Returns the controller number this hard drive is attached to.

Returns:

  • (Integer)

    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.

Returns:

  • (:IDE, :SCSI)

    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]

#diskObject

Returns the attached physical disk.

Returns:

  • (Object)

    the attached physical disk



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

attribute :disk

#idString (readonly)

Returns the GUID of this hard drive.

Returns:

  • (String)

    the GUID of this hard drive



10
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 10

identity :id

#maximum_iopsInteger

Returns the maximum number of IOPS allocated for this hard drive.

Returns:

  • (Integer)

    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_iopsInteger

Returns the minimum number of IOPS allocated for this hard drive.

Returns:

  • (Integer)

    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

#nameString (readonly)

Returns the name of this hard drive.

Returns:

  • (String)

    the name of this hard drive



40
# File 'lib/fog/hyperv/compute/models/hard_drive.rb', line 40

attribute :name

#pathString

Returns the path to the VHD file for this hard drive.

Returns:

  • (String)

    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_nameString

Returns the name of the pool storing this hard drive’s image.

Returns:

  • (String)

    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_bytesInteger? (readonly)

Returns the size of the underlying VHD if any.

Returns:

  • (Integer, nil)

    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_reservationsBoolean

Returns if the underlying hard drive supports SCSI persistent reservations. This should be set when multiple VMs share the same underlying disk.

Returns:

  • (Boolean)

    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

#vhdVhd?

Returns the VHD that is attached to this hard drive.

Returns:

  • (Vhd, nil)

    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_idString (readonly)

Returns the GUID of the VM this hard drive is attached to.

Returns:

  • (String)

    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

#createObject



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 underlying && vhd?
  true
end

#reloadObject



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

#updateObject



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?.

Returns:

  • (Boolean)

    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