|
| 1 | +module ManageIQ::Providers::IbmPowerHmc::InfraManager::Vm::Reconfigure |
| 2 | + def reconfigurable? |
| 3 | + host_hmc_managed |
| 4 | + end |
| 5 | + |
| 6 | + def max_total_vcpus |
| 7 | + # 64 is based on the CEC's CurrentMaximumVirtualProcessorsPerAIXOrLinuxPartition and |
| 8 | + # CurrentMaximumVirtualProcessorsPerVirtualIOServerPartition settings. |
| 9 | + # This can be further reduced by the partition's MaximumVirtualProcessors setting. |
| 10 | + host && try(:processor_share_type) == "dedicated" ? host.cpu_total_cores : 64 |
| 11 | + end |
| 12 | + |
| 13 | + def max_vcpus |
| 14 | + max_total_vcpus |
| 15 | + end |
| 16 | + |
| 17 | + def max_cpu_cores_per_socket(_total_vcpus = nil) |
| 18 | + 1 |
| 19 | + end |
| 20 | + |
| 21 | + def max_memory_mb |
| 22 | + host ? host.hardware.memory_mb : 1_024 |
| 23 | + end |
| 24 | + |
| 25 | + def build_config_spec(options) |
| 26 | + $ibm_power_hmc_log.debug("building spec for #{options}") |
| 27 | + |
| 28 | + lpar = ext_management_system.with_provider_connection { |connection| provider_object(connection) } |
| 29 | + |
| 30 | + # Dynamic Reconfiguration requires RMC to be active. |
| 31 | + raise MiqException::MiqVmError, "RMC is not active on target" if lpar.state == "running" && lpar.rmc_state != "active" |
| 32 | + |
| 33 | + # The HMC does not allow changing the VSWITCH or the VLAN of a client network adapter. |
| 34 | + # It could be done by deleting and recreating the adapter with the same MAC and options. |
| 35 | + raise MiqException::MiqVmError, "Cannot edit existing network adapter" if options.key?(:network_adapter_edit) |
| 36 | + |
| 37 | + spec = {} |
| 38 | + build_memory_config_spec(lpar, spec, options) if options.key?(:vm_memory) |
| 39 | + build_proc_config_spec(lpar, spec, options) if options.key?(:number_of_cpus) |
| 40 | + build_netadap_create_config_spec(spec, options) if options.key?(:network_adapter_add) |
| 41 | + build_netadap_delete_config_spec(spec, options) if options.key?(:network_adapter_remove) |
| 42 | + |
| 43 | + spec |
| 44 | + end |
| 45 | + |
| 46 | + def build_memory_config_spec(lpar, spec, options) |
| 47 | + desired_memory = options[:vm_memory].to_i |
| 48 | + |
| 49 | + raise MiqException::MiqVmError, "Memory cannot be lower than #{lpar.min_memory} MB" if desired_memory < lpar.min_memory.to_i |
| 50 | + raise MiqException::MiqVmError, "Memory cannot be greater than #{lpar.max_memory} MB" if desired_memory > lpar.max_memory.to_i |
| 51 | + |
| 52 | + spec[:desired_memory] = desired_memory |
| 53 | + end |
| 54 | + |
| 55 | + def build_proc_config_spec(lpar, spec, options) |
| 56 | + if lpar.dedicated == "true" |
| 57 | + min, max = lpar.minimum_procs, lpar.maximum_procs |
| 58 | + attr = :desired_procs |
| 59 | + else |
| 60 | + min, max = lpar.minimum_vprocs, lpar.maximum_vprocs |
| 61 | + attr = :desired_vprocs |
| 62 | + end |
| 63 | + |
| 64 | + desired_procs = options[:number_of_cpus].to_i |
| 65 | + |
| 66 | + raise MiqException::MiqVmError, "Processor count cannot be lower than #{min}" if desired_procs < min.to_i |
| 67 | + raise MiqException::MiqVmError, "Processor count cannot be greater than #{max}" if desired_procs > max.to_i |
| 68 | + |
| 69 | + spec[attr] = desired_procs |
| 70 | + end |
| 71 | + |
| 72 | + def build_netadap_create_config_spec(spec, options) |
| 73 | + spec[:netadap_create] = options[:network_adapter_add].map do |adapt| |
| 74 | + # Retrieve LAN attributes from DB. |
| 75 | + switch_ids = HostSwitch.where(:host_id => host.id).pluck(:switch_id) |
| 76 | + lan = Lan.find_by(:name => adapt[:network], :switch_id => switch_ids) |
| 77 | + raise MiqException::MiqVmError, "Network [#{adapt[:network]}] is not available on target" if lan.nil? |
| 78 | + |
| 79 | + { |
| 80 | + :sys_uuid => host.ems_ref, |
| 81 | + :vswitch_uuid => lan.switch.uid_ems, |
| 82 | + :attrs => {:vlan_id => lan.tag} |
| 83 | + } |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + def build_netadap_delete_config_spec(spec, options) |
| 88 | + spec[:netadap_delete] = options[:network_adapter_remove].map do |adapt| |
| 89 | + nic = nics.find_by(:address => adapt[:network][:mac]) |
| 90 | + raise MiqException::MiqVmError, "Network adapter [#{adapt[:network][:mac]}] is not available on target" if nic.nil? |
| 91 | + |
| 92 | + nic.uid_ems |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + def raw_reconfigure(spec) |
| 97 | + $ibm_power_hmc_log.debug("reconfiguring with spec=#{spec}") |
| 98 | + |
| 99 | + ext_management_system.with_provider_connection do |connection| |
| 100 | + attrs = spec.slice(:desired_memory, :desired_procs, :desired_vprocs) |
| 101 | + modify_attrs(connection, attrs) unless attrs.empty? |
| 102 | + |
| 103 | + spec[:netadap_delete].try(:each) do |uuid| |
| 104 | + connection.network_adapter_lpar_delete(ems_ref, uuid) |
| 105 | + end |
| 106 | + |
| 107 | + spec[:netadap_create].try(:each) do |netadap| |
| 108 | + connection.network_adapter_lpar_create(ems_ref, netadap[:sys_uuid], netadap[:vswitch_uuid], netadap[:attrs]) |
| 109 | + end |
| 110 | + end |
| 111 | + end |
| 112 | +end |
0 commit comments