fog-vcloud-director 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.gitignore +17 -0
  4. data/.hound.yml +2 -0
  5. data/.rubocop.yml +240 -0
  6. data/.ruby-gemset +1 -0
  7. data/.travis.yml +15 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.md +20 -0
  10. data/README.md +962 -0
  11. data/Rakefile +19 -0
  12. data/fog-vcloud-director.gemspec +31 -0
  13. data/lib/fog/vcloud_director.rb +1 -0
  14. data/lib/fog/vcloud_director/compute.rb +916 -0
  15. data/lib/fog/vcloud_director/core.rb +69 -0
  16. data/lib/fog/vcloud_director/generators/compute/compose_common.rb +122 -0
  17. data/lib/fog/vcloud_director/generators/compute/compose_vapp.rb +25 -0
  18. data/lib/fog/vcloud_director/generators/compute/create_snapshot.rb +25 -0
  19. data/lib/fog/vcloud_director/generators/compute/customization.rb +105 -0
  20. data/lib/fog/vcloud_director/generators/compute/disks.rb +186 -0
  21. data/lib/fog/vcloud_director/generators/compute/edge_gateway_service_configuration.rb +243 -0
  22. data/lib/fog/vcloud_director/generators/compute/instantiate_vapp_template_params.rb +30 -0
  23. data/lib/fog/vcloud_director/generators/compute/metadata.rb +104 -0
  24. data/lib/fog/vcloud_director/generators/compute/org_vdc_network.rb +88 -0
  25. data/lib/fog/vcloud_director/generators/compute/recompose_vapp.rb +34 -0
  26. data/lib/fog/vcloud_director/generators/compute/vapp.rb +28 -0
  27. data/lib/fog/vcloud_director/generators/compute/vm.rb +32 -0
  28. data/lib/fog/vcloud_director/generators/compute/vm_network.rb +119 -0
  29. data/lib/fog/vcloud_director/models/compute/catalog.rb +22 -0
  30. data/lib/fog/vcloud_director/models/compute/catalog_item.rb +30 -0
  31. data/lib/fog/vcloud_director/models/compute/catalog_items.rb +33 -0
  32. data/lib/fog/vcloud_director/models/compute/catalogs.rb +30 -0
  33. data/lib/fog/vcloud_director/models/compute/custom_field.rb +18 -0
  34. data/lib/fog/vcloud_director/models/compute/custom_fields.rb +67 -0
  35. data/lib/fog/vcloud_director/models/compute/disk.rb +53 -0
  36. data/lib/fog/vcloud_director/models/compute/disks.rb +44 -0
  37. data/lib/fog/vcloud_director/models/compute/media.rb +26 -0
  38. data/lib/fog/vcloud_director/models/compute/medias.rb +75 -0
  39. data/lib/fog/vcloud_director/models/compute/network.rb +25 -0
  40. data/lib/fog/vcloud_director/models/compute/networks.rb +62 -0
  41. data/lib/fog/vcloud_director/models/compute/organization.rb +37 -0
  42. data/lib/fog/vcloud_director/models/compute/organizations.rb +28 -0
  43. data/lib/fog/vcloud_director/models/compute/tag.rb +31 -0
  44. data/lib/fog/vcloud_director/models/compute/tags.rb +41 -0
  45. data/lib/fog/vcloud_director/models/compute/task.rb +55 -0
  46. data/lib/fog/vcloud_director/models/compute/tasks.rb +36 -0
  47. data/lib/fog/vcloud_director/models/compute/template_vm.rb +52 -0
  48. data/lib/fog/vcloud_director/models/compute/template_vms.rb +41 -0
  49. data/lib/fog/vcloud_director/models/compute/vapp.rb +144 -0
  50. data/lib/fog/vcloud_director/models/compute/vapp_template.rb +26 -0
  51. data/lib/fog/vcloud_director/models/compute/vapp_templates.rb +40 -0
  52. data/lib/fog/vcloud_director/models/compute/vapps.rb +40 -0
  53. data/lib/fog/vcloud_director/models/compute/vdc.rb +45 -0
  54. data/lib/fog/vcloud_director/models/compute/vdcs.rb +37 -0
  55. data/lib/fog/vcloud_director/models/compute/vm.rb +197 -0
  56. data/lib/fog/vcloud_director/models/compute/vm_customization.rb +40 -0
  57. data/lib/fog/vcloud_director/models/compute/vm_customizations.rb +29 -0
  58. data/lib/fog/vcloud_director/models/compute/vm_network.rb +27 -0
  59. data/lib/fog/vcloud_director/models/compute/vm_networks.rb +19 -0
  60. data/lib/fog/vcloud_director/models/compute/vms.rb +46 -0
  61. data/lib/fog/vcloud_director/parsers/compute/disks.rb +53 -0
  62. data/lib/fog/vcloud_director/parsers/compute/metadata.rb +61 -0
  63. data/lib/fog/vcloud_director/parsers/compute/network.rb +104 -0
  64. data/lib/fog/vcloud_director/parsers/compute/vm.rb +86 -0
  65. data/lib/fog/vcloud_director/parsers/compute/vm_customization.rb +55 -0
  66. data/lib/fog/vcloud_director/parsers/compute/vm_network.rb +107 -0
  67. data/lib/fog/vcloud_director/parsers/compute/vm_parser_helper.rb +62 -0
  68. data/lib/fog/vcloud_director/parsers/compute/vms.rb +68 -0
  69. data/lib/fog/vcloud_director/parsers/compute/vms_by_metadata.rb +37 -0
  70. data/lib/fog/vcloud_director/query.rb +59 -0
  71. data/lib/fog/vcloud_director/requests/compute/delete_catalog_item.rb +22 -0
  72. data/lib/fog/vcloud_director/requests/compute/delete_catalog_item_metadata_item_metadata.rb +25 -0
  73. data/lib/fog/vcloud_director/requests/compute/delete_disk.rb +60 -0
  74. data/lib/fog/vcloud_director/requests/compute/delete_disk_metadata_item_metadata.rb +25 -0
  75. data/lib/fog/vcloud_director/requests/compute/delete_logout.rb +18 -0
  76. data/lib/fog/vcloud_director/requests/compute/delete_media.rb +122 -0
  77. data/lib/fog/vcloud_director/requests/compute/delete_media_metadata_item_metadata.rb +25 -0
  78. data/lib/fog/vcloud_director/requests/compute/delete_network.rb +62 -0
  79. data/lib/fog/vcloud_director/requests/compute/delete_shadow_vm.rb +30 -0
  80. data/lib/fog/vcloud_director/requests/compute/delete_vapp.rb +59 -0
  81. data/lib/fog/vcloud_director/requests/compute/delete_vapp_metadata_item_metadata.rb +30 -0
  82. data/lib/fog/vcloud_director/requests/compute/delete_vapp_template.rb +27 -0
  83. data/lib/fog/vcloud_director/requests/compute/delete_vapp_template_metadata_item_metadata.rb +26 -0
  84. data/lib/fog/vcloud_director/requests/compute/get_allocated_ip_addresses.rb +25 -0
  85. data/lib/fog/vcloud_director/requests/compute/get_catalog.rb +63 -0
  86. data/lib/fog/vcloud_director/requests/compute/get_catalog_item.rb +48 -0
  87. data/lib/fog/vcloud_director/requests/compute/get_catalog_item_metadata.rb +25 -0
  88. data/lib/fog/vcloud_director/requests/compute/get_catalog_item_metadata_item_metadata.rb +26 -0
  89. data/lib/fog/vcloud_director/requests/compute/get_catalog_metadata.rb +25 -0
  90. data/lib/fog/vcloud_director/requests/compute/get_catalog_metadata_item_metadata.rb +26 -0
  91. data/lib/fog/vcloud_director/requests/compute/get_catalogs_from_query.rb +94 -0
  92. data/lib/fog/vcloud_director/requests/compute/get_control_access_params_catalog.rb +26 -0
  93. data/lib/fog/vcloud_director/requests/compute/get_control_access_params_vapp.rb +25 -0
  94. data/lib/fog/vcloud_director/requests/compute/get_cpu_rasd_item.rb +65 -0
  95. data/lib/fog/vcloud_director/requests/compute/get_current_session.rb +83 -0
  96. data/lib/fog/vcloud_director/requests/compute/get_disk.rb +123 -0
  97. data/lib/fog/vcloud_director/requests/compute/get_disk_metadata.rb +25 -0
  98. data/lib/fog/vcloud_director/requests/compute/get_disk_metadata_item_metadata.rb +26 -0
  99. data/lib/fog/vcloud_director/requests/compute/get_disk_owner.rb +70 -0
  100. data/lib/fog/vcloud_director/requests/compute/get_disks_from_query.rb +94 -0
  101. data/lib/fog/vcloud_director/requests/compute/get_disks_rasd_items_list.rb +90 -0
  102. data/lib/fog/vcloud_director/requests/compute/get_edge_gateway.rb +109 -0
  103. data/lib/fog/vcloud_director/requests/compute/get_entity.rb +38 -0
  104. data/lib/fog/vcloud_director/requests/compute/get_execute_query.rb +736 -0
  105. data/lib/fog/vcloud_director/requests/compute/get_groups_from_query.rb +95 -0
  106. data/lib/fog/vcloud_director/requests/compute/get_guest_customization_system_section_vapp.rb +69 -0
  107. data/lib/fog/vcloud_director/requests/compute/get_guest_customization_system_section_vapp_template.rb +25 -0
  108. data/lib/fog/vcloud_director/requests/compute/get_href.rb +21 -0
  109. data/lib/fog/vcloud_director/requests/compute/get_lease_settings_section_vapp.rb +59 -0
  110. data/lib/fog/vcloud_director/requests/compute/get_lease_settings_section_vapp_template.rb +25 -0
  111. data/lib/fog/vcloud_director/requests/compute/get_media.rb +111 -0
  112. data/lib/fog/vcloud_director/requests/compute/get_media_drives_rasd_items_list.rb +92 -0
  113. data/lib/fog/vcloud_director/requests/compute/get_media_metadata.rb +25 -0
  114. data/lib/fog/vcloud_director/requests/compute/get_media_metadata_item_metadata.rb +26 -0
  115. data/lib/fog/vcloud_director/requests/compute/get_media_owner.rb +70 -0
  116. data/lib/fog/vcloud_director/requests/compute/get_medias_from_query.rb +94 -0
  117. data/lib/fog/vcloud_director/requests/compute/get_memory_rasd_item.rb +64 -0
  118. data/lib/fog/vcloud_director/requests/compute/get_metadata.rb +41 -0
  119. data/lib/fog/vcloud_director/requests/compute/get_network.rb +67 -0
  120. data/lib/fog/vcloud_director/requests/compute/get_network_cards_items_list.rb +70 -0
  121. data/lib/fog/vcloud_director/requests/compute/get_network_complete.rb +78 -0
  122. data/lib/fog/vcloud_director/requests/compute/get_network_config_section_vapp.rb +61 -0
  123. data/lib/fog/vcloud_director/requests/compute/get_network_config_section_vapp_template.rb +25 -0
  124. data/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp.rb +68 -0
  125. data/lib/fog/vcloud_director/requests/compute/get_network_connection_system_section_vapp_template.rb +25 -0
  126. data/lib/fog/vcloud_director/requests/compute/get_network_metadata.rb +25 -0
  127. data/lib/fog/vcloud_director/requests/compute/get_network_metadata_item_metadata.rb +26 -0
  128. data/lib/fog/vcloud_director/requests/compute/get_network_section_vapp.rb +25 -0
  129. data/lib/fog/vcloud_director/requests/compute/get_network_section_vapp_template.rb +25 -0
  130. data/lib/fog/vcloud_director/requests/compute/get_operating_system_section.rb +59 -0
  131. data/lib/fog/vcloud_director/requests/compute/get_org_settings.rb +38 -0
  132. data/lib/fog/vcloud_director/requests/compute/get_org_vdc_gateways.rb +83 -0
  133. data/lib/fog/vcloud_director/requests/compute/get_organization.rb +100 -0
  134. data/lib/fog/vcloud_director/requests/compute/get_organization_metadata.rb +25 -0
  135. data/lib/fog/vcloud_director/requests/compute/get_organization_metadata_item_metadata.rb +28 -0
  136. data/lib/fog/vcloud_director/requests/compute/get_organizations.rb +52 -0
  137. data/lib/fog/vcloud_director/requests/compute/get_organizations_from_query.rb +95 -0
  138. data/lib/fog/vcloud_director/requests/compute/get_product_sections_vapp.rb +25 -0
  139. data/lib/fog/vcloud_director/requests/compute/get_product_sections_vapp_template.rb +26 -0
  140. data/lib/fog/vcloud_director/requests/compute/get_request.rb +19 -0
  141. data/lib/fog/vcloud_director/requests/compute/get_runtime_info_section_type.rb +57 -0
  142. data/lib/fog/vcloud_director/requests/compute/get_serial_ports_items_list.rb +25 -0
  143. data/lib/fog/vcloud_director/requests/compute/get_shadow_vm.rb +24 -0
  144. data/lib/fog/vcloud_director/requests/compute/get_snapshot_section.rb +55 -0
  145. data/lib/fog/vcloud_director/requests/compute/get_startup_section.rb +64 -0
  146. data/lib/fog/vcloud_director/requests/compute/get_supported_systems_info.rb +239 -0
  147. data/lib/fog/vcloud_director/requests/compute/get_supported_versions.rb +1159 -0
  148. data/lib/fog/vcloud_director/requests/compute/get_task.rb +168 -0
  149. data/lib/fog/vcloud_director/requests/compute/get_task_list.rb +130 -0
  150. data/lib/fog/vcloud_director/requests/compute/get_template_vm.rb +74 -0
  151. data/lib/fog/vcloud_director/requests/compute/get_template_vms.rb +41 -0
  152. data/lib/fog/vcloud_director/requests/compute/get_thumbnail.rb +28 -0
  153. data/lib/fog/vcloud_director/requests/compute/get_users_from_query.rb +95 -0
  154. data/lib/fog/vcloud_director/requests/compute/get_vapp.rb +176 -0
  155. data/lib/fog/vcloud_director/requests/compute/get_vapp_metadata.rb +84 -0
  156. data/lib/fog/vcloud_director/requests/compute/get_vapp_metadata_item_metadata.rb +26 -0
  157. data/lib/fog/vcloud_director/requests/compute/get_vapp_ovf_descriptor.rb +24 -0
  158. data/lib/fog/vcloud_director/requests/compute/get_vapp_owner.rb +58 -0
  159. data/lib/fog/vcloud_director/requests/compute/get_vapp_template.rb +25 -0
  160. data/lib/fog/vcloud_director/requests/compute/get_vapp_template_customization_system_section.rb +25 -0
  161. data/lib/fog/vcloud_director/requests/compute/get_vapp_template_metadata.rb +25 -0
  162. data/lib/fog/vcloud_director/requests/compute/get_vapp_template_metadata_item_metadata.rb +27 -0
  163. data/lib/fog/vcloud_director/requests/compute/get_vapp_template_ovf_descriptor.rb +24 -0
  164. data/lib/fog/vcloud_director/requests/compute/get_vapp_template_owner.rb +25 -0
  165. data/lib/fog/vcloud_director/requests/compute/get_vapp_templates_from_query.rb +95 -0
  166. data/lib/fog/vcloud_director/requests/compute/get_vapps_in_lease_from_query.rb +94 -0
  167. data/lib/fog/vcloud_director/requests/compute/get_vcloud.rb +76 -0
  168. data/lib/fog/vcloud_director/requests/compute/get_vdc.rb +174 -0
  169. data/lib/fog/vcloud_director/requests/compute/get_vdc_metadata.rb +25 -0
  170. data/lib/fog/vcloud_director/requests/compute/get_vdc_metadata_item_metadata.rb +28 -0
  171. data/lib/fog/vcloud_director/requests/compute/get_vdc_storage_class.rb +83 -0
  172. data/lib/fog/vcloud_director/requests/compute/get_vdc_storage_class_metadata.rb +27 -0
  173. data/lib/fog/vcloud_director/requests/compute/get_vdc_storage_class_metadata_item_metadata.rb +25 -0
  174. data/lib/fog/vcloud_director/requests/compute/get_vdcs_from_query.rb +94 -0
  175. data/lib/fog/vcloud_director/requests/compute/get_virtual_hardware_section.rb +29 -0
  176. data/lib/fog/vcloud_director/requests/compute/get_vm.rb +74 -0
  177. data/lib/fog/vcloud_director/requests/compute/get_vm_capabilities.rb +61 -0
  178. data/lib/fog/vcloud_director/requests/compute/get_vm_compliance_results.rb +24 -0
  179. data/lib/fog/vcloud_director/requests/compute/get_vm_customization.rb +31 -0
  180. data/lib/fog/vcloud_director/requests/compute/get_vm_disks.rb +51 -0
  181. data/lib/fog/vcloud_director/requests/compute/get_vm_network.rb +56 -0
  182. data/lib/fog/vcloud_director/requests/compute/get_vm_pending_question.rb +34 -0
  183. data/lib/fog/vcloud_director/requests/compute/get_vms.rb +41 -0
  184. data/lib/fog/vcloud_director/requests/compute/get_vms_by_metadata.rb +20 -0
  185. data/lib/fog/vcloud_director/requests/compute/get_vms_disk_attached_to.rb +39 -0
  186. data/lib/fog/vcloud_director/requests/compute/get_vms_in_lease_from_query.rb +150 -0
  187. data/lib/fog/vcloud_director/requests/compute/instantiate_vapp_template.rb +173 -0
  188. data/lib/fog/vcloud_director/requests/compute/post_acquire_ticket.rb +27 -0
  189. data/lib/fog/vcloud_director/requests/compute/post_answer_vm_pending_question.rb +36 -0
  190. data/lib/fog/vcloud_director/requests/compute/post_attach_disk.rb +51 -0
  191. data/lib/fog/vcloud_director/requests/compute/post_cancel_task.rb +43 -0
  192. data/lib/fog/vcloud_director/requests/compute/post_capture_vapp.rb +70 -0
  193. data/lib/fog/vcloud_director/requests/compute/post_check_vm_compliance.rb +28 -0
  194. data/lib/fog/vcloud_director/requests/compute/post_clone_media.rb +102 -0
  195. data/lib/fog/vcloud_director/requests/compute/post_clone_vapp.rb +62 -0
  196. data/lib/fog/vcloud_director/requests/compute/post_clone_vapp_template.rb +52 -0
  197. data/lib/fog/vcloud_director/requests/compute/post_compose_vapp.rb +45 -0
  198. data/lib/fog/vcloud_director/requests/compute/post_configure_edge_gateway_services.rb +73 -0
  199. data/lib/fog/vcloud_director/requests/compute/post_consolidate_vm_vapp.rb +27 -0
  200. data/lib/fog/vcloud_director/requests/compute/post_consolidate_vm_vapp_template.rb +27 -0
  201. data/lib/fog/vcloud_director/requests/compute/post_create_catalog_item.rb +56 -0
  202. data/lib/fog/vcloud_director/requests/compute/post_create_org_vdc_network.rb +171 -0
  203. data/lib/fog/vcloud_director/requests/compute/post_create_snapshot.rb +21 -0
  204. data/lib/fog/vcloud_director/requests/compute/post_deploy_vapp.rb +51 -0
  205. data/lib/fog/vcloud_director/requests/compute/post_detach_disk.rb +39 -0
  206. data/lib/fog/vcloud_director/requests/compute/post_disable_nested_hv.rb +27 -0
  207. data/lib/fog/vcloud_director/requests/compute/post_disable_vapp_template_download.rb +24 -0
  208. data/lib/fog/vcloud_director/requests/compute/post_discard_vapp_state.rb +30 -0
  209. data/lib/fog/vcloud_director/requests/compute/post_eject_cd_rom.rb +39 -0
  210. data/lib/fog/vcloud_director/requests/compute/post_enable_nested_hv.rb +27 -0
  211. data/lib/fog/vcloud_director/requests/compute/post_enable_vapp_template_download.rb +24 -0
  212. data/lib/fog/vcloud_director/requests/compute/post_enter_maintenance_mode.rb +26 -0
  213. data/lib/fog/vcloud_director/requests/compute/post_exit_maintenance_mode.rb +22 -0
  214. data/lib/fog/vcloud_director/requests/compute/post_insert_cd_rom.rb +39 -0
  215. data/lib/fog/vcloud_director/requests/compute/post_install_vmware_tools.rb +27 -0
  216. data/lib/fog/vcloud_director/requests/compute/post_instantiate_vapp_template.rb +196 -0
  217. data/lib/fog/vcloud_director/requests/compute/post_login_session.rb +39 -0
  218. data/lib/fog/vcloud_director/requests/compute/post_power_off_vapp.rb +36 -0
  219. data/lib/fog/vcloud_director/requests/compute/post_power_on_vapp.rb +71 -0
  220. data/lib/fog/vcloud_director/requests/compute/post_reboot_vapp.rb +33 -0
  221. data/lib/fog/vcloud_director/requests/compute/post_recompose_vapp.rb +21 -0
  222. data/lib/fog/vcloud_director/requests/compute/post_reconfigure_vm.rb +118 -0
  223. data/lib/fog/vcloud_director/requests/compute/post_remove_all_snapshots.rb +27 -0
  224. data/lib/fog/vcloud_director/requests/compute/post_reset_vapp.rb +33 -0
  225. data/lib/fog/vcloud_director/requests/compute/post_revert_snapshot.rb +27 -0
  226. data/lib/fog/vcloud_director/requests/compute/post_shutdown_vapp.rb +33 -0
  227. data/lib/fog/vcloud_director/requests/compute/post_suspend_vapp.rb +33 -0
  228. data/lib/fog/vcloud_director/requests/compute/post_undeploy_vapp.rb +66 -0
  229. data/lib/fog/vcloud_director/requests/compute/post_update_catalog_item_metadata.rb +52 -0
  230. data/lib/fog/vcloud_director/requests/compute/post_update_disk_metadata.rb +52 -0
  231. data/lib/fog/vcloud_director/requests/compute/post_update_media_metadata.rb +52 -0
  232. data/lib/fog/vcloud_director/requests/compute/post_update_vapp_metadata.rb +86 -0
  233. data/lib/fog/vcloud_director/requests/compute/post_update_vapp_template_metadata.rb +52 -0
  234. data/lib/fog/vcloud_director/requests/compute/post_upgrade_hw_version.rb +28 -0
  235. data/lib/fog/vcloud_director/requests/compute/post_upload_disk.rb +133 -0
  236. data/lib/fog/vcloud_director/requests/compute/post_upload_media.rb +120 -0
  237. data/lib/fog/vcloud_director/requests/compute/post_upload_vapp_template.rb +46 -0
  238. data/lib/fog/vcloud_director/requests/compute/put_catalog_item_metadata_item_metadata.rb +50 -0
  239. data/lib/fog/vcloud_director/requests/compute/put_cpu.rb +88 -0
  240. data/lib/fog/vcloud_director/requests/compute/put_disk_metadata_item_metadata.rb +46 -0
  241. data/lib/fog/vcloud_director/requests/compute/put_disks.rb +39 -0
  242. data/lib/fog/vcloud_director/requests/compute/put_guest_customization_section_vapp.rb +141 -0
  243. data/lib/fog/vcloud_director/requests/compute/put_media_metadata_item_metadata.rb +50 -0
  244. data/lib/fog/vcloud_director/requests/compute/put_memory.rb +89 -0
  245. data/lib/fog/vcloud_director/requests/compute/put_metadata_value.rb +26 -0
  246. data/lib/fog/vcloud_director/requests/compute/put_network.rb +162 -0
  247. data/lib/fog/vcloud_director/requests/compute/put_network_connection_system_section_vapp.rb +152 -0
  248. data/lib/fog/vcloud_director/requests/compute/put_product_sections.rb +46 -0
  249. data/lib/fog/vcloud_director/requests/compute/put_vapp_metadata_item_metadata.rb +85 -0
  250. data/lib/fog/vcloud_director/requests/compute/put_vapp_name_and_description.rb +36 -0
  251. data/lib/fog/vcloud_director/requests/compute/put_vapp_template_metadata_item_metadata.rb +50 -0
  252. data/lib/fog/vcloud_director/requests/compute/put_vm.rb +72 -0
  253. data/lib/fog/vcloud_director/requests/compute/put_vm_capabilities.rb +44 -0
  254. data/lib/fog/vcloud_director/version.rb +5 -0
  255. data/spec/spec_helper.rb +15 -0
  256. data/spec/vcloud_director/generators/compute/instantiate_vapp_template_params_spec.rb +68 -0
  257. data/spec/vcloud_director/requests/compute/instantiate_vapp_template_spec.rb +78 -0
  258. data/spec/vcloud_director/spec_helper.rb +11 -0
  259. data/tasks/bundler.rake +3 -0
  260. data/tasks/console.rake +12 -0
  261. data/tasks/lint.rake +3 -0
  262. data/tasks/test.rake +13 -0
  263. data/tests/helper.rb +32 -0
  264. data/tests/helpers/collection_helper.rb +97 -0
  265. data/tests/helpers/compute/flavors_helper.rb +32 -0
  266. data/tests/helpers/compute/server_helper.rb +25 -0
  267. data/tests/helpers/compute/servers_helper.rb +10 -0
  268. data/tests/helpers/formats_helper.rb +98 -0
  269. data/tests/helpers/formats_helper_tests.rb +110 -0
  270. data/tests/helpers/mock_helper.rb +95 -0
  271. data/tests/helpers/model_helper.rb +31 -0
  272. data/tests/helpers/responds_to_helper.rb +11 -0
  273. data/tests/helpers/schema_validator_tests.rb +107 -0
  274. data/tests/helpers/succeeds_helper.rb +9 -0
  275. data/tests/lorem.txt +1 -0
  276. data/tests/vcloud_director/ensure_list_tests.rb +84 -0
  277. data/tests/vcloud_director/fixtures/test.iso +1 -0
  278. data/tests/vcloud_director/fixtures/vapp.xml +532 -0
  279. data/tests/vcloud_director/fixtures/vm.xml +213 -0
  280. data/tests/vcloud_director/generators/compute/compose_vapp_tests.rb +108 -0
  281. data/tests/vcloud_director/models/compute/catalog_items_tests.rb +42 -0
  282. data/tests/vcloud_director/models/compute/catalogs_tests.rb +40 -0
  283. data/tests/vcloud_director/models/compute/helper.rb +60 -0
  284. data/tests/vcloud_director/models/compute/media_tests.rb +58 -0
  285. data/tests/vcloud_director/models/compute/network_tests.rb +108 -0
  286. data/tests/vcloud_director/models/compute/organizations_tests.rb +18 -0
  287. data/tests/vcloud_director/models/compute/tasks_tests.rb +56 -0
  288. data/tests/vcloud_director/models/compute/vapp_life_cycle_tests.rb +93 -0
  289. data/tests/vcloud_director/models/compute/vapp_template_tests.rb +29 -0
  290. data/tests/vcloud_director/models/compute/vapp_tests.rb +61 -0
  291. data/tests/vcloud_director/models/compute/vdcs_tests.rb +54 -0
  292. data/tests/vcloud_director/models/compute/vms_tests.rb +101 -0
  293. data/tests/vcloud_director/requests/compute/admin_tests.rb +16 -0
  294. data/tests/vcloud_director/requests/compute/catalog_tests.rb +42 -0
  295. data/tests/vcloud_director/requests/compute/disk_tests.rb +178 -0
  296. data/tests/vcloud_director/requests/compute/edge_gateway_tests.rb +217 -0
  297. data/tests/vcloud_director/requests/compute/groups_tests.rb +18 -0
  298. data/tests/vcloud_director/requests/compute/helper.rb +32 -0
  299. data/tests/vcloud_director/requests/compute/media_tests.rb +195 -0
  300. data/tests/vcloud_director/requests/compute/network_tests.rb +186 -0
  301. data/tests/vcloud_director/requests/compute/organization_tests.rb +37 -0
  302. data/tests/vcloud_director/requests/compute/ovf_descriptor_tests.rb +36 -0
  303. data/tests/vcloud_director/requests/compute/query_tests.rb +99 -0
  304. data/tests/vcloud_director/requests/compute/schema_helper.rb +663 -0
  305. data/tests/vcloud_director/requests/compute/session_tests.rb +14 -0
  306. data/tests/vcloud_director/requests/compute/supported_systems_tests.rb +11 -0
  307. data/tests/vcloud_director/requests/compute/task_tests.rb +35 -0
  308. data/tests/vcloud_director/requests/compute/users_tests.rb +18 -0
  309. data/tests/vcloud_director/requests/compute/vapp_tests.rb +123 -0
  310. data/tests/vcloud_director/requests/compute/vdc_storage_profile_tests.rb +27 -0
  311. data/tests/vcloud_director/requests/compute/vdc_tests.rb +36 -0
  312. data/tests/vcloud_director/requests/compute/versions_tests.rb +13 -0
  313. data/tests/vcloud_director/requests/compute/vm_tests.rb +185 -0
  314. data/tests/watchr.rb +22 -0
  315. metadata +461 -0
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Load all the rake tasks from the "tasks" folder. This folder
10
+ # allows us to nicely separate rake tasks into individual files
11
+ # based on their role, which makes development and debugging easier
12
+ # than one monolithic file.
13
+ task_dir = File.expand_path("../tasks", __FILE__)
14
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
15
+ load task_file
16
+ end
17
+
18
+ desc "Default Task"
19
+ task :default => "test:travis"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fog/vcloud_director/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-vcloud-director"
8
+ spec.version = Fog::VcloudDirector::VERSION
9
+ spec.authors = ["Luka Zakrajšek"]
10
+ spec.email = ["luka@bancek.net"]
11
+ spec.summary = "Module for the 'fog' gem to support vCloud Director."
12
+ spec.description = 'This library can be used as a module for `fog` or as standalone provider
13
+ to use the vCloud Director in applications.'
14
+ spec.homepage = "https://github.com/xlab-si/fog-vcloud-director"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = "~> 2.0"
22
+
23
+ spec.add_dependency "fog-core"
24
+ spec.add_dependency "fog-xml"
25
+
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "shindo"
28
+ spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "vcr"
30
+ spec.add_development_dependency "rubocop"
31
+ end
@@ -0,0 +1 @@
1
+ require 'fog/vcloud_director/compute'
@@ -0,0 +1,916 @@
1
+ require 'fog/vcloud_director/core'
2
+ require 'fog/vcloud_director/query'
3
+
4
+ class VcloudDirectorParser < Fog::Parsers::Base
5
+ def extract_attributes(attributes_xml)
6
+ attributes = {}
7
+ until attributes_xml.empty?
8
+ if attributes_xml.first.is_a?(Array)
9
+ until attributes_xml.first.empty?
10
+ attribute = attributes_xml.first.shift
11
+ attributes[attribute.localname.to_sym] = attribute.value
12
+ end
13
+ else
14
+ attribute = attributes_xml.shift
15
+ attributes[attribute.localname.to_sym] = attribute.value
16
+ end
17
+ end
18
+ attributes
19
+ end
20
+ end
21
+
22
+ class NonLoaded
23
+ end
24
+
25
+ module Fog
26
+ module Compute
27
+ class VcloudDirector < Fog::Service
28
+ module Defaults
29
+ PATH = '/api'
30
+ PORT = 443
31
+ SCHEME = 'https'
32
+ API_VERSION = '5.1'
33
+ OMIT_DEFAULT_PORT = true
34
+ end
35
+
36
+ class ServiceError < Fog::VcloudDirector::Errors::ServiceError; end
37
+
38
+ class BadRequest < Fog::VcloudDirector::Errors::BadRequest; end
39
+ class Unauthorized < Fog::VcloudDirector::Errors::Unauthorized; end
40
+ class Forbidden < Fog::VcloudDirector::Errors::Forbidden; end
41
+ class Conflict < Fog::VcloudDirector::Errors::Conflict; end
42
+ class MalformedResponse < Fog::VcloudDirector::Errors::MalformedResponse; end
43
+
44
+ class DuplicateName < Fog::VcloudDirector::Errors::DuplicateName; end
45
+ class TaskError < Fog::VcloudDirector::Errors::TaskError; end
46
+
47
+ requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
48
+ recognizes :vcloud_director_api_version, :vcloud_director_show_progress, :path, :vcloud_token
49
+
50
+ secrets :vcloud_director_password
51
+
52
+ model_path 'fog/vcloud_director/models/compute'
53
+ model :catalog
54
+ collection :catalogs
55
+ model :organization
56
+ collection :organizations
57
+ model :catalog_item
58
+ collection :vapp_templates
59
+ model :vapp_template
60
+ collection :template_vms
61
+ model :template_vm
62
+ collection :catalog_items
63
+ model :custom_field
64
+ collection :custom_fields
65
+ model :vdc
66
+ collection :vdcs
67
+ model :vapp
68
+ collection :vapps
69
+ model :task
70
+ collection :tasks
71
+ model :vm
72
+ collection :vms
73
+ model :vm_customization
74
+ collection :vm_customizations
75
+ model :network
76
+ collection :networks
77
+ model :disk
78
+ collection :disks
79
+ model :vm_network
80
+ collection :vm_networks
81
+ model :tag # this is called metadata in vcloud
82
+ collection :tags
83
+ model :media
84
+ collection :medias # sic
85
+
86
+ request_path 'fog/vcloud_director/requests/compute'
87
+ request :delete_catalog_item
88
+ request :delete_catalog_item_metadata_item_metadata
89
+ request :delete_disk
90
+ request :delete_disk_metadata_item_metadata
91
+ request :delete_logout
92
+ request :delete_media
93
+ request :delete_media_metadata_item_metadata
94
+ request :delete_network
95
+ request :delete_shadow_vm
96
+ request :delete_vapp
97
+ request :delete_vapp_metadata_item_metadata
98
+ request :delete_vapp_template
99
+ request :delete_vapp_template_metadata_item_metadata
100
+ request :get_allocated_ip_addresses
101
+ request :get_catalog
102
+ request :get_catalog_item
103
+ request :get_catalog_item_metadata
104
+ request :get_catalog_item_metadata_item_metadata
105
+ request :get_catalog_metadata
106
+ request :get_catalog_metadata_item_metadata
107
+ request :get_catalogs_from_query
108
+ request :get_control_access_params_catalog
109
+ request :get_control_access_params_vapp
110
+ request :get_cpu_rasd_item
111
+ request :get_current_session
112
+ request :get_disk
113
+ request :get_disk_metadata
114
+ request :get_disk_metadata_item_metadata
115
+ request :get_disk_owner
116
+ request :get_disks_from_query
117
+ request :get_disks_rasd_items_list
118
+ request :get_edge_gateway
119
+ request :get_entity
120
+ request :get_execute_query
121
+ request :get_groups_from_query
122
+ request :get_guest_customization_system_section_vapp
123
+ request :get_guest_customization_system_section_vapp_template
124
+ request :get_href # this is used for manual testing
125
+ request :get_lease_settings_section_vapp
126
+ request :get_lease_settings_section_vapp_template
127
+ request :get_media
128
+ request :get_media_drives_rasd_items_list
129
+ request :get_media_metadata
130
+ request :get_media_metadata_item_metadata
131
+ request :get_media_owner
132
+ request :get_medias_from_query
133
+ request :get_memory_rasd_item
134
+ request :get_metadata
135
+ request :get_network
136
+ request :get_network_cards_items_list
137
+ request :get_network_complete
138
+ request :get_network_config_section_vapp
139
+ request :get_network_config_section_vapp_template
140
+ request :get_network_connection_system_section_vapp
141
+ request :get_network_connection_system_section_vapp_template
142
+ request :get_network_metadata
143
+ request :get_network_metadata_item_metadata
144
+ request :get_network_section_vapp
145
+ request :get_network_section_vapp_template
146
+ request :get_operating_system_section
147
+ request :get_org_settings
148
+ request :get_org_vdc_gateways
149
+ request :get_organization
150
+ request :get_organization_metadata
151
+ request :get_organization_metadata_item_metadata
152
+ request :get_organizations
153
+ request :get_organizations_from_query
154
+ request :get_product_sections_vapp
155
+ request :get_product_sections_vapp_template
156
+ request :get_request # this is used for manual testing
157
+ request :get_runtime_info_section_type
158
+ request :get_serial_ports_items_list
159
+ request :get_shadow_vm
160
+ request :get_snapshot_section
161
+ request :get_startup_section
162
+ request :get_supported_systems_info
163
+ request :get_supported_versions
164
+ request :get_task
165
+ request :get_task_list
166
+ request :get_template_vm
167
+ request :get_template_vms
168
+ request :get_thumbnail
169
+ request :get_users_from_query
170
+ request :get_vapp
171
+ request :get_vapp_metadata
172
+ request :get_vapp_metadata_item_metadata
173
+ request :get_vapp_ovf_descriptor
174
+ request :get_vapp_owner
175
+ request :get_vapp_template
176
+ request :get_vapp_template_customization_system_section
177
+ request :get_vapp_template_metadata
178
+ request :get_vapp_template_metadata_item_metadata
179
+ request :get_vapp_template_ovf_descriptor
180
+ request :get_vapp_template_owner
181
+ request :get_vapp_templates_from_query
182
+ request :get_vapps_in_lease_from_query
183
+ request :get_vcloud
184
+ request :get_vdc
185
+ request :get_vdc_metadata
186
+ request :get_vdc_metadata_item_metadata
187
+ request :get_vdc_storage_class
188
+ request :get_vdc_storage_class_metadata
189
+ request :get_vdc_storage_class_metadata_item_metadata
190
+ request :get_vdcs_from_query
191
+ request :get_virtual_hardware_section
192
+ request :get_vm
193
+ request :get_vm_capabilities
194
+ request :get_vm_compliance_results
195
+ request :get_vm_customization
196
+ request :get_vm_disks
197
+ request :get_vm_network
198
+ request :get_vm_pending_question
199
+ request :get_vms
200
+ request :get_vms_by_metadata
201
+ request :get_vms_disk_attached_to
202
+ request :get_vms_in_lease_from_query
203
+ request :instantiate_vapp_template # to be deprecated
204
+ request :post_acquire_ticket
205
+ request :post_answer_vm_pending_question
206
+ request :post_attach_disk
207
+ request :post_cancel_task
208
+ request :post_capture_vapp
209
+ request :post_check_vm_compliance
210
+ request :post_clone_media
211
+ request :post_clone_vapp
212
+ request :post_clone_vapp_template
213
+ request :post_configure_edge_gateway_services
214
+ request :post_consolidate_vm_vapp
215
+ request :post_consolidate_vm_vapp_template
216
+ request :post_create_catalog_item
217
+ request :post_create_org_vdc_network
218
+ request :post_deploy_vapp
219
+ request :post_compose_vapp
220
+ request :post_recompose_vapp
221
+ request :post_detach_disk
222
+ request :post_disable_nested_hv
223
+ request :post_disable_vapp_template_download
224
+ request :post_discard_vapp_state
225
+ request :post_eject_cd_rom
226
+ request :post_enable_nested_hv
227
+ request :post_enable_vapp_template_download
228
+ request :post_enter_maintenance_mode
229
+ request :post_exit_maintenance_mode
230
+ request :post_insert_cd_rom
231
+ request :post_install_vmware_tools
232
+ request :post_instantiate_vapp_template
233
+ request :post_login_session
234
+ request :post_power_off_vapp
235
+ request :post_power_on_vapp
236
+ request :post_reboot_vapp
237
+ request :post_reconfigure_vm
238
+ request :post_remove_all_snapshots
239
+ request :post_reset_vapp
240
+ request :post_revert_snapshot
241
+ request :post_shutdown_vapp
242
+ request :post_suspend_vapp
243
+ request :post_undeploy_vapp
244
+ request :post_update_catalog_item_metadata
245
+ request :post_update_disk_metadata
246
+ request :post_update_media_metadata
247
+ request :post_update_vapp_metadata
248
+ request :post_update_vapp_template_metadata
249
+ request :post_upgrade_hw_version
250
+ request :post_upload_disk
251
+ request :post_upload_media
252
+ request :post_upload_vapp_template
253
+ request :post_create_snapshot
254
+ request :put_catalog_item_metadata_item_metadata
255
+ request :put_cpu
256
+ request :put_disk_metadata_item_metadata
257
+ request :put_disks
258
+ request :put_guest_customization_section_vapp
259
+ request :put_media_metadata_item_metadata
260
+ request :put_memory
261
+ request :put_metadata_value # deprecated
262
+ request :put_network
263
+ request :put_network_connection_system_section_vapp
264
+ request :put_product_sections
265
+ request :put_vapp_metadata_item_metadata
266
+ request :put_vapp_name_and_description
267
+ request :put_vapp_template_metadata_item_metadata
268
+ request :put_vm
269
+ request :put_vm_capabilities
270
+
271
+ class Model < Fog::Model
272
+ def initialize(attrs={})
273
+ super(attrs)
274
+ lazy_load_attrs.each do |attr|
275
+ attributes[attr]= NonLoaded if attributes[attr].nil?
276
+ make_lazy_load_method(attr)
277
+ end
278
+ self.class.attributes.each {|attr| make_attr_loaded_method(attr)}
279
+ end
280
+
281
+ def lazy_load_attrs
282
+ @lazy_load_attrs ||= self.class.attributes - attributes.keys
283
+ end
284
+
285
+ def make_lazy_load_method(attr)
286
+ self.class.instance_eval do
287
+ define_method(attr) do
288
+ reload if attributes[attr] == NonLoaded and !@inspecting
289
+ attributes[attr]
290
+ end
291
+ end
292
+ end
293
+
294
+ # it adds an attr_loaded? method to know if the value has been loaded
295
+ # yet or not: ie description_loaded?
296
+ def make_attr_loaded_method(attr)
297
+ self.class.instance_eval do
298
+ define_method("#{attr}_loaded?") do
299
+ attributes[attr] != NonLoaded
300
+ end
301
+ end
302
+ end
303
+
304
+ def inspect
305
+ @inspecting = true
306
+ out = super
307
+ @inspecting = false
308
+ out
309
+ end
310
+ end
311
+
312
+ class Collection < Fog::Collection
313
+ def all(lazy_load=true)
314
+ lazy_load ? index : get_everyone
315
+ end
316
+
317
+ def get(item_id)
318
+ item = get_by_id(item_id)
319
+ return nil unless item
320
+ new(item)
321
+ end
322
+
323
+ def get_by_name(item_name)
324
+ item_found = item_list.find {|item| item[:name] == item_name}
325
+ return nil unless item_found
326
+ get(item_found[:id])
327
+ end
328
+
329
+ def index
330
+ load(item_list)
331
+ end
332
+
333
+ def get_everyone
334
+ items = item_list.map {|item| get_by_id(item[:id])}
335
+ load(items)
336
+ end
337
+ end
338
+
339
+ class Real
340
+ extend Fog::Deprecation
341
+ deprecate :auth_token, :vcloud_token
342
+
343
+ attr_reader :end_point, :api_version, :show_progress
344
+ alias_method :show_progress?, :show_progress
345
+
346
+ def initialize(options={})
347
+ @vcloud_director_password = options[:vcloud_director_password]
348
+ @vcloud_director_username = options[:vcloud_director_username]
349
+ @connection_options = options[:connection_options] || {}
350
+ @connection_options[:omit_default_port] = Fog::Compute::VcloudDirector::Defaults::OMIT_DEFAULT_PORT unless @connection_options[:omit_default_port]
351
+ @host = options[:vcloud_director_host]
352
+ @path = options[:path] || Fog::Compute::VcloudDirector::Defaults::PATH
353
+ @persistent = options[:persistent] || false
354
+ @port = options[:port] || Fog::Compute::VcloudDirector::Defaults::PORT
355
+ @scheme = options[:scheme] || Fog::Compute::VcloudDirector::Defaults::SCHEME
356
+ @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
357
+ @end_point = "#{@scheme}://#{@host}#{@path}/"
358
+ @api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
359
+ @show_progress = options[:vcloud_director_show_progress]
360
+ @show_progress = $stdin.tty? if @show_progress.nil?
361
+ @vcloud_token = options[:vcloud_token]
362
+ end
363
+
364
+ def vcloud_token
365
+ login if @vcloud_token.nil?
366
+ @vcloud_token
367
+ end
368
+
369
+ def org_name
370
+ login if @org_name.nil?
371
+ @org_name
372
+ end
373
+
374
+ def user_name
375
+ login if @user_name.nil?
376
+ @user_name
377
+ end
378
+
379
+ def reload
380
+ @connection.reset
381
+ end
382
+
383
+ def request(params)
384
+ begin
385
+ do_request(params)
386
+ rescue EOFError
387
+ # This error can occur if Vcloud receives a request from a network
388
+ # it deems to be unauthorized; no HTTP response is sent, but the
389
+ # connection is sent a signal to terminate early.
390
+ raise(
391
+ MalformedResponse, "Connection unexpectedly terminated by vcloud"
392
+ )
393
+ # this is to know if Excon::Errors::Unauthorized really happens
394
+ #rescue Excon::Errors::Unauthorized
395
+ # login
396
+ # do_request(params)
397
+ end
398
+ end
399
+
400
+ # @api private
401
+ def do_request(params)
402
+ headers = {
403
+ 'Accept' => "application/*+xml;version=#{@api_version}",
404
+ 'x-vcloud-authorization' => vcloud_token
405
+ }
406
+ if params[:path]
407
+ if params[:override_path] == true
408
+ path = params[:path]
409
+ else
410
+ path = "#{@path}/#{params[:path]}"
411
+ end
412
+ else
413
+ path = "#{@path}"
414
+ end
415
+ @connection.request({
416
+ :body => params[:body],
417
+ :expects => params[:expects],
418
+ :headers => headers.merge!(params[:headers] || {}),
419
+ :idempotent => params[:idempotent],
420
+ :method => params[:method],
421
+ :parser => params[:parser],
422
+ :path => path,
423
+ :query => params[:query]
424
+ })
425
+ rescue Excon::Errors::HTTPStatusError => error
426
+ raise case error
427
+ when Excon::Errors::BadRequest then BadRequest.slurp(error);
428
+ when Excon::Errors::Unauthorized then Unauthorized.slurp(error);
429
+ when Excon::Errors::Forbidden then Forbidden.slurp(error);
430
+ when Excon::Errors::Conflict then Conflict.slurp(error);
431
+ else ServiceError.slurp(error)
432
+ end
433
+ end
434
+
435
+ def process_task(response_body)
436
+ task = make_task_object(response_body)
437
+ wait_and_raise_unless_success(task)
438
+ true
439
+ end
440
+
441
+ def make_task_object(task_response)
442
+ task_response[:id] = task_response[:href].split('/').last
443
+ tasks.new(task_response)
444
+ end
445
+
446
+ def wait_and_raise_unless_success(task)
447
+ task.wait_for { non_running? }
448
+ raise TaskError.new "status: #{task.status}, error: #{task.error}" unless task.success?
449
+ end
450
+
451
+ def add_id_from_href!(data={})
452
+ data[:id] = data[:href].split('/').last
453
+ end
454
+
455
+ # Compensate for Fog::ToHashDocument shortcomings.
456
+ # @api private
457
+ # @param [Hash] hash
458
+ # @param [String,Symbol] key1
459
+ # @param [String,Symbol] key2
460
+ # @return [Hash]
461
+ def ensure_list!(hash, key1, key2=nil)
462
+ if key2.nil?
463
+ hash[key1] ||= []
464
+ hash[key1] = [hash[key1]] if hash[key1].is_a?(Hash)
465
+ else
466
+ hash[key1] ||= {key2 => []}
467
+ hash[key1] = {key2 => []} if hash[key1].empty?
468
+ hash[key1][key2] = [hash[key1][key2]] if hash[key1][key2].is_a?(Hash)
469
+ end
470
+ hash
471
+ end
472
+
473
+ private
474
+
475
+ def login
476
+ @vcloud_token ||= ENV['FOG_VCLOUD_TOKEN']
477
+ if @vcloud_token
478
+ response = get_current_session
479
+ session_org = response.body[:org]
480
+ session_user = response.body[:user]
481
+
482
+ check_session_matches_credentials(session_org, session_user)
483
+ else
484
+ response = post_login_session
485
+ x_vcloud_authorization = response.headers.keys.find do |key|
486
+ key.downcase == 'x-vcloud-authorization'
487
+ end
488
+ @vcloud_token = response.headers[x_vcloud_authorization]
489
+ end
490
+
491
+ @org_name = response.body[:org]
492
+ @user_name = response.body[:user]
493
+ end
494
+
495
+ # @note This isn't needed.
496
+ def logout
497
+ delete_logout
498
+ @vcloud_token = nil
499
+ @org_name = nil
500
+ end
501
+
502
+ def check_session_matches_credentials(session_org, session_user)
503
+ fog_credential_org = @vcloud_director_username.split('@').last
504
+ fog_credential_user = @vcloud_director_username.split('@')[0...-1].join('@')
505
+
506
+ if session_org != fog_credential_org
507
+ raise Fog::Errors::Error.new "FOG_CREDENTIAL specified is for vCloud organisation '#{fog_credential_org}' but " +
508
+ "your current session is for '#{session_org}'. You should generate a new FOG_VCLOUD_TOKEN."
509
+ end
510
+
511
+ if session_user != fog_credential_user
512
+ raise Fog::Errors::Error.new "FOG_CREDENTIAL specified is for user '#{fog_credential_user}' but " +
513
+ "your current session is for '#{session_user}'. You should generate a new FOG_VCLOUD_TOKEN."
514
+ end
515
+ end
516
+ end
517
+
518
+ class Mock
519
+ attr_reader :end_point, :api_version
520
+
521
+ # This is used in some mocks so it's a method rather than a variable
522
+ def default_network_uuid
523
+ @default_network_uuid ||= uuid
524
+ end
525
+
526
+ def data
527
+ @@data ||= Hash.new do |hash, key|
528
+
529
+ vdc1_uuid = uuid
530
+ vdc2_uuid = uuid
531
+ uplink_network_uuid = uuid
532
+ isolated_vdc1_network_uuid = uuid
533
+ isolated_vdc2_network_uuid = uuid
534
+ vapp1_id = "vapp-#{uuid}"
535
+ vapp2_id = "vapp-#{uuid}"
536
+ vapp1vm1_id = "vm-#{uuid}"
537
+ vapp2vm1_id = "vm-#{uuid}"
538
+ vapp2vm2_id = "vm-#{uuid}"
539
+ catalog_uuid = uuid
540
+ template_uuid = uuid
541
+
542
+ hash[key] = {
543
+ :catalogs => {
544
+ catalog_uuid => {
545
+ :name => 'Default Catalog'
546
+ }
547
+ },
548
+ :catalog_items => {
549
+ uuid => {
550
+ :type => 'vAppTemplate',
551
+ :name => 'vAppTemplate 1',
552
+ :catalog => catalog_uuid,
553
+ :template_id => template_uuid
554
+ }
555
+ },
556
+ :disks => {
557
+ uuid => {
558
+ :name => 'Hard Disk 1',
559
+ :capacity => 10240,
560
+ :parent_vm => vapp1vm1_id
561
+ }
562
+ },
563
+ :edge_gateways => {
564
+ uuid => {
565
+ :name => 'MockEdgeGateway',
566
+ :networks => [uplink_network_uuid, default_network_uuid],
567
+ :vdc => vdc1_uuid,
568
+ :Configuration => {
569
+ :GatewayBackingConfig => "compact",
570
+ :GatewayInterfaces => {
571
+ :GatewayInterface => []},
572
+ :EdgeGatewayServiceConfiguration => {
573
+ :FirewallService => {
574
+ :IsEnabled => "true",
575
+ :DefaultAction => "drop",
576
+ :LogDefaultAction => "false",
577
+ :FirewallRule => []
578
+ },
579
+ :NatService => {:IsEnabled => "true"}},
580
+ :HaEnabled => "false",
581
+ :UseDefaultRouteForDnsRelay => "false"
582
+ }
583
+ }
584
+ },
585
+
586
+ :medias => {},
587
+
588
+ :networks => {
589
+
590
+ default_network_uuid => {
591
+ :IsShared => true,
592
+ :vdc => vdc1_uuid,
593
+ :FenceMode => 'natRouted',
594
+ :ApplyRateLimit => "false",
595
+ :Description => 'Org Network for mocking',
596
+ :Dns1 => '8.8.8.8',
597
+ :Dns2 => '8.8.4.4',
598
+ :DnsSuffix => 'example.com',
599
+ :Gateway => '192.168.1.1',
600
+ :InterfaceType => "internal",
601
+ :IpRanges => [{
602
+ :StartAddress=>'192.168.1.2',
603
+ :EndAddress=>'192.168.1.254'
604
+ }],
605
+ :IsInherited => false,
606
+ :Netmask => '255.255.255.0',
607
+ :name => 'vDC1 Default Network',
608
+ :SubnetParticipation => {
609
+ :Gateway => "192.168.1.0",
610
+ :Netmask => "255.255.0.0",
611
+ :IpAddress => "192.168.1.0"
612
+ },
613
+ :UseForDefaultRoute => "false"
614
+ },
615
+
616
+ isolated_vdc1_network_uuid => {
617
+ :IsShared => false,
618
+ :vdc => vdc1_uuid,
619
+ :ApplyRateLimit => "false",
620
+ :FenceMode => 'isolated',
621
+ :Description => 'Org Network for mocking',
622
+ :Dns1 => '8.8.8.8',
623
+ :Dns2 => '8.8.4.4',
624
+ :DnsSuffix => 'example.com',
625
+ :InterfaceType => "internal",
626
+ :IpRanges => [{
627
+ :StartAddress=>'10.1.0.100',
628
+ :EndAddress=>'10.1.0.200'
629
+ }],
630
+ :IsInherited => false,
631
+ :Netmask => '255.255.255.0',
632
+ :name => 'vDC1 backend network',
633
+ :SubnetParticipation => {
634
+ :Gateway => "192.168.1.0",
635
+ :Netmask => "255.255.0.0",
636
+ :IpAddress => "192.168.1.0"
637
+ },
638
+ :UseForDefaultRoute => "false"
639
+ },
640
+
641
+ isolated_vdc2_network_uuid => {
642
+ :IsShared => false,
643
+ :vdc => vdc2_uuid,
644
+ :ApplyRateLimit => "false",
645
+ :Description => 'Org Network for mocking',
646
+ :Dns1 => '8.8.8.8',
647
+ :Dns2 => '8.8.4.4',
648
+ :DnsSuffix => 'example.com',
649
+ :InterfaceType => "internal",
650
+ :IpRanges => [{
651
+ :StartAddress=>'10.2.0.100',
652
+ :EndAddress=>'10.2.0.200'
653
+ }],
654
+ :IsInherited => false,
655
+ :Netmask => '255.255.255.0',
656
+ :name => 'vDC2 backend network',
657
+ :SubnetParticipation => {
658
+ :Gateway => "192.168.1.0",
659
+ :Netmask => "255.255.0.0",
660
+ :IpAddress => "192.168.1.0"
661
+ },
662
+ :UseForDefaultRoute => "false"
663
+ },
664
+
665
+ uplink_network_uuid => {
666
+ :IsShared => false,
667
+ :vdc => vdc1_uuid,
668
+ :ApplyRateLimit => "false",
669
+ :FenceMode => 'bridged',
670
+ :Description => 'Uplink Network for mocking',
671
+ :Dns1 => '8.8.8.8',
672
+ :Dns2 => '8.8.4.4',
673
+ :DnsSuffix => 'example.com',
674
+ :Gateway => '198.51.100.1',
675
+ :InterfaceType => "uplink",
676
+ :IpRanges => [{
677
+ :StartAddress=>'198.51.100.2',
678
+ :EndAddress=>'198.51.100.254'
679
+ }],
680
+ :IsInherited => false,
681
+ :Netmask => '255.255.255.0',
682
+ :name => 'uplink Network',
683
+ :SubnetParticipation => {
684
+ :Gateway => "198.51.100.81",
685
+ :Netmask => "255.255.255.248",
686
+ :IpAddress => "198.51.100.83",
687
+ :IpRanges => {
688
+ :IpRange => {
689
+ :StartAddress => "198.51.100.84",
690
+ :EndAddress => "198.51.100.86"
691
+ }
692
+ }
693
+ },
694
+ :UseForDefaultRoute => "true"
695
+ }
696
+
697
+ },
698
+ :org => {
699
+ :description => 'Organization for mocking',
700
+ :full_name => 'Mock Organization',
701
+ :name => org_name,
702
+ :uuid => uuid
703
+ },
704
+
705
+ :tags => {},
706
+
707
+ :tasks => {},
708
+
709
+ :vapps => {
710
+ vapp1_id => {
711
+ :name => 'mock-vapp-1',
712
+ :vdc_id => vdc1_uuid,
713
+ :description => "Mock vApp 1",
714
+ :networks => [
715
+ { :parent_id => default_network_uuid, },
716
+ ],
717
+ },
718
+ vapp2_id => {
719
+ :name => 'mock-vapp-2',
720
+ :vdc_id => vdc2_uuid,
721
+ :description => "Mock vApp 2",
722
+ :networks => [
723
+ { :parent_id => default_network_uuid },
724
+ ]
725
+ },
726
+ },
727
+
728
+ :vdc_storage_classes => {
729
+ uuid => {
730
+ :default => true,
731
+ :enabled => true,
732
+ :limit => 2 * 1024 * 1024,
733
+ :name => 'DefaultMockStorageClass',
734
+ :units => 'MB',
735
+ :vdc => vdc1_uuid,
736
+ }
737
+ },
738
+
739
+ :vdcs => {
740
+ vdc1_uuid => {
741
+ :description => 'vDC1 for mocking',
742
+ :name => 'MockVDC 1'
743
+ },
744
+ vdc2_uuid => {
745
+ :description => 'vDC2 for mocking',
746
+ :name => 'MockVDC 2'
747
+ },
748
+ },
749
+
750
+ :vms => {
751
+ vapp1vm1_id => {
752
+ :name => 'mock-vm-1-1',
753
+ :parent_vapp => vapp1_id,
754
+ :nics => [
755
+ {
756
+ :network_name => 'Default Network',
757
+ :mac_address => "00:50:56:aa:bb:01",
758
+ :ip_address => "192.168.1.33",
759
+ },
760
+ ],
761
+ },
762
+ vapp2vm1_id => {
763
+ :name => 'mock-vm-2-1',
764
+ :parent_vapp => vapp2_id,
765
+ :nics => [
766
+ {
767
+ :network_name => 'Default Network',
768
+ :mac_address => "00:50:56:aa:bb:02",
769
+ :ip_address => "192.168.1.34",
770
+ },
771
+ ],
772
+ },
773
+ vapp2vm2_id => {
774
+ :name => 'mock-vm-2-2',
775
+ :parent_vapp => vapp2_id,
776
+ :nics => [
777
+ {
778
+ :network_name => 'Default Network',
779
+ :mac_address => "00:50:56:aa:bb:03",
780
+ :ip_address => "192.168.1.35",
781
+ },
782
+ ],
783
+ },
784
+ },
785
+
786
+ }
787
+ end[@vcloud_director_username]
788
+ end
789
+
790
+ def initialize(options={})
791
+ @vcloud_director_password = options[:vcloud_director_password]
792
+ @vcloud_director_username = options[:vcloud_director_username]
793
+ #@connection_options = options[:connection_options] || {}
794
+ @host = options[:vcloud_director_host]
795
+ @path = options[:path] || Fog::Compute::VcloudDirector::Defaults::PATH
796
+ @persistent = options[:persistent] || false
797
+ @port = options[:port] || Fog::Compute::VcloudDirector::Defaults::PORT
798
+ @scheme = options[:scheme] || Fog::Compute::VcloudDirector::Defaults::SCHEME
799
+ #@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
800
+ @end_point = "#{@scheme}://#{@host}#{@path}/"
801
+ @api_version = options[:vcloud_director_api_version] || Fog::Compute::VcloudDirector::Defaults::API_VERSION
802
+ @vcloud_token = options[:vcloud_token]
803
+ end
804
+
805
+ def vcloud_token
806
+ @vcloud_token || Fog::Mock.random_base64(32)
807
+ end
808
+
809
+ def org_name
810
+ @org_name ||=
811
+ begin
812
+ username = @vcloud_director_username.split('@')
813
+ if username.size >= 2 # may be 'email_address@org_name'
814
+ username.last
815
+ else
816
+ Fog::Logger.warning('vcloud_director_username should be in the form user@org_name')
817
+ 'vcd_org_name'
818
+ end
819
+ end
820
+ end
821
+
822
+ def user_name
823
+ @user_name ||= @vcloud_director_username.split('@').first
824
+ end
825
+
826
+ def user_uuid
827
+ @user_uuid ||= uuid
828
+ end
829
+
830
+ def uuid
831
+ [8,4,4,4,12].map {|i| Fog::Mock.random_hex(i)}.join('-')
832
+ end
833
+
834
+ # Create a task.
835
+ #
836
+ # @param [String] operation A message describing the operation that is
837
+ # tracked by this task.
838
+ # @param [String] operation_name The short name of the operation that
839
+ # is tracked by this task.
840
+ # @param [Hash] owner Reference to the owner of the task. This is
841
+ # typically the object that the task is creating or updating.
842
+ # * :href<~String> - Contains the URI to the entity.
843
+ # * :type<~String> - Contains the MIME type of the entity.
844
+ # @return [String] Object identifier of the task.
845
+ def enqueue_task(operation, operation_name, owner, options={})
846
+ task_id = uuid
847
+ now = DateTime.now
848
+
849
+ data[:tasks][task_id] = {
850
+ :cancel_requested => false,
851
+ :details => '',
852
+ :expiry_time => now + 86400, # in 24 hours
853
+ :name => 'task',
854
+ :progress => 1,
855
+ :service_namespace => 'com.vmware.vcloud',
856
+ :start_time => now,
857
+ :end_time => now + 86400,
858
+ :status => 'running',
859
+ }.merge(options).merge(
860
+ :operation => operation,
861
+ :operation_name => operation_name,
862
+ :owner => owner
863
+ )
864
+
865
+ task_id
866
+ end
867
+
868
+ # @note As far as this method is concerned, the only possible task
869
+ # states are 'running' and 'success'.
870
+ #
871
+ # @param [Hash] response_body
872
+ # @return [Boolean]
873
+ def process_task(response_body)
874
+ task_id = response_body[:href].split('/').last
875
+ task = data[:tasks][task_id]
876
+
877
+ if task[:status] == 'running'
878
+ task[:end_time] = DateTime.now
879
+ task[:progress] = 100
880
+ task[:status] = 'success'
881
+
882
+ if task[:on_success]
883
+ task[:on_success].call
884
+ task.delete(:on_success)
885
+ end
886
+ end
887
+
888
+ return true if task[:status] == 'success'
889
+ raise TaskError.new "status: #{task[:status]}, error: #{task[:Error]}"
890
+ end
891
+
892
+ def add_id_from_href!(data={})
893
+ data[:id] = data[:href].split('/').last
894
+ end
895
+
896
+ private
897
+
898
+ def make_href(path)
899
+ "#{@end_point}#{path}"
900
+ end
901
+
902
+ def xmlns
903
+ 'http://www.vmware.com/vcloud/v1.5'
904
+ end
905
+
906
+ def xmlns_xsi
907
+ 'http://www.w3.org/2001/XMLSchema-instance'
908
+ end
909
+
910
+ def xsi_schema_location
911
+ "http://www.vmware.com/vcloud/v1.5 http://#{@host}#{@path}/v1.5/schema/master.xsd"
912
+ end
913
+ end
914
+ end
915
+ end
916
+ end