openstudio-aws 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openstudio-aws.rb +2 -3
  3. data/lib/openstudio/aws/aws.rb +44 -46
  4. data/lib/openstudio/aws/config.rb +3 -3
  5. data/lib/openstudio/aws/version.rb +1 -1
  6. data/lib/openstudio/lib/ami_list.rb +24 -26
  7. data/lib/openstudio/lib/mongoid.yml.template +0 -1
  8. data/lib/openstudio/lib/openstudio_aws_instance.rb +45 -48
  9. data/lib/openstudio/lib/openstudio_aws_logger.rb +5 -5
  10. data/lib/openstudio/lib/openstudio_aws_methods.rb +52 -54
  11. data/lib/openstudio/lib/openstudio_aws_wrapper.rb +89 -94
  12. data/lib/openstudio/lib/os-aws.rb +46 -46
  13. data/lib/openstudio/lib/server_script.sh +45 -16
  14. data/lib/openstudio/lib/worker_script.sh.template +15 -6
  15. data/spec/aws_instances/aws_spec_api.rb +15 -15
  16. data/spec/openstudio-aws/ami_list_spec.rb +14 -14
  17. data/spec/openstudio-aws/aws_methods_spec.rb +7 -9
  18. data/spec/openstudio-aws/aws_spec.rb +43 -47
  19. data/spec/openstudio-aws/aws_wrapper_spec.rb +39 -41
  20. data/spec/openstudio-aws/config_spec.rb +2 -2
  21. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.7.xml +11 -0
  22. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.8.xml +11 -0
  23. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.36.xml +13 -0
  24. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.37.xml +13 -0
  25. data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.4.xml +9 -0
  26. data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.5.xml +9 -0
  27. data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.4.xml +9 -0
  28. data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.5.xml +9 -0
  29. data/spec/reports/SPEC-OpenStudio-Aws-Aws.42.xml +7 -0
  30. data/spec/reports/SPEC-OpenStudio-Aws-Aws.43.xml +7 -0
  31. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.61.xml +9 -0
  32. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.62.xml +9 -0
  33. data/spec/reports/SPEC-OpenStudio-Aws-Config.61.xml +7 -0
  34. data/spec/reports/SPEC-OpenStudio-Aws-Config.62.xml +7 -0
  35. data/spec/reports/SPEC-OpenStudioAmis-version-1.63.xml +13 -0
  36. data/spec/reports/SPEC-OpenStudioAmis-version-1.64.xml +13 -0
  37. data/spec/reports/SPEC-OpenStudioAmis-version-2.61.xml +9 -0
  38. data/spec/reports/SPEC-OpenStudioAmis-version-2.62.xml +9 -0
  39. data/spec/reports/SPEC-OpenStudioAmis.63.xml +7 -0
  40. data/spec/reports/SPEC-OpenStudioAmis.64.xml +7 -0
  41. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.63.xml +11 -0
  42. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.64.xml +11 -0
  43. data/spec/reports/SPEC-OpenStudioAwsMethods.63.xml +7 -0
  44. data/spec/reports/SPEC-OpenStudioAwsMethods.64.xml +7 -0
  45. data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.1.xml +9 -0
  46. data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.2.xml +9 -0
  47. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.62.xml +11 -0
  48. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.63.xml +11 -0
  49. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.53.xml +11 -0
  50. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.54.xml +11 -0
  51. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.62.xml +9 -0
  52. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.63.xml +9 -0
  53. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.11.xml +87 -0
  54. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.12.xml +87 -0
  55. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.11.xml +821 -0
  56. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.12.xml +821 -0
  57. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.62.xml +7 -0
  58. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.63.xml +7 -0
  59. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.63.xml +9 -0
  60. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.64.xml +9 -0
  61. data/spec/reports/SPEC-OpenStudioAwsWrapper.63.xml +7 -0
  62. data/spec/reports/SPEC-OpenStudioAwsWrapper.64.xml +7 -0
  63. data/spec/spec_helper.rb +1 -4
  64. metadata +85 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3df47902801ee1a4dd02804a004a89a2cf5ffd17
