openstudio-aws 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -13
  3. data/lib/openstudio-aws.rb +9 -7
  4. data/lib/openstudio/aws/aws.rb +53 -40
  5. data/lib/openstudio/aws/config.rb +0 -1
  6. data/lib/openstudio/aws/version.rb +2 -2
  7. data/lib/openstudio/lib/ami_list.rb +79 -0
  8. data/lib/openstudio/lib/openstudio_aws_instance.rb +138 -0
  9. data/lib/openstudio/lib/openstudio_aws_logger.rb +61 -0
  10. data/lib/openstudio/lib/openstudio_aws_methods.rb +232 -0
  11. data/lib/openstudio/lib/openstudio_aws_wrapper.rb +315 -0
  12. data/lib/openstudio/lib/os-aws.rb +77 -351
  13. data/spec/aws_instances/aws_spec_api.rb +70 -0
  14. data/spec/openstudio-aws/ami_list_spec.rb +37 -0
  15. data/spec/openstudio-aws/aws_methods_spec.rb +26 -0
  16. data/spec/openstudio-aws/lib_spec.rb +48 -0
  17. data/spec/reports/SPEC-OpenStudio-Aws-Aws-create-a-new-instance.xml +43 -0
  18. data/spec/reports/SPEC-OpenStudio-Aws-Aws-workers-before-server.xml +9 -0
  19. data/spec/reports/SPEC-OpenStudio-Aws-Aws.xml +7 -0
  20. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.0.xml +9 -0
  21. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.xml +9 -0
  22. data/spec/reports/SPEC-OpenStudio-Aws-Config.0.xml +7 -0
  23. data/spec/reports/SPEC-OpenStudio-Aws-Config.xml +7 -0
  24. data/spec/reports/SPEC-OpenStudioAmis-version-1.0.xml +13 -0
  25. data/spec/reports/SPEC-OpenStudioAmis-version-1.xml +13 -0
  26. data/spec/reports/SPEC-OpenStudioAmis.0.xml +7 -0
  27. data/spec/reports/SPEC-OpenStudioAmis.xml +7 -0
  28. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.0.xml +11 -0
  29. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.xml +11 -0
  30. data/spec/reports/SPEC-OpenStudioAwsMethods.0.xml +7 -0
  31. data/spec/reports/SPEC-OpenStudioAwsMethods.xml +7 -0
  32. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.0.xml +11 -0
  33. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.xml +11 -0
  34. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.0.xml +9 -0
  35. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.xml +9 -0
  36. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.0.xml +7 -0
  37. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.xml +7 -0
  38. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.0.xml +9 -0
  39. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.xml +9 -0
  40. data/spec/reports/SPEC-OpenStudioAwsWrapper.0.xml +7 -0
  41. data/spec/reports/SPEC-OpenStudioAwsWrapper.xml +7 -0
  42. metadata +70 -10
  43. data/lib/openstudio/aws/send_data.rb +0 -42
  44. data/spec/openstudio-aws/aws_spec.rb +0 -53
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4c759c2c748eb2f907a53b3f87390246b188a9e
4
- data.tar.gz: 614223c0a1d4195d0abfd0cfeb9c0e9e879640c0
3
+ metadata.gz: 883acd75472bdf8a4c5e0bbb2736c8b42360d498
4
+ data.tar.gz: 41253c1ce3d409e47a80785c2e8c8c51e154badb
5
5
  SHA512:
