ruby_vcloud_sdk 0.4.8 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +296 -0
  3. data/lib/ruby_vcloud_sdk.rb +0 -4
  4. data/lib/ruby_vcloud_sdk/catalog.rb +377 -0
  5. data/lib/ruby_vcloud_sdk/catalog_item.rb +26 -0
  6. data/lib/ruby_vcloud_sdk/client.rb +25 -882
  7. data/lib/ruby_vcloud_sdk/config.rb +1 -7
  8. data/lib/ruby_vcloud_sdk/connection/connection.rb +114 -54
  9. data/lib/ruby_vcloud_sdk/cpu.rb +11 -0
  10. data/lib/ruby_vcloud_sdk/disk.rb +55 -0
  11. data/lib/ruby_vcloud_sdk/edge_gateway.rb +32 -0
  12. data/lib/ruby_vcloud_sdk/infrastructure.rb +135 -0
  13. data/lib/ruby_vcloud_sdk/ip_ranges.rb +95 -0
  14. data/lib/ruby_vcloud_sdk/memory.rb +11 -0
  15. data/lib/ruby_vcloud_sdk/network.rb +32 -0
  16. data/lib/ruby_vcloud_sdk/powerable.rb +78 -0
  17. data/lib/ruby_vcloud_sdk/resources.rb +13 -0
  18. data/lib/ruby_vcloud_sdk/session.rb +46 -0
  19. data/lib/ruby_vcloud_sdk/vapp.rb +122 -0
  20. data/lib/ruby_vcloud_sdk/vdc.rb +210 -0
  21. data/lib/ruby_vcloud_sdk/vdc_storage_profile.rb +23 -0
  22. data/lib/ruby_vcloud_sdk/version.rb +1 -1
  23. data/lib/ruby_vcloud_sdk/vm.rb +132 -0
  24. data/lib/ruby_vcloud_sdk/xml/constants.rb +6 -4
  25. data/lib/ruby_vcloud_sdk/xml/wrapper.rb +109 -30
  26. data/lib/ruby_vcloud_sdk/xml/wrapper_classes.rb +45 -2
  27. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/admin_catalog.rb +13 -4
  28. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/allocated_ip_addresses.rb +9 -0
  29. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/catalog_item.rb +6 -14
  30. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk.rb +24 -14
  31. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_attach_or_detach_params.rb +0 -2
  32. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/disk_create_params.rb +1 -3
  33. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/edge_gateway.rb +13 -0
  34. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/gateway_interface.rb +22 -0
  35. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/hard_disk_item_wrapper.rb +4 -4
  36. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_address.rb +10 -0
  37. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_range.rb +13 -0
  38. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_ranges.rb +9 -0
  39. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/ip_scope.rb +6 -32
  40. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/item.rb +1 -7
  41. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/link.rb +14 -0
  42. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/media.rb +4 -20
  43. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/media_insert_or_eject_params.rb +1 -3
  44. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/network_connection_section.rb +0 -4
  45. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/nic_item_wrapper.rb +0 -2
  46. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/org.rb +44 -0
  47. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/org_vdc_network.rb +11 -3
  48. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/query_result_records.rb +14 -0
  49. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/recompose_vapp_params.rb +42 -0
  50. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/session.rb +5 -5
  51. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/supported_versions.rb +19 -0
  52. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/task.rb +1 -1
  53. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/upload_vapp_template_params.rb +2 -4
  54. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vapp.rb +13 -22
  55. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vapp_template.rb +0 -2
  56. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vcloud.rb +5 -3
  57. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vdc.rb +72 -15
  58. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb +8 -6
  59. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb +29 -25
  60. data/lib/ruby_vcloud_sdk/xml/wrapper_classes/vms.rb +12 -0
  61. data/lib/ruby_vcloud_sdk/xml/xml_templates/AdminCatalog.xml +6 -1
  62. data/lib/ruby_vcloud_sdk/xml/xml_templates/RecomposeVAppParams.xml +16 -1
  63. metadata +116 -233
  64. data/README +0 -1
  65. data/Rakefile +0 -50
  66. data/lib/ruby_vcloud_sdk/util.rb +0 -21
  67. data/spec/assets/admin_org_response.xml +0 -75
  68. data/spec/assets/catalog_add_item_response.xml +0 -8
  69. data/spec/assets/catalog_add_vapp_request.xml +0 -5
  70. data/spec/assets/catalog_item_added_response.xml +0 -19
  71. data/spec/assets/catalog_response.xml +0 -19
  72. data/spec/assets/existing_media_busy_response.xml +0 -19
  73. data/spec/assets/existing_media_catalog_item.xml +0 -8
  74. data/spec/assets/existing_media_delete_task_done.xml +0 -6
  75. data/spec/assets/existing_media_done_response.xml +0 -11
  76. data/spec/assets/existing_vapp_resolver_response.xml +0 -3
  77. data/spec/assets/existing_vapp_template_catalog_resolver_response.xml +0 -3
  78. data/spec/assets/existing_vapp_template_instantiate_response.xml +0 -20
  79. data/spec/assets/existing_vapp_template_instantiate_task_error_response.xml +0 -7
  80. data/spec/assets/existing_vapp_template_instantiate_task_start_response.xml +0 -7
  81. data/spec/assets/existing_vapp_template_instantiate_task_success_response.xml +0 -7
  82. data/spec/assets/existing_vapp_template_item_response.xml +0 -8
  83. data/spec/assets/existing_vapp_template_ready_response.xml +0 -79
  84. data/spec/assets/finalize_upload_task_done_response.xml +0 -7
  85. data/spec/assets/finalize_upload_task_response.xml +0 -7
  86. data/spec/assets/indy_disk_attach_request.xml +0 -3
  87. data/spec/assets/indy_disk_attach_task.xml +0 -6
  88. data/spec/assets/indy_disk_attach_task_error.xml +0 -6
  89. data/spec/assets/indy_disk_create_error.xml +0 -1
  90. data/spec/assets/indy_disk_create_request.xml +0 -4
  91. data/spec/assets/indy_disk_create_response.xml +0 -19
  92. data/spec/assets/indy_disk_delete_task.xml +0 -6
  93. data/spec/assets/indy_disk_detach_request.xml +0 -3
  94. data/spec/assets/indy_disk_detach_task.xml +0 -6
  95. data/spec/assets/indy_disk_response.xml +0 -11
  96. data/spec/assets/instantiated_suspended_vapp_response.xml +0 -209
  97. data/spec/assets/instantiated_vapp_delelete_done_task.xml +0 -5
  98. data/spec/assets/instantiated_vapp_delelete_running_task.xml +0 -6
  99. data/spec/assets/instantiated_vapp_network_config_add_network_request.xml +0 -36
  100. data/spec/assets/instantiated_vapp_network_config_modify_network_task_success.xml +0 -6
  101. data/spec/assets/instantiated_vapp_network_config_remove_network_request.xml +0 -6
  102. data/spec/assets/instantiated_vapp_network_config_section_response.xml +0 -17
  103. data/spec/assets/instantiated_vapp_off_response.xml +0 -206
  104. data/spec/assets/instantiated_vapp_on_response.xml +0 -205
  105. data/spec/assets/instantiated_vapp_power_task_running.xml +0 -6
  106. data/spec/assets/instantiated_vapp_power_task_success.xml +0 -6
  107. data/spec/assets/instantiated_vapp_response.xml +0 -205
  108. data/spec/assets/instantiated_vm_change_task_running.xml +0 -6
  109. data/spec/assets/instantiated_vm_change_task_success.xml +0 -6
  110. data/spec/assets/instantiated_vm_cpu_response.xml +0 -11
  111. data/spec/assets/instantiated_vm_insert_media_task_done.xml +0 -6
  112. data/spec/assets/instantiated_vm_memory_response.xml +0 -11
  113. data/spec/assets/instantiated_vm_modify_task_running.xml +0 -6
  114. data/spec/assets/instantiated_vm_modify_task_success.xml +0 -5
  115. data/spec/assets/instantiated_vm_network_section_response.xml +0 -11
  116. data/spec/assets/instantiated_vm_response.xml +0 -149
  117. data/spec/assets/media_add_to_catalog_request.xml +0 -5
  118. data/spec/assets/media_add_to_catalog_response.xml +0 -8
  119. data/spec/assets/media_delete_task_done.xml +0 -6
  120. data/spec/assets/media_upload_pending_response.xml +0 -13
  121. data/spec/assets/media_upload_request.xml +0 -2
  122. data/spec/assets/metadata_set_request.xml +0 -3
  123. data/spec/assets/metadata_set_task_done.xml +0 -6
  124. data/spec/assets/org_network_response.xml +0 -22
  125. data/spec/assets/reconfigure_vm_request.xml +0 -133
  126. data/spec/assets/reconfigure_vm_task.xml +0 -8
  127. data/spec/assets/session.xml +0 -7
  128. data/spec/assets/test-config.yml +0 -38
  129. data/spec/assets/undeploy_params.xml +0 -1
  130. data/spec/assets/vapp_template_catalog_resolver_response.xml +0 -3
  131. data/spec/assets/vapp_template_delelete_done_task.xml +0 -5
  132. data/spec/assets/vapp_template_delelete_running_task.xml +0 -6
  133. data/spec/assets/vapp_template_instantiate_request.xml +0 -8
  134. data/spec/assets/vapp_template_instantiate_with_locality_request.xml +0 -14
  135. data/spec/assets/vapp_template_no_disk_response.xml +0 -27
  136. data/spec/assets/vapp_template_ready_response.xml +0 -79
  137. data/spec/assets/vapp_template_upload_complete.xml +0 -28
  138. data/spec/assets/vapp_template_upload_failed.xml +0 -28
  139. data/spec/assets/vapp_template_upload_request.xml +0 -4
  140. data/spec/assets/vapp_template_upload_response.xml +0 -25
  141. data/spec/assets/vcloud_response.xml +0 -56
  142. data/spec/assets/vdc_response.xml +0 -57
  143. data/spec/spec_helper.rb +0 -107
  144. data/spec/unit/client_response.rb +0 -700
  145. data/spec/unit/client_spec.rb +0 -1152