4
- data.tar.gz: 843eb24cd84488b3c37a79e80b412fae5fea2446
3
+ metadata.gz: e5c42970e6b71829c0fe5f79e9ae4935a31b535f
4
+ data.tar.gz: 80093ee71f6360dd8c6fe3592b5e26d77c0f4116
5
5
  SHA512:
6
- metadata.gz: 158e202c176ba09d3bb394c08503bdecd2b6afaed767c7932889c046f1fe6bb62111eb4c55b8a66cf199caff844c1cf838134bc817fd00341aa705fd0489b91a
7
- data.tar.gz: 99b9feebfd8a48bf3858e375aa0ab6c8ea2950a4c14e2fd6cb1c83b502b70e2231ad80aa37cfc487a8acdd4bcba166527c864b4cafe312f19054117d0cb95e8c
6
+ metadata.gz: 8c9e0eb68f9f89280dddd808af1c7f454e89cb1865b70c60f5843d7ec42c99fbe50bfceb9f0f64d533d7313cd8c2637daa22d8e7974dd4fe48ebc7a33ca1deed
7
+ data.tar.gz: 5a44b30ed06bf6970834230e2b70f32c20158935f448f5aefec46818212cbd6be3a62a17cf0cb6a129881588e1f5685ba648c56217ea78c4b522003fefd7e3b9
@@ -10,8 +10,8 @@ require 'semantic/core_ext'
10
10
  begin
11
11
  require 'aws-sdk-core'
12
12
  rescue LoadError
13
- puts "Failed to load AWS-SDK-CORE gem"
14
- puts " try running: gem install aws-sdk-core"
13
+ puts 'Failed to load AWS-SDK-CORE gem'
14
+ puts ' try running: gem install aws-sdk-core'
15
15
  exit
16
16
  end
17
17
 
@@ -21,4 +21,3 @@ require 'openstudio/aws/version'
21
21
  require 'openstudio/lib/openstudio_aws_instance'
22
22
  require 'openstudio/lib/openstudio_aws_wrapper'
23
23
  require 'openstudio/lib/ami_list'
24
-
@@ -2,8 +2,8 @@
2
2
  module OpenStudio
3
3
  module Aws
4
4
  VALID_OPTIONS = [
5
- :proxy, :credentials, :ami_lookup_version, :openstudio_version,
6
- :openstudio_server_version, :region, :ssl_verify_peer, :host, :url
5
+ :proxy, :credentials, :ami_lookup_version, :openstudio_version,
6
+ :openstudio_server_version, :region, :ssl_verify_peer, :host, :url
7
7
  ]
8
8
 
9
9
  class Aws
@@ -17,31 +17,30 @@ module OpenStudio
17
17
  def initialize(options = {})
18
18
  invalid_options = options.keys - VALID_OPTIONS
19
19
  if invalid_options.any?
20
- raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
20
+ fail ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
21
21
  end
22
22
 
23
23
  # merge in some defaults
24
24
  defaults = {
25
- :ami_lookup_version => 1,
26
- :region => 'us-east-1',
27
- :ssl_verify_peer => false,
28
- :host => 'developer.nrel.gov',
29
- :url => '/downloads/buildings/openstudio/rsrc'
25
+ ami_lookup_version: 1,
26
+ region: 'us-east-1',
27
+ ssl_verify_peer: false,
28
+ host: 'developer.nrel.gov',
29
+ url: '/downloads/buildings/openstudio/api'
30
30
  }
31
31
  options = defaults.merge(options)
32
32
 
33
-
34
33
  # read in the config.yml file to get the secret/private key
35
34
  if !options[:credentials]
36
- config_file = OpenStudio::Aws::Config.new()
35
+ config_file = OpenStudio::Aws::Config.new
37
36
 
38
37
  # populate the credentials
39
38
  options[:credentials] =
