-
Notifications
You must be signed in to change notification settings - Fork 98
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
BZ #20538 - add compute profile commands #366
Conversation
3128983
to
2ed61ba
Compare
needs to merge : |
@mbacovsky please review :) |
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.
I found some minor issues. I think it's good to have them fixed anyway.
params = {} | ||
params['compute_attribute'] = {} | ||
profile = HammerCLIForeman.record_to_common_format( | ||
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_id'] }) |
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.
Not important, but still: Redundant curly braces around a hash parameter
profile = HammerCLIForeman.record_to_common_format( | ||
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_id'] }) | ||
) | ||
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, {'id' => options['option_compute_resource_id'] }) |
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.
ditto curly braces
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, {'id' => options['option_compute_profile_id'] }) | ||
) | ||
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, {'id' => options['option_compute_resource_id'] }) | ||
params['compute_attribute'] = profile['compute_attributes'].select{ |hash| hash['compute_resource_id']== options['option_compute_resource_id']}[0] || {} |
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.
again, not important, but some spaces are missing .select{
and hash['compute_resource_id']==
end | ||
|
||
class CreateCommand < HammerCLIForeman::CreateCommand | ||
success_message _('Compute profile created') |
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.
Almost all success messages should end with '.' at the end. You might use the test from this PR to check yourself.
validate_options do | ||
any(:option_name,:option_id).required | ||
end | ||
build_options :without => :name |
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.
Most likely I'm mistaken, but doesn't seem it does anything.
build_options :without => :id | ||
end | ||
|
||
class AddInterface < HammerCLIForeman::UpdateCommand |
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.
Maybe it should inherit CreateCommand
instead of UpdateCommand
?
Also it doesn't seem to work. I tried hammer compute-profile add-interface --compute-resorce tstracho-laptop --compute-profile 1-Small --set-values type=network,bridge=br1
and got Could not create interface: Error: undefined method `[]' for nil:NilClass
. Does it work for you?
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.
bridge is not allowed attribute for any of the compute resources
check hammer compute-profile add-interface --help
and I can't reproduce this error at all.. are the compute profile and compute resource name exists?
what is the compute resource your testing on? ovirt?
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.
I think UpdateCommand is correct as we add interface attrs by modifying existing compute_attribute. I was not able to reproduce the error. However it is a bit unclear what is the relation - can each compute profile have only one compute attribute per compute resource?
@shiramax I think it would be worth a comment in the code explaining why we use the Update predecessor. We will have to care about the --name
and --new-name
parameters. Option builder removed the --id but those left. Let me know if you don't find out how to remove 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.
the relation - can each compute profile have only one compute attribute per compute resource?
^^ you can have only one compute attribute, but inside the compute attribute you can have multiple volumens and interfaces.
build_options :without => :id | ||
end | ||
|
||
class RemoveInterface < HammerCLIForeman::UpdateCommand |
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.
Maybe it should inherit DeleteCommand
instead of UpdateCommand
?
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.
I think the UpdateCommand is needed in this case because the remove is done by updating the resource.
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.
@shiramax Could you add a explanation to the code and remove the --name options?
build_options :without => :id | ||
end | ||
|
||
class RemoveVolume < HammerCLIForeman::UpdateCommand |
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.
same I mentioned above
class RemoveInterface < HammerCLIForeman::UpdateCommand | ||
command_name _('remove-interface') | ||
resource :compute_attributes | ||
desc _('Update compute profile interface') |
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.
Maybe it should say "Remove compute ..."?
class RemoveVolume < HammerCLIForeman::UpdateCommand | ||
command_name _('remove-volume') | ||
resource :compute_attributes | ||
desc _('Update compute profile volume') |
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.
same I mentioned above
@ofedoren thanks! I fixed all the comments :) |
@shiramax great, thank you! But still I get
while trying
Is it only me? |
resource :compute_attributes | ||
desc _('Add volume for Compute Profile') | ||
|
||
option '--set-values', 'VOLUME', _('Volume parameters, should be comma separated list of values.'), |
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.
Sorry for bothering you with this again, but there is a convention, that says option descriptions should not end with a dot. Simply remove '.' at the end of option description.
resource :compute_attributes | ||
desc _('Update compute profile volume') | ||
|
||
option '--set-values', 'VOLUME', _('Volume parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end"
command_name _('remove-volume') | ||
resource :compute_attributes | ||
desc _('Remove compute profile volume') | ||
option '--volume-id', 'VOLUME_ID', _('Volume id.'), |
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.
ditto "dot at the end"
|
||
desc _('Update compute profile interface') | ||
|
||
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end"
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'), | ||
:required => true, | ||
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--interface-id', 'INTERFACE_ID', _('Interface id.'), |
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.
ditto "dot at the 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.
i don't really understand where to put the dot here
command_name _('add-interface') | ||
resource :compute_attributes | ||
desc _('Add interface for Compute Profile') | ||
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end"
|
||
option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes.'), | ||
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end"
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values.'), | ||
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end"
command_name _('update-attributes') | ||
resource :compute_attributes | ||
|
||
option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes, should be comma separated list of values.'), |
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.
ditto "dot at the end"
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--interface-id', 'INTERFACE_ID', _('Interface id'), | ||
:format => HammerCLI::Options::Normalizers::Number.new | ||
option '--volume', 'VOLUME', _('Volume parameters, should be comma separated list of values.'), |
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.
ditto "dot at the end" and 2 above
@shiramax I apologize for any misunderstanding, everything is fine now :) Thanks! |
@mbacovsky mind finishing the review? |
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.
@shiramax thanks for this extensive work! I've put my comments inline. For the first round I focused on the commands and structure of the code. Overall it looks very good. It passed some basic testing with exception for the translated commands and extra `--name' options.
I still need to go through the tests and help extensions withregard on the other help related work. Will update.
end | ||
|
||
class SetAttributes < HammerCLIForeman::CreateCommand | ||
command_name _('set-attributes') |
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.
Do not mark commands for translations
HammerCLIForeman::References.taxonomies(self) | ||
HammerCLIForeman::References.timestamps(self) | ||
|
||
collection :compute_attributes, 'Compute attributes' do |
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.
Compute attributes
needs translation
success_message _('Compute profile created.') | ||
failure_message _('Could not create a compute profile') | ||
|
||
validate_options do |
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.
The name is required by API no need for the validator.
profile = HammerCLIForeman.record_to_common_format( | ||
HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, 'id' => options['option_compute_profile_id'] ) | ||
) | ||
HammerCLIForeman.foreman_resource(:compute_resources).call(:show, 'id' => options['option_compute_resource_id'] ) |
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.
Is this value used anywhere?
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.
Do we need this call in here?
end | ||
|
||
def request_params | ||
params = {} |
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.
if you use params = super
here you don't have to care about compute attribute and compute profile name resolution later in this method
build_options :without => :id | ||
end | ||
|
||
class AddInterface < HammerCLIForeman::UpdateCommand |
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.
I think UpdateCommand is correct as we add interface attrs by modifying existing compute_attribute. I was not able to reproduce the error. However it is a bit unclear what is the relation - can each compute profile have only one compute attribute per compute resource?
@shiramax I think it would be worth a comment in the code explaining why we use the Update predecessor. We will have to care about the --name
and --new-name
parameters. Option builder removed the --id but those left. Let me know if you don't find out how to remove it.
end | ||
|
||
class UpdateInterface < HammerCLIForeman::UpdateCommand | ||
command_name _('update-interface') |
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.
There are --name
and --new-name
options left in the command.
build_options :without => :id | ||
end | ||
|
||
class RemoveInterface < HammerCLIForeman::UpdateCommand |
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.
@shiramax Could you add a explanation to the code and remove the --name options?
end | ||
|
||
class AddVolume < HammerCLIForeman::UpdateCommand | ||
command_name _('add-volume') |
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.
Same as for the commands above
build_options :without => :id | ||
end | ||
|
||
class UpdateVolume < HammerCLIForeman::UpdateCommand |
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.
Same as above
@mbacovsky could you please remind me in which file I can configure the help to show the translation? |
fa59974
to
621837c
Compare
@shiramax you need to set this option https://github.com/theforeman/hammer-cli/blob/master/config/cli_config.template.yml#L10. It is most likely in |
end | ||
|
||
class DeleteCommand < HammerCLIForeman::DeleteCommand | ||
success_message 'Compute profile deleted.' |
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.
Translation marker is missing
|
||
class DeleteCommand < HammerCLIForeman::DeleteCommand | ||
success_message 'Compute profile deleted.' | ||
failure_message 'Could not delete the Compute profile' |
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.
Translation marker is missing
|
||
option '--compute-attributes', 'COMPUTE_ATTRS', _('Compute resource attributes'), | ||
:format => HammerCLI::Options::Normalizers::KeyValueList.new | ||
option '--interface', 'INTERFACE', _('interface parameters, should be comma separated list of values'), |
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.
Capitalize "Interface"
command_name 'add-interface' | ||
resource :compute_attributes | ||
desc _('Add interface for Compute Profile.') | ||
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values'), |
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.
underscore missing in 'SET_VALUES'
|
||
desc _('Update compute profile interface.') | ||
|
||
option '--set-values', 'SET VALUES', _('Interface parameters, should be comma separated list of values'), |
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.
Underscore is missing in 'SET_VALUES"
end | ||
end | ||
|
||
def validate_options |
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.
Validators are preferred in a block:
validate_options do
any(:option_compute_profile_id, :option_compute_profile_name ).required
any(:option_compute_resource_id, :option_compute_resource_name).required
end
end | ||
|
||
def validate_options | ||
super |
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.
We prefer validators in a block (see comment above).
super | ||
validator.any(:option_compute_profile_id, :option_compute_profile_name ).required | ||
validator.any(:option_compute_resource_id, :option_compute_resource_name).required | ||
validator.any(:option_interface, :option_volume, :option_compute_attributes).required |
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.
How do I identify what compute attribute I'm going to update? I'd expect --compute-attribute
or --compute-attribute-id
.
Is compute-attribute-name unique or do we need to add also compute profile or compute resource to search for the compute attribute by name? If so It should be required only when there is compute attribute name given.
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.
Or is it that (compute profile, compute resource) has at most one compute attribute?
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.
compute attribute is a combination of compute profile and compute resource. It doesn't have a name
|
||
# Using the Update command because adding a new interface is done by modifying existing compute_attribute | ||
class AddInterface < HammerCLIForeman::UpdateCommand | ||
command_name 'add-interface' |
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.
What is the difference between compute-profile update-attributes --volume <attrs>
and compute-profile update-volume --set-values <attrs>
?
If it is the same functionality isn't it confusing for the user to have two similar ways how to achieve the same?
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.
Yes, I I remember correctly when designing the commands, we talked about it.
the update attributes will let the user update in one command interface & volume & other attributes.
update-volume is easier if the user wants to update the volume.
I agree it might be confusing, what do you think is the best approach here?
@shiramax, thanks for fixing the issues mentioned in my comments! I finally did another round of review and found out the UX a bit unclear. The most prominent thing is that it is not clear to me what is the difference between Another thing are the parameters used to address the compute attributes. What I'm concerned about is I didn't found 'compute attributes' mentioned in the UI (besides the URLs). In the UI we present the compute profile as a set of compute profiles with same name for different resources. Do you think it would make sense to mimic this in the CLI somehow? Was the UX design discussed before? |
Would you mind and rebase this PR? Also it seems the validations will be easier to do once I merge theforeman/hammer-cli#242 so it can wait till the merge happens and the UX is resolved. |
@mbacovsky , please tell me what do you think, thanks for the review! |
No description provided.