@@ -1,1152 +0,0 @@
1
- require "spec_helper"
2
- require "client_response"
3
- require "stringio"
4
- require "logger"
5
- require "nokogiri/diff"
6
-
7
- module VCloudSdk
8
- vcd = VCloudSdk::Test::vcd_settings
9
- logger = Config.logger
10
-
11
- Config.configure({"logger" => logger,
12
- "rest_logger" =>VCloudSdk::Test::rest_logger(logger),
13
- "rest_throttle" => vcd["control"]["rest_throttle"]})
14
-
15
- describe Client, :min, :all do
16
- let(:url) { vcd["url"] }
17
- let(:username) { vcd["user"] }
18
- let(:password) { vcd["password"] }
19
- let(:control) { vcd["control"] }
20
- let(:entities) { vcd["entities"] }
21
- let(:auth_cookies) { {"vcloud-token" => vcd["testing"]["cookies"]} }
22
-
23
- def mock_rest_connection
24
- @upload_file_state = "success"
25
- current_vapp_state = "nothing"
26
- finalize_vapp_task_state = "running"
27
- delete_vapp_template_task_state = "running"
28
- delete_vapp_task_state = "running"
29
- change_vm_task_state = "running"
30
- catalog_state = "not_added"
31
- template_instantiate_state = "running"
32
- vapp_power_state = "off"
33
- existing_media_state = "busy"
34
- metadata_value = ""
35
- metadata_xml = ""
36
- rest_client = mock("Rest Client")
37
- response_mapping = {
38
- :get => {
39
- Test::Response::ADMIN_VCLOUD_LINK => lambda {
40
- |url, headers| Test::Response::VCLOUD_RESPONSE },
41
- Test::Response::ADMIN_ORG_LINK => lambda {
42
- |url, headers| Test::Response::ADMIN_ORG_RESPONSE },
43
- Test::Response::VDC_LINK => lambda {
44
- |url, headers| Test::Response::VDC_RESPONSE },
45
- Test::Response::CATALOG_LINK => lambda { |url, headers|
46
- case (catalog_state)
47
- when "not_added"
48
- Test::Response::CATALOG_RESPONSE
49
- when "added"
50
- Test::Response::CATALOG_ITEM_ADDED_RESPONSE
51
- end
52
- },
53
- Test::Response::CATALOG_ITEM_VAPP_LINK => lambda {
54
- |url, headers| Test::Response::CATALOG_ADD_ITEM_RESPONSE
55
- },
56
- Test::Response::VAPP_TEMPLATE_LINK => lambda { |url, headers|
57
- case (current_vapp_state)
58
- when "ovf_uploaded"
59
- Test::Response::VAPP_TEMPLATE_NO_DISKS_RESPONSE
60
- when "nothing"
61
- Test::Response::VAPP_TEMPLATE_UPLOAD_OVF_WAITING_RESPONSE
62
- when "disks_uploaded"
63
- Test::Response::VAPP_TEMPLATE_UPLOAD_COMPLETE
64
- when "disks_upload_failed"
65
- Test::Response::VAPP_TEMPLATE_UPLOAD_FAILED
66
- when "finalized"
67
- Test::Response::VAPP_TEMPLATE_READY_RESPONSE
68
- end
69
- },
70
- Test::Response::FINALIZE_UPLOAD_TASK_LINK => lambda {
71
- |url, headers|
72
- case (finalize_vapp_task_state)
73
- when "running"
74
- finalize_vapp_task_state = "success"
75
- current_vapp_state = "finalized"
76
- Test::Response::FINALIZE_UPLOAD_TASK_RESPONSE
77
- when "success"
78
- Test::Response::FINALIZE_UPLOAD_TASK_DONE_RESPONSE
79
- end
80
- },
81
- Test::Response::VAPP_TEMPLATE_DELETE_TASK_LINK => lambda {
82
- |url, headers|
83
- case (delete_vapp_template_task_state)
84
- when "running"
85
- delete_vapp_template_task_state = "success"
86
- Test::Response::VAPP_TEMPLATE_DELETE_RUNNING_TASK
87
- when "success"
88
- Test::Response::VAPP_TEMPLATE_DELETE_DONE_TASK
89
- end
90
- },
91
- Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_ITEM_LINK =>
92
- lambda { |url, headers|
93
- Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_ITEM_RESPONSE
94
- },
95
- Test::Response::EXISTING_VAPP_TEMPLATE_LINK => lambda {
96
- |url, headers|
97
- Test::Response::EXISTING_VAPP_TEMPLATE_READY_RESPONSE
98
- },
99
- Test::Response::EXISTING_VAPP_TEMPLATE_INSTANTIATE_TASK_LINK =>
100
- lambda { |url, headers|
101
- case (template_instantiate_state)
102
- when "running"
103
- template_instantiate_state = "success"
104
- Test::Response::
105
- EXISTING_VAPP_TEMPLATE_INSTANTIATE_TASK_START_RESPONSE
106
- when "success"
107
- Test::Response::
108
- EXISTING_VAPP_TEMPLATE_INSTANTIATE_TASK_SUCCESS_RESPONSE
109
- end
110
- },
111
- Test::Response::INSTANTIATED_VAPP_LINK => lambda {
112
- |url, headers|
113
- case(vapp_power_state)
114
- when "off"
115
- Test::Response::INSTANTIAED_VAPP_RESPONSE
116
- when "on"
117
- Test::Response::INSTANTIAED_VAPP_ON_RESPONSE
118
- when "powered-off"
119
- Test::Response::INSTANTIAED_VAPP_POWERED_OFF_RESPONSE
120
- when "suspended"
121
- Test::Response::INSTANTIATED_SUSPENDED_VAPP_RESPONSE
122
- end
123
- },
124
- Test::Response::INSTANTIATED_VAPP_DELETE_TASK_LINK => lambda {
125
- |url, headers|
126
- case (delete_vapp_task_state)
127
- when "running"
128
- delete_vapp_task_state = "success"
129
- Test::Response::INSTANTIATED_VAPP_DELETE_RUNNING_TASK
130
- when "success"
131
- Test::Response::INSTANTIATED_VAPP_DELETE_DONE_TASK
132
- end
133
- },
134
- Test::Response::INSTANTIATED_VM_LINK => lambda { |url, headers|
135
- Test::Response::INSTANTIATED_VM_RESPONSE
136
- },
137
- Test::Response::INSTANTIATED_VM_CPU_LINK => lambda {
138
- |url, headers| Test::Response::INSTANTIATED_VM_CPU_RESPONSE
139
- },
140
- Test::Response::INSTANTIATED_VM_MEMORY_LINK => lambda {
141
- |url, headers| Test::Response::INSTANTIATED_VM_MEMORY_RESPONSE
142
- },
143
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_LINK => lambda {
144
- |url, headers|
145
- case(change_vm_task_state)
146
- when "running"
147
- change_vm_task_state = "success"
148
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
149
- when "success"
150
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_SUCCESS
151
- end
152
- },
153
- Test::Response::EXISTING_VAPP_LINK => lambda { |url, headers|
154
- Test::Response::INSTANTIAED_VAPP_RESPONSE
155
- },
156
- Test::Response::INSTANTIATED_VAPP_POWER_ON_TASK_LINK => lambda {
157
- |url, headers|
158
- Test::Response::INSTANTED_VAPP_POWER_TASK_SUCCESS
159
- },
160
- Test::Response::ORG_NETWORK_LINK => lambda { |url, headers|
161
- Test::Response::ORG_NETWORK_RESPONSE
162
- },
163
- Test::Response::INSTANTIATED_VAPP_NETWORK_CONFIG_SECTION_LINK =>
164
- lambda { |url, headers|
165
- Test::Response::
166
- INSTANTIATED_VAPP_NETWORK_CONFIG_SECTION_RESPONSE
167
- },
168
- Test::Response::
169
- INSTANTIATED_VAPP_NETWORK_CONFIG_ADD_NETWORK_TASK_LINK =>
170
- lambda { |url, headers|
171
- Test::Response::
172
- INSTANTIATED_VAPP_NETWORK_CONFIG_MODIFY_NETWORK_TASK_SUCCESS
173
- },
174
- Test::Response::INSTANTIATED_VM_NETWORK_SECTION_LINK => lambda {
175
- |url, headers|
176
- Test::Response::INSTANTIATED_VM_NETWORK_SECTION_RESPONSE
177
- },
178
- Test::Response::MEDIA_LINK => lambda { |url, headers|
179
- Test::Response::MEDIA_UPLOAD_PENDING_RESPONSE
180
- },
181
- Test::Response::EXISTING_MEDIA_CATALOG_ITEM_LINK => lambda {
182
- |url, headers| Test::Response::EXISTING_MEDIA_CATALOG_ITEM
183
- },
184
- Test::Response::EXISTING_MEDIA_LINK => lambda { |url, headers|
185
- case(existing_media_state)
186
- when "busy"
187
- existing_media_state = "done"
188
- Test::Response::EXISTING_MEDIA_BUSY_RESPONSE
189
- when "done"
190
- Test::Response::EXISTING_MEDIA_DONE_RESPONSE
191
- end
192
- },
193
- Test::Response::METADATA_SET_LINK => lambda { |url, headers|
194
- metadata_xml
195
- },
196
- Test::Response::INDY_DISK_URL => lambda { |url, headers|
197
- Test::Response::INDY_DISK_RESPONSE
198
- },
199
- Test::Response::EXISTING_VAPP_RESOLVER_URL => lambda {
200
- |url,headers| Test::Response::EXISTING_VAPP_RESOLVER_RESPONSE
201
- },
202
- Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_RESOLVER_URL =>
203
- lambda { |url,headers|
204
- Test::Response::
205
- EXISTING_VAPP_TEMPLATE_CATALOG_RESOLVER_RESPONSE
206
- },
207
- Test::Response::VAPP_TEMPLATE_CATALOG_RESOLVER_URL => lambda {
208
- |url,headers|
209
- Test::Response::VAPP_TEMPLATE_CATALOG_RESOLVER_RESPONSE
210
- }
211
- },
212
- :post => {
213
- Test::Response::LOGIN_LINK => lambda { |url, data, headers|
214
- session_object = Test::Response::SESSION
215
-
216
- def session_object.cookies
217
- {"vcloud-token" =>
218
- VCloudSdk::Test::vcd_settings["testing"]["cookies"]}
219
- end
220
-
221
- session_object
222
- },
223
- Test::Response::VDC_VAPP_UPLOAD_LINK => lambda {
224
- |url, data, headers|
225
- current_vapp_state = "nothing"
226
- Test::Response::VAPP_TEMPLATE_UPLOAD_OVF_WAITING_RESPONSE
227
- },
228
- Test::Response::CATALOG_ADD_ITEM_LINK => lambda {
229
- |url, data, headers|
230
- case(Xml::WrapperFactory.wrap_document(data))
231
- when Xml::WrapperFactory.wrap_document(
232
- Test::Response::CATALOG_ADD_VAPP_REQUEST)
233
- catalog_state = "added"
234
- Test::Response::CATALOG_ADD_ITEM_RESPONSE
235
- when Xml::WrapperFactory.wrap_document(
236
- Test::Response::MEDIA_ADD_TO_CATALOG_REQUEST)
237
- catalog_state = "added"
238
- Test::Response::MEDIA_ADD_TO_CATALOG_RESPONSE
239
- else
240
- Config.logger.error("Response mapping not found for " +
241
- "POST and #{url} and #{data}")
242
- raise "Response mapping not found."
243
- end
244
- },
245
- Test::Response::VAPP_TEMPLATE_INSTANTIATE_LINK => lambda {
246
- |url, data, headers|
247
- Test::Response::EXISTING_VAPP_TEMPLATE_INSTANTIATE_RESPONSE
248
- },
249
- Test::Response::RECONFIGURE_VM_LINK => lambda {
250
- |url, data, headers|
251
- Test::Response::RECONFIGURE_VM_TASK
252
- },
253
- Test::Response::INSTANTIATED_VAPP_POWER_ON_LINK => lambda {
254
- |url, data, headers|
255
- vapp_power_state = "on"
256
- Test::Response::INSTANTED_VAPP_POWER_TASK_RUNNING
257
- },
258
- Test::Response::INSTANTIATED_VAPP_POWER_OFF_LINK => lambda {
259
- |url, data, headers|
260
- vapp_power_state = "powered-off"
261
- Test::Response::INSTANTED_VAPP_POWER_TASK_RUNNING
262
- },
263
- Test::Response::INSTANTIATED_VAPP_POWER_REBOOT_LINK => lambda {
264
- |url, data, headers|
265
- vapp_power_state = "on"
266
- Test::Response::INSTANTED_VAPP_POWER_TASK_RUNNING
267
- },
268
- Test::Response::INSTANTIATED_VAPP_UNDEPLOY_LINK => lambda {
269
- |url, data, headers|
270
- vapp_power_state = "off"
271
- Test::Response::INSTANTED_VAPP_POWER_TASK_RUNNING
272
- },
273
- Test::Response::INSTANTIATED_VAPP_DISCARD_STATE_LINK => lambda {
274
- |url, data, headers|
275
- vapp_power_state = "off"
276
- Test::Response::INSTANTED_VAPP_POWER_TASK_RUNNING
277
- },
278
- Test::Response::MEDIA_UPLOAD_LINK => lambda {
279
- |url, data, headers|
280
- Test::Response::MEDIA_UPLOAD_PENDING_RESPONSE
281
- },
282
- Test::Response::INSTANTIATED_VM_INSERT_MEDIA_LINK => lambda {
283
- |url, data, headers|
284
- Test::Response::INSTANTIATED_VM_INSERT_MEDIA_TASK_DONE
285
- },
286
- Test::Response::VDC_INDY_DISKS_LINK => lambda {
287
- |url, data, headers|
288
- Test::Response::INDY_DISK_CREATE_RESPONSE
289
- },
290
- Test::Response::INSTANTIATED_VM_ATTACH_DISK_LINK => lambda {
291
- |url, data, headers|
292
- Test::Response::INDY_DISK_ATTACH_TASK
293
- }
294
- },
295
- :put => {
296
- Test::Response::VAPP_TEMPLATE_UPLOAD_OVF_LINK => lambda {
297
- |url, data, headers|
298
- current_vapp_state = "ovf_uploaded"
299
- ""
300
- },
301
- Test::Response::INSTANTIATED_VM_CPU_LINK => lambda {
302
- |url, data, headers|
303
- change_vm_task_state = "running"
304
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
305
- },
306
- Test::Response::INSTANTIATED_VM_MEMORY_LINK => lambda {
307
- |url, data, headers|
308
- change_vm_task_state = "running"
309
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
310
- },
311
- Test::Response::INSTANTIATED_VM_LINK => lambda {
312
- |url, data, headers|
313
- change_vm_task_state = "running"
314
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
315
- },
316
- Test::Response::INSTANTIATED_VM_HARDWARE_SECTION_LINK =>
317
- lambda { |url, data, headers|
318
- change_vm_task_state = "running"
319
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
320
- },
321
- Test::Response::INSTANTIATED_VAPP_NETWORK_CONFIG_SECTION_LINK =>
322
- lambda { |url, data, headers|
323
- Test::Response::
324
- INSTANTIATED_VAPP_NETWORK_CONFIG_MODIFY_NETWORK_TASK_SUCCESS
325
- },
326
- Test::Response::INSTANTIATED_VM_NETWORK_SECTION_LINK => lambda {
327
- |url, data, headers|
328
- change_vm_task_state = "running"
329
- Test::Response::INSTANTIATED_VM_MODIFY_TASK_RUNNING
330
- },
331
- Test::Response::METADATA_SET_LINK => lambda {
332
- |url, data, headers|
333
- received = Xml::WrapperFactory.wrap_document(data)
334
- metadata_value = received.value
335
- metadata_xml = data
336
- Test::Response::METADATA_SET_TASK_DONE
337
- }
338
- },
339
- :delete => {
340
- Test::Response::VAPP_TEMPLATE_LINK => lambda { |url, headers|
341
- Test::Response::VAPP_TEMPLATE_DELETE_RUNNING_TASK
342
- },
343
- Test::Response::INSTANTIATED_VAPP_LINK => lambda {
344
- |url, headers|
345
- Test::Response::INSTANTIATED_VAPP_DELETE_RUNNING_TASK
346
- },
347
- Test::Response::CATALOG_ITEM_VAPP_LINK => lambda {
348
- |url, headers|
349
- nil
350
- },
351
- Test::Response::EXISTING_MEDIA_LINK => lambda { |url, headers|
352
- Test::Response::EXISTING_MEDIA_DELETE_TASK_DONE
353
- },
354
- Test::Response::EXISTING_MEDIA_CATALOG_ITEM_LINK => lambda {
355
- |url, headers|
356
- nil
357
- },
358
- Test::Response::MEDIA_LINK => lambda { |url, headers|
359
- Test::Response::MEDIA_DELETE_TASK_DONE
360
- },
361
- Test::Response::INDY_DISK_URL => lambda { |url, headers|
362
- Test::Response::INDY_DISK_DELETE_TASK
363
- },
364
- }
365
- }
366
-
367
- #Working around Ruby 1.8"s lack of define_singleton_method
368
- metaclass = class << response_mapping;
369
- self;
370
- end
371
-
372
- metaclass.send :define_method, :get_mapping do |http_method, url|
373
- mapping = self[http_method][url]
374
- if mapping.nil?
375
- Config.logger.error("Response mapping not found for " +
376
- "#{http_method} and #{url}")
377
- # string substitution doesn"t work here for some reason
378
- raise "Response mapping not found."
379
- else
380
- mapping
381
- end
382
- end
383
-
384
- rest_client.stub(:get) do |headers|
385
- response_mapping.get_mapping(:get, build_url).call(build_url, headers)
386
- end
387
- rest_client.stub(:post) do |data, headers|
388
- response_mapping.get_mapping(:post, build_url).call(build_url, data,
389
- headers)
390
- end
391
- rest_client.stub(:put) do |data, headers|
392
- response_mapping.get_mapping(:put, build_url).call(build_url, data,
393
- headers)
394
- end
395
- rest_client.stub(:delete) do |headers|
396
- response_mapping.get_mapping(:delete, build_url).call(build_url,
397
- headers)
398
- end
399
- rest_client.stub(:vapp_state=) do |value|
400
- current_vapp_state = value
401
- end
402
- rest_client.stub(:vapp_state) do
403
- current_vapp_state
404
- end
405
- rest_client.stub(:response_mapping) do
406
- response_mapping
407
- end
408
- rest_client.stub(:vapp_power_state=) do |value|
409
- vapp_power_state = value
410
- end
411
- rest_client.stub(:[]) do |value|
412
- @resource = value
413
- @rest_connection
414
- end
415
-
416
- rest_client
417
- end
418
-
419
- def build_url
420
- url + @resource
421
- end
422
-
423
- def nested(url)
424
- URI.parse(url).path
425
- end
426
-
427
- class MockRestClient
428
- class << self
429
- attr_accessor :log
430
- end
431
- end
432
-
433
- def create_mock_client
434
- @rest_connection = mock_rest_connection()
435
- file_uploader = mock("File Uploader")
436
- file_uploader.stub(:upload) do
437
- @rest_connection.vapp_state = @upload_file_state == "success" ?
438
- "disks_uploaded" : "disks_upload_failed"
439
- end
440
- conn = Connection::Connection.new(url, entities["organization"],
441
- control["time_limit_sec"]["http_request"], MockRestClient,
442
- @rest_connection, file_uploader)
443
- conn.stub(:file_uploader) do
444
- file_uploader
445
- end
446
- conn.stub(:rest_connection) do
447
- @rest_connection
448
- end
449
- conn
450
- end
451
-
452
- def create_mock_ovf_directory(string_io)
453
- directory = mock("Directory")
454
- # Actual content of the OVF is irrelevant as long as the client gives
455
- # back the same one given to it
456
- ovf_string = "ovf_string"
457
- ovf_string_io = StringIO.new(ovf_string)
458
- directory.stub(:ovf_file_path) { "ovf_file" }
459
- directory.stub(:ovf_file) {
460
- ovf_string_io
461
- }
462
- directory.stub(:vmdk_file_path) do |file_name|
463
- file_name
464
- end
465
- directory.stub(:vmdk_file) do |file_name|
466
- string_io
467
- end
468
- directory
469
- end
470
-
471
- def create_mock_media_file()
472
- media_string = Test::Response::MEDIA_CONTENT
473
- string_io = StringIO.new(media_string)
474
- string_io.stub(:path) { "bogus/bogus.iso" }
475
- string_io.stub(:stat) {
476
- o = Object.new
477
- o.stub(:size) { media_string.length }
478
- o
479
- }
480
- string_io
481
- end
482
-
483
-
484
- describe "VCD Adapter client", :positive, :min, :all do
485
- it "logs into organization with usename and password and get the " +
486
- "organization VDC" do
487
- conn = mock("Connection")
488
- root_session = Xml::WrapperFactory.wrap_document(
489
- Test::Response::SESSION)
490
- vcloud_response = Xml::WrapperFactory.wrap_document(
491
- Test::Response::VCLOUD_RESPONSE)
492
- admin_org_response = Xml::WrapperFactory.wrap_document(
493
- Test::Response::ADMIN_ORG_RESPONSE)
494
- vdc_response = Xml::WrapperFactory.wrap_document(
495
- Test::Response::VDC_RESPONSE)
496
- conn.should_receive(:connect).with(username, password).and_return(
497
- root_session)
498
- conn.should_receive(:get).with(root_session.admin_root).and_return(
499
- vcloud_response)
500
- conn.should_receive(:get).with(vcloud_response.organization(
501
- entities["organization"])).and_return(admin_org_response)
502
- Client.new(nil, username, password, entities, control, conn)
503
- end
504
- end
505
-
506
- describe "VCD Adapter client", :upload, :all do
507
- it "uploads an OVF to the OVDC", :positive do
508
- vmdk_string = "vmdk"
509
- vmdk_string_io = StringIO.new(vmdk_string)
510
- directory = create_mock_ovf_directory(vmdk_string_io)
511
-
512
- conn = create_mock_client
513
-
514
- vapp_name = Test::Response::VAPP_TEMPLATE_NAME
515
-
516
- client = Client.new(nil, username, password, entities, control, conn)
517
-
518
- conn.file_uploader.should_receive(:upload).with(
519
- Test::Response::VAPP_TEMPLATE_DISK_UPLOAD_1, vmdk_string_io,
520
- auth_cookies)
521
- catalog_item = client.upload_vapp_template(vapp_name, directory)
522
- # Since the wrapper classes are used to hide away the raw XML,
523
- # compare the wrapped versions
524
- catalog_item.should eq(Xml::WrapperFactory.wrap_document(
525
- Test::Response::CATALOG_ADD_ITEM_RESPONSE))
526
- end
527
-
528
- it "reports an exception upon error in transferring an OVF file",
529
- :negative do
530
- vmdk_string = "vmdk"
531
- vmdk_string_io = StringIO.new(vmdk_string)
532
- directory = create_mock_ovf_directory(vmdk_string_io)
533
-
534
- conn = create_mock_client
535
- @upload_file_state = "failed"
536
- vapp_name = Test::Response::VAPP_TEMPLATE_NAME
537
- client = Client.new(nil, username, password, entities, control, conn)
538
-
539
- conn.file_uploader.should_receive(:upload).with(
540
- Test::Response::VAPP_TEMPLATE_DISK_UPLOAD_1, vmdk_string_io,
541
- auth_cookies)
542
- expect {
543
- client.upload_vapp_template(vapp_name, directory)
544
- }.to raise_exception("Error uploading vApp template")
545
- @upload_file_state = "success"
546
- end
547
-
548
- it "deletes the vApp template if there's an error uploading it to " +
549
- "the catalog", :negative do
550
- vmdk_string = "vmdk"
551
- vmdk_string_io = StringIO.new(vmdk_string)
552
- directory = create_mock_ovf_directory(vmdk_string_io)
553
-
554
- conn = create_mock_client
555
- conn.rest_connection.response_mapping[:post][
556
- Test::Response::CATALOG_ADD_ITEM_LINK] =
557
- lambda { |url, data, headers|
558
- raise ApiError, "Bogus add to catalog error"
559
- }
560
- vapp_name = Test::Response::VAPP_TEMPLATE_NAME
561
- conn.rest_connection.should_receive(:[]).with(
562
- nested(Test::Response::VAPP_TEMPLATE_LINK))
563
- conn.rest_connection.should_receive(:delete).with(anything())
564
- client = Client.new(nil, username, password, entities, control, conn)
565
- expect {
566
- client.upload_vapp_template(vapp_name, directory)
567
- }.to raise_exception("Bogus add to catalog error")
568
- end
569
-
570
- end
571
-
572
- describe "VCD Adapter client", :delete, :all do
573
- it "deletes a vApp template from the catalog", :positive do
574
- vmdk_string = "vmdk"
575
- vmdk_string_io = StringIO.new(vmdk_string)
576
- directory = create_mock_ovf_directory(vmdk_string_io)
577
-
578
- conn = create_mock_client
579
- client = Client.new(nil, username, password, entities, control, conn)
580
- vapp_name = Test::Response::VAPP_TEMPLATE_NAME
581
- conn.rest_connection.should_receive(:[]).with(
582
- nested(Test::Response::VAPP_TEMPLATE_LINK))
583
- conn.rest_connection.should_receive(:delete).with(anything())
584
- catalog_item = client.upload_vapp_template(vapp_name, directory)
585
- client.delete_catalog_vapp(catalog_item.urn)
586
- end
587
-
588
- it "no exception for delete catalog vapp if the vApp does not exist",
589
- :negative do
590
- conn = create_mock_client
591
- client = Client.new(nil, username, password, entities, control, conn)
592
- client.delete_catalog_vapp("bogus")
593
- end
594
-
595
- it "raise exception for upload media to catalog if the catalog does " +
596
- "not exist", :negative do
597
- conn = create_mock_client
598
- ent_clone = entities.clone
599
- ent_clone["media_catalog"] = "bogus"
600
- media_file = create_mock_media_file()
601
- client = Client.new(nil, username, password, ent_clone, control, conn)
602
- media_name = Test::Response::MEDIA_NAME
603
-
604
- conn.file_uploader.stub(:upload) do |href, data, headers|
605
- href.should eq(Test::Response::MEDIA_ISO_LINK)
606
- data.read.should eq(Test::Response::MEDIA_CONTENT)
607
- end
608
- conn.rest_connection.should_receive(:[]).with(
609
- nested(Test::Response::MEDIA_LINK))
610
- conn.rest_connection.should_receive(:delete).with(anything())
611
- expect {
612
- client.upload_catalog_media(media_name, media_file)
613
- }.to raise_exception(/.+ catalog .+ not found\./)
614
- end
615
-
616
- it "should not raise if underlying vApp no longer exists when " +
617
- "deleting a vApp from the catalog", :negative do
618
- conn = create_mock_client
619
- client = Client.new(nil, username, password, entities, control, conn)
620
- conn.rest_connection.response_mapping[:delete][
621
- Test::Response::VAPP_TEMPLATE_LINK] = lambda { |urls, headers|
622
- raise RestClient::ResourceNotFound
623
- }
624
- client.delete_catalog_vapp(Test::Response::VAPP_TEMPLATE_NAME)
625
- end
626
- end
627
-
628
- describe "VCD Adapter client", :instantiate_template, :all do
629
- it "instantiates a vApp from the catalog", :positive do
630
- conn = create_mock_client
631
- client = Client.new(nil, username, password, entities, control, conn)
632
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
633
- vapp_name = Test::Response::VAPP_NAME
634
- conn.rest_connection.should_receive(:[]).with(
635
- nested(Test::Response::VAPP_TEMPLATE_INSTANTIATE_LINK))
636
- conn.rest_connection.should_receive(:post).with(
637
- Test::Response::EXISTING_VAPP_TEMPLATE_INSTANTIATE_REQUEST,
638
- anything())
639
- client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
640
- end
641
-
642
- it "instantiates with locality a vApp from the catalog", :positive do
643
- conn = create_mock_client
644
- client = Client.new(nil, username, password, entities, control, conn)
645
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
646
- vapp_name = Test::Response::VAPP_NAME
647
- conn.rest_connection.should_receive(:[]).with(
648
- nested(Test::Response::VAPP_TEMPLATE_INSTANTIATE_LINK))
649
- conn.rest_connection.should_receive(:post).with(
650
- Test::Response::
651
- EXISTING_VAPP_TEMPLATE_INSTANTIATE_WITH_LOCALITY_REQUEST,
652
- anything())
653
- client.instantiate_vapp_template(catalog_vapp_id, vapp_name, "desc",
654
- [ Test::Response::INDY_DISK_URL ])
655
- end
656
-
657
- it "instantiates raises an exception if the task fails", :negative do
658
- conn = create_mock_client
659
- client = Client.new(nil, username, password, entities, control, conn)
660
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
661
- vapp_name = Test::Response::VAPP_NAME
662
- conn.rest_connection.response_mapping[:get][
663
- Test::Response::EXISTING_VAPP_TEMPLATE_INSTANTIATE_TASK_LINK] =
664
- lambda { |url, headers|
665
- Test::Response::
666
- EXISTING_VAPP_TEMPLATE_INSTANTIATE_TASK_ERROR_RESPONSE
667
- }
668
- conn.rest_connection.should_receive(:[]).with(
669
- nested(Test::Response::INSTANTIATED_VAPP_LINK))
670
- conn.rest_connection.should_receive(:delete).with(anything())
671
- expect {
672
- client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
673
- }.to raise_exception(/.+Creating Virtual.+did not complete success.+/)
674
- end
675
-
676
- end
677
-
678
- describe "VCD Adapter client", :modify_vm, :all do
679
- it "reconfigures a VM", :positive do
680
- conn = create_mock_client
681
- client = Client.new(nil, username, password, entities, control, conn)
682
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
683
- vapp_name = Test::Response::VAPP_NAME
684
- conn.rest_connection.should_receive(:[]).with(
685
- nested(Test::Response::RECONFIGURE_VM_LINK))
686
- conn.rest_connection.should_receive(:post).with(
687
- Test::Response::RECONFIGURE_VM_REQUEST, anything())
688
- vapp = client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
689
- vm = vapp.vms.first
690
- client.reconfigure_vm(vm) do |v|
691
- vm.name = Test::Response::CHANGED_VM_NAME
692
- vm.description = Test::Response::CHANGED_VM_DESCRIPTION
693
- v.change_cpu_count(Test::Response::CHANGED_VM_CPU)
694
- v.change_memory(Test::Response::CHANGED_VM_MEMORY)
695
- v.add_hard_disk(Test::Response::CHANGED_VM_DISK)
696
- v.delete_nic(*vm.hardware_section.nics)
697
- end
698
- end
699
-
700
- it "gets information on HD", :positive do
701
- conn = create_mock_client
702
- client = Client.new(nil, username, password, entities, control, conn)
703
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
704
- vm = vapp.vms.first
705
- vm.hardware_section.hard_disks.each do |h|
706
- h.capacity_mb.should_not be_nil
707
- h.disk_id.should_not be_nil
708
- h.bus_sub_type.should_not be_nil
709
- h.bus_type.should_not be_nil
710
- end
711
-
712
- vm.hardware_section.nics.each do |n|
713
- n.mac_address.should_not be_nil
714
- end
715
-
716
- end
717
-
718
- end
719
-
720
- describe "VCD Adapter client", :power_vapp, :all do
721
- it "finds and powers on a vApp and powers it off" , :positive do
722
- conn = create_mock_client
723
- client = Client.new(nil, username, password, entities, control, conn)
724
-
725
- conn.rest_connection.should_receive(:[]).with(
726
- nested(Test::Response::INSTANTIATED_VAPP_POWER_ON_LINK))
727
- conn.rest_connection.should_receive(:post).with(
728
- anything(), anything())
729
- conn.rest_connection.should_receive(:[]).with(
730
- nested(Test::Response::INSTANTIATED_VAPP_POWER_OFF_LINK))
731
- conn.rest_connection.should_receive(:post).with(
732
- anything(), anything())
733
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
734
- client.power_on_vapp(vapp)
735
- client.power_off_vapp(vapp, false)
736
- end
737
-
738
- it "finds and powers on a powered-on vApp" , :negative do
739
- conn = create_mock_client
740
- client = Client.new(nil, username, password, entities, control, conn)
741
-
742
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
743
- client.power_on_vapp(vapp)
744
- conn.rest_connection.should_not_receive(:[]).with(
745
- nested(Test::Response::INSTANTIATED_VAPP_POWER_ON_LINK))
746
- conn.rest_connection.should_not_receive(:post).with(
747
- anything(), anything())
748
- client.power_on_vapp(vapp)
749
- end
750
-
751
- it "finds and powers off a powered-off vApp" , :negative do
752
- conn = create_mock_client
753
- client = Client.new(nil, username, password, entities, control, conn)
754
-
755
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
756
- client.power_off_vapp(vapp, false)
757
- conn.rest_connection.should_not_receive(:[]).with(
758
- nested(Test::Response::INSTANTIATED_VAPP_POWER_OFF_LINK))
759
- conn.rest_connection.should_not_receive(:post).with(
760
- anything(), anything())
761
- client.power_off_vapp(vapp, false)
762
- end
763
-
764
- it "finds and powers on a vApp and undeploys it" , :positive do
765
- conn = create_mock_client
766
- client = Client.new(nil, username, password, entities, control, conn)
767
-
768
- conn.rest_connection.should_receive(:[]).with(
769
- nested(Test::Response::INSTANTIATED_VAPP_POWER_ON_LINK))
770
- conn.rest_connection.should_receive(:post).with(
771
- anything(), anything())
772
- conn.rest_connection.should_receive(:[]).with(
773
- nested(Test::Response::INSTANTIATED_VAPP_UNDEPLOY_LINK))
774
- conn.rest_connection.should_receive(:post).with(
775
- anything(), anything())
776
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
777
- client.power_on_vapp(vapp)
778
- client.power_off_vapp(vapp)
779
- end
780
-
781
- it "finds and undeploys an undeployed vapp" , :negative do
782
- conn = create_mock_client
783
- client = Client.new(nil, username, password, entities, control, conn)
784
-
785
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
786
- client.power_off_vapp(vapp)
787
- conn.rest_connection.should_not_receive(:[]).with(
788
- nested(Test::Response::INSTANTIATED_VAPP_UNDEPLOY_LINK))
789
- conn.rest_connection.should_not_receive(:post).with(
790
- anything(), anything())
791
- client.power_off_vapp(vapp)
792
- end
793
-
794
- it "finds and undeploys a powered-off vapp" , :positive do
795
- conn = create_mock_client
796
- client = Client.new(nil, username, password, entities, control, conn)
797
-
798
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
799
- client.power_on_vapp(vapp)
800
- client.power_off_vapp(vapp, false)
801
- conn.rest_connection.should_receive(:[]).with(
802
- nested(Test::Response::INSTANTIATED_VAPP_UNDEPLOY_LINK))
803
- conn.rest_connection.should_receive(:post).with(
804
- Test::Response::UNDEPLOY_PARAMS, anything())
805
- client.power_off_vapp(vapp)
806
- end
807
-
808
- it "discards state of a suspended vapp" , :positive do
809
- conn = create_mock_client
810
- client = Client.new(nil, username, password, entities, control, conn)
811
-
812
- conn.rest_connection.response_mapping[:get][
813
- Test::Response::EXISTING_VAPP_LINK] = lambda { |url, headers|
814
- Test::Response::INSTANTIATED_SUSPENDED_VAPP_RESPONSE }
815
- conn.rest_connection.vapp_power_state = "suspended"
816
-
817
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
818
- conn.rest_connection.should_receive(:[]).with(
819
- nested(Test::Response::INSTANTIATED_VAPP_DISCARD_STATE_LINK))
820
- conn.rest_connection.should_receive(:post).with(
821
- anything(), anything())
822
-
823
- client.discard_suspended_state_vapp(vapp)
824
- end
825
-
826
- it "finds and powers on a vApp and reboots it" , :positive do
827
- conn = create_mock_client
828
- client = Client.new(nil, username, password, entities, control, conn)
829
-
830
- conn.rest_connection.should_receive(:[]).with(
831
- nested(Test::Response::INSTANTIATED_VAPP_POWER_ON_LINK))
832
- conn.rest_connection.should_receive(:post).with(
833
- anything(), anything())
834
- conn.rest_connection.should_receive(:[]).with(
835
- nested(Test::Response::INSTANTIATED_VAPP_POWER_REBOOT_LINK))
836
- conn.rest_connection.should_receive(:post).with(
837
- anything(), anything())
838
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
839
- client.power_on_vapp(vapp)
840
- client.reboot_vapp(vapp)
841
- end
842
-
843
- it "reboot of a powered-off vApp raises an exception" , :positive do
844
- conn = create_mock_client
845
- client = Client.new(nil, username, password, entities, control, conn)
846
-
847
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
848
- expect {
849
- client.reboot_vapp(vapp)
850
- }.to raise_exception(VappPoweredOffError)
851
- end
852
-
853
- it "reboot of a suspended vApp raises an exception" , :positive do
854
- conn = create_mock_client
855
- client = Client.new(nil, username, password, entities, control, conn)
856
- conn.rest_connection.vapp_power_state = "suspended"
857
-
858
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
859
- expect {
860
- client.reboot_vapp(vapp)
861
- }.to raise_exception(VappSuspendedError)
862
- end
863
- end
864
-
865
- describe "VCD Adapter client", :delete_vapp, :all do
866
- it "finds a vApp and deletes it without undeploying", :positive do
867
- conn = create_mock_client
868
- client = Client.new(nil, username, password, entities, control, conn)
869
-
870
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
871
- conn.rest_connection.should_not_receive(:[]).with(
872
- nested(Test::Response::INSTANTIATED_VAPP_UNDEPLOY_LINK))
873
- conn.rest_connection.should_not_receive(:post).with(
874
- anything(), anything())
875
- conn.rest_connection.should_receive(:[]).with(
876
- nested(Test::Response::INSTANTIATED_VAPP_LINK))
877
- conn.rest_connection.should_receive(:delete).with(anything())
878
- client.delete_vapp(vapp)
879
- end
880
-
881
- it "finds and powers on a vApp and fails on delete vApp", :negative do
882
- conn = create_mock_client
883
- client = Client.new(nil, username, password, entities, control, conn)
884
-
885
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
886
- client.power_on_vapp(vapp)
887
- conn.rest_connection.should_receive(:[]).once.with(
888
- nested(Test::Response::INSTANTIATED_VAPP_LINK))
889
- conn.rest_connection.should_not_receive(:delete).with(anything())
890
- expect {
891
- client.delete_vapp(vapp)
892
- }.to raise_exception(/vApp .+ powered on, power-off before deleting./)
893
- end
894
- end
895
-
896
- describe "VCD Adapter client", :add_vapp_network, :all do
897
- it "finds a network and vapp and adds the network to the vApp",
898
- :positive do
899
- conn = create_mock_client
900
- client = Client.new(nil, username, password, entities, control, conn)
901
-
902
- network_name = Test::Response::ORG_NETWORK_NAME
903
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
904
- network = client.get_ovdc.available_networks.find {
905
- |n| n["name"] == network_name }
906
- conn.rest_connection.should_receive(:[]).with(nested(
907
- Test::Response::INSTANTIATED_VAPP_NETWORK_CONFIG_SECTION_LINK))
908
- conn.rest_connection.should_receive(:put).with(Test::Response::
909
- INSTANTIATED_VAPP_NETWORK_CONFIG_ADD_NETWORK_REQUEST,
910
- anything())
911
- client.add_network(vapp, network)
912
- end
913
-
914
- it "removes all networks", :positive do
915
- conn = create_mock_client
916
- client = Client.new(nil, username, password, entities, control, conn)
917
-
918
- conn.rest_connection.response_mapping[:put][
919
- Test::Response::INSTANTIATED_VAPP_NETWORK_CONFIG_SECTION_LINK] =
920
- lambda { |url, data, headers|
921
- expected = Xml::WrapperFactory.wrap_document(
922
- Test::Response::
923
- INSTANTIATED_VAPP_NETWORK_CONFIG_REMOVE_NETWORK_REQUEST)
924
- received = Xml::WrapperFactory.wrap_document(data)
925
- received.should eq(expected)
926
- Test::Response::
927
- INSTANTIATED_VAPP_NETWORK_CONFIG_MODIFY_NETWORK_TASK_SUCCESS
928
- }
929
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
930
- client.delete_networks(vapp)
931
- end
932
- end
933
-
934
- describe "VCD Adapter client", :add_remove_insert_media, :all do
935
- it "uploads media to VDC and adds it to the catalog", :positive do
936
- conn = create_mock_client
937
- media_file = create_mock_media_file()
938
- client = Client.new(nil, username, password, entities, control, conn)
939
- media_name = Test::Response::MEDIA_NAME
940
-
941
- conn.file_uploader.stub(:upload) do |href, data, headers|
942
- href.should eq(Test::Response::MEDIA_ISO_LINK)
943
- data.read.should eq(Test::Response::MEDIA_CONTENT)
944
- end
945
-
946
- conn.rest_connection.should_receive(:[]).with(
947
- nested(Test::Response::CATALOG_ADD_ITEM_LINK))
948
- conn.rest_connection.should_receive(:post).with(
949
- Test::Response::MEDIA_ADD_TO_CATALOG_REQUEST, anything())
950
-
951
- client.upload_catalog_media(media_name, media_file)
952
-
953
- end
954
-
955
- it "deletes a media from catalog and the VDC", :positive do
956
- conn = create_mock_client
957
- client = Client.new(nil, username, password, entities, control, conn)
958
- media_name = Test::Response::EXISTING_MEDIA_NAME
959
-
960
- conn.rest_connection.should_receive(:[]).with(
961
- nested(Test::Response::EXISTING_MEDIA_LINK))
962
- conn.rest_connection.should_receive(:delete).with(anything())
963
- conn.rest_connection.should_receive(:[]).with(
964
- nested(Test::Response::EXISTING_MEDIA_CATALOG_ITEM_LINK))
965
- conn.rest_connection.should_receive(:delete).with(anything())
966
- client.delete_catalog_media(media_name)
967
-
968
- end
969
-
970
- it "uploads media to VDC, fails to add to catalog, and rolls back",
971
- :negative do
972
- conn = create_mock_client
973
- media_file = create_mock_media_file()
974
- client = Client.new(nil, username, password, entities, control, conn)
975
- media_name = Test::Response::MEDIA_NAME
976
-
977
- conn.rest_connection.response_mapping[:post][
978
- Test::Response::CATALOG_ADD_ITEM_LINK] = lambda {
979
- |url, data, headers|
980
- raise ApiError, "bogus error"
981
- }
982
-
983
- conn.rest_connection.should_receive(:[]).with(
984
- nested(Test::Response::MEDIA_LINK))
985
- conn.rest_connection.should_receive(:delete).with(anything())
986
- expect {
987
- client.upload_catalog_media(media_name, media_file)
988
- }.to raise_exception(/bogus error/)
989
-
990
- end
991
-
992
- it "inserts a media into a VM", :positive do
993
- conn = create_mock_client
994
-
995
- client = Client.new(nil, username, password, entities, control, conn)
996
- media_name = Test::Response::EXISTING_MEDIA_NAME
997
-
998
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
999
- vapp_name = Test::Response::VAPP_NAME
1000
-
1001
- vapp = client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
1002
- vm = vapp.vms.first
1003
- client.insert_catalog_media(vm, media_name)
1004
-
1005
- end
1006
-
1007
- end
1008
-
1009
- describe "VCD Adapter client", :metadata, :all do
1010
- it "sets and gets metadata on a VM", :positive do
1011
- conn = create_mock_client
1012
-
1013
- client = Client.new(nil, username, password, entities, control, conn)
1014
-
1015
- metadata_key = Test::Response::METADATA_KEY
1016
- metadata_value = Test::Response::METADATA_VALUE
1017
- vapp = client.get_vapp(Test::Response::EXISTING_VAPP_URN)
1018
- vm = vapp.vms.first
1019
- client.set_metadata(vm, metadata_key, metadata_value)
1020
- value = client.get_metadata(vm, metadata_key)
1021
- value.should eq metadata_value
1022
- end
1023
-
1024
- end
1025
-
1026
- describe "VCD Adapter client", :indy_disk, :all do
1027
- it "creates an indepdent disk", :positive do
1028
- disk_name = Test::Response::INDY_DISK_NAME
1029
- disk_size = Test::Response::INDY_DISK_SIZE
1030
-
1031
- conn = create_mock_client
1032
-
1033
- client = Client.new(nil, username, password, entities, control, conn)
1034
-
1035
- conn.rest_connection.should_receive(:[]).with(
1036
- nested(Test::Response::VDC_INDY_DISKS_LINK))
1037
- conn.rest_connection.should_receive(:post).with(
1038
- Test::Response::INDY_DISK_CREATE_REQUEST, anything())
1039
-
1040
- client.create_disk(disk_name, disk_size)
1041
-
1042
- end
1043
-
1044
- it "creates an indepdent disk but hits an error", :negative do
1045
- disk_name = Test::Response::INDY_DISK_NAME
1046
- disk_size = Test::Response::INDY_DISK_SIZE
1047
-
1048
- conn = create_mock_client
1049
-
1050
- client = Client.new(nil, username, password, entities, control, conn)
1051
-
1052
- conn.rest_connection.response_mapping[:post][
1053
- Test::Response::VDC_INDY_DISKS_LINK] = lambda {
1054
- |href, data, headers|
1055
- Test::Response::INDY_DISK_CREATE_ERROR
1056
- }
1057
- expect {
1058
- client.create_disk(disk_name, disk_size)
1059
- }.to raise_exception(ApiRequestError)
1060
-
1061
- end
1062
-
1063
- it "attaches an indepdent disk to a VM and then detaches", :positive do
1064
- disk_name = Test::Response::INDY_DISK_NAME
1065
-
1066
- conn = create_mock_client
1067
-
1068
- client = Client.new(nil, username, password, entities, control, conn)
1069
-
1070
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
1071
- vapp_name = Test::Response::VAPP_NAME
1072
-
1073
- vapp = client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
1074
- vm = vapp.vms.first
1075
-
1076
- vdc = client.get_ovdc()
1077
- disk = vdc.disks(disk_name).first
1078
-
1079
- conn.rest_connection.response_mapping[:post][
1080
- Test::Response::INSTANTIATED_VM_ATTACH_DISK_LINK] = lambda {
1081
- |href, data, headers|
1082
- data_xml = Nokogiri::XML(data)
1083
- expected_xml = Nokogiri::XML(
1084
- Test::Response::INDY_DISK_ATTACH_REQUEST)
1085
- equality = VCloudSdk::Test::compare_xml(data_xml, expected_xml)
1086
- equality.should == true
1087
- Test::Response::INDY_DISK_ATTACH_TASK
1088
- }
1089
-
1090
- client.attach_disk(disk, vm)
1091
-
1092
- conn.rest_connection.response_mapping[:post][
1093
- Test::Response::INSTANTIATED_VM_DETACH_DISK_LINK] = lambda {
1094
- |href, data, headers|
1095
- data_xml = Nokogiri::XML(data)
1096
- expected_xml = Nokogiri::XML(
1097
- Test::Response::INDY_DISK_DETACH_REQUEST)
1098
- equality = VCloudSdk::Test::compare_xml(data_xml, expected_xml)
1099
- equality.should == true
1100
- Test::Response::INDY_DISK_DETACH_TASK
1101
- }
1102
-
1103
- client.detach_disk(disk, vm)
1104
-
1105
-
1106
- end
1107
-
1108
- it "attaches an indepdent disk to a VM but has an error", :negative do
1109
- disk_name = Test::Response::INDY_DISK_NAME
1110
-
1111
- conn = create_mock_client
1112
-
1113
- client = Client.new(nil, username, password, entities, control, conn)
1114
-
1115
- catalog_vapp_id = Test::Response::EXISTING_VAPP_TEMPLATE_CATALOG_URN
1116
- vapp_name = Test::Response::VAPP_NAME
1117
-
1118
- vapp = client.instantiate_vapp_template(catalog_vapp_id, vapp_name)
1119
- vm = vapp.vms.first
1120
-
1121
- vdc = client.get_ovdc()
1122
- disk = vdc.disks(disk_name).first
1123
-
1124
- conn.rest_connection.response_mapping[:post][
1125
- Test::Response::INSTANTIATED_VM_ATTACH_DISK_LINK] = lambda {
1126
- |href, data, headers|
1127
- Test::Response::INDY_DISK_ATTACH_TASK_ERROR
1128
- }
1129
-
1130
- expect {
1131
- client.attach_disk(disk, vm)
1132
- }.to raise_exception(/.+ Attaching Disk .+ complete successfully\./)
1133
-
1134
- end
1135
-
1136
- it "deletes an independent disk", :positive do
1137
- disk_name = Test::Response::INDY_DISK_NAME
1138
-
1139
- conn = create_mock_client
1140
- client = Client.new(nil, username, password, entities, control, conn)
1141
- vdc = client.get_ovdc()
1142
- disk = vdc.disks(disk_name).first
1143
- conn.rest_connection.should_receive(:[]).with(
1144
- nested(Test::Response::INDY_DISK_URL))
1145
- conn.rest_connection.should_receive(:delete).with(anything())
1146
- client.delete_disk(disk)
1147
- end
1148
-
1149
- end
1150
-
1151
- end
1152
- end