40
39
  {
41
- :access_key_id => config_file.access_key,
42
- :secret_access_key => config_file.secret_key,
43
- :region => options[:region],
44
- :ssl_verify_peer => options[:ssl_verify_peer]
40
+ access_key_id: config_file.access_key,
41
+ secret_access_key: config_file.secret_key,
42
+ region: options[:region],
43
+ ssl_verify_peer: options[:ssl_verify_peer]
45
44
  }
46
45
  else
47
46
  options[:credentials][:region] = options[:region]
@@ -58,12 +57,12 @@ module OpenStudio
58
57
  # todo: remove this proxy_uri and make a method to format correctly
59
58
  options[:proxy_uri] = proxy_uri
60
59
 
61
- #todo: do we need to escape a couple of the argument of username and password
60
+ # todo: do we need to escape a couple of the argument of username and password
62
61
 
63
- #todo: set some environment variables for system based proxy
62
+ # todo: set some environment variables for system based proxy
64
63
  end
65
64
 
66
- #puts "Final options are: #{options.inspect}"
65
+ # puts "Final options are: #{options.inspect}"
67
66
 
68
67
  @os_aws = OpenStudioAwsWrapper.new(options)
69
68
  @local_key_file_name = nil
@@ -75,35 +74,35 @@ module OpenStudio
75
74
  ami_options[:openstudio_version] = options[:openstudio_version] if options[:openstudio_version]
76
75
  ami_options[:host] = options[:host] if options[:host]
77
76
  ami_options[:url] = options[:url] if options[:url]
78
-
77
+
79
78
  @default_amis = OpenStudioAmis.new(options[:ami_lookup_version], ami_options).get_amis
80
79
  end
81
80
 
82
81
  # command line call to create a new instance. This should be more tightly integrated with teh os-aws.rb gem
83
- def create_server(instance_data = {}, server_json_filename = "server_data.json", user_id="unknown_user")
84
- defaults = {instance_type: "m2.xlarge", image_id: @default_amis[:server]}
82
+ def create_server(instance_data = {}, server_json_filename = 'server_data.json', user_id = 'unknown_user')
83
+ defaults = { instance_type: 'm2.xlarge', image_id: @default_amis[:server] }
85
84
  instance_data = defaults.merge(instance_data)
86
85
 
87
- @os_aws.create_or_retrieve_security_group("openstudio-worker-sg-v1")
86
+ @os_aws.create_or_retrieve_security_group('openstudio-worker-sg-v1')
88
87
  @os_aws.create_or_retrieve_key_pair
89
88
 
90
- @local_key_file_name = "ec2_server_key.pem"
89
+ @local_key_file_name = 'ec2_server_key.pem'
91
90
  @os_aws.save_private_key(@local_key_file_name)
92
- @os_aws.launch_server(instance_data[:image_id], instance_data[:instance_type], {:user_id => user_id})
91
+ @os_aws.launch_server(instance_data[:image_id], instance_data[:instance_type], user_id: user_id)
93
92
 
94
93
  puts @os_aws.server.to_os_hash.to_json
95
94
 
96
- File.open(server_json_filename, "w") { |f| f << JSON.pretty_generate(@os_aws.server.to_os_hash) }
95
+ File.open(server_json_filename, 'w') { |f| f << JSON.pretty_generate(@os_aws.server.to_os_hash) }
97
96
 
98
97
  # Print out some debugging commands (probably work on mac/linux only)
99
- puts ""
100
- puts "Server SSH Command:"
98
+ puts ''
99
+ puts 'Server SSH Command:'
101
100
 
102
101
  puts "ssh -i #{@local_key_file_name} ubuntu@#{@os_aws.server.data[:dns]}"
103
102
  end
104
103
 
105
- def create_workers(number_of_instances, instance_data = {}, user_id="unknown_user")
106
- defaults = {instance_type: "m2.4xlarge"}
104
+ def create_workers(number_of_instances, instance_data = {}, user_id = 'unknown_user')
105
+ defaults = { instance_type: 'm2.4xlarge' }
107
106
  instance_data = defaults.merge(instance_data)
108
107
 
109
108
  if instance_data[:image_id].nil?
@@ -114,35 +113,35 @@ module OpenStudio
114
113
  end
115
114
  end
116
115
 
