openstudio-aws 0.7.0.alpha0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fb9aaca2642160b5eac43e603457fd77c65d4a2
4
- data.tar.gz: 3b400a0863047b7032d8e5d6e11be3e53358e9e8
3
+ metadata.gz: 3a8f166aa5280130c5e02e2bbca8e7916c5a4f18
4
+ data.tar.gz: 44e37969328af52966ae23f81a8ee47da2ce006e
5
5
  SHA512:
6
- metadata.gz: 37303ed113a04f581b786e30071afc8a66313dd8fe9cc1adb5df85ff1f4cb0a8c7f7813ba62040674a2feb521d8d1770952dd6377f40c6f4775204e2055e834c
7
- data.tar.gz: 6220220f3210530359bdda6a1b8823d776ac123383a705b39bfe4d6265af74233da098e407dc2ac58b6f729c2fcd2e383efe06c6b02299aca4c05434c514dcb7
6
+ metadata.gz: e3af181f0922fc772948ad6010d40390c654e1f8d04efe688802ea74fd72778f0fa987473990cc2029746446c3a8358b1d05948d50adb677f729d07fd9dc7b68
7
+ data.tar.gz: 44de6b22099110cda2aced58100800adc3d9a0881cc1b4999cea68544afdefb224a19c43cc696d77903a2c0f0c56fa7b492e90e74e1040bea6e0344812374eca
data/.gitignore CHANGED
@@ -19,3 +19,5 @@ spec/output
19
19
  *.pem
20
20
  *.pub
21
21
  *.config
22
+ .rubocop-http*
23
+ gems
data/.rubocop.yml CHANGED
@@ -1,133 +1,10 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - 'doc/**/*'
4
+ - 'gems/**/*'
4
5
 
5
- # ==================== Linters ====================
6
- Lint/AmbiguousOperator:
7
- Enabled: true
8
-
9
- Lint/BlockAlignment:
10
- Enabled: true
11
-
12
- Lint/ParenthesesAsGroupedExpression:
13
- Enabled: true
14
-
15
- Lint/RequireParentheses:
16
- Enabled: true
17
-
18
- # Offense count: 1
19
- Lint/UnreachableCode:
20
- Enabled: false
21
-
22
- # Offense count: 51
23
- Lint/UselessAssignment:
24
- Enabled: true
25
-
26
- # ==================== Styles / Metrics====================
27
- # Offense count: 4
28
- Metrics/BlockNesting:
29
- Max: 4
30
-
31
- # Offense count: 18
32
- # Configuration parameters: CountComments.
33
- Metrics/ClassLength:
34
- Max: 500
35
-
36
- # Offense count: 27
37
- Metrics/CyclomaticComplexity:
38
- Max: 48
39
-
40
- # Offense count: 974
41
- Metrics/LineLength:
42
- Max: 1200
43
-
44
- # Offense count: 87
45
- # Configuration parameters: CountComments.
46
- Metrics/MethodLength:
47
- Max: 350
48
-
49
- # Offense count: 1
50
- # Configuration parameters: CountKeywordArgs.
51
- Metrics/ParameterLists:
52
- Max: 8
53
-
54
- # ==================== Disabled on Purpose ====================
55
- # Offense count: 3
56
- Style/AccessorMethodName:
57
- Enabled: true
58
-
59
- # Need to allow indented case statements
60
- # Offense count: 9
61
- # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
62
- Style/CaseIndentation:
63
- Enabled: false
64
-
65
- # Offense count: 18
66
- # Configuration parameters: EnforcedStyle, SupportedStyles.
67
- Style/ClassAndModuleChildren:
68
- Enabled: false
69
-
70
- # Offense count: 2
71
- Style/ClassVars:
72
- Enabled: false
73
-
74
- # Offense count: 42
75
- Style/Documentation:
6
+ Security/YAMLLoad:
76
7
  Enabled: false
77
8
 
