bbrowning-deltacloud-core 0.0.4-java

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. data/COPYING +176 -0
  2. data/Rakefile +99 -0
  3. data/bin/deltacloudd +120 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +18 -0
  6. data/lib/deltacloud/base_driver/base_driver.rb +229 -0
  7. data/lib/deltacloud/base_driver/features.rb +166 -0
  8. data/lib/deltacloud/base_driver/mock_driver.rb +40 -0
  9. data/lib/deltacloud/base_driver.rb +20 -0
  10. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +410 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  12. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +332 -0
  14. data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
  15. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  16. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  17. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  18. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  19. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  20. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  21. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  22. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  23. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  24. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  25. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  26. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  27. data/lib/deltacloud/drivers/mock/mock_driver.rb +277 -0
  28. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  29. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  30. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  31. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
  32. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +182 -0
  33. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +255 -0
  34. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
  35. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
  36. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +286 -0
  37. data/lib/deltacloud/hardware_profile.rb +153 -0
  38. data/lib/deltacloud/helpers/application_helper.rb +115 -0
  39. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  40. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  41. data/lib/deltacloud/helpers.rb +5 -0
  42. data/lib/deltacloud/method_serializer.rb +85 -0
  43. data/lib/deltacloud/models/base_model.rb +59 -0
  44. data/lib/deltacloud/models/image.rb +27 -0
  45. data/lib/deltacloud/models/instance.rb +38 -0
  46. data/lib/deltacloud/models/instance_profile.rb +48 -0
  47. data/lib/deltacloud/models/key.rb +35 -0
  48. data/lib/deltacloud/models/realm.rb +26 -0
  49. data/lib/deltacloud/models/storage_snapshot.rb +27 -0
  50. data/lib/deltacloud/models/storage_volume.rb +28 -0
  51. data/lib/deltacloud/state_machine.rb +84 -0
  52. data/lib/deltacloud/validation.rb +70 -0
  53. data/lib/drivers.rb +50 -0
  54. data/lib/sinatra/accept_media_types.rb +128 -0
  55. data/lib/sinatra/lazy_auth.rb +56 -0
  56. data/lib/sinatra/rabbit.rb +273 -0
  57. data/lib/sinatra/respond_to.rb +272 -0
  58. data/lib/sinatra/static_assets.rb +83 -0
  59. data/lib/sinatra/url_for.rb +53 -0
  60. data/public/favicon.ico +0 -0
  61. data/public/images/grid.png +0 -0
  62. data/public/images/logo-wide.png +0 -0
  63. data/public/images/rails.png +0 -0
  64. data/public/images/topbar-bg.png +0 -0
  65. data/public/javascripts/application.js +32 -0
  66. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  67. data/public/stylesheets/compiled/application.css +613 -0
  68. data/public/stylesheets/compiled/ie.css +31 -0
  69. data/public/stylesheets/compiled/print.css +27 -0
  70. data/public/stylesheets/compiled/screen.css +456 -0
  71. data/server.rb +354 -0
  72. data/support/fedora/deltacloudd +68 -0
  73. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  74. data/tests/api_test.rb +37 -0
  75. data/tests/hardware_profiles_test.rb +120 -0
  76. data/tests/images_test.rb +111 -0
  77. data/tests/instance_states_test.rb +52 -0
  78. data/tests/instances_test.rb +219 -0
  79. data/tests/realms_test.rb +78 -0
  80. data/tests/url_for_test.rb +50 -0
  81. data/views/accounts/index.html.haml +11 -0
  82. data/views/accounts/show.html.haml +30 -0
  83. data/views/api/show.html.haml +15 -0
  84. data/views/api/show.xml.haml +5 -0
  85. data/views/docs/collection.html.haml +37 -0
  86. data/views/docs/collection.xml.haml +14 -0
  87. data/views/docs/index.html.haml +15 -0
  88. data/views/docs/index.xml.haml +5 -0
  89. data/views/docs/operation.html.haml +31 -0
  90. data/views/docs/operation.xml.haml +10 -0
  91. data/views/errors/auth_exception.html.haml +8 -0
  92. data/views/errors/auth_exception.xml.haml +2 -0
  93. data/views/errors/backend_error.html.haml +19 -0
  94. data/views/errors/backend_error.xml.haml +8 -0
  95. data/views/errors/not_found.html.haml +6 -0
  96. data/views/errors/not_found.xml.haml +2 -0
  97. data/views/errors/validation_failure.html.haml +11 -0
  98. data/views/errors/validation_failure.xml.haml +7 -0
  99. data/views/hardware_profiles/index.html.haml +25 -0
  100. data/views/hardware_profiles/index.xml.haml +4 -0
  101. data/views/hardware_profiles/show.html.haml +19 -0
  102. data/views/hardware_profiles/show.xml.haml +18 -0
  103. data/views/images/index.html.haml +30 -0
  104. data/views/images/index.xml.haml +8 -0
  105. data/views/images/show.html.haml +21 -0
  106. data/views/images/show.xml.haml +5 -0
  107. data/views/instance_states/show.gv.erb +45 -0
  108. data/views/instance_states/show.html.haml +31 -0
  109. data/views/instance_states/show.xml.haml +8 -0
  110. data/views/instances/index.html.haml +30 -0
  111. data/views/instances/index.xml.haml +21 -0
  112. data/views/instances/new.html.haml +55 -0
  113. data/views/instances/show.html.haml +43 -0
  114. data/views/instances/show.xml.haml +49 -0
  115. data/views/keys/index.html.haml +26 -0
  116. data/views/keys/index.xml.haml +4 -0
  117. data/views/keys/new.html.haml +8 -0
  118. data/views/keys/show.html.haml +22 -0
  119. data/views/keys/show.xml.haml +20 -0
  120. data/views/layout.html.haml +26 -0
  121. data/views/realms/index.html.haml +29 -0
  122. data/views/realms/index.xml.haml +10 -0
  123. data/views/realms/show.html.haml +15 -0
  124. data/views/realms/show.xml.haml +9 -0
  125. data/views/root/index.html.haml +4 -0
  126. data/views/storage_snapshots/index.html.haml +20 -0
  127. data/views/storage_snapshots/index.xml.haml +9 -0
  128. data/views/storage_snapshots/show.html.haml +14 -0
  129. data/views/storage_snapshots/show.xml.haml +7 -0
  130. data/views/storage_volumes/index.html.haml +21 -0
  131. data/views/storage_volumes/index.xml.haml +13 -0
  132. data/views/storage_volumes/show.html.haml +20 -0
  133. data/views/storage_volumes/show.xml.haml +11 -0
  134. metadata +334 -0
