openstudio-aws 0.1.15 → 0.1.16

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 (134) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openstudio/aws/aws.rb +43 -21
  3. data/lib/openstudio/aws/version.rb +1 -1
  4. data/lib/openstudio/lib/ami_list.rb +35 -13
  5. data/lib/openstudio/lib/openstudio_aws_instance.rb +3 -2
  6. data/lib/openstudio/lib/openstudio_aws_wrapper.rb +25 -7
  7. data/spec/openstudio-aws/ami_list_spec.rb +1 -1
  8. data/spec/openstudio-aws/aws_spec.rb +47 -11
  9. data/spec/openstudio-aws/aws_wrapper_spec.rb +1 -1
  10. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.0.xml +18 -0
  11. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.1.xml +19 -0
  12. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.2.xml +11 -0
  13. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.3.xml +11 -0
  14. data/spec/reports/SPEC-OpenStudio-Aws-Aws-ami-lists.xml +18 -0
  15. data/spec/reports/SPEC-OpenStudio-Aws-Aws-create-a-new-instance.6.xml +26 -0
  16. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.26.xml +13 -0
  17. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.27.xml +13 -0
  18. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.28.xml +13 -0
  19. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.29.xml +13 -0
  20. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.30.xml +16 -0
  21. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.31.xml +13 -0
  22. data/spec/reports/SPEC-OpenStudio-Aws-Aws-proxy-configuration.32.xml +13 -0
  23. data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.0.xml +9 -0
  24. data/spec/reports/SPEC-OpenStudio-Aws-Aws-should-error.xml +9 -0
  25. data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.0.xml +9 -0
  26. data/spec/reports/SPEC-OpenStudio-Aws-Aws-version-testing.xml +9 -0
  27. data/spec/reports/SPEC-OpenStudio-Aws-Aws.31.xml +7 -0
  28. data/spec/reports/SPEC-OpenStudio-Aws-Aws.32.xml +7 -0
  29. data/spec/reports/SPEC-OpenStudio-Aws-Aws.33.xml +7 -0
  30. data/spec/reports/SPEC-OpenStudio-Aws-Aws.34.xml +7 -0
  31. data/spec/reports/SPEC-OpenStudio-Aws-Aws.35.xml +7 -0
  32. data/spec/reports/SPEC-OpenStudio-Aws-Aws.36.xml +7 -0
  33. data/spec/reports/SPEC-OpenStudio-Aws-Aws.37.xml +7 -0
  34. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.52.xml +9 -0
  35. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.53.xml +9 -0
  36. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.54.xml +9 -0
  37. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.55.xml +9 -0
  38. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.56.xml +9 -0
  39. data/spec/reports/SPEC-OpenStudio-Aws-Config-create-a-new-config.57.xml +9 -0
  40. data/spec/reports/SPEC-OpenStudio-Aws-Config.52.xml +7 -0
  41. data/spec/reports/SPEC-OpenStudio-Aws-Config.53.xml +7 -0
  42. data/spec/reports/SPEC-OpenStudio-Aws-Config.54.xml +7 -0
  43. data/spec/reports/SPEC-OpenStudio-Aws-Config.55.xml +7 -0
  44. data/spec/reports/SPEC-OpenStudio-Aws-Config.56.xml +7 -0
  45. data/spec/reports/SPEC-OpenStudio-Aws-Config.57.xml +7 -0
  46. data/spec/reports/SPEC-OpenStudioAmis-version-1.53.xml +13 -0
  47. data/spec/reports/SPEC-OpenStudioAmis-version-1.54.xml +13 -0
  48. data/spec/reports/SPEC-OpenStudioAmis-version-1.55.xml +13 -0
  49. data/spec/reports/SPEC-OpenStudioAmis-version-1.56.xml +13 -0
  50. data/spec/reports/SPEC-OpenStudioAmis-version-1.57.xml +13 -0
  51. data/spec/reports/SPEC-OpenStudioAmis-version-1.58.xml +13 -0
  52. data/spec/reports/SPEC-OpenStudioAmis-version-1.59.xml +13 -0
  53. data/spec/reports/SPEC-OpenStudioAmis-version-2.51.xml +9 -0
  54. data/spec/reports/SPEC-OpenStudioAmis-version-2.52.xml +9 -0
  55. data/spec/reports/SPEC-OpenStudioAmis-version-2.53.xml +9 -0
  56. data/spec/reports/SPEC-OpenStudioAmis-version-2.54.xml +9 -0
  57. data/spec/reports/SPEC-OpenStudioAmis-version-2.55.xml +9 -0
  58. data/spec/reports/SPEC-OpenStudioAmis-version-2.56.xml +9 -0
  59. data/spec/reports/SPEC-OpenStudioAmis-version-2.57.xml +9 -0
  60. data/spec/reports/SPEC-OpenStudioAmis.53.xml +7 -0
  61. data/spec/reports/SPEC-OpenStudioAmis.54.xml +7 -0
  62. data/spec/reports/SPEC-OpenStudioAmis.55.xml +7 -0
  63. data/spec/reports/SPEC-OpenStudioAmis.56.xml +7 -0
  64. data/spec/reports/SPEC-OpenStudioAmis.57.xml +7 -0
  65. data/spec/reports/SPEC-OpenStudioAmis.58.xml +7 -0
  66. data/spec/reports/SPEC-OpenStudioAmis.59.xml +7 -0
  67. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.53.xml +11 -0
  68. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.54.xml +11 -0
  69. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.55.xml +11 -0
  70. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.56.xml +11 -0
  71. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.57.xml +11 -0
  72. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.58.xml +11 -0
  73. data/spec/reports/SPEC-OpenStudioAwsMethods-processors.59.xml +11 -0
  74. data/spec/reports/SPEC-OpenStudioAwsMethods.53.xml +7 -0
  75. data/spec/reports/SPEC-OpenStudioAwsMethods.54.xml +7 -0
  76. data/spec/reports/SPEC-OpenStudioAwsMethods.55.xml +7 -0
  77. data/spec/reports/SPEC-OpenStudioAwsMethods.56.xml +7 -0
  78. data/spec/reports/SPEC-OpenStudioAwsMethods.57.xml +7 -0
  79. data/spec/reports/SPEC-OpenStudioAwsMethods.58.xml +7 -0
  80. data/spec/reports/SPEC-OpenStudioAwsMethods.59.xml +7 -0
  81. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.52.xml +11 -0
  82. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.53.xml +11 -0
  83. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.54.xml +11 -0
  84. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.55.xml +11 -0
  85. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.56.xml +9 -0
  86. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.57.xml +11 -0
  87. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-availability.58.xml +11 -0
  88. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.44.xml +11 -0
  89. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.45.xml +11 -0
  90. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.46.xml +11 -0
  91. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.47.xml +11 -0
  92. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.48.xml +11 -0
  93. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-create-new-ami-json.49.xml +11 -0
  94. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.52.xml +9 -0
  95. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.53.xml +9 -0
  96. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.54.xml +9 -0
  97. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.55.xml +9 -0
  98. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.56.xml +9 -0
  99. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.57.xml +9 -0
  100. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-new-instance.58.xml +9 -0
  101. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.2.xml +19 -0
  102. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.3.xml +9 -0
  103. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.4.xml +9 -0
  104. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.5.xml +9 -0
  105. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.6.xml +125 -0
  106. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-1.7.xml +125 -0
  107. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.2.xml +9 -0
  108. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.3.xml +9 -0
  109. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.4.xml +9 -0
  110. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.5.xml +9 -0
  111. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.6.xml +9 -0
  112. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session-version-2.7.xml +9 -0
  113. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.52.xml +7 -0
  114. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.53.xml +7 -0
  115. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.54.xml +7 -0
  116. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.55.xml +7 -0
  117. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.56.xml +8 -0
  118. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.57.xml +7 -0
  119. data/spec/reports/SPEC-OpenStudioAwsWrapper-authenticated-session.58.xml +7 -0
  120. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.53.xml +9 -0
  121. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.54.xml +9 -0
  122. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.55.xml +9 -0
  123. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.56.xml +9 -0
  124. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.57.xml +9 -0
  125. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.58.xml +9 -0
  126. data/spec/reports/SPEC-OpenStudioAwsWrapper-unauthenticated-session.59.xml +9 -0
  127. data/spec/reports/SPEC-OpenStudioAwsWrapper.53.xml +7 -0
  128. data/spec/reports/SPEC-OpenStudioAwsWrapper.54.xml +7 -0
  129. data/spec/reports/SPEC-OpenStudioAwsWrapper.55.xml +7 -0
  130. data/spec/reports/SPEC-OpenStudioAwsWrapper.56.xml +7 -0
  131. data/spec/reports/SPEC-OpenStudioAwsWrapper.57.xml +7 -0
  132. data/spec/reports/SPEC-OpenStudioAwsWrapper.58.xml +7 -0
  133. data/spec/reports/SPEC-OpenStudioAwsWrapper.59.xml +7 -0
  134. metadata +250 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69767aa78e359c8d227e8275de37f91730182216