6
- metadata.gz: 5f41d38ccbb517dbcf10f189dfcc01dd85f2dac7a4bcc5900d89e278834990041538d00247f6bd4a907b91f0af9dfefeb1d6498fe5b204ee822fecea22eecdaf
7
- data.tar.gz: 3703c7acb4ded02951821d9dca099dc0616c6475d42a050dc45a52a211cbd5f6790bd696c1a8d9493026a58334ae66bb650fc40a1fdf620221ed254ba5a6f1ff
6
+ metadata.gz: 07039c60796d51fda00f35310a33f30078487cbfafdf1a4654ead5bc35d7ac7f788e3ef78aac505038524f0d019519a1a4ca1a4a166d56e0cf1d49f23e0c54b5
7
+ data.tar.gz: 0dbf6db0cb50dae855d71a7da96e600e872417462226131d5f69f62c36f833488ab482a564d8980bf1bc5b0791ca1f8dfd55532ba500316c4307d57ac3927ecb
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require "bundler"
2
2
  Bundler.setup
3
- #Bundler.require
4
3
 
5
4
  require "rake"
6
5
  require "rspec/core/rake_task"
@@ -18,6 +17,7 @@ task :install => :build do
18
17
  system "gem install openstudio-aws-#{OpenStudio::Aws::VERSION}.gem --no-ri --no-rdoc"
19
18
  end
20
19
 
20
+ desc "build and release the gem using rubygems and git tags"
21
21
  task :release => :build do
22
22
  system "git tag -a v#{OpenStudio::Aws::VERSION} -m 'Tagging #{OpenStudio::Aws::VERSION}'"
23
23
  system "git push --tags"
@@ -26,13 +26,13 @@ task :release => :build do
26
26
  end
27
27
 
28
28
  RSpec::Core::RakeTask.new("spec") do |spec|
29
- spec.rspec_opts = %w(--format progress)
30
- spec.pattern = "spec/**/config_spec.rb"
29
+ spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
30
+ spec.pattern = "spec/**/*_spec.rb"
31
31
  end
32
32
 
33
- RSpec::Core::RakeTask.new("spec:all") do |spec|
34
- spec.rspec_opts = %w(--format progress)
35
- spec.pattern = "spec/**/*_spec.rb"
33
+ RSpec::Core::RakeTask.new("spec:api") do |spec|
34
+ spec.rspec_opts = %w(--format progress --format CI::Reporter::RSpec)
35
+ spec.pattern = "spec/**/*_spec_api.rb"
36
36
  end
37
37
 
38
38
  task :default => :spec
@@ -42,13 +42,14 @@ task :import_files do
42
42
  puts "Importing data from other repos until this repo is self contained"
43
43
  # Copy data from github openstudio source
44
44
 
45
- os_file = "./lib/openstudio/lib/os-aws.rb"
46
- system "curl -S -s -L -o #{os_file} https://raw.github.com/NREL/OpenStudio/develop/openstudiocore/ruby/cloud/aws.rb.in"
47
- if File.exists?(os_file)
48
- system "ruby -i -pe 'puts \"# NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files\" if $.==1' #{os_file}"
49
- system "sed -i '' 's/\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}.\${CMAKE_VERSION_PATCH}/#{OpenStudio::Aws::OPENSTUDIO_VERSION}/g' #{os_file}"
50
- end
51
-
45
+ # this has been forked at the moment until openstudio team supports the new aws-sdk gem
46
+ #os_file = "./lib/openstudio/lib/os-aws.rb"
47
+ #system "curl -S -s -L -o #{os_file} https://raw.github.com/NREL/OpenStudio/develop/openstudiocore/ruby/cloud/aws.rb.in"
48
+ #if File.exists?(os_file)
49
+ # system "ruby -i -pe 'puts \"# NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files\" if $.==1' #{os_file}"
50
+ # system "sed -i '' 's/\${CMAKE_VERSION_MAJOR}.\${CMAKE_VERSION_MINOR}.\${CMAKE_VERSION_PATCH}/#{OpenStudio::Aws::OPENSTUDIO_VERSION}/g' #{os_file}"
51
+ #end
52
+ #
52
53
  os_file = "./lib/openstudio/lib/mongoid.yml.template"
53
54
  system "curl -S -s -L -o #{os_file} https://raw.github.com/NREL/OpenStudio/develop/openstudiocore/ruby/cloud/mongoid.yml.template"
