Add image_id method and update openstack_command
This change adds a new method to libraries/cli.rb which we will use in new cookbook-openstack-integration-test to obtain a glance image id from a glance image name. Additionally, we've had to update openstack-command method to handle situation where we have commands like "glance image-show <id|name>". Currently, it only seems to work with commands like "keystone user-list". Change-Id: Ie4b063340e813ac50cbd4b21e41cc3fa65eebeca
This commit is contained in:
@@ -53,7 +53,11 @@ module ::Openstack # rubocop:disable Documentation
|
||||
# update the provider to use this.
|
||||
#
|
||||
def openstack_command(cmd, options = '', env = {}, args = {})
|
||||
openstackcmd = [cmd] << options
|
||||
# NOTE: Here we split options (which creates an array) and then merge that
|
||||
# array into [cmd]. This is done to accomdate cmd + options like:
|
||||
# keystone user-list
|
||||
# glance image-show <id|name>
|
||||
openstackcmd = [cmd].concat(options.split)
|
||||
args.each do |key, val|
|
||||
openstackcmd << "--#{key}" << val.to_s
|
||||
end
|
||||
@@ -87,4 +91,21 @@ module ::Openstack # rubocop:disable Documentation
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
# return id for a glance image.
|
||||
#
|
||||
# @param [String] name of image
|
||||
# @param [Hash] environment to use.
|
||||
# @return [String] id or nil
|
||||
def image_id(name, env, args = {})
|
||||
begin
|
||||
output = openstack_command('glance', "image-show #{name}", env, args)
|
||||
prettytable_to_array(output).each do |obj|
|
||||
return obj['id'] if obj.key?('id')
|
||||
end
|
||||
rescue RuntimeError => e
|
||||
raise "Could not lookup ID for image #{name}. Error was #{e.message}"
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user