117
- raise "Can't create workers without a server instance running" if @os_aws.server.nil?
116
+ fail "Can't create workers without a server instance running" if @os_aws.server.nil?
118
117
 
119
- @os_aws.launch_workers(instance_data[:image_id], instance_data[:instance_type], number_of_instances, {:user_id => user_id})
118
+ @os_aws.launch_workers(instance_data[:image_id], instance_data[:instance_type], number_of_instances, user_id: user_id)
120
119
 
121
120
  ## append the information to the server_data hash that already exists
122
- #@server_data[:instance_type] = instance_data[:instance_type]
123
- #@server_data[:num] = number_of_instances
124
- #server_string = @server_data.to_json.gsub("\"", "\\\\\"")
121
+ # @server_data[:instance_type] = instance_data[:instance_type]
122
+ # @server_data[:num] = number_of_instances
123
+ # server_string = @server_data.to_json.gsub("\"", "\\\\\"")
125
124
  #
126
- #start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_workers \"#{server_string}\""
127
- #puts "Worker Command: #{start_string}"
128
- #worker_data_string = `#{start_string}`
129
- #@worker_data = JSON.parse(worker_data_string, :symbolize_names => true)
130
- #File.open("worker_data.json", "w") { |f| f << JSON.pretty_generate(worker_data) }
125
+ # start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_workers \"#{server_string}\""
126
+ # puts "Worker Command: #{start_string}"
127
+ # worker_data_string = `#{start_string}`
128
+ # @worker_data = JSON.parse(worker_data_string, :symbolize_names => true)
129
+ # File.open("worker_data.json", "w") { |f| f << JSON.pretty_generate(worker_data) }
131
130
  #
132
131
  ## Print out some debugging commands (probably work on mac/linux only)
133
- puts ""
134
- puts "Worker SSH Command:"
132
+ puts ''
133
+ puts 'Worker SSH Command:'
135
134
  @os_aws.workers.each do |worker|
136
135
  puts "ssh -i #{@local_key_file_name} ubuntu@#{worker.data[:dns]}"
137
136
  end
138
137
 
139
- puts ""
140
- puts "Waiting for server/worker configurations"
138
+ puts ''
139
+ puts 'Waiting for server/worker configurations'
141
140
 
142
141
  @os_aws.configure_server_and_workers
143
142
  end
144
143
 
145
- def kill_instances()
144
+ def kill_instances
146
145
  # Add this method to kill all the running instances
147
146
  end
148
147
 
@@ -150,12 +149,11 @@ module OpenStudio
150
149
 
151
150
  def os_aws_file_location
152
151
  # Get the location of the os-aws.rb file. Use the relative path from where this file exists
153
- os_aws_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "os-aws.rb"))
154
- raise "os_aws_file does not exist where it is expected: #{os_aws_file}" unless File.exists?(os_aws_file)
152
+ os_aws_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'os-aws.rb'))
153
+ fail "os_aws_file does not exist where it is expected: #{os_aws_file}" unless File.exist?(os_aws_file)
155
154
 
156
155
  os_aws_file
157
156
  end
158
-
159
157
  end
160
158
  end
161
159
  end
@@ -8,10 +8,10 @@ module OpenStudio
8
8
  @yml_config_file = yml_config_file
9
9
  @config = nil
10
10
  if @yml_config_file.nil?
11
- @yml_config_file = File.join(File.expand_path("~"), "aws_config.yml")
12
- if !File.exists?(@yml_config_file)
11
+ @yml_config_file = File.join(File.expand_path('~'), 'aws_config.yml')
12
+ unless File.exist?(@yml_config_file)
13
13
  write_config_file
14
- raise "No Config File in user home directory. A template has been added, please edit and save: #{@yml_config_file}"
14
+ fail "No Config File in user home directory. A template has been added, please edit and save: #{@yml_config_file}"
15
15
  exit 1
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module OpenStudio
2
2
  module Aws
3
- VERSION = "0.1.22"
3
+ VERSION = '0.1.23'
4
4
  end
5
5
  end
@@ -1,18 +1,18 @@
1
1
  # NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files