@@ -0,0 +1,111 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class HardwareProfilesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_require_authentication
12
+ require_authentication?('/api/images').should == true
13
+ end
14
+
15
+ def test_it_returns_images
16
+ do_xml_request '/api/images', {}, true
17
+ (last_xml_response/'images/image').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/images', {}, true
22
+ (last_xml_response/'images/image').each do |image|
23
+ image.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_img1_has_correct_attributes
28
+ do_xml_request '/api/images', {}, true
29
+ image = (last_xml_response/'images/image[@id="img1"]')
30
+ test_image_attributes(image)
31
+ end
32
+
33
+ def test_it_returns_valid_image
34
+ do_xml_request '/api/images/img1', {}, true
35
+ image = (last_xml_response/'image')
36
+ test_image_attributes(image)
37
+ end
38
+
39
+ def test_it_has_unique_ids
40
+ do_xml_request '/api/images', {}, true
41
+ ids = []
42
+ (last_xml_response/'images/image').each do |image|
43
+ ids << image['id'].to_s
44
+ end
45
+ ids.sort.should == ids.sort.uniq
46
+ end
47
+
48
+ def test_it_has_valid_urls
49
+ do_xml_request '/api/images', {}, true
50
+ ids = []
51
+ images = (last_xml_response/'images/image')
52
+ images.each do |image|
53
+ do_xml_request image['href'].to_s, {}, true
54
+ (last_xml_response/'image').first['href'].should == image['href'].to_s
55
+ end
56
+ end
57
+
58
+ def test_it_can_filter_using_owner_id
59
+ do_xml_request '/api/images', { :owner_id => 'mockuser' }, true
60
+ (last_xml_response/'images/image').size.should == 1
61
+ (last_xml_response/'images/image/owner_id').first.text.should == 'mockuser'
62
+ end
63
+
64
+ def test_it_can_filter_using_unknown_owner_id
65
+ do_xml_request '/api/images', { :architecture => 'unknown_user' }, true
66
+ (last_xml_response/'images/image').size.should == 0
67
+ end
68
+
69
+ def test_it_can_filter_using_architecture
70
+ do_xml_request '/api/images', { :architecture => 'x86_64' }, true
71
+ (last_xml_response/'images/image').size.should == 1
72
+ (last_xml_response/'images/image/architecture').first.text.should == 'x86_64'
73
+ end
74
+
75
+ def test_it_can_filter_using_unknown_architecture
76
+ do_xml_request '/api/images', { :architecture => 'unknown_arch' }, true
77
+ (last_xml_response/'images/image').size.should == 0
78
+ end
79
+
80
+ def test_it_responses_to_json
81
+ do_request '/api/images', {}, true, { :format => :json }
82
+ JSON::parse(last_response.body).class.should == Hash
83
+ JSON::parse(last_response.body)['images'].class.should == Array
84
+
85
+ do_request '/api/images/img1', {}, true, { :format => :json }
86
+ last_response.status.should == 200
87
+ JSON::parse(last_response.body).class.should == Hash
88
+ JSON::parse(last_response.body)['image'].class.should == Hash
89
+ end
90
+
91
+ def test_it_responses_to_html
92
+ do_request '/api/images', {}, true, { :format => :html }
93
+ last_response.status.should == 200
94
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
95
+
96
+ do_request '/api/images/img1', {}, true, { :format => :html }
97
+ last_response.status.should == 200
98
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
99
+ end
100
+
101
+ private
102
+
103
+ def test_image_attributes(image)
104
+ (image/'name').text.should_not nil
105
+ (image/'owner_id').text.should_not nil
106
+ (image/'description').text.should_not nil
107
+ (image/'architecture').text.should_not nil
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,52 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
14
+
15
+ def test_it_returns_instance_states
16
+ do_xml_request '/api/instance_states', {}, true
17
+ (last_xml_response/'states/state').map.size.should > 0
18
+ end
19
+
20
+ def test_each_state_has_transition
21
+ do_xml_request '/api/instance_states', {}, true
22
+ (last_xml_response/'states/state').each do |state|
23
+ next if state['name'].eql?('finish') # Finnish state doesn't have transitions
24
+ (state/'transition').map.size.should > 0
25
+ (state/'transition').each do |transition|
26
+ transition['to'].should_not == nil
27
+ end
28
+ end
29
+ end
30
+
31
+ def test_it_responses_to_json
32
+ do_request '/api/instance_states', {}, false, { :format => :json }
33
+ JSON::parse(last_response.body).class.should == Array
34
+ JSON::parse(last_response.body).first['transitions'].class.should == Array
35
+ JSON::parse(last_response.body).first['name'].should == 'start'
36
+ end
37
+
38
+ def test_it_responses_to_html
39
+ do_request '/api/instance_states', {}, false, { :format => :html }
40
+ last_response.status.should == 200
41
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
42
+ end
43
+
44
+ def test_it_responses_to_png
45
+ do_request '/api/instance_states', {}, false, { :format => :png }
46
+ last_response.status.should == 200
47
+ last_response.headers['Content-Type'].should == 'image/png'
48
+ #last_response.headers['Content-Length'].should == '4371'
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,219 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class InstancesTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_require_authentication
12
+ require_authentication?('/api/instances').should == true
13
+ end
14
+
15
+ def test_it_returns_instances
16
+ do_xml_request '/api/instances', {}, true
17
+ (last_xml_response/'instances/instance').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/images', {}, true
22
+ (last_xml_response/'images/image').each do |image|
23
+ image.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_it_has_unique_ids
28
+ do_xml_request '/api/instances', {}, true
29
+ ids = []
30
+ (last_xml_response/'instances/instance').each do |image|
31
+ ids << image['id'].to_s
32
+ end
33
+ ids.sort.should == ids.sort.uniq
34
+ end
35
+
36
+ def test_inst1_has_correct_attributes
37
+ do_xml_request '/api/instances', {}, true
38
+ instance = (last_xml_response/'instances/instance[@id="inst1"]')
39
+ test_instance_attributes(instance)
40
+ end
41
+
42
+ def test_it_returns_valid_realm
43
+ do_xml_request '/api/instances/inst1', {}, true
44
+ instance = (last_xml_response/'instance')
45
+ test_instance_attributes(instance)
46
+ end
47
+
48
+ def test_it_responses_to_json
49
+ do_request '/api/instances', {}, true, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['instances'].class.should == Array
52
+
53
+ do_request '/api/instances/inst1', {}, true, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['instance'].class.should == Hash
57
+ end
58
+
59
+ def test_it_responses_to_html
60
+ do_request '/api/instances', {}, true, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
+
64
+ do_request '/api/instances/inst1', {}, true, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
68
+
69
+ def test_it_create_a_new_instance_using_image_id
70
+ params = {
71
+ :image_id => 'img1'
72
+ }
73
+ post '/api/instances', params, authenticate(:format => :xml)
74
+ last_response.status.should == 302
75
+ last_response.headers['Location'].should_not == nil
76
+ do_xml_request last_response.headers['Location'], {}, true
77
+ (last_xml_response/'instance/name').should_not == nil
78
+ add_created_instance (last_xml_response/'instance').first['id']
79
+ test_instance_attributes(last_xml_response/'instance')
80
+ end
81
+
82
+ def test_it_create_a_new_instance_using_image_id_and_name
83
+ params = {
84
+ :image_id => 'img1',
85
+ :name => "unit_test_instance1"
86
+ }
87
+ post '/api/instances', params, authenticate(:format => :xml)
88
+ last_response.status.should == 302
89
+ last_response.headers['Location'].should_not == nil
90
+ do_xml_request last_response.headers['Location'], {}, true
91
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
92
+ add_created_instance (last_xml_response/'instance').first['id']
93
+ test_instance_attributes(last_xml_response/'instance')
94
+ end
95
+
96
+ def test_it_create_a_new_instance_using_image_id_and_name_and_hwp
97
+ params = {
98
+ :image_id => 'img1',
99
+ :name => "unit_test_instance1",
100
+ :hwp_id => "m1-xlarge"
101
+ }
102
+ post '/api/instances', params, authenticate(:format => :xml)
103
+ last_response.status.should == 302
104
+ last_response.headers['Location'].should_not == nil
105
+ do_xml_request last_response.headers['Location'], {}, true
106
+ (last_xml_response/'instance/name').text.should == 'unit_test_instance1'
107
+ (last_xml_response/'instance/hardware_profile').first['id'].should == 'm1-xlarge'
108
+ add_created_instance (last_xml_response/'instance').first['id']
109
+ test_instance_attributes(last_xml_response/'instance')
110
+ end
111
+
112
+ def test_it_z0_stop_and_start_instance
113
+ $created_instances.each do |instance_id|
114
+ do_xml_request "/api/instances/#{instance_id}", {}, true
115
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
116
+ stop_url.should_not == nil
117
+ post create_url(stop_url), {}, authenticate(:format => :xml)
118
+ last_response.status.should == 200
119
+ instance = Nokogiri::XML(last_response.body)
120
+ test_instance_attributes(instance)
121
+ (instance/'state').text.should == 'STOPPED'
122
+ do_xml_request "/api/instances/#{instance_id}", {}, true
123
+ start_url = (last_xml_response/'actions/link[@rel="start"]').first['href']
124
+ start_url.should_not == nil
125
+ post create_url(start_url), {}, authenticate(:format => :xml)
126
+ last_response.status.should == 200
127
+ instance = Nokogiri::XML(last_response.body)
128
+ test_instance_attributes(instance)
129
+ (instance/'state').text.should == 'RUNNING'
130
+ end
131
+ end
132
+
133
+ def test_z0_reboot_instance
134
+ $created_instances.each do |instance_id|
135
+ do_xml_request "/api/instances/#{instance_id}", {}, true
136
+ reboot_url = (last_xml_response/'actions/link[@rel="reboot"]').first['href']
137
+ reboot_url.should_not == nil
138
+ post create_url(reboot_url), {}, authenticate(:format => :xml)
139
+ last_response.status.should == 200
140
+ instance = Nokogiri::XML(last_response.body)
141
+ test_instance_attributes(instance)
142
+ (instance/'state').text.should == 'RUNNING'
143
+ end
144
+ end
145
+
146
+ def test_z1_stop_created_instances
147
+ $created_instances.each do |instance_id|
148
+ do_xml_request "/api/instances/#{instance_id}", {}, true
149
+ stop_url = (last_xml_response/'actions/link[@rel="stop"]').first['href']
150
+ stop_url.should_not == nil
151
+ post create_url(stop_url), {}, authenticate(:format => :xml)
152
+ last_response.status.should == 200
153
+ instance = Nokogiri::XML(last_response.body)
154
+ test_instance_attributes(instance)
155
+ (instance/'state').text.should == 'STOPPED'
156
+ end
157
+ end
158
+
159
+ def test_z2_destroy_created_instances
160
+ $created_instances.each do |instance_id|
161
+ do_xml_request "/api/instances/#{instance_id}", {}, true
162
+ destroy_url = (last_xml_response/'actions/link[@rel="destroy"]').first['href']
163
+ destroy_url.should_not == nil
164
+ delete create_url(destroy_url), {}, authenticate(:format => :xml)
165
+ last_response.status.should == 302
166
+ do_xml_request last_response.headers['Location'], {}, true
167
+ (last_xml_response/'instances').should_not == nil
168
+ do_xml_request "/api/instances/#{instance_id}", {}, true
169
+ last_response.status.should == 404
170
+ end
171
+ end
172
+
173
+ private
174
+
175
+ def test_instance_attributes(instance)
176
+ (instance/'name').should_not == nil
177
+ (instance/'owner_id').should_not == nil
178
+ ['RUNNING', 'STOPPED'].include?((instance/'state').text).should == true
179
+
180
+ (instance/'public_addreses').should_not == nil
181
+ (instance/'public_addresses/address').map.size.should > 0
182
+ (instance/'public_addresses/address').first.text.should_not == ""
183
+
184
+ (instance/'private_addresses').should_not == nil
185
+ (instance/'private_addresses/address').map.size.should > 0
186
+ (instance/'private_addresses/address').first.text.should_not == ""
187
+
188
+ (instance/'actions/link').map.size.should > 0
189
+ (instance/'actions/link').each do |link|
190
+ link['href'].should_not == ""
191
+ link['rel'].should_not == ""
192
+ link['method'].should_not == ""
193
+ ['get', 'post', 'delete', 'put'].include?(link['method']).should == true
194
+ end
195
+
196
+ (instance/'image').size.should > 0
197
+ (instance/'image').first['href'].should_not == ""
198
+ (instance/'image').first['id'].should_not == ""
199
+ do_xml_request (instance/'image').first['href'], {}, true
200
+ (last_xml_response/'image').should_not == nil
201
+ (last_xml_response/'image').first['href'] == (instance/'image').first['href']
202
+
203
+ (instance/'realm').size.should > 0
204
+ (instance/'realm').first['href'].should_not == ""
205
+ (instance/'realm').first['id'].should_not == ""
206
+ do_xml_request (instance/'realm').first['href']
207
+ (last_xml_response/'realm').should_not == nil
208
+ (last_xml_response/'realm').first['href'] == (instance/'realm').first['href']
209
+
210
+ (instance/'hardware_profile').size.should > 0
211
+ (instance/'hardware_profile').first['href'].should_not == ""
212
+ (instance/'hardware_profile').first['id'].should_not == ""
213
+ do_xml_request (instance/'hardware_profile').first['href']
214
+ (last_xml_response/'hardware_profile').should_not == nil
215
+ (last_xml_response/'hardware_profile').first['href'] == (instance/'hardware_profile').first['href']
216
+ end
217
+
218
+ end
219
+ end
@@ -0,0 +1,78 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class RealmsTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_not_require_authentication
12
+ require_authentication?('/api/realms').should_not == true
13
+ end
14
+
15
+ def test_it_returns_realms
16
+ do_xml_request '/api/realms', {}, true
17
+ (last_xml_response/'realms/realm').map.size.should > 0
18
+ end
19
+
20
+ def test_it_has_correct_attributes_set
21
+ do_xml_request '/api/realms', {}, true
22
+ (last_xml_response/'realms/realm').each do |realm|
23
+ realm.attributes.keys.sort.should == [ 'href', 'id' ]
24
+ end
25
+ end
26
+
27
+ def test_us_has_correct_attributes
28
+ do_xml_request '/api/realms', {}, true
29
+ realm = (last_xml_response/'realms/realm[@id="us"]')
30
+ test_realm_attributes(realm)
31
+ end
32
+
33
+ def test_it_returns_valid_realm
34
+ do_xml_request '/api/realms/us', {}, true
35
+ realm = (last_xml_response/'realm')
36
+ test_realm_attributes(realm)
37
+ end
38
+
39
+ def test_it_has_unique_ids
40
+ do_xml_request '/api/realms', {}, true
41
+ ids = []
42
+ (last_xml_response/'realms/realm').each do |realm|
43
+ ids << realm['id'].to_s
44
+ end
45
+ ids.sort.should == ids.sort.uniq
46
+ end
47
+
48
+ def test_it_responses_to_json
49
+ do_request '/api/realms', {}, false, { :format => :json }
50
+ JSON::parse(last_response.body).class.should == Hash
51
+ JSON::parse(last_response.body)['realms'].class.should == Array
52
+
53
+ do_request '/api/realms/us', {}, false, { :format => :json }
54
+ last_response.status.should == 200
55
+ JSON::parse(last_response.body).class.should == Hash
56
+ JSON::parse(last_response.body)['realm'].class.should == Hash
57
+ end
58
+
59
+ def test_it_responses_to_html
60
+ do_request '/api/realms', {}, false, { :format => :html }
61
+ last_response.status.should == 200
62
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
63
+
64
+ do_request '/api/realms/us', {}, false, { :format => :html }
65
+ last_response.status.should == 200
66
+ Nokogiri::HTML(last_response.body).search('html').first.name.should == 'html'
67
+ end
68
+
69
+ private
70
+
71
+ def test_realm_attributes(realm)
72
+ (realm/'name').should_not == nil
73
+ (realm/'limit').should_not == nil
74
+ ['AVAILABLE'].include?((realm/'state').text).should == true
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,50 @@
1
+ require 'tests/common'
2
+
3
+ module DeltacloudUnitTest
4
+ class UrlForTest < Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ Sinatra::Application
9
+ end
10
+
11
+ def test_it_works_for_root
12
+ verify_url_for("/", "/")
13
+ end
14
+
15
+ def test_it_works_for_root_absolute
16
+ verify_url_for("/", "http://localhost/", :full)
17
+ end
18
+
19
+ def test_it_works_with_spaces
20
+ verify_url_for("/url with spaces", "/url%20with%20spaces")
21
+ end
22
+
23
+ def test_it_works_when_given_absolute
24
+ verify_url_for("http://test.com", "http://test.com")
25
+ end
26
+
27
+ def test_it_works_when_not_at_root_context
28
+ verify_url_for("/", "context/", :path_only, {}, {"SCRIPT_NAME" => "context"})
29
+ end
30
+
31
+ def verify_url_for(url, expected_url, mode=:path_only, params={}, rack_env={})
32
+ # generate a unique url for each test
33
+ test_url = "/url_for_test/#{expected_url.hash}/#{Time.now.to_f}"
34
+ # Create our sinatra test endpoint
35
+ self.class.create_test_url_content(test_url, url, mode)
36
+
37
+ # verify the generated url matches what we expect
38
+ get test_url, params, rack_env
39
+ last_response.body.should == expected_url
40
+ end
41
+
42
+ def self.create_test_url_content(test_url, url_content, mode)
43
+ get test_url do
44
+ content_type "text/plain"
45
+ url_for(url_content, mode)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ %h1 Accounts
2
+
3
+ %table
4
+ %thead
5
+ %tr
6
+ %th ID
7
+ %tbody
8
+ - @accounts.each do |account|
9
+ %tr
10
+ %td
11
+ = link_to account, account
@@ -0,0 +1,30 @@
1
+ %h1
2
+ = @account[:id]
3
+
4
+ %h2 Instances
5
+
6
+ %table
7
+ %thead
8
+ %tr
9
+ %th Instance ID
10
+ %tbody
11
+ - @account[:instance_ids].each do |instance_id|
12
+ %tr
13
+ %td
14
+ = link_to instance_id, instance_url( instance_id )
15
+
16
+ %h2 Images
17
+
18
+ %table
19
+ %thead
20
+ %tr
21
+ %th Image ID
22
+ %th Description
23
+ %tbody
24
+ %tbody
25
+ - @images.each do |image|
26
+ %tr
27
+ %td
28
+ = link_to image[:id], image_url( image[:id] )
29
+ %td
30
+ = image[:description]
@@ -0,0 +1,15 @@
1
+ %h1
2
+ API v#{@version}
3
+
4
+ %ul
5
+ - collections.keys.sort_by { |k| k.to_s }.each do |key|
6
+ %li
7
+ = link_to key.to_s.gsub('_', ' ').titlecase, url_for("/api/#{key}")
8
+ %dl
9
+ - collections[key].operations.each_key do |op|
10
+ - next if [:index, :show].include?(op)
11
+ %dt
12
+ = op
13
+ %li
14
+ %strong
15
+ %a{:href => url_for("/api/docs")} Documentation (v#{@version})
@@ -0,0 +1,5 @@
1
+ %api{ :version=>@version, :driver=>DRIVER }
2
+ - for entry_point in entry_points
3
+ %link{ :rel=>entry_point[0], :href=>entry_point[1] }
4
+ - for feature in driver.features(entry_point[0])
5
+ %feature{ :name=>feature.name }
@@ -0,0 +1,37 @@
1
+ %h2
2
+ = @collection.name.to_s.titlecase
3
+
4
+ %p #{@collection.description}
5
+
6
+ %br
7
+
8
+ %h3 Operations:
9
+
10
+ %table
11
+ %thead
12
+ %tr
13
+ %th Name
14
+ %th Description
15
+ %tbody
16
+ - @operations.keys.sort_by { |k| k.to_s }.each do |operation|
17
+ %tr
18
+ %td{:style => "width:15em"}
19
+ %a{:href => url_for("/api/docs/#{@collection.name.to_s}/#{operation}")} #{operation}
20
+ %td{:style => "width:10em"} #{@operations[operation].description}
21
+
22
+ %h3 Features:
23
+
24
+ %table
25
+ %thead
26
+ %tr
27
+ %th Name
28
+ %th Description
29
+ %th Modified Operations
30
+ %tbody
31
+ - @features.sort_by { |f| f.name.to_s }.each do |feature|
32
+ %tr
33
+ %td= feature.name
34
+ %td= feature.description
35
+ %td
36
+ - feature.operations.each do |op|
37
+ %a{:href => url_for("/api/docs/#{@collection.name.to_s}/#{op.name}")} #{op.name}
@@ -0,0 +1,14 @@
1
+ %docs{:status => "unsupported"}
2
+ %collection{:url => url_for("/api/docs/#{@collection.name}"), :name => "#{@collection.name}"}
3
+ %description #{@collection.description}
4
+ %operations
5
+ - @operations.keys.sort_by { |k| k.to_s }.each do |operation|
6
+ %operation{:url => url_for("/api/#{@collection.name.to_s}"), :name => "#{operation}", :href => url_for("#{@operations[operation].path}"), :method => "#{@operations[operation].method}"}
7
+ %description #{@operations[operation].description}
8
+ - @operations[operation].each_param do |param|
9
+ %parameter{:name => "#{param.name}", :type => "#{param.type}"}
10
+ %class #{param.klass}
11
+ - unless param.options.empty?
12
+ %values
13
+ - param.options.each do |v|
14
+ %value #{v}
@@ -0,0 +1,15 @@
1
+ %h2 API Documentation
2
+
3
+ %h3 Collections:
4
+
5
+ %table
6
+ %thead
7
+ %tr
8
+ %th Name
9
+ %th Description
10
+ %tbody
11
+ - collections.keys.sort_by { |k| k.to_s }.each do |collection|
12
+ %tr
13
+ %td{:style => "width:15em"}
14
+ %a{:href => url_for("/api/docs/#{collection}")} #{collection}
15
+ %td{:style => "width:10em"} #{collections[collection].description}
@@ -0,0 +1,5 @@
1
+ %docs{:status => "unsupported"}
2
+ - collections.keys.sort_by { |k| k.to_s }.each do |collection|
3
+ %collection{:url => url_for("/api/docs/#{collection}")}
4
+ %name #{collection}
5
+ %description #{collections[collection].description}