openstudio-aws 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openstudio/aws/aws.rb +15 -19
- data/lib/openstudio/aws/version.rb +1 -1
- data/lib/openstudio/lib/ami_list.rb +19 -2
- data/lib/openstudio/lib/openstudio_aws_instance.rb +28 -31
- data/lib/openstudio/lib/openstudio_aws_wrapper.rb +61 -49
- data/spec/aws_instances/aws_spec_api.rb +0 -1
- data/spec/openstudio-aws/ami_list_spec.rb +0 -1
- data/spec/openstudio-aws/aws_spec.rb +2 -2
- data/spec/openstudio-aws/aws_wrapper_spec.rb +0 -2
- data/spec/openstudio-aws/config_spec.rb +0 -1
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.22.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.23.xml +46 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.24.xml +46 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.25.xml +49 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.26.xml +49 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.27.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.22.xml +11 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.23.xml +33 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.24.xml +33 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.25.xml +35 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.26.xml +35 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-custom-keys.27.xml +11 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.22.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.23.xml +46 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.24.xml +46 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.25.xml +49 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.26.xml +49 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.27.xml +13 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.23.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.24.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.25.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.26.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.27.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.23.xml +20 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.24.xml +20 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.25.xml +21 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.26.xml +21 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.27.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.26.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Aws.27.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.20.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.21.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.23.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.24.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.25.xml +9 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.20.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.21.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudio-Aws-Config.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.22.xml +14 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.23.xml +39 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.24.xml +39 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.25.xml +42 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.26.xml +42 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-1.27.xml +14 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.23.xml +18 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.24.xml +18 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.25.xml +19 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.26.xml +19 -0
- data/spec/reports/SPEC-OpenStudioAmis-version-2.27.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAmis.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis.26.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAmis.27.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.22.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.23.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.24.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.25.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.26.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance-processors.27.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.26.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsInstance.27.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.20.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.21.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.22.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.23.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.24.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-ami-list.25.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.22.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.23.xml +33 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.24.xml +33 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.25.xml +35 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.26.xml +35 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.27.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.22.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.23.xml +33 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.24.xml +33 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.25.xml +35 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.26.xml +35 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.27.xml +11 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.23.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.24.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.25.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.26.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.27.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.21.xml +156 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.22.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.23.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.24.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.25.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.26.xml +156 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.20.xml +2151 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.21.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.22.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.23.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.24.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.25.xml +2151 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.26.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.27.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.0.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.1.xml +20 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.2.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.3.xml +21 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.4.xml +53 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-security-groups.xml +53 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.22.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.23.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.24.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.25.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.26.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.27.xml +9 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.22.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.23.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.24.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.25.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.26.xml +7 -0
- data/spec/reports/SPEC-OpenStudioAwsWrapper.27.xml +7 -0
- metadata +282 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62fe65f799f5982237127e58ec68bdd92ed883e1
|
4
|
+
data.tar.gz: fc6ece5979bc471e2ef8c5ca67d02ad9ebb5f1e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e01949a6660d24ebce0feafbe9a46f34e389ef302bcb015f92f4bbf9619b988f17ff63c9722de7b4d423503cd2d3ba791e9f427b0864026e24ba3f081ed359f8
|
7
|
+
data.tar.gz: a6f8f3a8d246b3bafbc1c61be9ecbba0ebc6c116b09a404ccac45c12826a0e53ca4a3584ac0164d1d63b72672bffd357a6dfaef5872a1623e5ed4c49e126642f
|
data/lib/openstudio/aws/aws.rb
CHANGED
@@ -55,12 +55,12 @@ module OpenStudio
|
|
55
55
|
else
|
56
56
|
proxy_uri = "https://#{options[:proxy][:host]}:#{options[:proxy][:port]}"
|
57
57
|
end
|
58
|
-
#
|
58
|
+
# TODO: remove this proxy_uri and make a method to format correctly
|
59
59
|
options[:proxy_uri] = proxy_uri
|
60
60
|
|
61
|
-
#
|
61
|
+
# TODO: do we need to escape a couple of the argument of username and password
|
62
62
|
|
63
|
-
#
|
63
|
+
# TODO: set some environment variables for system based proxy
|
64
64
|
end
|
65
65
|
|
66
66
|
# puts "Final options are: #{options.inspect}"
|
@@ -80,8 +80,6 @@ module OpenStudio
|
|
80
80
|
@default_amis = OpenStudioAmis.new(options[:ami_lookup_version], ami_options).get_amis
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
83
|
# # def load_data_from_json(json_filename)
|
86
84
|
# @os_aws.load_data_from_json
|
87
85
|
#
|
@@ -108,8 +106,8 @@ module OpenStudio
|
|
108
106
|
|
109
107
|
# for backwards compatibilty, still allow security_group
|
110
108
|
if options[:security_group]
|
111
|
-
warn
|
112
|
-
options[:security_groups] = [
|
109
|
+
warn 'Pass security_groups as an array instead of security_group. security_group will be deprecated in 0.4.0'
|
110
|
+
options[:security_groups] = [options[:security_group]]
|
113
111
|
end
|
114
112
|
|
115
113
|
if options[:aws_key_pair_name]
|
@@ -136,10 +134,10 @@ module OpenStudio
|
|
136
134
|
end
|
137
135
|
|
138
136
|
server_options = {
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
137
|
+
user_id: options[:user_id],
|
138
|
+
tags: options[:tags],
|
139
|
+
subnet_id: options[:subnet_id],
|
140
|
+
associate_public_ip_address: options[:associate_public_ip_address]
|
143
141
|
}
|
144
142
|
|
145
143
|
# save the worker pem and public to the directory
|
@@ -181,11 +179,10 @@ module OpenStudio
|
|
181
179
|
|
182
180
|
# for backwards compatibilty, still allow security_group
|
183
181
|
if options[:security_group]
|
184
|
-
warn
|
185
|
-
options[:security_groups] = [
|
182
|
+
warn 'Pass security_groups as an array instead of security_group. security_group will be deprecated in 0.4.0'
|
183
|
+
options[:security_groups] = [options[:security_group]]
|
186
184
|
end
|
187
185
|
|
188
|
-
|
189
186
|
# Get the right worker AMI ids based on the type of instance
|
190
187
|
if options[:image_id].nil?
|
191
188
|
options[:image_id] = determine_image_type(options[:instance_type])
|
@@ -198,10 +195,10 @@ module OpenStudio
|
|
198
195
|
puts 'No workers requested'
|
199
196
|
else
|
200
197
|
worker_options = {
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
198
|
+
user_id: options[:user_id],
|
199
|
+
tags: options[:tags],
|
200
|
+
subnet_id: options[:subnet_id],
|
201
|
+
associate_public_ip_address: options[:associate_public_ip_address]
|
205
202
|
}
|
206
203
|
|
207
204
|
# if options[:ebs_volume_size]
|
@@ -288,7 +285,6 @@ module OpenStudio
|
|
288
285
|
return false
|
289
286
|
end
|
290
287
|
|
291
|
-
# load the worker nodes someday
|
292
288
|
true
|
293
289
|
end
|
294
290
|
|
@@ -99,7 +99,6 @@ class OpenStudioAmis
|
|
99
99
|
# just grab the most recent server
|
100
100
|
# need to do a sort to get the most recent because we can't promise that they are in order
|
101
101
|
json[:openstudio].each do |_k, _v|
|
102
|
-
|
103
102
|
end
|
104
103
|
key, value = json[:openstudio_server].first
|
105
104
|
|
@@ -115,9 +114,27 @@ class OpenStudioAmis
|
|
115
114
|
|
116
115
|
private
|
117
116
|
|
117
|
+
# fetch the URL with redirects
|
118
|
+
def fetch(uri_str, limit = 10)
|
119
|
+
# You should choose better exception.
|
120
|
+
fail ArgumentError, 'HTTP redirect too deep' if limit == 0
|
121
|
+
|
122
|
+
url = URI.parse(uri_str)
|
123
|
+
req = Net::HTTP::Get.new(url.path)
|
124
|
+
response = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
|
125
|
+
case response
|
126
|
+
when Net::HTTPSuccess then
|
127
|
+
response
|
128
|
+
when Net::HTTPRedirection then
|
129
|
+
fetch(response['location'], limit - 1)
|
130
|
+
else
|
131
|
+
response.error!
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
118
135
|
def retrieve_json(endpoint)
|
119
136
|
result = nil
|
120
|
-
resp =
|
137
|
+
resp = fetch("http://#{@options[:host]}/#{endpoint}")
|
121
138
|
if resp.code == '200'
|
122
139
|
result = JSON.parse(resp.body, symbolize_names: true)
|
123
140
|
else
|
@@ -27,7 +27,6 @@ class OpenStudioAwsInstance
|
|
27
27
|
attr_reader :private_ip_address
|
28
28
|
attr_reader :group_uuid
|
29
29
|
|
30
|
-
|
31
30
|
# param security_groups can be a single instance or an array
|
32
31
|
def initialize(aws_session, openstudio_instance_type, key_pair_name, security_groups, group_uuid, private_key,
|
33
32
|
private_key_file_name, subnet_id, proxy = nil)
|
@@ -78,10 +77,10 @@ class OpenStudioAwsInstance
|
|
78
77
|
# need to wait until it is available
|
79
78
|
|
80
79
|
@aws.attach_volume(
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
volume_id: resp[:volume_id],
|
81
|
+
instance_id: instance_id,
|
82
|
+
# required
|
83
|
+
device: '/dev/sdh'
|
85
84
|
)
|
86
85
|
|
87
86
|
# Wait for the volume to attach
|
@@ -92,14 +91,14 @@ class OpenStudioAwsInstance
|
|
92
91
|
def launch_instance(image_id, instance_type, user_data, user_id, options = {})
|
93
92
|
# determine the instance type of the server
|
94
93
|
instance = {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
94
|
+
image_id: image_id,
|
95
|
+
key_name: @key_pair_name,
|
96
|
+
security_group_ids: @security_groups,
|
97
|
+
subnet_id: options[:subnet_id],
|
98
|
+
user_data: Base64.encode64(user_data),
|
99
|
+
instance_type: instance_type,
|
100
|
+
min_count: 1,
|
101
|
+
max_count: 1
|
103
102
|
}
|
104
103
|
|
105
104
|
if options[:availability_zone]
|
@@ -113,19 +112,18 @@ class OpenStudioAwsInstance
|
|
113
112
|
# You have to delete the security group and subnet_id from the instance hash and put into the network interface
|
114
113
|
# otherwise you will get an error on launch with an InvalidParameterCombination error.
|
115
114
|
instance[:network_interfaces] = [
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
{
|
116
|
+
subnet_id: instance.delete(:subnet_id),
|
117
|
+
groups: instance.delete(:security_group_ids),
|
118
|
+
device_index: 0,
|
119
|
+
associate_public_ip_address: true
|
120
|
+
}
|
122
121
|
]
|
123
122
|
end
|
124
123
|
|
125
124
|
# Documentation for run_instances is here: http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Client.html#run_instances-instance_method
|
126
125
|
result = @aws.run_instances(instance)
|
127
126
|
|
128
|
-
|
129
127
|
# determine how many processors are suppose to be in this image (lookup for now?)
|
130
128
|
processors = find_processors(instance_type)
|
131
129
|
|
@@ -160,15 +158,14 @@ class OpenStudioAwsInstance
|
|
160
158
|
tries ||= 3
|
161
159
|
aws_instance = result.data.instances.first
|
162
160
|
@aws.create_tags(
|
163
|
-
|
164
|
-
|
161
|
+
resources: [aws_instance.instance_id],
|
162
|
+
tags: aws_tags
|
165
163
|
)
|
166
164
|
rescue Aws::EC2::Errors::InvalidInstanceIDNotFound
|
167
165
|
sleep 1000
|
168
166
|
retry unless (tries -= 1).zero?
|
169
167
|
end
|
170
168
|
|
171
|
-
|
172
169
|
# get the instance information
|
173
170
|
test_result = @aws.describe_instance_status(instance_ids: [aws_instance.instance_id]).data.instance_statuses.first
|
174
171
|
begin
|
@@ -190,7 +187,7 @@ class OpenStudioAwsInstance
|
|
190
187
|
end
|
191
188
|
|
192
189
|
# now grab information about the instance
|
193
|
-
#
|
190
|
+
# TODO: check lengths on all of arrays
|
194
191
|
instance_data = @aws.describe_instances(instance_ids: [aws_instance.instance_id]).data.reservations.first.instances.first.to_hash
|
195
192
|
logger.info "instance description is: #{instance_data}"
|
196
193
|
|
@@ -427,13 +424,13 @@ class OpenStudioAwsInstance
|
|
427
424
|
def create_struct(instance, procs)
|
428
425
|
instance_struct = Struct.new(:instance, :id, :ip, :dns, :procs, :availability_zone, :private_ip_address)
|
429
426
|
s = instance_struct.new(
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
427
|
+
instance,
|
428
|
+
instance[:instance_id],
|
429
|
+
instance[:public_ip_address],
|
430
|
+
instance[:public_dns_name],
|
431
|
+
procs,
|
432
|
+
instance[:placement][:availability_zone],
|
433
|
+
instance[:private_ip_address]
|
437
434
|
)
|
438
435
|
|
439
436
|
# store some values into the member variables
|
@@ -82,20 +82,20 @@ class OpenStudioAwsWrapper
|
|
82
82
|
logger.info 'security group not found --- will create a new one'
|
83
83
|
@aws.create_security_group(group_name: tmp_name, description: "group dynamically created by #{__FILE__}")
|
84
84
|
@aws.authorize_security_group_ingress(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
85
|
+
group_name: tmp_name,
|
86
|
+
ip_permissions: [
|
87
|
+
{ ip_protocol: 'tcp', from_port: 22, to_port: 22, ip_ranges: [cidr_ip: '0.0.0.0/0'] }, # Eventually make this only the user's IP address seen by the internet
|
88
|
+
{ ip_protocol: 'tcp', from_port: 80, to_port: 80, ip_ranges: [cidr_ip: '0.0.0.0/0'] },
|
89
|
+
{ ip_protocol: 'tcp', from_port: 443, to_port: 443, ip_ranges: [cidr_ip: '0.0.0.0/0'] },
|
90
|
+
{ ip_protocol: 'tcp', from_port: 0, to_port: 65535, user_id_group_pairs: [{ group_name: tmp_name }] }, # allow all machines in the security group talk to each other openly
|
91
|
+
{ ip_protocol: 'icmp', from_port: -1, to_port: -1, ip_ranges: [cidr_ip: '0.0.0.0/0'] }
|
92
|
+
]
|
93
93
|
)
|
94
94
|
|
95
95
|
# reload group information
|
96
96
|
group = @aws.describe_security_groups(filters: [{ name: 'group-name', values: [tmp_name] }])
|
97
97
|
else
|
98
|
-
logger.info
|
98
|
+
logger.info 'Found existing security group'
|
99
99
|
end
|
100
100
|
|
101
101
|
@security_groups = [group.data.security_groups.first.group_id]
|
@@ -134,11 +134,11 @@ class OpenStudioAwsWrapper
|
|
134
134
|
resp = nil
|
135
135
|
if group_uuid
|
136
136
|
resp = @aws.describe_instances(
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
filters: [
|
138
|
+
{ name: 'instance-state-code', values: [0.to_s, 16.to_s] }, # running or pending
|
139
|
+
{ name: 'tag-key', values: ['GroupUUID'] },
|
140
|
+
{ name: 'tag-value', values: [group_uuid.to_s] }
|
141
|
+
]
|
142
142
|
)
|
143
143
|
else
|
144
144
|
resp = @aws.describe_instances
|
@@ -153,7 +153,7 @@ class OpenStudioAwsWrapper
|
|
153
153
|
if group_uuid && openstudio_instance_type
|
154
154
|
# {:key=>"Purpose", :value=>"OpenStudioWorker"}
|
155
155
|
if i_h[:tags].any? { |h| (h[:key] == 'Purpose') && (h[:value] == "OpenStudio#{openstudio_instance_type.capitalize}") } &&
|
156
|
-
|
156
|
+
i_h[:tags].any? { |h| (h[:key] == 'GroupUUID') && (h[:value] == group_uuid.to_s) }
|
157
157
|
instance_data << i_h
|
158
158
|
end
|
159
159
|
elsif group_uuid
|
@@ -177,7 +177,7 @@ class OpenStudioAwsWrapper
|
|
177
177
|
def describe_amis(filter = nil, image_ids = [], owned_by_me = true)
|
178
178
|
resp = nil
|
179
179
|
|
180
|
-
#
|
180
|
+
# TODO: test the filter. i don't think that it is exposed in the AWS gem?
|
181
181
|
if owned_by_me
|
182
182
|
if filter
|
183
183
|
resp = @aws.describe_images(owners: [:self], filter: filter).data
|
@@ -212,8 +212,8 @@ class OpenStudioAwsWrapper
|
|
212
212
|
|
213
213
|
def stop_instances(ids)
|
214
214
|
resp = @aws.stop_instances(
|
215
|
-
|
216
|
-
|
215
|
+
instance_ids: ids,
|
216
|
+
force: true
|
217
217
|
)
|
218
218
|
|
219
219
|
resp
|
@@ -222,7 +222,7 @@ class OpenStudioAwsWrapper
|
|
222
222
|
def terminate_instances(ids)
|
223
223
|
begin
|
224
224
|
resp = @aws.terminate_instances(
|
225
|
-
|
225
|
+
instance_ids: ids
|
226
226
|
)
|
227
227
|
rescue Aws::EC2::Errors::InvalidInstanceIDNotFound
|
228
228
|
# Log that the instances couldn't be found?
|
@@ -264,7 +264,7 @@ class OpenStudioAwsWrapper
|
|
264
264
|
end
|
265
265
|
|
266
266
|
def load_private_key(filename)
|
267
|
-
|
267
|
+
unless File.exist? filename
|
268
268
|
# check if the file basename exists in your user directory
|
269
269
|
filename = File.expand_path("~/.ssh/#{File.basename(filename)}")
|
270
270
|
if File.exist? filename
|
@@ -290,23 +290,23 @@ class OpenStudioAwsWrapper
|
|
290
290
|
end
|
291
291
|
|
292
292
|
# save off the worker public/private keys that were created
|
293
|
-
def save_worker_keys(directory='.')
|
294
|
-
File.open("#{directory}/ec2_worker_key.pem", 'w') { |f| f << @worker_keys.private_key}
|
295
|
-
File.open("#{directory}/ec2_worker_key.pub", 'w') { |f| f << @worker_keys.public_key}
|
293
|
+
def save_worker_keys(directory = '.')
|
294
|
+
File.open("#{directory}/ec2_worker_key.pem", 'w') { |f| f << @worker_keys.private_key }
|
295
|
+
File.open("#{directory}/ec2_worker_key.pub", 'w') { |f| f << @worker_keys.public_key }
|
296
296
|
end
|
297
297
|
|
298
298
|
def launch_server(image_id, instance_type, launch_options = {})
|
299
299
|
defaults = {
|
300
|
-
|
301
|
-
|
302
|
-
|
300
|
+
user_id: 'unknown_user',
|
301
|
+
tags: [],
|
302
|
+
ebs_volume_size: nil
|
303
303
|
}
|
304
304
|
launch_options = defaults.merge(launch_options)
|
305
305
|
|
306
306
|
# replace the server_script.sh.template with the keys to add
|
307
307
|
user_data = File.read(File.expand_path(File.dirname(__FILE__)) + '/server_script.sh.template')
|
308
308
|
user_data.gsub!(/SERVER_HOSTNAME/, 'openstudio.server')
|
309
|
-
user_data.gsub!(/WORKER_PRIVATE_KEY_TEMPLATE/, worker_keys.private_key.gsub("\n",
|
309
|
+
user_data.gsub!(/WORKER_PRIVATE_KEY_TEMPLATE/, worker_keys.private_key.gsub("\n", '\\n'))
|
310
310
|
user_data.gsub!(/WORKER_PUBLIC_KEY_TEMPLATE/, worker_keys.ssh_public_key)
|
311
311
|
|
312
312
|
@server = OpenStudioAwsInstance.new(@aws, :server, @key_pair_name, @security_groups, @group_uuid, @private_key,
|
@@ -321,11 +321,11 @@ class OpenStudioAwsWrapper
|
|
321
321
|
|
322
322
|
def launch_workers(image_id, instance_type, num, launch_options = {})
|
323
323
|
defaults = {
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
324
|
+
user_id: 'unknown_user',
|
325
|
+
tags: [],
|
326
|
+
ebs_volume_size: nil,
|
327
|
+
availability_zone: @server.data.availability_zone,
|
328
|
+
worker_public_key: ''
|
329
329
|
}
|
330
330
|
launch_options = defaults.merge(launch_options)
|
331
331
|
|
@@ -351,8 +351,8 @@ class OpenStudioAwsWrapper
|
|
351
351
|
end
|
352
352
|
threads.each(&:join)
|
353
353
|
|
354
|
-
#
|
355
|
-
#
|
354
|
+
# TODO: do we need to have a flag if the worker node is successful?
|
355
|
+
# TODO: do we need to check the current list of running workers?
|
356
356
|
end
|
357
357
|
|
358
358
|
# blocking method that waits for servers and workers to be fully configured (i.e. execution of user_data has
|
@@ -400,17 +400,18 @@ class OpenStudioAwsWrapper
|
|
400
400
|
logger.info "finding the server for groupid of #{group_uuid}"
|
401
401
|
fail 'no group uuid defined either in member variable or method argument' if group_uuid.nil?
|
402
402
|
|
403
|
-
|
403
|
+
# This should really just be a single call to describe running instances
|
404
|
+
@server = nil
|
404
405
|
resp = describe_running_instances(group_uuid, :server)
|
405
406
|
if resp
|
406
407
|
fail "more than one server running with group uuid of #{group_uuid} found, expecting only one" if resp.size > 1
|
407
408
|
resp = resp.first
|
408
409
|
if !@server
|
409
|
-
|
410
|
-
|
411
|
-
|
410
|
+
if resp
|
411
|
+
logger.info "Server found and loading data into object [instance id is #{resp[:instance_id]}]"
|
412
|
+
@server = OpenStudioAwsInstance.new(@aws, :server, resp[:key_name], resp[:security_groups].first[:group_name], group_uuid, @private_key, @private_key_file_name, @proxy)
|
412
413
|
|
413
|
-
|
414
|
+
@server.load_instance_data(resp)
|
414
415
|
end
|
415
416
|
else
|
416
417
|
logger.info "Server instance is already defined with instance #{resp[:instance_id]}"
|
@@ -419,6 +420,19 @@ class OpenStudioAwsWrapper
|
|
419
420
|
puts 'could not find a running server instance'
|
420
421
|
end
|
421
422
|
|
423
|
+
# find the workers
|
424
|
+
if @workers.size == 0
|
425
|
+
resp = describe_running_instances(group_uuid, :worker)
|
426
|
+
if resp
|
427
|
+
resp.each do |r|
|
428
|
+
@workers << OpenStudioAwsInstance.new(@aws, :worker, r[:key_name], r[:security_groups].first[:group_name], group_uuid, @private_key, @private_key_file_name, @proxy)
|
429
|
+
@workers.last.load_instance_data(r)
|
430
|
+
end
|
431
|
+
end
|
432
|
+
else
|
433
|
+
logger.info 'Worker nodes are already defined'
|
434
|
+
end
|
435
|
+
|
422
436
|
# Really don't need to return anything because this sets the class instance variable
|
423
437
|
@server
|
424
438
|
end
|
@@ -439,7 +453,7 @@ class OpenStudioAwsWrapper
|
|
439
453
|
version1 = {}
|
440
454
|
|
441
455
|
# now grab the good keys - they should be sorted newest to older... so go backwards
|
442
|
-
amis[:openstudio_server].keys.
|
456
|
+
amis[:openstudio_server].keys.reverse_each do |key|
|
443
457
|
next if amis[:openstudio_server][key][:deprecate]
|
444
458
|
|
445
459
|
a = amis[:openstudio_server][key]
|
@@ -470,12 +484,12 @@ class OpenStudioAwsWrapper
|
|
470
484
|
worker_hash = []
|
471
485
|
@workers.each do |worker|
|
472
486
|
worker_hash.push(
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
487
|
+
id: worker.data.id,
|
488
|
+
ip: "http://#{worker.data.ip}",
|
489
|
+
dns: worker.data.dns,
|
490
|
+
procs: worker.data.procs,
|
491
|
+
private_key_file_name: worker.private_key_file_name,
|
492
|
+
private_ip_address: worker.private_ip_address
|
479
493
|
)
|
480
494
|
end
|
481
495
|
|
@@ -495,9 +509,7 @@ class OpenStudioAwsWrapper
|
|
495
509
|
end
|
496
510
|
|
497
511
|
# get the max version in the list_of_svs
|
498
|
-
while list_of_svs.include?(b.to_s)
|
499
|
-
b.patch += 1
|
500
|
-
end
|
512
|
+
b.patch += 1 while list_of_svs.include?(b.to_s)
|
501
513
|
|
502
514
|
# return the value back as a string
|
503
515
|
b.to_s
|