54
55
 
@@ -1,20 +1,22 @@
1
1
  require 'json'
2
2
  require 'net/scp'
3
+ require 'net/http'
3
4
  require 'yaml'
5
+ require 'logger'
4
6
 
5
- # AWS SDK
7
+ # AWS SDK CORE
6
8
  begin
7
- puts `gem list`
8
- gem "aws-sdk", ">= 1.30.1"
9
- require 'aws-sdk'
9
+ require 'aws-sdk-core'
10
10
  rescue LoadError
11
- puts "Failed to AWS-SDK gem"
12
- puts " gem install aws-sdk"
11
+ puts "Failed to load AWS-SDK-CORE gem"
12
+ puts " try running: gem install aws-sdk-core"
13
13
  exit
14
14
  end
15
15
 
16
16
  require 'openstudio/aws/version'
17
17
  require 'openstudio/aws/aws'
18
18
  require 'openstudio/aws/config'
19
- require 'openstudio/aws/send_data'
19
+ require 'openstudio/lib/openstudio_aws_instance'
20
+ require 'openstudio/lib/openstudio_aws_wrapper'
21
+ require 'openstudio/lib/ami_list'
20
22
 
@@ -1,83 +1,96 @@
1
1
  # This class is a wrapper around the command line version that is in the OpenStudio repository.
2
-
3
-
4
2
  module OpenStudio
5
3
  module Aws
6
4
  class Aws
7
- attr_reader :server_data
8
- attr_reader :worker_data
5
+ attr_reader :os_aws
9
6
 
10
7
  def initialize()
11
8
  # read in the config.yml file to get the secret/private key
12
9
  @config = OpenStudio::Aws::Config.new()
13
- @server_data = nil
14
- @worker_data = nil
10
+
11
+ config = {:access_key_id => @config.access_key, :secret_access_key => @config.secret_key, :region => "us-east-1", :ssl_verify_peer => false}
12
+ @os_aws = OpenStudioAwsWrapper.new(config)
13
+ @local_key_file_name = nil
15
14
  end
16
15
 
17
16
  # command line call to create a new instance. This should be more tightly integrated with teh os-aws.rb gem
18
17
  def create_server(instance_data = {})
19
- # TODO: find a way to override the instance ids here in case we want to prototype
20
18
  defaults = {instance_type: "m2.xlarge"}
21
19
  instance_data = defaults.merge(instance_data)
22
20
 
23
- # Since this is a command line call then make sure to escape the quotes in the JSON
24
- instance_string = instance_data.to_json.gsub("\"", "\\\\\"")
21
+ # todo: grab the image id the instance_data if not set
22
+
23
+ @os_aws.create_or_retrieve_security_group("openstudio-worker-sg-v1")
24
+ @os_aws.create_or_retrieve_key_pair
25
+
26
+ @local_key_file_name = "ec2_server_key.pem"
27
+ @os_aws.save_private_key(@local_key_file_name)
28
+ @os_aws.launch_server(instance_data[:image_id], instance_data[:instance_type])
25
29
 
30
+ puts @os_aws.server.to_os_hash.to_json
26
31
 
27
32
  # Call the openstudio script to start the ec2 instance
28
- start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_server \"#{instance_string}\""
29
- puts "Server Command: #{start_string}"
30
- server_data_str = `#{start_string}`
31
- @server_data = JSON.parse(server_data_str, :symbolize_names => true)
33
+ #start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_server \"#{instance_string}\""
34
+ #puts "Server Command: #{start_string}"
35
+ #server_data_str = `#{start_string}`
36
+ #@server_data = JSON.parse(server_data_str, :symbolize_names => true)
32
37
 
33
38
  # Save pieces of the data for passing to the worker node
34
- server_key_file = "ec2_server_key.pem"
35
- File.open(server_key_file, "w") { |f| f << @server_data[:private_key] }
36
- File.chmod(0600, server_key_file)
39
+
40
+ #File.open(server_key_file, "w") { |f| f << @server_data[:private_key] }
41
+ #File.chmod(0600, server_key_file)
37
42
 
