New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add placement group option to powervs vm provisioning #427
Conversation
1f2c5f2
to
b86af82
Compare
ar_placement_groups = ar_ems.placement_groups | ||
placement_groups = ar_placement_groups&.map { |group| [group['ems_ref'], "#{group['policy']}: #{group['name']}"] } | ||
Hash[placement_groups || {}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do a few different things here,
- Ensure ar_placement_groups is at least
[]
likear_placement_groups = ar_ems.placement_groups || []
then you don't need the&.map
- You can
.to_h
the possiblynil
value likear_placement_groups&.map { |group| }.to_h
which would turnnil
to{}
This is good because you want to use.to_h
on the array anyway instead ofHash[placement_groups]
ar_placement_groups = ar_ems.placement_groups | |
placement_groups = ar_placement_groups&.map { |group| [group['ems_ref'], "#{group['policy']}: #{group['name']}"] } | |
Hash[placement_groups || {}] | |
ar_ems.placement_groups&.map { |group| [group['ems_ref'], "#{group['policy']}: #{group['name']}"] }.to_h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually when would ar_ems.placement_group
be nil
? If it is an association it will at least be an empty assoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare
ok, so I should just remove the & and ignore the first suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you can pass a block to .to_h
so even better would be:
ar_ems.placement_groups.to_h { |group| [group.ems_ref, "#{group.policy}: #{group.name}"] }
def validate_placement_group(_filed, _values, _dlg, _fld, value) | ||
return if value.blank? | ||
|
||
placement_group = ar_ems.placement_groups.find_by(:ems_ref => value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend either .find_by!
which will raise an exception if it can't find the record or handling placement_group
being nil
if it isn't found by value
...odels/manageiq/providers/ibm_cloud/power_virtual_servers/cloud_manager/provision_workflow.rb
Show resolved
Hide resolved
b86af82
to
01085d1
Compare
@@ -17,12 +17,21 @@ | |||
:fields: | |||
:ip_addr: | |||
:description: Specify an IPv4 address (applies to first attached network) | |||
:required_method: :validate_ip_address | |||
:validation_method: :validate_ip_address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks like it is from another PR, make sure to rebase this branch on master
else | ||
true | ||
end | ||
return _('Invalid placement group - incompatible colocation policy') unless valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You actually don't need this redundant return
here as ruby automatically returns the last statement
return _('Invalid placement group - incompatible colocation policy') unless valid | |
_('Invalid placement group - incompatible colocation policy') unless valid |
@@ -122,6 +122,12 @@ def allowed_cloud_volumes(_options = {}) | |||
Hash[cloud_volumes || {}] | |||
end | |||
|
|||
def allowed_placement_groups(_options = {}) | |||
return {} if ar_ems.nil? | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to remove the trailing whitespace here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agrare
I will remove if you think I should, but just noting that I had originally left the white space in, even with the rubocop warning, to follow the same pattern as similar methods within this file.
Lines 57 to 124 in 01085d1
def allowed_instance_type(_options = {}) | |
return {} if ar_ems.nil? | |
if sap_image? | |
{ | |
0 => "dedicated" | |
} | |
else | |
{ | |
0 => "capped", | |
1 => "shared", | |
2 => "dedicated" | |
} | |
end | |
end | |
def allowed_sys_type(_options = {}) | |
return {} if ar_ems.nil? | |
flavor_type = "ManageIQ::Providers::IbmCloud::PowerVirtualServers::CloudManager::#{sap_image? ? 'SAPProfile' : 'SystemType'}" | |
ar_sys_types = ar_ems.flavors.find_all { |flavor| flavor.type == flavor_type } | |
sys_types = ar_sys_types&.map&.each_with_index { |sys_type, i| [i, sys_type['name']] } | |
Hash[sys_types || {}] | |
end | |
def allowed_storage_type(_options = {}) | |
return {} if ar_ems.nil? | |
ar_storage_types = ar_ems.cloud_volume_types | |
storage_types = ar_storage_types&.map&.each_with_index { |storage_type, i| [i, storage_type['name']] } | |
Hash[storage_types || none] | |
end | |
def allowed_guest_access_key_pairs(_options = {}) | |
return {} if ar_ems.nil? | |
ar_key_pairs = ar_ems.key_pairs | |
key_pairs = ar_key_pairs&.map&.with_index(1) { |key_pair, i| [i, key_pair['name']] } | |
none = [0, 'None'] | |
Hash[key_pairs&.insert(0, none) || none] | |
end | |
def allowed_subnets(_options = {}) | |
return {} if ar_ems.nil? | |
ar_subnets = ar_ems.cloud_subnets | |
subnets = ar_subnets&.collect { |subnet| [subnet[:ems_ref], subnet[:name]] } | |
none = ['None', 'None (Must attach to new public network)'] | |
Hash[subnets.unshift(none)] | |
end | |
def allowed_cloud_volumes(_options = {}) | |
return {} if ar_ems.nil? | |
storage_type = values&.dig(:storage_type, 1) | |
ar_volumes = ar_ems.cloud_volumes.select do |cloud_volume| | |
cloud_volume['volume_type'] == storage_type && | |
(cloud_volume['multi_attachment'] || cloud_volume['status'] == 'available') | |
end | |
cloud_volumes = ar_volumes&.map { |cloud_volume| [cloud_volume['ems_ref'], cloud_volume['name']] } | |
Hash[cloud_volumes || {}] | |
end | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other methods in this file are wrong then 😄 I'm guessing they were merged while miq-bot was down since github's diff doesn't show it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think there was a miscommunication. The issue isn't the extra newline it was the trailing whitespace.
So:
def allowed_instance_type(_options = {})
return {} if ar_ems.nil?
if sap_image?
Is fine, but
def allowed_instance_type(_options = {})
return {} if ar_ems.nil?
if sap_image?
Is the issue
Just a couple more items then this LGTM |
01085d1
to
2e8656c
Compare
528dac2
to
8ab9e51
Compare
Checked commit alizapeikes@8ab9e51 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint |
That looks better, recommend using an editor with a setting to strip trailing whitespace as that is what most of our devs use |
connected to ManageIQ/manageiq-ui-classic#8486