78
- # Offense count: 1
79
- Style/EachWithObject:
80
- Enabled: false
81
-
82
- # Offense count: 2
83
- # Configuration parameters: AllowedVariables.
84
- Style/GlobalVars:
85
- Enabled: false
86
-
87
- # Offense count: 7
88
- # Configuration parameters: MinBodyLength.
89
- Style/GuardClause:
90
- Enabled: true
91
-
92
- # Offense count: 17
93
- # Configuration parameters: MaxLineLength.
94
- Style/IfUnlessModifier:
95
- Enabled: false
96
-
97
- # Do NOT enable. For some reason this is catchy any next which I feel are okay.
98
- # Offense count: 18
99
- # Configuration parameters: EnforcedStyle, SupportedStyles.
100
- Style/Next:
101
- Enabled: false
102
-
103
- # Do NOT enable this because it appears $? is different than $CHILD_STATUS.
104
- # Offense count: 7
105
- # Cop supports --auto-correct.
106
- Style/SpecialGlobalVars:
107
- Enabled: false
108
-
109
- # More Changes per DLM -- pulled from https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
110
- Style/RedundantReturn:
111
- Description: 'Do not use return where it is not required.'
112
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-return'
113
- Enabled: false
114
-
115
- Style/NumericLiterals:
116
- Description: 'Add underscores to large numeric literals to improve readability.'
117
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscores-in-numerics'
118
- Enabled: false
119
-
120
- Lint/UnusedBlockArgument:
121
- Description: 'Checks for unused block arguments.'
122
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
123
- Enabled: false
124
-
125
- Lint/UnusedMethodArgument:
126
- Description: 'Checks for unused method arguments.'
127
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
128
- Enabled: false
129
-
130
- Lint/UselessAssignment:
131
- Description: 'Checks for useless assignment to a local variable.'
132
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars'
133
- Enabled: false
9
+ inherit_from:
10
+ - http://s3.amazonaws.com/openstudio-resources/styles/rubocop.yml
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.7
4
- - 2.0.0
3
+ - 2.2.4
5
4
  script:
6
5
  - bundle exec rake spec:no_auth
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  OpenStudio AWS Gem Change Log
2
2
  ==================================
3
3
 
4
+
5
+ Version 0.7.0
6
+ -------------
7
+ * Fix worker off by one bug
8
+ * Update Net SSH and Net SCP
9
+
10
+ Version 0.5 - 0.6
11
+ -----------------
12
+ * These releases did not include change logs
13
+
4
14
  Version 0.4.2
5
15
  -------------
6
16
  * Fix net-ssh to 3.0.2 because newer version caused infinite loop
data/Gemfile CHANGED
@@ -3,8 +3,8 @@ source 'http://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'rspec', '~> 3.3'
7
6
  gem 'ci_reporter_rspec'
8
- gem 'rubocop', '~> 0.31'
7
+ gem 'rspec', '~> 3.8.0'
8
+ gem 'rubocop', '~> 0.68.1'
9
9
  gem 'rubocop-checkstyle_formatter', '~> 0.2'
10
10
  end
data/Rakefile CHANGED
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  require 'bundler'
2
37
  Bundler.setup
3
38
 
@@ -10,21 +45,21 @@ require 'ci/reporter/rake/rspec'
10
45
  # Gem tasks
11
46
  require 'bundler/gem_tasks'
12
47
 
13
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
48
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
14
49
  require 'openstudio-aws'
15
50
 
16
51
  RSpec::Core::RakeTask.new('spec') do |spec|
17
- spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
52
+ spec.rspec_opts = ['--format', 'progress', '--format', 'CI::Reporter::RSpec']
18
53
  spec.pattern = 'spec/**/*_spec.rb'
19
54
  end
20
55
 
21
56
  RSpec::Core::RakeTask.new('spec:api') do |spec|
22
- spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
57
+ spec.rspec_opts = ['--format', 'progress', '--format', 'CI::Reporter::RSpec']
23
58
  spec.pattern = 'spec/**/*_spec_api.rb'
24
59
  end
25
60
 
26
61
  RSpec::Core::RakeTask.new('spec:no_auth') do |spec|
27
- spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
62
+ spec.rspec_opts = ['--format', 'progress', '--format', 'CI::Reporter::RSpec']
28
63
 
29
64
  file_list = FileList['spec/**/*_spec.rb']
30
65
  file_list = file_list.exclude('spec/**/aws_wrapper_spec.rb')