2
2
  ######################################################################
3
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
4
4
  # All rights reserved.
5
- #
5
+ #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
8
8
  # License as published by the Free Software Foundation; either
9
9
  # version 2.1 of the License, or (at your option) any later version.
10
- #
10
+ #
11
11
  # This library is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
  # Lesser General Public License for more details.
15
- #
15
+ #
16
16
  # You should have received a copy of the GNU Lesser General Public
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,24 +20,23 @@
20
20
 
21
21
  # Class for managing the AMI ids based on the openstudio version and the openstudio-server version
22
22
 
23
-
24
23
  class OpenStudioAmis
25
24
  VALID_OPTIONS = [
26
- :openstudio_version, :openstudio_server_version, :host, :url
25
+ :openstudio_version, :openstudio_server_version, :host, :url
27
26
  ]
28
-
27
+
29
28
  def initialize(version = 1, options = {})
30
29
  invalid_options = options.keys - VALID_OPTIONS
31
30
  if invalid_options.any?
32
- raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
31
+ fail ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
33
32
  end
34
33
 
35
34
  # merge in some defaults
36
35
  defaults = {
37
- :openstudio_version => 'default',
38
- :openstudio_server_version => 'default',
39
- :host => 'developer.nrel.gov',
40
- :url => '/downloads/buildings/openstudio/rsrc'
36
+ openstudio_version: 'default',
37
+ openstudio_server_version: 'default',
38
+ host: 'developer.nrel.gov',
39
+ url: '/downloads/buildings/openstudio/api'
41
40
  }
42
41
  @version = version
43
42
  @options = defaults.merge(options)
@@ -49,7 +48,7 @@ class OpenStudioAmis
49
48
  if OpenStudioAmis.method_defined?(command)
50
49
  json = send(command)
51
50
  else
52
- raise "Unknown api version command #{command}"
51
+ fail "Unknown api version command #{command}"
53
52
  end
54
53
 
55
54
  json
@@ -61,10 +60,10 @@ class OpenStudioAmis
61
60
  if OpenStudioAmis.method_defined?(command)
62
61
  amis = send(command)
63
62
  else
64
- raise "Unknown api version command #{command}"
63
+ fail "Unknown api version command #{command}"
65
64
  end
66
65
 
67
- raise "Could not find any amis for #{@version}" if amis.nil?
66
+ fail "Could not find any amis for #{@version}" if amis.nil?
68
67
 
69
68
  amis
70
69
  end
@@ -85,28 +84,27 @@ class OpenStudioAmis
85
84
  json
86
85
  end
87
86
 
88
- def get_ami_version_1()
87
+ def get_ami_version_1
89
88
  json = list_amis_version_1
90
- version = json.has_key?(@options[:openstudio_version].to_sym) ? @options[:openstudio_version].to_sym : 'default'
89
+ version = json.key?(@options[:openstudio_version].to_sym) ? @options[:openstudio_version].to_sym : 'default'
91
90
 
92
91
  json[version]
93
92
  end
94
93
 
95
- def get_ami_version_2()
94
+ def get_ami_version_2
96
95
  json = list_amis_version_2
97
-
96
+
98
97
  amis = nil
99
98
  if @options[:openstudio_server_version].to_sym == :default
100
99
  # just grab the most recent server
101
100
  # need to do a sort to get the most recent because we can't promise that they are in order
102
- json[:openstudio].each do |k,v|
103
-
104
-
101
+ json[:openstudio].each do |k, v|
102
+
105
103
  end
106
104
  key, value = json[:openstudio_server].first
107
-
105
+
108
106
  amis = value[:amis]
109
- #puts json.inspect
107
+ # puts json.inspect
110
108
  else
111
109
  value = json[:openstudio_server][@options[:openstudio_server_version].to_sym]
112
110
  amis = value[:amis]
@@ -121,9 +119,9 @@ class OpenStudioAmis
121
119
  result = nil
122
120
  resp = Net::HTTP.get_response(@options[:host], endpoint)
123
121
  if resp.code == '200'