38
43
  # Save off the server data to be loaded into the worker nodes. The Private key needs to e read from a
39
44
  # file in the worker node, so save that name instead in the HASH along with a couple other changes
40
- @server_data[:private_key] = server_key_file
41
- if @server_data[:server]
42
- @server_data[:server_id] = @server_data[:server][:id]
43
- @server_data[:server_ip] = @server_data[:server][:ip]
44
- @server_data[:server_dns] = @server_data[:server][:dns]
45
- end
45
+ #@server_data[:private_key] = server_key_file
46
+ #if @server_data[:server]
47
+ # @server_data[:server_id] = @server_data[:server][:id]
48
+ # @server_data[:server_ip] = @server_data[:server][:ip]
49
+ # @server_data[:server_dns] = @server_data[:server][:dns]
50
+ #end
46
51
 
47
- File.open("server_data.json", "w") { |f| f << JSON.pretty_generate(@server_data) }
52
+ File.open("server_data.json", "w") { |f| f << JSON.pretty_generate(@os_aws.server.to_os_hash) }
48
53
 
49
54
  # Print out some debugging commands (probably work on mac/linux only)
50
55
  puts ""
51
56
  puts "Server SSH Command:"
52
57
 
53
- puts "ssh -i #{server_key_file} ubuntu@#{@server_data[:server_dns]}"
58
+ puts "ssh -i #{@local_key_file_name} ubuntu@#{@os_aws.server.data[:dns]}"
54
59
  end
55
60
 
56
61
  def create_workers(number_of_instances, instance_data = {})
57
62
  defaults = {instance_type: "m2.4xlarge"}
58
63
  instance_data = defaults.merge(instance_data)
59
64
 
60
- raise "Can't create workers without a server instance running" if @server_data.nil?
61
-
62
- # append the information to the server_data hash that already exists
63
- @server_data[:instance_type] = instance_data[:instance_type]
64
- @server_data[:num] = number_of_instances
65
- server_string = @server_data.to_json.gsub("\"", "\\\\\"")
65
+ raise "Can't create workers without a server instance running" if @os_aws.server.nil?
66
66
 
67
- start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_workers \"#{server_string}\""
68
- puts "Worker Command: #{start_string}"
69
- worker_data_string = `#{start_string}`
70
- @worker_data = JSON.parse(worker_data_string, :symbolize_names => true)
71
- File.open("worker_data.json", "w") { |f| f << JSON.pretty_generate(worker_data) }
72
-
73
- # Print out some debugging commands (probably work on mac/linux only)
74
- @worker_data[:workers].each do |worker|
67
+
68
+ @os_aws.launch_workers(instance_data[:image_id], instance_data[:instance_type], number_of_instances)
69
+
70
+ ## append the information to the server_data hash that already exists
71
+ #@server_data[:instance_type] = instance_data[:instance_type]
72
+ #@server_data[:num] = number_of_instances
73
+ #server_string = @server_data.to_json.gsub("\"", "\\\\\"")
74
+ #
75
+ #start_string = "ruby #{os_aws_file_location} #{@config.access_key} #{@config.secret_key} us-east-1 EC2 launch_workers \"#{server_string}\""
76
+ #puts "Worker Command: #{start_string}"
77
+ #worker_data_string = `#{start_string}`
78
+ #@worker_data = JSON.parse(worker_data_string, :symbolize_names => true)
79
+ #File.open("worker_data.json", "w") { |f| f << JSON.pretty_generate(worker_data) }
80
+ #
81
+ ## Print out some debugging commands (probably work on mac/linux only)
82
+ @os_aws.workers.each do |worker|
75
83
  puts ""
76
84
  puts "Worker SSH Command:"