@@ -1,5 +1,5 @@
1
1
  # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC.
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
3
  # All rights reserved.
4
4
  # Redistribution and use in source and binary forms, with or without
5
5
  # modification, are permitted provided that the following conditions are met:
@@ -40,7 +40,7 @@ module OpenStudio
40
40
  :proxy, :credentials, :ami_lookup_version, :openstudio_version,
41
41
  :openstudio_server_version, :region, :ssl_verify_peer, :host, :url, :stable,
42
42
  :save_directory, :subnet_id
43
- ]
43
+ ].freeze
44
44
 
45
45
  class Aws
46
46
  include Logging
@@ -64,7 +64,7 @@ module OpenStudio
64
64
  def initialize(options = {})
65
65
  invalid_options = options.keys - VALID_OPTIONS
66
66
  if invalid_options.any?
67
- fail ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
67
+ raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
68
68
  end
69
69
 
70
70
  # merge in some defaults
@@ -87,12 +87,12 @@ module OpenStudio
87
87
 
88
88
  # populate the credentials
89
89
  options[:credentials] =
90
- {
91
- access_key_id: config_file.access_key,
92
- secret_access_key: config_file.secret_key,
93
- region: options[:region],
94
- ssl_verify_peer: options[:ssl_verify_peer]
95
- }
90
+ {
91
+ access_key_id: config_file.access_key,
92
+ secret_access_key: config_file.secret_key,
93
+ region: options[:region],
94
+ ssl_verify_peer: options[:ssl_verify_peer]
95
+ }
96
96
  else
97
97
  options[:credentials][:region] = options[:region]
98
98
  options[:credentials][:ssl_verify_peer] = options[:ssl_verify_peer]
@@ -111,7 +111,7 @@ module OpenStudio
111
111
  @os_aws = OpenStudioAwsWrapper.new(options)
112
112
  @os_cloudwatch = OpenStudioCloudWatch.new(options)
113
113
 
114
- @dockerized = options[:ami_lookup_version] == 3 ? true : false
114
+ @dockerized = options[:ami_lookup_version] == 3
115
115
 
116
116
  # this will grab the default version of openstudio ami versions
117
117
  # get the arugments for the AMI lookup
@@ -157,14 +157,14 @@ module OpenStudio
157
157
  end
158
158
 
159
159
  if options[:aws_key_pair_name]
160
- fail 'Must pass in the private_key_file_name' unless options[:private_key_file_name]
161
- fail "Private key was not found: #{options[:private_key_file_name]}" unless File.exist? options[:private_key_file_name]
160
+ raise 'Must pass in the private_key_file_name' unless options[:private_key_file_name]
161
+ raise "Private key was not found: #{options[:private_key_file_name]}" unless File.exist? options[:private_key_file_name]
162
162
  end
163
163
 
164
164
  if options[:security_groups].empty?
165
165
  # if the user has not specified any security groups, then create one called: 'openstudio-server-sg-v2'
166
166
  @os_aws.create_or_retrieve_default_security_group(tmp_name = 'openstudio-server-sg-v2.2',
167
- vpc_id=options[:vpc_id])
167
+ vpc_id = options[:vpc_id])
168
168
  else
169
169
  @os_aws.security_groups = options[:security_groups]
170
170
  end
@@ -232,7 +232,8 @@ module OpenStudio
232
232
  options[:image_id] = determine_image_type(options[:instance_type])
233
233
  end
234
234
 
235
- fail "Can't create workers without a server instance running" if @os_aws.server.nil?
235
+ raise "Can't create workers without a server instance running" if @os_aws.server.nil?
236
+
236
237
  user_data_file = @dockerized ? 'worker_script.sh.docker.template' : 'worker_script.sh.template'
237
238
 
238
239
  unless number_of_instances == 0
@@ -259,8 +260,8 @@ module OpenStudio
259
260
  else
260
261
  @os_aws.configure_server_and_workers
261
262
  end
262
- rescue => e
263
- fail "Configuring the cluster failed with error `#{e.message}` in:\n#{e.backtrace.join('\n')}"
263
+ rescue StandardError => e
264
+ raise "Configuring the cluster failed with error `#{e.message}` in:\n#{e.backtrace.join('\n')}"
264
265
  end