4
- data.tar.gz: c292e58432dcf8b83b29a4c81a516e8730c07021
3
+ metadata.gz: efb7b51f623a6281881c9a2dc12e481b79f6b421
4
+ data.tar.gz: 7faf36a9857a0251fc291b61bbb7c591e76319e9
5
5
  SHA512:
6
- metadata.gz: 140717519b189a2c170d0b185c1428eec29d8fc043242b4e4065e62ab974059034e432911829ed9dd8320aeda08ae1fd16176982ebf14d02bc2a3ed1a37c8de3
7
- data.tar.gz: 4cbf7d4f48a035651ffce4abaddf2c901f31105d618eb37f2bcc85281921343f72c5a8c0a4fb651e4db7741986b5ac1ad5218c8fc716f369a9c0c4ee8bce425e
6
+ metadata.gz: e2ff331d5294a79f0e2afdc7ad1a99f2d2ce5647a78d2e49e1ed6fd0c0f1fcf5a781958eb8d04b86b782b33d11290207adcd55200adb31a516941cd0f6248a7b
7
+ data.tar.gz: aeff692fe3684060a92c24408a1af49a614f71485db974f15c55c4aa9be8756e699cb8f43e361d517871f177eeb0cc944e24ca08373c29fb626173d11a47ed59
@@ -2,11 +2,13 @@
2
2
  module OpenStudio
