Skip to content

Commit db73578

Browse files
committed
Merge pull request #839 from Autosde/411361_vmware_disk_size
add a customizable disk_size field to vm post-provision
2 parents 84e6290 + ec33f2e commit db73578

File tree

12 files changed

+118
-31
lines changed

12 files changed

+118
-31
lines changed

app/models/manageiq/providers/vmware/infra_manager/provision/configuration.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,37 @@ module ManageIQ::Providers::Vmware::InfraManager::Provision::Configuration
55
include_concern 'Network'
66
include_concern 'Disk'
77

8-
def reconfigure_hardware_on_destination?
8+
def reconfigure_container_on_destination?
99
# Do we need to perform a post-clone hardware reconfigure on the new VM?
1010
[:cpu_limit, :memory_limit, :cpu_reserve, :memory_reserve].any? do |k|
1111
return false unless options.key?(k)
1212
destination.send(k) != options[k]
1313
end
1414
end
15+
16+
def reconfigure_disk_on_destination?
17+
return false unless options.key?(:allocated_disk_storage)
18+
19+
# TODO: short-term fix to only enable :allocated_disk_storage in machines that have a single hard disk
20+
# in the long-term it should be able to deal with multiple hard disks
21+
if vm.hardware.disks.where(:device_type => "disk").length != 1
22+
_log.info("custom disk size is currently only supported for machines that have a single hard disk")
23+
return false
24+
end
25+
26+
default_size = vm.hardware.disks.find_by(:device_type => "disk").size / (1024**3)
27+
get_option(:allocated_disk_storage).to_f > default_size
28+
end
29+
30+
def reconfigure_hardware
31+
config_spec = VimHash.new("VirtualMachineConfigSpec") do |vmcs|
32+
set_cpu_and_memory_allocation(vmcs) if reconfigure_container_on_destination?
33+
set_disk_allocation(vm, vmcs) if reconfigure_disk_on_destination?
34+
end
35+
return if config_spec.empty?
36+
37+
_log.info("Calling VM reconfiguration")
38+
dump_obj(config_spec, "#{_log.prefix} Post-create Config spec: ", $log, :info)
39+
vm.spec_reconfigure(config_spec)
40+
end
1541
end

app/models/manageiq/providers/vmware/infra_manager/provision/configuration/container.rb

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,19 @@ def get_next_device_idx
107107
@new_device_idx -= 1
108108
end
109109

110-
def set_cpu_and_memory_allocation(vm)
111-
config_spec = VimHash.new("VirtualMachineConfigSpec") do |vmcs|
112-
vmcs.cpuAllocation = VimHash.new("ResourceAllocationInfo") do |rai|
113-
set_spec_option(rai, :limit, :cpu_limit, nil, :to_i)
114-
set_spec_option(rai, :reservation, :cpu_reserve, nil, :to_i)
115-
end
116-
117-
vmcs.memoryAllocation = VimHash.new("ResourceAllocationInfo") do |rai|
118-
set_spec_option(rai, :limit, :memory_limit, nil, :to_i)
119-
set_spec_option(rai, :reservation, :memory_reserve, nil, :to_i)
120-
end
110+
def set_cpu_and_memory_allocation(vmcs)
111+
vmcs.cpuAllocation = VimHash.new("ResourceAllocationInfo") do |rai|
112+
set_spec_option(rai, :limit, :cpu_limit, nil, :to_i)
113+
set_spec_option(rai, :reservation, :cpu_reserve, nil, :to_i)
114+
end
121115

122-
# Only explicitly disable #MemoryReservationLockedToMax if the memory reserve
123-
# is less than the total vm memory
124-
vmcs.memoryReservationLockedToMax = false if get_option(:memory_reserve).to_i < get_option(:vm_memory).to_i
116+
vmcs.memoryAllocation = VimHash.new("ResourceAllocationInfo") do |rai|
117+
set_spec_option(rai, :limit, :memory_limit, nil, :to_i)
118+
set_spec_option(rai, :reservation, :memory_reserve, nil, :to_i)
125119
end
126120

127-
_log.info("Calling VM reconfiguration")
128-
dump_obj(config_spec, "#{_log.prefix} Post-create Config spec: ", $log, :info)
129-
vm.spec_reconfigure(config_spec)
121+
# Only explicitly disable #MemoryReservationLockedToMax if the memory reserve
122+
# is less than the total vm memory
123+
vmcs.memoryReservationLockedToMax = false if get_option(:memory_reserve).to_i < get_option(:vm_memory).to_i
130124
end
131125
end