124
- result = JSON.parse(resp.body, :symbolize_names => true)
122
+ result = JSON.parse(resp.body, symbolize_names: true)
125
123
  else
126
- raise "#{resp.code} Unable to download AMI IDs"
124
+ fail "#{resp.code} Unable to download AMI IDs"
127
125
  end
128
126
 
129
127
  result
@@ -16,4 +16,3 @@ production:
16
16
  options:
17
17
  allow_dynamic_fields: true
18
18
  raise_not_found_error: false
19
-
@@ -1,18 +1,18 @@
1
1
  # NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files
2
2
  ######################################################################
3
- # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
3
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
4
4
  # All rights reserved.
5
- #
5
+ #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
8
8
  # License as published by the Free Software Foundation; either
9
9
  # version 2.1 of the License, or (at your option) any later version.
10
- #
10
+ #
11
11
  # This library is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
14
  # Lesser General Public License for more details.
15
- #
15
+ #
16
16
  # You should have received a copy of the GNU Lesser General Public
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -22,7 +22,6 @@ require 'securerandom'
22
22
  require_relative 'openstudio_aws_logger'
23
23
  require_relative 'openstudio_aws_methods'
24
24
 
25
-
26
25
  class OpenStudioAwsInstance
27
26
  include Logging
28
27
  include OpenStudioAwsMethods
@@ -38,103 +37,101 @@ class OpenStudioAwsInstance
38
37
  @security_group_name = security_group_name
39
38
  @group_uuid = group_uuid.to_s
40
39
  @private_key = private_key
41
- @proxy = proxy
40
+ @proxy = proxy
42
41
  end
43
42
 
44
43
  def launch_instance(image_id, instance_type, user_data, user_id)
45
- #logger.info("user_data #{user_data.inspect}")
44
+ # logger.info("user_data #{user_data.inspect}")
46
45
  instance = {
47
- :image_id => image_id,
48
- :key_name => @key_pair_name,
49
- :security_groups => [@security_group_name],
50
- :user_data => Base64.encode64(user_data),
51
- :instance_type => instance_type,
52
- :min_count => 1,
53
- :max_count => 1
46
+ image_id: image_id,
47
+ key_name: @key_pair_name,
48
+ security_groups: [@security_group_name],
49
+ user_data: Base64.encode64(user_data),
50
+ instance_type: instance_type,
51
+ min_count: 1,
52
+ max_count: 1
54
53
  }
55
- #logger.info instance.inspect
54
+ # logger.info instance.inspect
56
55
  result = @aws.run_instances(instance)
57
56
 
58
57
  # determine how many processors are suppose to be in this image (lookup for now?)
59
58
  processors = find_processors(instance_type)
60
59
 
61
- # only asked for 1 instance, so therefore it should be the first
60
+ # only asked for 1 instance, so therefore it should be the first
62
61
  aws_instance = result.data.instances.first