3
3
  module Aws
4
4
  VALID_OPTIONS = [
5
- :proxy, :credentials
5
+ :proxy, :credentials, :ami_lookup_version, :openstudio_version,
6
+ :openstudio_server_version, :region, :ssl_verify_peer, :host, :url
6
7
  ]
7
8
 
8
9
  class Aws
9
10
  attr_reader :os_aws
11
+ attr_reader :default_amis
10
12
 
11
13
  # default constructor to create the AWS class that can spin up server and worker instances.
12
14
  # options are optional with the following support:
@@ -18,20 +20,32 @@ module OpenStudio
18
20
  raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
19
21
  end
20
22
 
23
+ # merge in some defaults
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/server'
30
+ }
31
+ options = defaults.merge(options)
32
+
33
+
21
34
  # read in the config.yml file to get the secret/private key
22
- if !options[:credentials]
35
+ if !options[:credentials]
23
36
  config_file = OpenStudio::Aws::Config.new()
24
37
 
25
38
  # populate the credentials
26
- options = {
27
- :credentials =>
28
- {
29
- :access_key_id => config_file.access_key,
30
- :secret_access_key => config_file.secret_key,
31
- :region => "us-east-1", #todo: move this to a default
32
- :ssl_verify_peer => false
33
- }
34
- }
39
+ options[:credentials] =
40
+ {
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]
45
+ }
46
+ else
47
+ options[:credentials][:region] = options[:region]
48
+ options[:credentials][:ssl_verify_peer] = options[:ssl_verify_peer]
35
49
  end
36
50
 
37
51
  if options[:proxy]
@@ -45,21 +59,29 @@ module OpenStudio
45
59
  options[:proxy_uri] = proxy_uri
46
60
 
47
61
  #todo: do we need to escape a couple of the argument of username and password
48
-
62
+
49
63
  #todo: set some environment variables for system based proxy
50
-
51
64
  end
52
65
 
66
+ #puts "Final options are: #{options.inspect}"
67
+
53
68
  @os_aws = OpenStudioAwsWrapper.new(options)
54
69
  @local_key_file_name = nil
55
70
 
56
71
  # this will grab the default version of openstudio ami versions
57
- @default_amis = OpenStudioAmis.new(1).get_amis
72
+ # get the arugments for the AMI lookup
73
+ ami_options = {}
74
+ ami_options[:openstudio_server_version] = options[:openstudio_server_version] if options[:openstudio_server_version]
75
+ ami_options[:openstudio_version] = options[:openstudio_version] if options[:openstudio_version]
76
+ ami_options[:host] = options[:host] if options[:host]
77
+ ami_options[:url] = options[:url] if options[:url]
78
+
79
+ @default_amis = OpenStudioAmis.new(options[:ami_lookup_version], ami_options).get_amis
58
80
  end