265
266
  end
266
267
 
@@ -272,7 +273,7 @@ module OpenStudio
272
273
  puts ''
273
274
  puts 'Server SSH Command:'
274
275
  puts "ssh -i #{@os_aws.private_key_file_name} ubuntu@#{@os_aws.server.data[:dns]}"
275
- if @os_aws.workers.size > 0
276
+ if !@os_aws.workers.empty?
276
277
  puts ''
277
278
  puts 'Worker SSH Command:'
278
279
  @os_aws.workers.each do |worker|
@@ -402,7 +403,7 @@ module OpenStudio
402
403
 
403
404
  # Warning, it appears that this terminates all the instances
404
405
  def terminate_instances_by_group_id(group_id)
405
- fail 'Group ID not defined' unless group_id
406
+ raise 'Group ID not defined' unless group_id
406
407
 
407
408
  instances = @os_aws.describe_running_instances(group_id)
408
409
  logger.info instances
@@ -423,7 +424,7 @@ module OpenStudio
423
424
  end
424
425
 
425
426
  def load_instance_info_from_file(filename)
426
- fail 'Could not find instance description JSON file' unless File.exist? filename
427
+ raise 'Could not find instance description JSON file' unless File.exist? filename
427
428
 
428
429
  h = JSON.parse(File.read(filename), symbolize_names: true)
429
430
  if h[:location] == 'AWS'
@@ -444,10 +445,12 @@ module OpenStudio
444
445
  def upload_file(server_or_workers, local_file, remote_file)
445
446
  case server_or_workers
446
447
  when :server
447
- fail 'Server node is nil' unless @os_aws.server
448
+ raise 'Server node is nil' unless @os_aws.server
449
+
448
450
  return @os_aws.server.upload_file(local_file, remote_file)
449
451
  when :worker
450
- fail 'Worker list is empty' if @os_aws.workers.empty?
452
+ raise 'Worker list is empty' if @os_aws.workers.empty?
453
+
451
454
  return @os_aws.workers.each { |w| w.upload_file(local_file, remote_file) }
452
455
  end
453
456
  end
@@ -455,10 +458,12 @@ module OpenStudio
455
458
  def shell_command(server_or_workers, command, load_env = true)
456
459
  case server_or_workers
457
460
  when :server
458
- fail 'Server node is nil' unless @os_aws.server
461
+ raise 'Server node is nil' unless @os_aws.server
462
+
459
463
  return @os_aws.server.shell_command(command, load_env)
460
464
  when :worker
461
- fail 'Worker list is empty' if @os_aws.workers.empty?
465
+ raise 'Worker list is empty' if @os_aws.workers.empty?
466
+
462
467
  return @os_aws.workers.each { |w| w.shell_command(command, load_env) }
463
468
  end
464
469
  end
@@ -468,10 +473,11 @@ module OpenStudio
468
473
  def download_remote_file(server_or_workers, remote_file, local_file)
469
474
  case server_or_workers
470
475
  when :server
471
- fail 'Server node is nil' unless @os_aws.server
476
+ raise 'Server node is nil' unless @os_aws.server
477
+
472
478
  return @os_aws.server.download_file(remote_file, local_file)
473
479
  when :worker
474
- fail 'Worker file download is not available'
480
+ raise 'Worker file download is not available'
475
481
  end
476
482
  end
477
483
 
@@ -498,7 +504,7 @@ module OpenStudio
498
504
  def os_aws_file_location
499
505
  # Get the location of the os-aws.rb file. Use the relative path from where this file exists
500
506
  os_aws_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'os-aws.rb'))
501
- fail "os_aws_file does not exist where it is expected: #{os_aws_file}" unless File.exist?(os_aws_file)
507
+ raise "os_aws_file does not exist where it is expected: #{os_aws_file}" unless File.exist?(os_aws_file)
502
508
 
503
509
  os_aws_file
504
510
  end
@@ -1,5 +1,5 @@
1
1
  # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC.
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
3
  # All rights reserved.
4
4
  # Redistribution and use in source and binary forms, with or without
