Skip to content

Commit

Permalink
Add placement group option to powervs vm provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
alizapeikes committed Oct 19, 2022
1 parent 2383e9b commit 8ab9e51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def prepare_for_clone
specs['sys_type'] = get_option_last(:sys_type)
end

specs['placement_group'] = get_option(:placement_group) unless get_option(:placement_group).nil?
user_script_text = options[:user_script_text]
user_script_text64 = Base64.encode64(user_script_text) unless user_script_text.nil?
specs['user_data'] = user_script_text64 unless user_script_text64.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def allowed_cloud_volumes(_options = {})
Hash[cloud_volumes || {}]
end

def allowed_placement_groups(_options = {})
return {} if ar_ems.nil?

ar_ems.placement_groups.to_h { |group| [group.ems_ref, "#{group.policy}: #{group.name}"] }
end

def set_request_values(values)
values[:new_volumes] = parse_new_volumes_fields(values)
super
Expand Down Expand Up @@ -176,6 +182,21 @@ def validate_ip_address(_field, _values, _dlg, _fld, value)
return _('IP-address field has to be either blank or a valid IPv4 address') unless valid
end

def validate_placement_group(_filed, _values, _dlg, _fld, value)
return if value.blank?

placement_group = ar_ems.placement_groups.find_by!(:ems_ref => value)
vms_in_placement_group = placement_group.vms

# If policy is affinity, check to make sure the new vm has the same flavor as all the members of the group
valid = if placement_group[:policy] == 'affinity' && vms_in_placement_group.present?
vms_in_placement_group.first.flavor.name == values&.dig(:sys_type, 1)
else
true
end
_('Invalid placement group - incompatible colocation policy') unless valid
end

private

def ar_ems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
:data_type: :string
:min_length: 8
:max_length: 16
:placement_group:
:values_from:
:method: :allowed_placement_groups
:description: Placement Group
:required: false
:validation_method: :validate_placement_group
:display: :edit
:auto_select_single: false
:data_type: :string
:pin_policy:
:values:
1: "none"
Expand Down

0 comments on commit 8ab9e51

Please sign in to comment.