59
81
 
60
82
  # command line call to create a new instance. This should be more tightly integrated with teh os-aws.rb gem
61
- def create_server(instance_data = {}, server_json_filename = "server_data.json")
62
- defaults = {instance_type: "m2.xlarge", image_id: @default_amis['server']}
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]}
63
85
  instance_data = defaults.merge(instance_data)
64
86
 
65
87
  @os_aws.create_or_retrieve_security_group("openstudio-worker-sg-v1")
@@ -67,7 +89,7 @@ module OpenStudio
67
89
 
68
90
  @local_key_file_name = "ec2_server_key.pem"
69
91
  @os_aws.save_private_key(@local_key_file_name)
70
- @os_aws.launch_server(instance_data[:image_id], instance_data[:instance_type])
92
+ @os_aws.launch_server(instance_data[:image_id], instance_data[:instance_type], {:user_id => user_id})
71
93
 
72
94
  puts @os_aws.server.to_os_hash.to_json
73
95
 
@@ -80,21 +102,21 @@ module OpenStudio
80
102
  puts "ssh -i #{@local_key_file_name} ubuntu@#{@os_aws.server.data[:dns]}"
81
103
  end
82
104
 
83
- def create_workers(number_of_instances, instance_data = {})
105
+ def create_workers(number_of_instances, instance_data = {}, user_id="unknown_user")
84
106
  defaults = {instance_type: "m2.4xlarge"}
85
107
  instance_data = defaults.merge(instance_data)
86
108
 
87
109
  if instance_data[:image_id].nil?
88
110
  if instance_data[:instance_type] =~ /cc2|c3/
89
- instance_data[:image_id] = @default_amis['cc2worker']
111
+ instance_data[:image_id] = @default_amis[:cc2worker]
90
112
  else
91
- instance_data[:image_id] = @default_amis['worker']
113
+ instance_data[:image_id] = @default_amis[:worker]
92
114
  end
93
115
  end
94
116
 
95
117
  raise "Can't create workers without a server instance running" if @os_aws.server.nil?
96
118
 
97
- @os_aws.launch_workers(instance_data[:image_id], instance_data[:instance_type], number_of_instances)
119
+ @os_aws.launch_workers(instance_data[:image_id], instance_data[:instance_type], number_of_instances, {:user_id => user_id})
98
120
 
99
121
  ## append the information to the server_data hash that already exists
100
122
  #@server_data[:instance_type] = instance_data[:instance_type]
@@ -1,6 +1,6 @@
1
1
  module OpenStudio
2
2
  module Aws
3
- VERSION = "0.1.15"
3
+ VERSION = "0.1.16"
4
4
  OPENSTUDIO_VERSION = "1.2.1"
5
5
  end
6
6
  end
@@ -21,11 +21,25 @@
21
21
  # Class for managing the AMI ids based on the openstudio version and the openstudio-server version
22
22
 
23
23
  class OpenStudioAmis
24
+ VALID_OPTIONS = [
25
+ :openstudio_version, :openstudio_server_version, :host, :url
26
+ ]
27
+
28
+ def initialize(version = 1, options = {})
29
+ invalid_options = options.keys - VALID_OPTIONS
30
+ if invalid_options.any?
31
+ raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}"
32
+ end
24
33
 
25
- def initialize(version = 1, openstudio_version = 'default', openstudio_server_version = 'default')
26
- @version = 1
27
- @openstudio_version = openstudio_version.to_sym
28
- @openstudio_server_version = openstudio_server_version.to_sym
34
+ # merge in some defaults
35
+ defaults = {
36
+ :openstudio_version => 'default',
37
+ :openstudio_server_version => 'default',
38
+ :host => 'developer.nrel.gov',
39
+ :url => '/downloads/buildings/openstudio/server'
40
+ }
41
+ @version = version
42
+ @options = defaults.merge(options)
29
43
  end
30
44
 
31
45
  def list
@@ -36,7 +50,7 @@ class OpenStudioAmis
36
50
  else
37
51
  raise "Unknown api version command #{command}"
38
52
  end
39
-
53
+
40
54
  json
41
55
  end
42
56
 