5
5
  # modification, are permitted provided that the following conditions are met:
@@ -59,7 +59,7 @@ module OpenStudio
59
59
 
60
60
  unless File.exist?(@yml_config_file)
61
61
  write_config_file
62
- fail "Config file not found. A template has been added, please edit and save: #{@yml_config_file}"
62
+ raise "Config file not found. A template has been added, please edit and save: #{@yml_config_file}"
63
63
  exit 1
64
64
  end
65
65
 
@@ -71,7 +71,7 @@ module OpenStudio
71
71
 
72
72
  @access_key = @config[:access_key_id]
73
73
  @secret_key = @config[:secret_access_key]
74
- rescue
74
+ rescue StandardError
75
75
  raise "Couldn't read config file #{@yml_config_file}. Delete file then recreate by rerunning script"
76
76
  end
77
77
  end
@@ -1,5 +1,40 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  module OpenStudio
2
37
  module Aws
3
- VERSION = '0.7.0.alpha0'
38
+ VERSION = '0.7.0'.freeze
4
39
  end
5
40
  end
@@ -1,3 +1,38 @@
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
+ # All rights reserved.
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+ #
7
+ # (1) Redistributions of source code must retain the above copyright notice,
8
+ # this list of conditions and the following disclaimer.
9
+ #
10
+ # (2) Redistributions in binary form must reproduce the above copyright notice,
11
+ # this list of conditions and the following disclaimer in the documentation
12
+ # and/or other materials provided with the distribution.
13
+ #
14
+ # (3) Neither the name of the copyright holder nor the names of any contributors
15
+ # may be used to endorse or promote products derived from this software without
16
+ # specific prior written permission from the respective party.
17
+ #
18
+ # (4) Other than as required in clauses (1) and (2), distributions in any form
19
+ # of modifications or other derivative works may not use the "OpenStudio"
20
+ # trademark, "OS", "os", or any other confusingly similar designation without
21
+ # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
+ #
23
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER, THE UNITED STATES
27
+ # GOVERNMENT, OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33
+ # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+ # *******************************************************************************
35
+
1
36
  # From: https://github.com/rails/rails/blob/001b270611cd9cb653124775899bdbc2548333ab/activesupport/lib/active_support/core_ext/hash/except.rb
2
37
  class Hash
3
38
  # Returns a hash that includes everything but the given keys.
@@ -1,5 +1,5 @@
1
1
  # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2016, Alliance for Sustainable Energy, LLC.
2
+ # OpenStudio(R), Copyright (c) 2008-2019, Alliance for Sustainable Energy, LLC.
3
3
  # All rights reserved.
4
4
  # Redistribution and use in source and binary forms, with or without
5
5
  # modification, are permitted provided that the following conditions are met:
@@ -40,7 +40,7 @@ class OpenStudioAmis
40
40
 
41
41
  VALID_OPTIONS = [
42
42
  :openstudio_version, :openstudio_server_version, :host, :url, :stable
43
- ]
43
+ ].freeze
44
44
 
45
45
  # Initializer for listing the AMIs and grabbing the correct version of the AMIs based on the OpenStudio version or
46
46
  # OpenStudio Server version.
@@ -52,11 +52,11 @@ class OpenStudioAmis
52
52
  def initialize(version = 1, options = {})
53
53
  invalid_options = options.keys - VALID_OPTIONS
54
54
  if invalid_options.any?
55
- fail ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
55
+ raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
56
56
  end
57
57
 
58
58
  if options[:openstudio_version] && options[:openstudio_server_version]
59
- fail 'Must pass only an openstudio_version or openstudio_server_version when looking up AMIs'
59
+ raise 'Must pass only an openstudio_version or openstudio_server_version when looking up AMIs'
60
60
  end
61
61
 
62
62
  # merge in some defaults
@@ -73,7 +73,7 @@ class OpenStudioAmis
73
73
  @options = defaults.merge(options)
74
74
 
75
75
  if @options[:openstudio_version] != 'default' && @options[:openstudio_server_version] != 'default'
76
- fail 'Must pass either the openstudio_version or openstudio_server_version when looking up AMIs, not both'
76
+ raise 'Must pass either the openstudio_version or openstudio_server_version when looking up AMIs, not both'
77
77
  end