63
62
  @aws.create_tags(
64
- {
65
- :resources => [aws_instance.instance_id],
66
- :tags => [
67
- {:key => 'Name', :value => "OpenStudio-#{@openstudio_instance_type.capitalize}"}, # todo: abstract out the server and version
68
- {:key => 'GroupUUID', :value => @group_uuid},
69
- {:key => 'NumberOfProcessors', :value => processors.to_s},
70
- {:key => 'Purpose', :value => "OpenStudio#{@openstudio_instance_type.capitalize}"},
71
- {:key => 'UserID', :value => user_id}
63
+
64
+ resources: [aws_instance.instance_id],
65
+ tags: [
66
+ { key: 'Name', value: "OpenStudio-#{@openstudio_instance_type.capitalize}" }, # todo: abstract out the server and version
67
+ { key: 'GroupUUID', value: @group_uuid },
68
+ { key: 'NumberOfProcessors', value: processors.to_s },
69
+ { key: 'Purpose', value: "OpenStudio#{@openstudio_instance_type.capitalize}" },
70
+ { key: 'UserID', value: user_id }
72
71
  ]
73
- }
72
+
74
73
  )
75
74
 
76
- # get the instance information
77
- test_result = @aws.describe_instance_status({:instance_ids => [aws_instance.instance_id]}).data.instance_statuses.first
75
+ # get the instance information
76
+ test_result = @aws.describe_instance_status(instance_ids: [aws_instance.instance_id]).data.instance_statuses.first
78
77
  begin
79
- Timeout::timeout(600) {# 10 minutes
80
- while test_result.nil? || test_result.instance_state.name != "running"
78
+ Timeout.timeout(600) {# 10 minutes
79
+ while test_result.nil? || test_result.instance_state.name != 'running'
81
80
  # refresh the server instance information
82
81
 
83
82
  sleep 5
84
- test_result = @aws.describe_instance_status({:instance_ids => [aws_instance.instance_id]}).data.instance_statuses.first
85
- logger.info "... waiting for instance to be running ..."
83
+ test_result = @aws.describe_instance_status(instance_ids: [aws_instance.instance_id]).data.instance_statuses.first
84
+ logger.info '... waiting for instance to be running ...'
86
85
  end
87
86
  }
88
87
  rescue TimeoutError
89
88
  raise "Intance was unable to launch due to timeout #{aws_instance.instance_id}"
90
89
  end
91
90
 
92
- # now grab information about the instance
91
+ # now grab information about the instance
93
92
  # todo: check lengths on all of arrays
94
- instance_data = @aws.describe_instances({:instance_ids => [aws_instance.instance_id]}).data.reservations.first.instances.first.to_hash
93
+ instance_data = @aws.describe_instances(instance_ids: [aws_instance.instance_id]).data.reservations.first.instances.first.to_hash
95
94
  logger.info "instance description is: #{instance_data}"
96
95
 
97
96
  @data = create_struct(instance_data, processors)
98
97
  end
99
-
98
+
100
99
  # if the server already exists, then load the data about the server into the object
101
- # instance_data is passed in and in the form of the instance data (as a hash) structured as the
100
+ # instance_data is passed in and in the form of the instance data (as a hash) structured as the
102
101
  # result of the amazon describe instance
103
102
  def load_instance_data(instance_data)
104
- @data = create_struct(instance_data, find_processors(instance_data[:instance_type]))
103
+ @data = create_struct(instance_data, find_processors(instance_data[:instance_type]))
105
104
  end
106
105
 
107
106
  # Format of the OS JSON that is used for the command line based script
108
107
  def to_os_hash
109
- h = ""
108
+ h = ''
110
109
  if @openstudio_instance_type == :server
111
110
  h = {
112
- :timestamp => @group_uuid,
111
+ timestamp: @group_uuid,
113
112
  #:private_key => @private_key, # need to stop printing this out
114
- :server => {
115
- :id => @data.id,
116
- :ip => 'http://' + @data.ip,
117
- :dns => @data.dns,
118
- :procs => @data.procs
113
+ server: {
114
+ id: @data.id,
115
+ ip: 'http://' + @data.ip,
116
+ dns: @data.dns,
117
+ procs: @data.procs
119
118
  }
120
119
  }
121
120
  else
122
- raise "do not know how to convert :worker instance to_os_hash. Use the os_aws.to_worker_hash method"
121
+ fail 'do not know how to convert :worker instance to_os_hash. Use the os_aws.to_worker_hash method'
123
122
  end
124
-
125
123
 
126
124
  logger.info("server info #{h}")
127
125
 
128
126
  h
129
127
  end
130
-
128
+
131
129
  private
132
130
 
133
131
  # store the data into a custom struct. The instance is the full description. The remaining fields are
134
132
  # just easier accessors to the data in the raw request except for procs which is a custom request.
135
133
  def create_struct(instance, procs)
136
134
  instance_struct = Struct.new(:instance, :id, :ip, :dns, :procs)
137
- return instance_struct.new(instance, instance[:instance_id], instance[:public_ip_address], instance[:public_dns_name], procs)
135
+ instance_struct.new(instance, instance[:instance_id], instance[:public_ip_address], instance[:public_dns_name], procs)
138
136
  end
139
-
140
137
  end