@@ -57,14 +71,14 @@ class OpenStudioAmis
57
71
  protected
58
72
 
59
73
  def list_amis_version_1
60
- endpoint = '/downloads/buildings/openstudio/rsrc/amis.json'
74
+ endpoint = "#{@options[:url]}/amis_v1.json"
61
75
  json = retrieve_json(endpoint)
62
76
 
63
77
  json
64
78
  end
65
79
 
66
80
  def list_amis_version_2
67
- endpoint = '/downloads/buildings/openstudio/rsrc/amis_v2.json'
81
+ endpoint = "#{@options[:url]}/amis_v2.json"
68
82
 
69
83
  json = retrieve_json(endpoint)
70
84
  json
@@ -72,25 +86,33 @@ class OpenStudioAmis
72
86
 
73
87
  def get_ami_version_1()
74
88
  json = list_amis_version_1
75
- version = json.has_key?(@openstudio_version) ? @openstudio_version : 'default'
89
+ version = json.has_key?(@options[:openstudio_version].to_sym) ? @options[:openstudio_version].to_sym : 'default'
76
90
 
77
91
  json[version]
78
92
  end
79
93
 
80
94
  def get_ami_version_2()
81
95
  json = list_amis_version_2
82
- version = json.has_key?(@openstudio_version) ? @openstudio_version : 'default'
96
+
97
+ amis = nil
98
+ if @options[:openstudio_server_version].to_sym == :default
99
+ # just grab the most recent server
100
+ key, value = json[:openstudio_server].first
101
+ amis = value[:amis]
102
+ #puts json.inspect
103
+ else
104
+ value = json[:openstudio_server][@options[:openstudio_server_version].to_sym]
105
+ amis = value[:amis]
106
+ end
83
107
 
84
- #logic logic
108
+ amis
85
109
  end
86
110
 
87
111
  private
88
-
89
-
90
112
 
91
113
  def retrieve_json(endpoint)
92
114
  result = nil
93
- resp = Net::HTTP.get_response('developer.nrel.gov', endpoint)
115
+ resp = Net::HTTP.get_response(@options[:host], endpoint)
94
116
  if resp.code == '200'
95
117
  result = JSON.parse(resp.body, :symbolize_names => true)
96
118
  else
@@ -41,7 +41,7 @@ class OpenStudioAwsInstance
41
41
  @proxy = proxy
42
42
  end
43
43
 
44
- def launch_instance(image_id, instance_type, user_data)
44
+ def launch_instance(image_id, instance_type, user_data, user_id)
45
45
  #logger.info("user_data #{user_data.inspect}")
46
46
  instance = {
47
47
  :image_id => image_id,
@@ -67,7 +67,8 @@ class OpenStudioAwsInstance
67
67
  {:key => 'Name', :value => "OpenStudio-#{@openstudio_instance_type.capitalize}"}, # todo: abstract out the server and version
68
68
  {:key => 'GroupUUID', :value => @group_uuid},
69
69
  {:key => 'NumberOfProcessors', :value => processors.to_s},
70
- {:key => 'Purpose', :value => "OpenStudio#{@openstudio_instance_type.capitalize}"}
70
+ {:key => 'Purpose', :value => "OpenStudio#{@openstudio_instance_type.capitalize}"},
71
+ {:key => 'UserID', :value => user_id}
71
72
  ]
72
73
  }
73
74
  )
@@ -248,16 +248,22 @@ class OpenStudioAwsWrapper
248
248
  end
249
249
  end
250
250
 
251
- def launch_server(image_id, instance_type)
251
+ def launch_server(image_id, instance_type, options = {})
252
+ defaults = { :user_id => "unknown_user" }
253
+ options = defaults.merge(options)
254
+
252
255
  user_data = File.read(File.expand_path(File.dirname(__FILE__))+'/server_script.sh')
253
256
  @server = OpenStudioAwsInstance.new(@aws, :server, @key_pair_name, @security_group_name, @group_uuid, @private_key, @proxy)
254
257
 
255
258
  raise "image_id is nil" if not image_id
256
259
  raise "instance type is nil" if not instance_type
257
- @server.launch_instance(image_id, instance_type, user_data)
260
+ @server.launch_instance(image_id, instance_type, user_data, options[:user_id])
258
261
  end
259
262
 