78
78
  end
79
79
 
@@ -100,10 +100,10 @@ class OpenStudioAmis
100
100
  if OpenStudioAmis.method_defined?(command)
101
101
  amis = send(command)
102
102
  else
103
- fail "Unknown api version command #{command}"
103
+ raise "Unknown api version command #{command}"
104
104
  end
105
105
 
106
- fail "Could not find any amis for #{@version}" if amis.nil?
106
+ raise "Could not find any amis for #{@version}" if amis.nil?
107
107
 
108
108
  amis
109
109
  end
@@ -141,8 +141,10 @@ class OpenStudioAmis
141
141
  value = json[:openstudio_server][stable.to_sym]
142
142
  amis = value[:amis]
143
143
  else
144
- logger.info "Could not find a stable version for OpenStudio version #{@options[:openstudio_version]}. "\
145
- 'Looking up older versions to find the latest stable.' unless stable
144
+ unless stable
145
+ logger.info "Could not find a stable version for OpenStudio version #{@options[:openstudio_version]}. "\
146
+ 'Looking up older versions to find the latest stable.'
147
+ end
146
148
 
147
149
  json[:openstudio].each do |os_version, values|
148
150
  next if os_version == :default
@@ -160,12 +162,13 @@ class OpenStudioAmis
160
162
  end
161
163
  end
162
164
 
163
- fail "Could not find a stable version for openstudio version #{@options[:openstudio_version]}" unless amis
165
+ raise "Could not find a stable version for openstudio version #{@options[:openstudio_version]}" unless amis
164
166
  end
165
167
  else
166
168
  # return the default version (which is the latest)
167
169
  default = json[:openstudio][@options[:openstudio_version].to_sym][:default]
168
- fail "Could not find a default version for openstudio version #{@options[:openstudio_version]}" unless default
170
+ raise "Could not find a default version for openstudio version #{@options[:openstudio_version]}" unless default
171
+
169
172
  value = json[:openstudio][@options[:openstudio_version].to_sym][default.to_sym]
170
173
  amis = value[:amis]
171
174
  end
@@ -189,14 +192,16 @@ class OpenStudioAmis
189
192
  elsif @options[:openstudio_server_version] != 'default'
190
193
  hash_array = json[:builds]
191
194
  hash = hash_array.select { |hash| hash[:name] == @options[:openstudio_server_version] }
192
- fail "Multiple | no entries found matching name key `#{@options[:openstudio_server_version]}`" unless hash.length == 1
195
+ raise "Multiple | no entries found matching name key `#{@options[:openstudio_server_version]}`" unless hash.length == 1
196
+
193
197
  amis = {}
194
198
  amis[:server] = hash.first[:ami]
195
199
  amis[:worker] = hash.first[:ami]
196
200
  elsif @options[:openstudio_version] != 'default'
197
- fail 'Currently the openstudio_version lookup is not supported in v3.'
201
+ raise 'Currently the openstudio_version lookup is not supported in v3.'
198
202
  end
199
- fail 'The requested AMI key is NULL.' if amis[:server] == nil
203
+ raise 'The requested AMI key is NULL.' if amis[:server].nil?
204
+
200
205
  logger.info "AMI IDs are #{amis}" if amis
201
206
 
202
207
  amis
@@ -207,7 +212,7 @@ class OpenStudioAmis
207
212
  # fetch the URL with redirects
208
213
  def fetch(uri_str, limit = 10)
209
214
  # You should choose better exception.
210
- fail ArgumentError, 'HTTP redirect too deep' if limit == 0
215
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
211
216
 
212
217
  url = URI.parse(uri_str)
213
218
  req = Net::HTTP::Get.new(url.path)
@@ -229,7 +234,7 @@ class OpenStudioAmis
229
234
  if resp.code == '200'
230
235
  result = JSON.parse(resp.body, symbolize_names: true)
231
236
  else
232
- fail "#{resp.code} Unable to download AMI IDs"
237
+ raise "#{resp.code} Unable to download AMI IDs"
233
238
  end
234
239
 
235
240
  result