app/models/manageiq/providers/vmware/infra_manager/provision/configuration/disk.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,23 @@ def add_disk(vmcs, disk, controller, new_dev_key)
105105
end
106106
end
107107

108+
def set_disk_allocation(vm, vmcs)
109+
disk = vm.hardware.disks.find_by(:device_type => "disk")
110+
vm.with_provider_object do |vim_obj|
111+
device = vim_obj.getDeviceByLabel(disk.device_name)
112+
new_capacity_in_kb = (get_option(:allocated_disk_storage).to_f * 1.megabyte).to_i
113+
add_device_config_spec(vmcs, VirtualDeviceConfigSpecOperation::Edit) do |vdcs|
114+
vdcs.device = VimHash.new("VirtualDisk") do |dev|
115+
dev.key = device.key
116+
dev.capacityInKB = new_capacity_in_kb
117+
dev.controllerKey = device.controllerKey
118+
dev.unitNumber = device.unitNumber
119+
dev.backing = device.backing
120+
end
121+
end
122+
end
123+
end
124+
108125
private
109126

110127
def devices

app/models/manageiq/providers/vmware/infra_manager/provision/state_machine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def customize_destination
7272
_log.info("Post-processing #{destination_type} id: [#{destination.id}], name: [#{dest_name}]")
7373
update_and_notify_parent(:message => "Starting New #{destination_type} Customization")
7474

75-
set_cpu_and_memory_allocation(destination) if reconfigure_hardware_on_destination?
75+
reconfigure_hardware
7676
signal :autostart_destination
7777
end
7878

app/models/manageiq/providers/vmware/infra_manager/provision_via_pxe/state_machine.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ def customize_destination
33
_log.info("Post-processing #{destination_type} id: [#{destination.id}], name: [#{dest_name}]")
44
update_and_notify_parent(:message => "Starting New #{destination_type} Customization")
55

6-
set_cpu_and_memory_allocation(destination) if reconfigure_hardware_on_destination?
7-
6+
reconfigure_hardware
87
signal :create_pxe_configuration_file
98
end
109

content/miq_dialogs/miq_provision_vmware_cluster_dialogs_template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@
615615
:display: :edit
616616
:default: unchanged
617617
:data_type: :string
618+
:allocated_disk_storage:
619+
:description: Allocated Disk Storage (GB)
620+
:required: false
621+
:display: :edit
622+
:data_type: :string
623+
:notes: (default taken from template, custom can only be larger)
624+
:notes_display: :show
618625
:cpu_limit:
619626
:description: CPU (MHz)
620627
:required: false

content/miq_dialogs/miq_provision_vmware_dialogs_clone_to_template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,13 @@
652652
:display: :edit
653653
:default: unchanged
654654
:data_type: :string
655+
:allocated_disk_storage:
656+
:description: Allocated Disk Storage (GB)
657+
:required: false
658+
:display: :edit
659+
:data_type: :string
660+
:notes: (default taken from template, custom can only be larger)
661+
:notes_display: :show
655662
:cpu_limit:
656663
:description: CPU (MHz)
657664
:required: false

content/miq_dialogs/miq_provision_vmware_dialogs_clone_to_vm.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,13 @@
661661
:display: :edit
662662
:default: unchanged
663663
:data_type: :string
664+
:allocated_disk_storage:
665+
:description: Allocated Disk Storage (GB)
666+
:required: false
667+
:display: :edit
668+
:data_type: :string
669+
:notes: (default taken from template, custom can only be larger)
670+
:notes_display: :show
664671
:cpu_limit:
665672
:description: CPU (MHz)
666673
:required: false

content/miq_dialogs/miq_provision_vmware_dialogs_ovf.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@
677677
:display: :edit
678678
:default: unchanged
679679
:data_type: :string
680+
:allocated_disk_storage:
681+
:description: Allocated Disk Storage (GB)
682+
:required: false
683+
:display: :edit
684+
:data_type: :string
685+
:notes: (default taken from template, custom can only be larger)
686+
:notes_display: :show
680687
:cpu_limit:
681688
:description: CPU (MHz)
682689
:required: false

content/miq_dialogs/miq_provision_vmware_dialogs_template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@
693693
:display: :edit
694694
:default: unchanged
695695
:data_type: :string
696+
:allocated_disk_storage:
697+
:description: Allocated Disk Storage (GB)
698+
:required: false
699+
:display: :edit
700+
:data_type: :string
701+
:notes: (default taken from template, custom can only be larger)
702+
:notes_display: :show
696703
:cpu_limit:
697704
:description: CPU (MHz)
698705
:required: false

0 commit comments

Comments
 (0)