77
- puts "ssh -i #{@server_data[:private_key]} ubuntu@#{worker[:dns]}"
85
+ puts "ssh -i #{@local_key_file_name} ubuntu@#{worker.data[:dns]}"
78
86
  end
87
+
88
+ puts ""
89
+ puts "Waiting for server/worker configurations"
90
+
91
+ @os_aws.configure_server_and_workers
79
92
  end
80
-
93
+
81
94
  def kill_instances()
82
95
  # Add this method to kill all the running instances
83
96
  end
@@ -9,7 +9,6 @@ module OpenStudio
9
9
  @config = nil
10
10
  if @yml_config_file.nil?
11
11
  @yml_config_file = File.join(File.expand_path("~"), "aws_config.yml")
12
- puts @yml_config_file
13
12
  if !File.exists?(@yml_config_file)
14
13
  write_config_file
15
14
  puts "No Config File in user home directory. A template has been added, please edit and save: #{@yml_config_file}"
@@ -1,6 +1,6 @@
1
1
  module OpenStudio
2
2
  module Aws
3
- VERSION = "0.1.7"
4
- OPENSTUDIO_VERSION = "1.1.4"
3
+ VERSION = "0.1.8"
4
+ OPENSTUDIO_VERSION = "1.2.1"
5
5
  end
6
6
  end
