Skip to content

Commit

Permalink
Fixes #6159 - move image_id to be under the compute_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
shiramax authored and mbacovsky committed May 20, 2019
1 parent 1789509 commit ca785b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/hammer_cli_foreman/compute_attribute.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'hammer_cli_foreman/image'
require 'hammer_cli_foreman/compute_resource/register_compute_resources'
require 'hammer_cli_foreman/compute_resource/help_utils'
require 'hammer_cli_foreman/compute_resource/utils'

module HammerCLIForeman
class ComputeAttribute < HammerCLIForeman::Command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,21 @@ def self.extend_help(h, attributes, add_host_specific_attrs: false )
end
end
end

def self.get_image_uuid(compute_resource_id, image_id)
HammerCLIForeman.record_to_common_format(
HammerCLIForeman.foreman_resource(:images).call(
:show, {'compute_resource_id' => compute_resource_id, 'id' => image_id,}
)["uuid"]
)
end

def self.get_host_compute_resource_id(host_id)
HammerCLIForeman.record_to_common_format(
HammerCLIForeman.foreman_resource(:hosts).call(
:show, {'id' => host_id}
)["compute_resource_id"]
)
end
end
end
5 changes: 1 addition & 4 deletions lib/hammer_cli_foreman/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
require 'hammer_cli_foreman/hosts/common_update_options'
require 'hammer_cli_foreman/hosts/common_update_help'
require 'hammer_cli_foreman/compute_resource/register_compute_resources'
require 'hammer_cli_foreman/compute_resource/help_utils'

require 'hammer_cli_foreman/compute_resource/utils'
require 'highline/import'

module HammerCLIForeman
Expand Down Expand Up @@ -299,13 +298,11 @@ def validate_options
end
end
end

end

class UpdateCommand < HammerCLIForeman::UpdateCommand
success_message _("Host updated.")
failure_message _("Could not update the host")

include HammerCLIForeman::Hosts::CommonUpdateOptions
include HammerCLIForeman::Hosts::CommonUpdateHelp
end
Expand Down
7 changes: 6 additions & 1 deletion lib/hammer_cli_foreman/hosts/common_update_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def self.ask_password

def request_params
params = super

owner_id = get_resource_id(HammerCLIForeman.foreman_resource(:users), :required => false, :scoped => true)
params['host']['owner_id'] ||= owner_id unless owner_id.nil?

Expand Down Expand Up @@ -83,6 +82,12 @@ def request_params
params['host']['interfaces_attributes'] = interfaces_attributes
end

if options["option_image_id"]
compute_resource_id = params['host']['compute_resource_id'] || ::HammerCLIForeman::ComputeResources.get_host_compute_resource_id(params['id'])
raise ArgumentError, "Missing argument for 'compute_resource'" if compute_resource_id.nil?
image_uuid = ::HammerCLIForeman::ComputeResources.get_image_uuid(compute_resource_id, options["option_image_id"])
params['host']['compute_attributes']['image_id'] = image_uuid
end
params['host']['root_pass'] = option_root_password unless option_root_password.nil?

if option_ask_root_password
Expand Down

0 comments on commit ca785b3

Please sign in to comment.