260
- def launch_workers(image_id, instance_type, num)
263
+ def launch_workers(image_id, instance_type, num, options = {})
264
+ defaults = { :user_id => "unknown_user" }
265
+ options = defaults.merge(options)
266
+
261
267
  user_data = File.read(File.expand_path(File.dirname(__FILE__))+'/worker_script.sh.template')
262
268
  user_data.gsub!(/SERVER_IP/, @server.data.ip)
263
269
  user_data.gsub!(/SERVER_HOSTNAME/, 'master')
@@ -273,7 +279,7 @@ class OpenStudioAwsWrapper
273
279
  threads = []
274
280
  @workers.each do |worker|
275
281
  threads << Thread.new do
276
- worker.launch_instance(image_id, instance_type, user_data)
282
+ worker.launch_instance(image_id, instance_type, user_data, options[:user_id])
277
283
  end
278
284
  end
279
285
  threads.each { |t| t.join }
@@ -355,7 +361,7 @@ class OpenStudioAwsWrapper
355
361
  available_amis = describe_amis()
356
362
 
357
363
  amis = transform_ami_lists(existing_amis, available_amis)
358
-
364
+
359
365
  if version == 1
360
366
  version1 = {}
361
367
 
@@ -376,10 +382,22 @@ class OpenStudioAwsWrapper
376
382
  end
377
383
 
378
384
  # create the default version. First sort, then grab the first hash's values
379
- version1.sort_by { |k, _| Semantic::Version.new(k.to_s) }
380
- version1[:default] = version1.first[1]
385
+ puts JSON.pretty_generate(version1)
386
+ default_v = nil
387
+ version1.each do |k,v|
388
+ default_v ||= k
389
+ # todo: add a check if the AMI is not marked as invalid
390
+ if Semantic::Version.new(k.to_s) >= Semantic::Version.new(default_v.to_s)
391
+ default_v = k
392
+ end
393
+ end
394
+ puts JSON.pretty_generate(version1)
395
+
396
+ version1[:default] = version1[default_v]
397
+ puts JSON.pretty_generate(version1)
381
398
 
382
399
  amis = version1
400
+
383
401
  elsif version == 2
384
402
  # don't need to transform anything right now
385
403
  end
@@ -13,7 +13,7 @@ describe OpenStudioAmis do
13
13
  end
14
14
 
15
15
  it "should return specific amis if passed a version" do
16
- a = OpenStudioAmis.new(1, "1.2.0")
16
+ a = OpenStudioAmis.new(1, {:openstudio_version => "1.2.0"})
17
17
 
18
18
  amis = a.get_amis
19
19
 
@@ -1,23 +1,63 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe OpenStudio::Aws::Aws do
4
- context "proxy configuration" do
5
- before :all do
4
+ context "ami lists" do
5
+ it "should allow a different region" do
6
+ options = {
7
+ :region => "sa-east-1",
8
+ :credentials =>
9
+ {
10
+ :access_key_id => "some_random_access_key_id",
11
+ :secret_access_key => "some_super_secret_access_key",
12
+ }
13
+ }
14
+ aws = OpenStudio::Aws::Aws.new(options)
15
+ end
16
+
17
+ it "should allow a different region" do
18
+ options = {
19
+ :ami_lookup_version => 2
20
+ }
21
+ aws = OpenStudio::Aws::Aws.new(options)
22
+
23
+ expect(aws.default_amis).not_to be_nil
24
+ end
25
+ end
6
26
 
27
+ context "should error" do
28
+ it "should not find a json" do
29
+ options = {
30
+ :ami_lookup_version => 2,
31
+ :url => '/unknown/url'
32
+ }
33
+ expect { aws = OpenStudio::Aws::Aws.new(options) }.to raise_exception
34
+ end
35
+ end
36
+
37
+ context "version testing" do
38
+ it "version 2: should find the right AMIs Server 1.3.1" do
39
+ options = {
40
+ :ami_lookup_version => 2,
41
+ :openstudio_server_version => "1.3.1"
42
+ }
43
+ aws = OpenStudio::Aws::Aws.new(options)
44
+ expect(aws.default_amis[:worker]).to eq("ami-39bb8750")
45
+ expect(aws.default_amis[:server]).to eq("ami-a9bb87c0")
7
46
  end
8
-
47
+ end
48
+
49
+ context "proxy configuration" do
9
50
  it "should create an instance" do