@@ -0,0 +1,79 @@
1
+ # NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files
2
+ ######################################################################
3
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
4
+ # All rights reserved.
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ ######################################################################
20
+
21
+ # Class for managing the AMI ids based on the openstudio version and the openstudio-server version
22
+
23
+ class OpenStudioAmis
24
+
25
+ def initialize(version = 1, openstudio_version = 'default', openstudio_server_version = 'default')
26
+ @version = 1
27
+ @openstudio_version = openstudio_version
28
+ @openstudio_server_version = openstudio_server_version
29
+ end
30
+
31
+ def get_amis()
32
+ amis = nil
33
+ command = "get_ami_version_#{@version}"
34
+ if OpenStudioAmis.method_defined?(command)
35
+ amis = send(command)
36
+ else
37
+ raise "Unknown api version command #{command}"
38
+ end
39
+
40
+ raise "Could not find any amis for #{@version}" if amis.nil?
41
+
42
+ puts amis.inspect
43
+ amis
44
+ end
45
+
46
+ protected
47
+
48
+ def get_ami_version_1()
49
+ endpoint = '/downloads/buildings/openstudio/rsrc/amis.json'
50
+
51
+ json = retrieve_json(endpoint)
52
+ version = json.has_key?(@openstudio_version) ? @openstudio_version : 'default'
53
+
54
+ json[version]
55
+ end
56
+
57
+ def get_ami_version_2()
58
+ endpoint = '/downloads/buildings/openstudio/rsrc/amis_v2.json'
59
+
60
+ json = retrieve_json(endpoint)
61
+ version = json.has_key?(@openstudio_version) ? @openstudio_version : 'default'
62
+
63
+ #logic logic
64
+ end
65
+
66
+ private
67
+
68
+ def retrieve_json(endpoint)
69
+ result = nil
70
+ resp = Net::HTTP.get_response('developer.nrel.gov', endpoint)
71
+ if resp.code == '200'
72
+ result = JSON.parse(resp.body)
73
+ else
74
+ raise "#{resp.code} Unable to download AMI IDs"
75
+ end
76
+
77
+ result
78
+ end
79
+ end
@@ -0,0 +1,138 @@
1
+ # NOTE: Do not modify this file as it is copied over. Modify the source file and rerun rake import_files
2
+ ######################################################################
3
+ # Copyright (c) 2008-2014, Alliance for Sustainable Energy.
4
+ # All rights reserved.
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ ######################################################################
20
+
21
+ require 'securerandom'
22
+ require_relative 'openstudio_aws_logger'
23
+ require_relative 'openstudio_aws_methods'
24
+
25
+ class OpenStudioAwsInstance
26
+ include Logging
27
+ include OpenStudioAwsMethods
28
+
29
+ attr_reader :openstudio_instance_type
30
+ attr_reader :data
31
+
32
+ def initialize(aws_session, openstudio_instance_type, key_pair_name, security_group_name, group_uuid, private_key)
33
+ @data = nil # stored information about the instance
34
+ @aws = aws_session
35
+ @openstudio_instance_type = openstudio_instance_type # :server, :worker
36
+ @key_pair_name = key_pair_name
37
+ @security_group_name = security_group_name
38
+ @group_uuid = group_uuid.to_s
39
+ @private_key = private_key
40
+ end
41
+
42
+
43
+ def launch_instance(image_id, instance_type, user_data)
44
+ logger.info("user_data #{user_data.inspect}")
45
+ result = @aws.run_instances(
46
+ {
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
54
+ }
55
+ )
56
+
57
+ # determine how many processors are suppose to be in this image (lookup for now?)
58
+ processors = find_processors(instance_type)
59
+
60
+ # only asked for 1 instance, so therefore it should be the first
61
+ aws_instance = result.data.instances.first
62
+ @aws.create_tags(
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
+ ]
71
+ }
72
+ )
73
+
74
+ # get the instance information
75
+ test_result = @aws.describe_instance_status({:instance_ids => [aws_instance.instance_id]}).data.instance_statuses.first
76
+ begin
77
+ Timeout::timeout(600) {# 10 minutes
78
+ while test_result.nil? || test_result.instance_state.name != "running"
79
+ # refresh the server instance information
80
+
81
+ sleep 5
82
+ test_result = @aws.describe_instance_status({:instance_ids => [aws_instance.instance_id]}).data.instance_statuses.first
83
+ logger.info "... waiting for instance to be running ..."
84
+ end
85
+ }
86
+ rescue TimeoutError
87
+ raise "Intance was unable to launch due to timeout #{aws_instance.instance_id}"
88
+ end
89
+
90
+ # now grab information about the instance
91
+ # todo: check lengths on all of arrays
92
+ instance_data = @aws.describe_instances({:instance_ids => [aws_instance.instance_id]}).data.reservations.first.instances.first.to_hash
93
+ logger.info "instance description is: #{instance_data}"
94
+
95
+ @data = create_struct(instance_data, processors)
96
+ end
97
+
98
+ # if the server already exists, then load the data about the server into the object
99
+ # instance_data is passed in and in the form of the instance data (as a hash) structured as the
100
+ # result of the amazon describe instance
101
+ def load_instance_data(instance_data)
102
+ @data = create_struct(instance_data, find_processors(instance_data[:instance_type]))
103
+ end
104
+
105
+ # Format of the OS JSON that is used for the command line based script
106
+ def to_os_hash
107
+ h = ""
108
+ if @openstudio_instance_type == :server
109
+ h = {
110
+ :timestamp => @group_uuid,
111
+ #:private_key => @private_key, # need to stop printing this out
112
+ :server => {
113
+ :id => @data.id,
114
+ :ip => 'http://' + @data.ip,
115
+ :dns => @data.dns,
116
+ :procs => @data.procs
117
+ }
118
+ }
119
+ else
120
+ raise "do not know how to convert :worker instance to_os_hash. Use the os_aws.to_worker_hash method"
121
+ end
122
+
123
+
124
+ logger.info("server info #{h}")
125
+
126
+ h
127
+ end
128
+
129
+ private
130
+
131
+ # store the data into a custom struct. The instance is the full description. The remaining fields are
132
+ # just easier accessors to the data in the raw request except for procs which is a custom request.
133
+ def create_struct(instance, procs)
134
+ instance_struct = Struct.new(:instance, :id, :ip, :dns, :procs)
135
+ return instance_struct.new(instance, instance[:instance_id], instance[:public_ip_address], instance[:public_dns_name], procs)
136
+ end
137
+
138
+ end