Class: OpenStudioAmis
- Inherits:
-
Object
- Object
- OpenStudioAmis
- Includes:
- Logging
- Defined in:
- lib/openstudio/lib/ami_list.rb
Overview
Class for managing the AMI ids based on the openstudio version and the openstudio-server version
Constant Summary collapse
- VALID_OPTIONS =
[ :openstudio_version, :openstudio_server_version, :host, :url, :stable ]
Instance Method Summary collapse
-
#get_amis ⇒ Object
Return the AMIs for the specific openstudio_version or openstudio_server_version.
-
#initialize(version = 1, options = {}) ⇒ OpenStudioAmis
constructor
Initializer for listing the AMIs and grabbing the correct version of the AMIs based on the OpenStudio version or OpenStudio Server version.
-
#list ⇒ Object
List the AMIs based on the version and host.
Methods included from Logging
configure_logger_for, #logger, logger_for
Constructor Details
#initialize(version = 1, options = {}) ⇒ OpenStudioAmis
Initializer for listing the AMIs and grabbing the correct version of the AMIs based on the OpenStudio version or OpenStudio Server version.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openstudio/lib/ami_list.rb', line 52 def initialize(version = 1, = {}) = .keys - VALID_OPTIONS if .any? fail ArgumentError, "invalid option(s): #{.join(', ')}" end if [:openstudio_version] && [:openstudio_server_version] fail 'Must pass only an openstudio_version or openstudio_server_version when looking up AMIs' end # merge in some defaults defaults = { openstudio_version: 'default', openstudio_server_version: 'default', # host: 'developer.nrel.gov', # url: '/downloads/buildings/openstudio/api' host: 's3.amazonaws.com', url: '/openstudio-resources/server/api' } @version = version @options = defaults.merge() if @options[:openstudio_version] != 'default' && @options[:openstudio_server_version] != 'default' fail 'Must pass either the openstudio_version or openstudio_server_version when looking up AMIs, not both' end end |
Instance Method Details
#get_amis ⇒ Object
Return the AMIs for the specific openstudio_version or openstudio_server_version
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/openstudio/lib/ami_list.rb', line 97 def get_amis amis = nil command = "get_ami_version_#{@version}" if OpenStudioAmis.method_defined?(command) amis = send(command) else fail "Unknown api version command #{command}" end fail "Could not find any amis for #{@version}" if amis.nil? amis end |
#list ⇒ Object
List the AMIs based on the version and host. This method does catch old ‘developer.nrel.gov’ hosts and formats the endpoint using the old ‘<host>/<url>/amis_#version.json’ instead of the new, more restful, syntax of <host>/<url>/v#version/amis.json
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/openstudio/lib/ami_list.rb', line 83 def list endpoint = nil # for backwards compatibility with developer if @options[:host] =~ /developer.nrel/ endpoint = "#{@options[:url]}/amis_v#{@version}.json" else endpoint = "#{@options[:url]}/v#{@version}/amis.json" end retrieve_json(endpoint) end |