10
51
  options = {
11
52
  :credentials =>
12
53
  {
13
54
  :access_key_id => "some_random_access_key_id",
14
55
  :secret_access_key => "some_super_secret_access_key",
15
- :region => "us-east-1",
16
- :ssl_verify_peer => false
17
56
  }
18
- }
19
-
57
+ }
58
+
20
59
  @aws = OpenStudio::Aws::Aws.new(options)
60
+ #puts @aws.inspect
21
61
  expect(@aws.os_aws).not_to be_nil
22
62
  end
23
63
 
@@ -27,8 +67,6 @@ describe OpenStudio::Aws::Aws do
27
67
  {
28
68
  :access_key_id => "some_random_access_key_id",
29
69
  :secret_access_key => "some_super_secret_access_key",
30
- :region => "us-east-1",
31
- :ssl_verify_peer => false
32
70
  },
33
71
  :proxy => {
34
72
  :host => "192.168.0.1",
@@ -45,8 +83,6 @@ describe OpenStudio::Aws::Aws do
45
83
  {
46
84
  :access_key_id => "some_random_access_key_id",
47
85
  :secret_access_key => "some_super_secret_access_key",
48
- :region => "us-east-1",
49
- :ssl_verify_peer => false
50
86
  },
51
87
  :proxy => {
52
88
  :host => "192.168.0.1",
@@ -67,7 +67,7 @@ describe OpenStudioAwsWrapper do
67
67
  resp = @aws.os_aws.create_new_ami_json(1)
68
68
  expect(resp["1.1.3".to_sym][:server]).to eq("ami-fb301292")
69
69
  expect(resp["1.2.1".to_sym][:server]).to eq("ami-89744be0")
70
- expect(resp["default".to_sym][:server]).to eq("ami-89744be0")
70
+ expect(resp["default".to_sym][:server]).to_not eq("ami-89744be0")
71
71
  end
72
72
  end
73
73
 
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws ami lists" tests="1" time="0.083118" failures="0" errors="1" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.082912">
4
+ <failure type="Aws::Errors::MissingRegionError" message="Aws::Errors::MissingRegionError">
5
+ Aws::Errors::MissingRegionError (Aws::Errors::MissingRegionError)
6
+ Aws::Errors::MissingRegionError:
7
+ Aws::Errors::MissingRegionError
8
+ ./lib/openstudio/lib/openstudio_aws_wrapper.rb:69:in `initialize'
9
+ ./lib/openstudio/aws/aws.rb:56:in `new'
10
+ ./lib/openstudio/aws/aws.rb:56:in `initialize'
11
+ ./spec/openstudio-aws/aws_spec.rb:15:in `new'
12
+ ./spec/openstudio-aws/aws_spec.rb:15:in `block (3 levels) in &lt;top (required)&gt;' </failure>
13
+ </testcase>
14
+ <system-out>
15
+ </system-out>
16
+ <system-err>
17
+ </system-err>
18
+ </testsuite>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws ami lists" tests="1" time="0.060319" failures="0" errors="1" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.060138">
4
+ <failure type="Aws::Errors::MissingRegionError" message="Aws::Errors::MissingRegionError">
5
+ Aws::Errors::MissingRegionError (Aws::Errors::MissingRegionError)
6
+ Aws::Errors::MissingRegionError:
7
+ Aws::Errors::MissingRegionError
8
+ ./lib/openstudio/lib/openstudio_aws_wrapper.rb:69:in `initialize'
9
+ ./lib/openstudio/aws/aws.rb:57:in `new'
10
+ ./lib/openstudio/aws/aws.rb:57:in `initialize'
11
+ ./spec/openstudio-aws/aws_spec.rb:15:in `new'
12
+ ./spec/openstudio-aws/aws_spec.rb:15:in `block (3 levels) in &lt;top (required)&gt;' </failure>
13
+ </testcase>
14
+ <system-out>
15
+ {:ami_lookup_version=&gt;1, :region=&gt;"sa-east-1", :credentials=&gt;{:access_key_id=&gt;"some_random_access_key_id", :secret_access_key=&gt;"some_super_secret_access_key", :ssl_verify_peer=&gt;false}}
16
+ </system-out>
17
+ <system-err>
18
+ </system-err>
19
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws ami lists" tests="2" time="0.275788" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.201982">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.073603">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws ami lists" tests="2" time="0.2939" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.201705">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.091975">
6
+ </testcase>
7
+ <system-out>
8
+ </system-out>
9
+ <system-err>
10
+ </system-err>
11
+ </testsuite>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws ami lists" tests="1" time="0.128722" failures="0" errors="1" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws ami lists should allow a different region" time="0.128541">
4
+ <failure type="Aws::Errors::MissingRegionError" message="Aws::Errors::MissingRegionError">
5
+ Aws::Errors::MissingRegionError (Aws::Errors::MissingRegionError)
6
+ Aws::Errors::MissingRegionError:
7
+ Aws::Errors::MissingRegionError
8
+ ./lib/openstudio/lib/openstudio_aws_wrapper.rb:69:in `initialize'
9
+ ./lib/openstudio/aws/aws.rb:56:in `new'
10
+ ./lib/openstudio/aws/aws.rb:56:in `initialize'
11
+ ./spec/openstudio-aws/aws_spec.rb:15:in `new'
12
+ ./spec/openstudio-aws/aws_spec.rb:15:in `block (3 levels) in &lt;top (required)&gt;' </failure>
13
+ </testcase>
14
+ <system-out>
15
+ </system-out>
16
+ <system-err>
17
+ </system-err>
18
+ </testsuite>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws create a new instance" tests="5" time="193376.590119" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws create a new instance should create a new instance" time="0.001172">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws create a new instance should ask the user to create a new config file" time="0.000125">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws create a new instance should create a server" time="35.035334">
8
+ </testcase>
9
+ <testcase>
10
+ </testcase>
11
+ <testcase>
12
+ </testcase>
13
+ <system-out>
14
+ {"timestamp":"1390600048","server":{"id":"i-2f15580f","ip":"http://54.234.28.217","dns":"ec2-54-234-28-217.compute-1.amazonaws.com","procs":1}}
15
+
16
+ Server SSH Command:
17
+ ssh -i ec2_server_key.pem ubuntu@ec2-54-234-28-217.compute-1.amazonaws.com
18
+
19
+ Worker SSH Command:
20
+ ssh -i ec2_server_key.pem ubuntu@ec2-23-22-87-129.compute-1.amazonaws.com
21
+
22
+ Waiting for server/worker configurations
23
+ </system-out>
24
+ <system-err>
25
+ </system-err>
26
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.07276" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.060141">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.00575">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.006519">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.076653" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.061784">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.00808">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.006428">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.033589" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.005949">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.007908">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.0194">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.030081" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.006072">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.0053">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.018383">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.0314" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.006098">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.005309">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.019675">
8
+ </testcase>
9
+ <system-out>
10
+ {:ami_lookup_version=&gt;1, :region=&gt;"us-east-1", :credentials=&gt;{:access_key_id=&gt;"some_random_access_key_id", :secret_access_key=&gt;"some_super_secret_access_key", :region=&gt;"us-east-1", :ssl_verify_peer=&gt;false}}
11
+ {:ami_lookup_version=&gt;1, :region=&gt;"us-east-1", :credentials=&gt;{:access_key_id=&gt;"some_random_access_key_id", :secret_access_key=&gt;"some_super_secret_access_key", :region=&gt;"us-east-1", :ssl_verify_peer=&gt;false}, :proxy=&gt;{:host=&gt;"192.168.0.1", :port=&gt;8080}}
12
+ {:ami_lookup_version=&gt;1, :region=&gt;"us-east-1", :credentials=&gt;{:access_key_id=&gt;"some_random_access_key_id", :secret_access_key=&gt;"some_super_secret_access_key", :region=&gt;"us-east-1", :ssl_verify_peer=&gt;false}, :proxy=&gt;{:host=&gt;"192.168.0.1", :port=&gt;8080, :username=&gt;"username", :password=&gt;"password"}}
13
+ </system-out>
14
+ <system-err>
15
+ </system-err>
16
+ </testsuite>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="OpenStudio::Aws::Aws proxy configuration" tests="3" time="0.221583" failures="0" errors="0" skipped="0">
3
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create an instance" time="0.075528">
4
+ </testcase>
5
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy" time="0.070993">
6
+ </testcase>
7
+ <testcase name="OpenStudio::Aws::Aws proxy configuration should create a AWS instance with a proxy with username / password" time="0.074723">
8
+ </testcase>
9
+ <system-out>
10
+ </system-out>
11
+ <system-err>
12
+ </system-err>
13
+ </testsuite>