cifrado 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (361) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.gitignore +18 -0
  3. data/CHANGELOG.md +44 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +247 -0
  7. data/RELEASE.md +10 -0
  8. data/Rakefile +21 -0
  9. data/TODO.md +6 -0
  10. data/bin/cifrado +7 -0
  11. data/cifrado.gemspec +31 -0
  12. data/gem-public_cert.pem +20 -0
  13. data/lib/cifrado.rb +48 -0
  14. data/lib/cifrado/cli.rb +140 -0
  15. data/lib/cifrado/cli/cinema.rb +81 -0
  16. data/lib/cifrado/cli/delete.rb +36 -0
  17. data/lib/cifrado/cli/download.rb +54 -0
  18. data/lib/cifrado/cli/jukebox.rb +94 -0
  19. data/lib/cifrado/cli/list.rb +64 -0
  20. data/lib/cifrado/cli/post.rb +10 -0
  21. data/lib/cifrado/cli/progressbar.rb +86 -0
  22. data/lib/cifrado/cli/saio.rb +11 -0
  23. data/lib/cifrado/cli/saio/base.rb +20 -0
  24. data/lib/cifrado/cli/saio/bootstrap.rb +118 -0
  25. data/lib/cifrado/cli/saio/destroy.rb +16 -0
  26. data/lib/cifrado/cli/saio/scripts/saio.sh.erb +445 -0
  27. data/lib/cifrado/cli/set_acl.rb +10 -0
  28. data/lib/cifrado/cli/setup.rb +64 -0
  29. data/lib/cifrado/cli/stat.rb +41 -0
  30. data/lib/cifrado/cli/upload.rb +269 -0
  31. data/lib/cifrado/config.rb +18 -0
  32. data/lib/cifrado/core_ext/ruby18_base64.rb +15 -0
  33. data/lib/cifrado/crypto_services.rb +218 -0
  34. data/lib/cifrado/file_splitter.rb +67 -0
  35. data/lib/cifrado/rate_limit.rb +23 -0
  36. data/lib/cifrado/streaming_downloader.rb +49 -0
  37. data/lib/cifrado/streaming_uploader.rb +57 -0
  38. data/lib/cifrado/swift_client.rb +313 -0
  39. data/lib/cifrado/utils.rb +59 -0
  40. data/lib/cifrado/version.rb +3 -0
  41. data/tests/cli/list_tests.rb +28 -0
  42. data/tests/cli/upload_multi_tests.rb +94 -0
  43. data/tests/cli/upload_tests.rb +167 -0
  44. data/tests/cli_tests.rb +2 -0
  45. data/tests/crypto_services_tests.rb +145 -0
  46. data/tests/file_splitter_tests.rb +61 -0
  47. data/tests/helper.rb +117 -0
  48. data/tests/swift_client/create_directory.rb +14 -0
  49. data/tests/swift_client/download_tests.rb +208 -0
  50. data/tests/swift_client/file_available.rb +25 -0
  51. data/tests/swift_client/head_tests.rb +34 -0
  52. data/tests/swift_client/match_tests.rb +29 -0
  53. data/tests/swift_client/upload_tests.rb +70 -0
  54. data/tests/swift_client_tests.rb +29 -0
  55. data/tests/utils_tests.rb +33 -0
  56. data/vendor/fog/.document +3 -0
  57. data/vendor/fog/.gitignore +23 -0
  58. data/vendor/fog/.irbrc +82 -0
  59. data/vendor/fog/.travis.yml +21 -0
  60. data/vendor/fog/README.cifrado +3 -0
  61. data/vendor/fog/README.md +156 -0
  62. data/vendor/fog/RELEASE.md +39 -0
  63. data/vendor/fog/changelog.txt +4156 -0
  64. data/vendor/fog/fog.gemspec +70 -0
  65. data/vendor/fog/lib/fog.rb +17 -0
  66. data/vendor/fog/lib/fog/cdn.rb +30 -0
  67. data/vendor/fog/lib/fog/compute.rb +127 -0
  68. data/vendor/fog/lib/fog/compute/models/server.rb +73 -0
  69. data/vendor/fog/lib/fog/core.rb +38 -0
  70. data/vendor/fog/lib/fog/core/attributes.rb +221 -0
  71. data/vendor/fog/lib/fog/core/collection.rb +145 -0
  72. data/vendor/fog/lib/fog/core/connection.rb +36 -0
  73. data/vendor/fog/lib/fog/core/credentials.rb +65 -0
  74. data/vendor/fog/lib/fog/core/current_machine.rb +34 -0
  75. data/vendor/fog/lib/fog/core/deprecated_connection_accessors.rb +41 -0
  76. data/vendor/fog/lib/fog/core/deprecation.rb +23 -0
  77. data/vendor/fog/lib/fog/core/errors.rb +108 -0
  78. data/vendor/fog/lib/fog/core/hmac.rb +48 -0
  79. data/vendor/fog/lib/fog/core/json.rb +34 -0
  80. data/vendor/fog/lib/fog/core/logger.rb +45 -0
  81. data/vendor/fog/lib/fog/core/mock.rb +92 -0
  82. data/vendor/fog/lib/fog/core/model.rb +79 -0
  83. data/vendor/fog/lib/fog/core/parser.rb +116 -0
  84. data/vendor/fog/lib/fog/core/provider.rb +35 -0
  85. data/vendor/fog/lib/fog/core/scp.rb +96 -0
  86. data/vendor/fog/lib/fog/core/service.rb +223 -0
  87. data/vendor/fog/lib/fog/core/ssh.rb +137 -0
  88. data/vendor/fog/lib/fog/core/time.rb +32 -0
  89. data/vendor/fog/lib/fog/core/timeout.rb +11 -0
  90. data/vendor/fog/lib/fog/core/wait_for.rb +15 -0
  91. data/vendor/fog/lib/fog/digitalocean.rb +9 -0
  92. data/vendor/fog/lib/fog/digitalocean/compute.rb +100 -0
  93. data/vendor/fog/lib/fog/digitalocean/examples/getting_started.md +106 -0
  94. data/vendor/fog/lib/fog/digitalocean/models/compute/flavor.rb +14 -0
  95. data/vendor/fog/lib/fog/digitalocean/models/compute/flavors.rb +25 -0
  96. data/vendor/fog/lib/fog/digitalocean/models/compute/image.rb +15 -0
  97. data/vendor/fog/lib/fog/digitalocean/models/compute/images.rb +25 -0
  98. data/vendor/fog/lib/fog/digitalocean/models/compute/region.rb +14 -0
  99. data/vendor/fog/lib/fog/digitalocean/models/compute/regions.rb +25 -0
  100. data/vendor/fog/lib/fog/digitalocean/models/compute/server.rb +150 -0
  101. data/vendor/fog/lib/fog/digitalocean/models/compute/servers.rb +27 -0
  102. data/vendor/fog/lib/fog/digitalocean/requests/compute/create_server.rb +49 -0
  103. data/vendor/fog/lib/fog/digitalocean/requests/compute/create_ssh_key.rb +26 -0
  104. data/vendor/fog/lib/fog/digitalocean/requests/compute/destroy_server.rb +28 -0
  105. data/vendor/fog/lib/fog/digitalocean/requests/compute/get_server_details.rb +25 -0
  106. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_flavors.rb +25 -0
  107. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_images.rb +25 -0
  108. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_regions.rb +25 -0
  109. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_servers.rb +25 -0
  110. data/vendor/fog/lib/fog/digitalocean/requests/compute/list_ssh_keys.rb +25 -0
  111. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_cycle_server.rb +25 -0
  112. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_off_server.rb +25 -0
  113. data/vendor/fog/lib/fog/digitalocean/requests/compute/power_on_server.rb +25 -0
  114. data/vendor/fog/lib/fog/digitalocean/requests/compute/reboot_server.rb +25 -0
  115. data/vendor/fog/lib/fog/digitalocean/requests/compute/shutdown_server.rb +25 -0
  116. data/vendor/fog/lib/fog/dns.rb +59 -0
  117. data/vendor/fog/lib/fog/identity.rb +27 -0
  118. data/vendor/fog/lib/fog/image.rb +24 -0
  119. data/vendor/fog/lib/fog/local.rb +11 -0
  120. data/vendor/fog/lib/fog/local/models/storage/directories.rb +33 -0
  121. data/vendor/fog/lib/fog/local/models/storage/directory.rb +57 -0
  122. data/vendor/fog/lib/fog/local/models/storage/file.rb +131 -0
  123. data/vendor/fog/lib/fog/local/models/storage/files.rb +87 -0
  124. data/vendor/fog/lib/fog/local/storage.rb +103 -0
  125. data/vendor/fog/lib/fog/network.rb +26 -0
  126. data/vendor/fog/lib/fog/openstack.rb +214 -0
  127. data/vendor/fog/lib/fog/openstack/README.identity.md +69 -0
  128. data/vendor/fog/lib/fog/openstack/compute.rb +423 -0
  129. data/vendor/fog/lib/fog/openstack/identity.rb +299 -0
  130. data/vendor/fog/lib/fog/openstack/image.rb +217 -0
  131. data/vendor/fog/lib/fog/openstack/models/compute/address.rb +71 -0
  132. data/vendor/fog/lib/fog/openstack/models/compute/addresses.rb +33 -0
  133. data/vendor/fog/lib/fog/openstack/models/compute/flavor.rb +45 -0
  134. data/vendor/fog/lib/fog/openstack/models/compute/flavors.rb +28 -0
  135. data/vendor/fog/lib/fog/openstack/models/compute/host.rb +29 -0
  136. data/vendor/fog/lib/fog/openstack/models/compute/hosts.rb +32 -0
  137. data/vendor/fog/lib/fog/openstack/models/compute/image.rb +58 -0
  138. data/vendor/fog/lib/fog/openstack/models/compute/images.rb +33 -0
  139. data/vendor/fog/lib/fog/openstack/models/compute/key_pair.rb +60 -0
  140. data/vendor/fog/lib/fog/openstack/models/compute/key_pairs.rb +31 -0
  141. data/vendor/fog/lib/fog/openstack/models/compute/metadata.rb +68 -0
  142. data/vendor/fog/lib/fog/openstack/models/compute/metadatum.rb +29 -0
  143. data/vendor/fog/lib/fog/openstack/models/compute/network.rb +13 -0
  144. data/vendor/fog/lib/fog/openstack/models/compute/networks.rb +29 -0
  145. data/vendor/fog/lib/fog/openstack/models/compute/security_group.rb +44 -0
  146. data/vendor/fog/lib/fog/openstack/models/compute/security_groups.rb +27 -0
  147. data/vendor/fog/lib/fog/openstack/models/compute/server.rb +278 -0
  148. data/vendor/fog/lib/fog/openstack/models/compute/servers.rb +44 -0
  149. data/vendor/fog/lib/fog/openstack/models/compute/snapshot.rb +44 -0
  150. data/vendor/fog/lib/fog/openstack/models/compute/snapshots.rb +26 -0
  151. data/vendor/fog/lib/fog/openstack/models/compute/tenant.rb +24 -0
  152. data/vendor/fog/lib/fog/openstack/models/compute/tenants.rb +24 -0
  153. data/vendor/fog/lib/fog/openstack/models/compute/volume.rb +59 -0
  154. data/vendor/fog/lib/fog/openstack/models/compute/volumes.rb +26 -0
  155. data/vendor/fog/lib/fog/openstack/models/identity/ec2_credential.rb +44 -0
  156. data/vendor/fog/lib/fog/openstack/models/identity/ec2_credentials.rb +53 -0
  157. data/vendor/fog/lib/fog/openstack/models/identity/role.rb +50 -0
  158. data/vendor/fog/lib/fog/openstack/models/identity/roles.rb +21 -0
  159. data/vendor/fog/lib/fog/openstack/models/identity/tenant.rb +62 -0
  160. data/vendor/fog/lib/fog/openstack/models/identity/tenants.rb +29 -0
  161. data/vendor/fog/lib/fog/openstack/models/identity/user.rb +70 -0
  162. data/vendor/fog/lib/fog/openstack/models/identity/users.rb +32 -0
  163. data/vendor/fog/lib/fog/openstack/models/image/image.rb +91 -0
  164. data/vendor/fog/lib/fog/openstack/models/image/images.rb +60 -0
  165. data/vendor/fog/lib/fog/openstack/models/meta_parent.rb +33 -0
  166. data/vendor/fog/lib/fog/openstack/models/network/floating_ip.rb +52 -0
  167. data/vendor/fog/lib/fog/openstack/models/network/floating_ips.rb +34 -0
  168. data/vendor/fog/lib/fog/openstack/models/network/network.rb +47 -0
  169. data/vendor/fog/lib/fog/openstack/models/network/networks.rb +34 -0
  170. data/vendor/fog/lib/fog/openstack/models/network/port.rb +53 -0
  171. data/vendor/fog/lib/fog/openstack/models/network/ports.rb +34 -0
  172. data/vendor/fog/lib/fog/openstack/models/network/subnet.rb +56 -0
  173. data/vendor/fog/lib/fog/openstack/models/network/subnets.rb +34 -0
  174. data/vendor/fog/lib/fog/openstack/models/storage/directories.rb +39 -0
  175. data/vendor/fog/lib/fog/openstack/models/storage/directory.rb +50 -0
  176. data/vendor/fog/lib/fog/openstack/models/storage/file.rb +152 -0
  177. data/vendor/fog/lib/fog/openstack/models/storage/files.rb +94 -0
  178. data/vendor/fog/lib/fog/openstack/models/volume/volume.rb +47 -0
  179. data/vendor/fog/lib/fog/openstack/models/volume/volumes.rb +27 -0
  180. data/vendor/fog/lib/fog/openstack/network.rb +247 -0
  181. data/vendor/fog/lib/fog/openstack/requests/compute/add_fixed_ip.rb +29 -0
  182. data/vendor/fog/lib/fog/openstack/requests/compute/allocate_address.rb +42 -0
  183. data/vendor/fog/lib/fog/openstack/requests/compute/associate_address.rb +27 -0
  184. data/vendor/fog/lib/fog/openstack/requests/compute/attach_volume.rb +38 -0
  185. data/vendor/fog/lib/fog/openstack/requests/compute/boot_from_snapshot.rb +41 -0
  186. data/vendor/fog/lib/fog/openstack/requests/compute/change_server_password.rb +24 -0
  187. data/vendor/fog/lib/fog/openstack/requests/compute/confirm_resize_server.rb +24 -0
  188. data/vendor/fog/lib/fog/openstack/requests/compute/create_flavor.rb +85 -0
  189. data/vendor/fog/lib/fog/openstack/requests/compute/create_image.rb +49 -0
  190. data/vendor/fog/lib/fog/openstack/requests/compute/create_key_pair.rb +49 -0
  191. data/vendor/fog/lib/fog/openstack/requests/compute/create_security_group.rb +52 -0
  192. data/vendor/fog/lib/fog/openstack/requests/compute/create_security_group_rule.rb +59 -0
  193. data/vendor/fog/lib/fog/openstack/requests/compute/create_server.rb +131 -0
  194. data/vendor/fog/lib/fog/openstack/requests/compute/create_volume.rb +54 -0
  195. data/vendor/fog/lib/fog/openstack/requests/compute/create_volume_snapshot.rb +47 -0
  196. data/vendor/fog/lib/fog/openstack/requests/compute/delete_flavor.rb +28 -0
  197. data/vendor/fog/lib/fog/openstack/requests/compute/delete_image.rb +40 -0
  198. data/vendor/fog/lib/fog/openstack/requests/compute/delete_key_pair.rb +31 -0
  199. data/vendor/fog/lib/fog/openstack/requests/compute/delete_metadata.rb +28 -0
  200. data/vendor/fog/lib/fog/openstack/requests/compute/delete_security_group.rb +33 -0
  201. data/vendor/fog/lib/fog/openstack/requests/compute/delete_security_group_rule.rb +31 -0
  202. data/vendor/fog/lib/fog/openstack/requests/compute/delete_server.rb +38 -0
  203. data/vendor/fog/lib/fog/openstack/requests/compute/delete_snapshot.rb +26 -0
  204. data/vendor/fog/lib/fog/openstack/requests/compute/delete_volume.rb +26 -0
  205. data/vendor/fog/lib/fog/openstack/requests/compute/detach_volume.rb +26 -0
  206. data/vendor/fog/lib/fog/openstack/requests/compute/disassociate_address.rb +27 -0
  207. data/vendor/fog/lib/fog/openstack/requests/compute/get_address.rb +41 -0
  208. data/vendor/fog/lib/fog/openstack/requests/compute/get_console_output.rb +28 -0
  209. data/vendor/fog/lib/fog/openstack/requests/compute/get_flavor_details.rb +43 -0
  210. data/vendor/fog/lib/fog/openstack/requests/compute/get_host_details.rb +74 -0
  211. data/vendor/fog/lib/fog/openstack/requests/compute/get_image_details.rb +33 -0
  212. data/vendor/fog/lib/fog/openstack/requests/compute/get_limits.rb +93 -0
  213. data/vendor/fog/lib/fog/openstack/requests/compute/get_metadata.rb +29 -0
  214. data/vendor/fog/lib/fog/openstack/requests/compute/get_quota.rb +31 -0
  215. data/vendor/fog/lib/fog/openstack/requests/compute/get_quota_defaults.rb +31 -0
  216. data/vendor/fog/lib/fog/openstack/requests/compute/get_security_group.rb +49 -0
  217. data/vendor/fog/lib/fog/openstack/requests/compute/get_server_details.rb +32 -0
  218. data/vendor/fog/lib/fog/openstack/requests/compute/get_server_volumes.rb +23 -0
  219. data/vendor/fog/lib/fog/openstack/requests/compute/get_snapshot_details.rb +39 -0
  220. data/vendor/fog/lib/fog/openstack/requests/compute/get_usage.rb +53 -0
  221. data/vendor/fog/lib/fog/openstack/requests/compute/get_vnc_console.rb +40 -0
  222. data/vendor/fog/lib/fog/openstack/requests/compute/get_volume_details.rb +42 -0
  223. data/vendor/fog/lib/fog/openstack/requests/compute/list_address_pools.rb +23 -0
  224. data/vendor/fog/lib/fog/openstack/requests/compute/list_addresses.rb +32 -0
  225. data/vendor/fog/lib/fog/openstack/requests/compute/list_all_addresses.rb +64 -0
  226. data/vendor/fog/lib/fog/openstack/requests/compute/list_flavors.rb +38 -0
  227. data/vendor/fog/lib/fog/openstack/requests/compute/list_flavors_detail.rb +38 -0
  228. data/vendor/fog/lib/fog/openstack/requests/compute/list_hosts.rb +32 -0
  229. data/vendor/fog/lib/fog/openstack/requests/compute/list_images.rb +33 -0
  230. data/vendor/fog/lib/fog/openstack/requests/compute/list_images_detail.rb +39 -0
  231. data/vendor/fog/lib/fog/openstack/requests/compute/list_key_pairs.rb +39 -0
  232. data/vendor/fog/lib/fog/openstack/requests/compute/list_metadata.rb +28 -0
  233. data/vendor/fog/lib/fog/openstack/requests/compute/list_private_addresses.rb +32 -0
  234. data/vendor/fog/lib/fog/openstack/requests/compute/list_public_addresses.rb +32 -0
  235. data/vendor/fog/lib/fog/openstack/requests/compute/list_security_groups.rb +50 -0
  236. data/vendor/fog/lib/fog/openstack/requests/compute/list_servers.rb +37 -0
  237. data/vendor/fog/lib/fog/openstack/requests/compute/list_servers_detail.rb +44 -0
  238. data/vendor/fog/lib/fog/openstack/requests/compute/list_snapshots.rb +32 -0
  239. data/vendor/fog/lib/fog/openstack/requests/compute/list_tenants.rb +45 -0
  240. data/vendor/fog/lib/fog/openstack/requests/compute/list_usages.rb +43 -0
  241. data/vendor/fog/lib/fog/openstack/requests/compute/list_volumes.rb +51 -0
  242. data/vendor/fog/lib/fog/openstack/requests/compute/live_migrate_server.rb +31 -0
  243. data/vendor/fog/lib/fog/openstack/requests/compute/migrate_server.rb +24 -0
  244. data/vendor/fog/lib/fog/openstack/requests/compute/pause_server.rb +24 -0
  245. data/vendor/fog/lib/fog/openstack/requests/compute/reboot_server.rb +24 -0
  246. data/vendor/fog/lib/fog/openstack/requests/compute/rebuild_server.rb +31 -0
  247. data/vendor/fog/lib/fog/openstack/requests/compute/release_address.rb +34 -0
  248. data/vendor/fog/lib/fog/openstack/requests/compute/remove_fixed_ip.rb +29 -0
  249. data/vendor/fog/lib/fog/openstack/requests/compute/rescue_server.rb +24 -0
  250. data/vendor/fog/lib/fog/openstack/requests/compute/reset_server_state.rb +24 -0
  251. data/vendor/fog/lib/fog/openstack/requests/compute/resize_server.rb +24 -0
  252. data/vendor/fog/lib/fog/openstack/requests/compute/resume_server.rb +24 -0
  253. data/vendor/fog/lib/fog/openstack/requests/compute/revert_resize_server.rb +30 -0
  254. data/vendor/fog/lib/fog/openstack/requests/compute/server_action.rb +18 -0
  255. data/vendor/fog/lib/fog/openstack/requests/compute/server_actions.rb +27 -0
  256. data/vendor/fog/lib/fog/openstack/requests/compute/server_diagnostics.rb +25 -0
  257. data/vendor/fog/lib/fog/openstack/requests/compute/set_metadata.rb +45 -0
  258. data/vendor/fog/lib/fog/openstack/requests/compute/set_tenant.rb +21 -0
  259. data/vendor/fog/lib/fog/openstack/requests/compute/suspend_server.rb +24 -0
  260. data/vendor/fog/lib/fog/openstack/requests/compute/unpause_server.rb +24 -0
  261. data/vendor/fog/lib/fog/openstack/requests/compute/update_metadata.rb +46 -0
  262. data/vendor/fog/lib/fog/openstack/requests/compute/update_quota.rb +32 -0
  263. data/vendor/fog/lib/fog/openstack/requests/compute/update_server.rb +35 -0
  264. data/vendor/fog/lib/fog/openstack/requests/identity/add_user_to_tenant.rb +34 -0
  265. data/vendor/fog/lib/fog/openstack/requests/identity/check_token.rb +23 -0
  266. data/vendor/fog/lib/fog/openstack/requests/identity/create_ec2_credential.rb +58 -0
  267. data/vendor/fog/lib/fog/openstack/requests/identity/create_role.rb +37 -0
  268. data/vendor/fog/lib/fog/openstack/requests/identity/create_tenant.rb +32 -0
  269. data/vendor/fog/lib/fog/openstack/requests/identity/create_user.rb +47 -0
  270. data/vendor/fog/lib/fog/openstack/requests/identity/create_user_role.rb +26 -0
  271. data/vendor/fog/lib/fog/openstack/requests/identity/delete_ec2_credential.rb +44 -0
  272. data/vendor/fog/lib/fog/openstack/requests/identity/delete_role.rb +32 -0
  273. data/vendor/fog/lib/fog/openstack/requests/identity/delete_tenant.rb +31 -0
  274. data/vendor/fog/lib/fog/openstack/requests/identity/delete_user.rb +32 -0
  275. data/vendor/fog/lib/fog/openstack/requests/identity/delete_user_role.rb +26 -0
  276. data/vendor/fog/lib/fog/openstack/requests/identity/get_ec2_credential.rb +49 -0
  277. data/vendor/fog/lib/fog/openstack/requests/identity/get_role.rb +28 -0
  278. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenant.rb +31 -0
  279. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenants_by_id.rb +23 -0
  280. data/vendor/fog/lib/fog/openstack/requests/identity/get_tenants_by_name.rb +23 -0
  281. data/vendor/fog/lib/fog/openstack/requests/identity/get_user_by_id.rb +34 -0
  282. data/vendor/fog/lib/fog/openstack/requests/identity/get_user_by_name.rb +31 -0
  283. data/vendor/fog/lib/fog/openstack/requests/identity/list_ec2_credentials.rb +44 -0
  284. data/vendor/fog/lib/fog/openstack/requests/identity/list_endpoints_for_token.rb +23 -0
  285. data/vendor/fog/lib/fog/openstack/requests/identity/list_roles.rb +36 -0
  286. data/vendor/fog/lib/fog/openstack/requests/identity/list_roles_for_user_on_tenant.rb +30 -0
  287. data/vendor/fog/lib/fog/openstack/requests/identity/list_tenants.rb +45 -0
  288. data/vendor/fog/lib/fog/openstack/requests/identity/list_user_global_roles.rb +22 -0
  289. data/vendor/fog/lib/fog/openstack/requests/identity/list_users.rb +34 -0
  290. data/vendor/fog/lib/fog/openstack/requests/identity/remove_user_from_tenant.rb +20 -0
  291. data/vendor/fog/lib/fog/openstack/requests/identity/set_tenant.rb +21 -0
  292. data/vendor/fog/lib/fog/openstack/requests/identity/update_tenant.rb +28 -0
  293. data/vendor/fog/lib/fog/openstack/requests/identity/update_user.rb +36 -0
  294. data/vendor/fog/lib/fog/openstack/requests/identity/validate_token.rb +23 -0
  295. data/vendor/fog/lib/fog/openstack/requests/image/add_member_to_image.rb +23 -0
  296. data/vendor/fog/lib/fog/openstack/requests/image/create_image.rb +79 -0
  297. data/vendor/fog/lib/fog/openstack/requests/image/delete_image.rb +25 -0
  298. data/vendor/fog/lib/fog/openstack/requests/image/get_image.rb +45 -0
  299. data/vendor/fog/lib/fog/openstack/requests/image/get_image_by_id.rb +32 -0
  300. data/vendor/fog/lib/fog/openstack/requests/image/get_image_members.rb +29 -0
  301. data/vendor/fog/lib/fog/openstack/requests/image/get_shared_images.rb +29 -0
  302. data/vendor/fog/lib/fog/openstack/requests/image/list_public_images.rb +32 -0
  303. data/vendor/fog/lib/fog/openstack/requests/image/list_public_images_detailed.rb +31 -0
  304. data/vendor/fog/lib/fog/openstack/requests/image/remove_member_from_image.rb +23 -0
  305. data/vendor/fog/lib/fog/openstack/requests/image/set_tenant.rb +21 -0
  306. data/vendor/fog/lib/fog/openstack/requests/image/update_image.rb +70 -0
  307. data/vendor/fog/lib/fog/openstack/requests/image/update_image_members.rb +37 -0
  308. data/vendor/fog/lib/fog/openstack/requests/network/associate_floating_ip.rb +49 -0
  309. data/vendor/fog/lib/fog/openstack/requests/network/create_floating_ip.rb +50 -0
  310. data/vendor/fog/lib/fog/openstack/requests/network/create_network.rb +44 -0
  311. data/vendor/fog/lib/fog/openstack/requests/network/create_port.rb +52 -0
  312. data/vendor/fog/lib/fog/openstack/requests/network/create_subnet.rb +56 -0
  313. data/vendor/fog/lib/fog/openstack/requests/network/delete_floating_ip.rb +30 -0
  314. data/vendor/fog/lib/fog/openstack/requests/network/delete_network.rb +30 -0
  315. data/vendor/fog/lib/fog/openstack/requests/network/delete_port.rb +30 -0
  316. data/vendor/fog/lib/fog/openstack/requests/network/delete_subnet.rb +30 -0
  317. data/vendor/fog/lib/fog/openstack/requests/network/disassociate_floating_ip.rb +49 -0
  318. data/vendor/fog/lib/fog/openstack/requests/network/get_floating_ip.rb +42 -0
  319. data/vendor/fog/lib/fog/openstack/requests/network/get_network.rb +42 -0
  320. data/vendor/fog/lib/fog/openstack/requests/network/get_port.rb +48 -0
  321. data/vendor/fog/lib/fog/openstack/requests/network/get_subnet.rb +49 -0
  322. data/vendor/fog/lib/fog/openstack/requests/network/list_floating_ips.rb +27 -0
  323. data/vendor/fog/lib/fog/openstack/requests/network/list_networks.rb +27 -0
  324. data/vendor/fog/lib/fog/openstack/requests/network/list_ports.rb +27 -0
  325. data/vendor/fog/lib/fog/openstack/requests/network/list_subnets.rb +27 -0
  326. data/vendor/fog/lib/fog/openstack/requests/network/set_tenant.rb +21 -0
  327. data/vendor/fog/lib/fog/openstack/requests/network/update_network.rb +41 -0
  328. data/vendor/fog/lib/fog/openstack/requests/network/update_port.rb +44 -0
  329. data/vendor/fog/lib/fog/openstack/requests/network/update_subnet.rb +44 -0
  330. data/vendor/fog/lib/fog/openstack/requests/storage/copy_object.rb +27 -0
  331. data/vendor/fog/lib/fog/openstack/requests/storage/delete_container.rb +22 -0
  332. data/vendor/fog/lib/fog/openstack/requests/storage/delete_object.rb +23 -0
  333. data/vendor/fog/lib/fog/openstack/requests/storage/get_container.rb +44 -0
  334. data/vendor/fog/lib/fog/openstack/requests/storage/get_containers.rb +33 -0
  335. data/vendor/fog/lib/fog/openstack/requests/storage/get_object.rb +29 -0
  336. data/vendor/fog/lib/fog/openstack/requests/storage/get_object_https_url.rb +51 -0
  337. data/vendor/fog/lib/fog/openstack/requests/storage/head_container.rb +28 -0
  338. data/vendor/fog/lib/fog/openstack/requests/storage/head_containers.rb +25 -0
  339. data/vendor/fog/lib/fog/openstack/requests/storage/head_object.rb +23 -0
  340. data/vendor/fog/lib/fog/openstack/requests/storage/post_set_meta_temp_url_key.rb +37 -0
  341. data/vendor/fog/lib/fog/openstack/requests/storage/put_container.rb +22 -0
  342. data/vendor/fog/lib/fog/openstack/requests/storage/put_object.rb +30 -0
  343. data/vendor/fog/lib/fog/openstack/requests/storage/put_object_manifest.rb +25 -0
  344. data/vendor/fog/lib/fog/openstack/requests/volume/create_volume.rb +54 -0
  345. data/vendor/fog/lib/fog/openstack/requests/volume/create_volume_snapshot.rb +47 -0
  346. data/vendor/fog/lib/fog/openstack/requests/volume/delete_snapshot.rb +26 -0
  347. data/vendor/fog/lib/fog/openstack/requests/volume/delete_volume.rb +26 -0
  348. data/vendor/fog/lib/fog/openstack/requests/volume/get_snapshot_details.rb +39 -0
  349. data/vendor/fog/lib/fog/openstack/requests/volume/get_volume_details.rb +42 -0
  350. data/vendor/fog/lib/fog/openstack/requests/volume/list_snapshots.rb +32 -0
  351. data/vendor/fog/lib/fog/openstack/requests/volume/list_volumes.rb +55 -0
  352. data/vendor/fog/lib/fog/openstack/requests/volume/set_tenant.rb +21 -0
  353. data/vendor/fog/lib/fog/openstack/storage.rb +162 -0
  354. data/vendor/fog/lib/fog/openstack/volume.rb +219 -0
  355. data/vendor/fog/lib/fog/providers.rb +2 -0
  356. data/vendor/fog/lib/fog/schema/data_validator.rb +154 -0
  357. data/vendor/fog/lib/fog/storage.rb +97 -0
  358. data/vendor/fog/lib/fog/version.rb +3 -0
  359. data/vendor/fog/lib/fog/volume.rb +25 -0
  360. metadata +576 -0
  361. metadata.gz.sig +0 -0
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Network
3
+
4
+ def self.[](provider)
5
+ self.new(:provider => provider)
6
+ end
7
+
8
+ def self.new(attributes)
9
+ attributes = attributes.dup # Prevent delete from having side effects
10
+ provider = attributes.delete(:provider).to_s.downcase.to_sym
11
+
12
+ case provider
13
+ when :openstack
14
+ require 'fog/openstack/network'
15
+ Fog::Network::OpenStack.new(attributes)
16
+ else
17
+ raise ArgumentError.new("#{provider} has no network service")
18
+ end
19
+ end
20
+
21
+ def self.providers
22
+ Fog.services[:network]
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,214 @@
1
+ require 'fog/core'
2
+
3
+ Cifrado::Log.debug 'Loading vendored fog'
4
+
5
+ module Fog
6
+ module OpenStack
7
+ extend Fog::Provider
8
+
9
+ module Errors
10
+ class ServiceError < Fog::Errors::Error
11
+ attr_reader :response_data
12
+
13
+ def self.slurp(error)
14
+ if error.response.body.empty?
15
+ data = nil
16
+ message = nil
17
+ else
18
+ data = Fog::JSON.decode(error.response.body)
19
+ message = data['message']
20
+ if message.nil? and !data.values.first.nil?
21
+ message = data.values.first['message']
22
+ end
23
+ end
24
+
25
+ new_error = super(error, message)
26
+ new_error.instance_variable_set(:@response_data, data)
27
+ new_error
28
+ end
29
+ end
30
+
31
+ class ServiceUnavailable < ServiceError; end
32
+
33
+ class BadRequest < ServiceError
34
+ attr_reader :validation_errors
35
+
36
+ def self.slurp(error)
37
+ new_error = super(error)
38
+ unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil?
39
+ new_error.instance_variable_set(:@validation_errors, new_error.response_data['badRequest']['validationErrors'])
40
+ end
41
+ new_error
42
+ end
43
+ end
44
+ end
45
+
46
+ service(:compute , 'openstack/compute' , 'Compute' )
47
+ service(:identity, 'openstack/identity', 'Identity')
48
+ service(:network, 'openstack/network', 'Network')
49
+ service(:storage, 'openstack/storage', 'Storage')
50
+
51
+ # legacy v1.0 style auth
52
+ def self.authenticate_v1(options, connection_options = {})
53
+ uri = options[:openstack_auth_uri]
54
+ connection = Fog::Connection.new(uri.to_s, false, connection_options)
55
+ @openstack_api_key = options[:openstack_api_key]
56
+ @openstack_username = options[:openstack_username]
57
+
58
+ response = connection.request({
59
+ :expects => [200, 204],
60
+ :headers => {
61
+ 'X-Auth-Key' => @openstack_api_key,
62
+ 'X-Auth-User' => @openstack_username
63
+ },
64
+ :host => uri.host,
65
+ :method => 'GET',
66
+ :path => (uri.path and not uri.path.empty?) ? uri.path : 'v1.0'
67
+ })
68
+
69
+ return {
70
+ :token => response.headers['X-Auth-Token'],
71
+ :server_management_url => response.headers['X-Server-Management-Url'],
72
+ :identity_public_endpoint => response.headers['X-Keystone']
73
+ }
74
+ end
75
+
76
+ # Keystone Style Auth
77
+ def self.authenticate_v2(options, connection_options = {})
78
+ uri = options[:openstack_auth_uri]
79
+ tenant_name = options[:openstack_tenant]
80
+ service_type = options[:openstack_service_type]
81
+ service_name = options[:openstack_service_name]
82
+ identity_service_type = options[:openstack_identity_service_type]
83
+ endpoint_type = (options[:openstack_endpoint_type] || 'publicURL').to_s
84
+ openstack_region = options[:openstack_region]
85
+
86
+
87
+ body = retrieve_tokens_v2(options, connection_options)
88
+ service = get_service(body, service_type, service_name)
89
+
90
+ options[:unscoped_token] = body['access']['token']['id']
91
+
92
+ unless service
93
+ unless tenant_name
94
+ response = Fog::Connection.new(
95
+ "#{uri.scheme}://#{uri.host}:#{uri.port}/v2.0/tenants", false, connection_options).request({
96
+ :expects => [200, 204],
97
+ :headers => {'Content-Type' => 'application/json',
98
+ 'Accept' => 'application/json',
99
+ 'X-Auth-Token' => body['access']['token']['id']},
100
+ :host => uri.host,
101
+ :method => 'GET'
102
+ })
103
+
104
+ body = Fog::JSON.decode(response.body)
105
+ if body['tenants'].empty?
106
+ raise Fog::Errors::NotFound.new('No Tenant Found')
107
+ else
108
+ options[:openstack_tenant] = body['tenants'].first['name']
109
+ end
110
+ end
111
+
112
+ body = retrieve_tokens_v2(options, connection_options)
113
+ service = get_service(body, service_type, service_name)
114
+
115
+ end
116
+
117
+ service['endpoints'] = service['endpoints'].select do |endpoint|
118
+ endpoint['region'] == openstack_region
119
+ end if openstack_region
120
+
121
+ if service['endpoints'].empty?
122
+ raise Errors::NotFound.new("No endpoints available for region '#{openstack_region}'")
123
+ end if openstack_region
124
+
125
+ unless service
126
+ available = body['access']['serviceCatalog'].map { |endpoint|
127
+ endpoint['type']
128
+ }.sort.join ', '
129
+
130
+ missing = service_type
131
+
132
+ message = "Could not find service #{missing}. Have #{available}"
133
+
134
+ raise Fog::Errors::NotFound, message
135
+ end
136
+
137
+ if service['endpoints'].count > 1
138
+ regions = service["endpoints"].map{ |e| e['region'] }.uniq.join(',')
139
+ raise Fog::Errors::NotFound.new("Multiple regions available choose one of these '#{regions}'")
140
+ end
141
+
142
+ identity_service = get_service(body, identity_service_type) if identity_service_type
143
+ tenant = body['access']['token']['tenant']
144
+ user = body['access']['user']
145
+
146
+ management_url = service['endpoints'].detect{|s| s[endpoint_type]}[endpoint_type]
147
+ identity_url = identity_service['endpoints'].detect{|s| s['publicURL']}['publicURL'] if identity_service
148
+
149
+ {
150
+ :user => user,
151
+ :tenant => tenant,
152
+ :identity_public_endpoint => identity_url,
153
+ :server_management_url => management_url,
154
+ :token => body['access']['token']['id'],
155
+ :expires => body['access']['token']['expires'],
156
+ :current_user_id => body['access']['user']['id'],
157
+ :unscoped_token => options[:unscoped_token]
158
+ }
159
+
160
+ end
161
+
162
+ def self.get_service(body, service_type=[], service_name=nil)
163
+ body['access']['serviceCatalog'].detect do |s|
164
+ if service_name.nil? or service_name.empty?
165
+ service_type.include?(s['type'])
166
+ else
167
+ service_type.include?(s['type']) and s['name'] == service_name
168
+ end
169
+ end
170
+ end
171
+
172
+ def self.retrieve_tokens_v2(options, connection_options = {})
173
+ api_key = options[:openstack_api_key].to_s
174
+ username = options[:openstack_username].to_s
175
+ tenant_name = options[:openstack_tenant].to_s
176
+ auth_token = options[:openstack_auth_token] || options[:unscoped_token]
177
+ uri = options[:openstack_auth_uri]
178
+
179
+ connection = Fog::Connection.new(uri.to_s, false, connection_options)
180
+ request_body = {:auth => Hash.new}
181
+
182
+ if auth_token
183
+ request_body[:auth][:token] = {
184
+ :id => auth_token
185
+ }
186
+ else
187
+ request_body[:auth][:passwordCredentials] = {
188
+ :username => username,
189
+ :password => api_key
190
+ }
191
+ end
192
+ request_body[:auth][:tenantName] = tenant_name if tenant_name
193
+
194
+ response = connection.request({
195
+ :expects => [200, 204],
196
+ :headers => {'Content-Type' => 'application/json'},
197
+ :body => Fog::JSON.encode(request_body),
198
+ :host => uri.host,
199
+ :method => 'POST',
200
+ :path => (uri.path and not uri.path.empty?) ? uri.path : 'v2.0'
201
+ })
202
+
203
+ Fog::JSON.decode(response.body)
204
+ end
205
+
206
+ # CGI.escape, but without special treatment on spaces
207
+ def self.escape(str,extra_exclude_chars = '')
208
+ str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do
209
+ '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
210
+ end
211
+ end
212
+
213
+ end
214
+ end
@@ -0,0 +1,69 @@
1
+ # OpenStack Identity Service (Keystone) Example
2
+
3
+ require 'fog'
4
+ require 'pp'
5
+
6
+ auth_url = "https://example.net/v2.0/tokens"
7
+ username = 'admin@example.net'
8
+ password = 'secret'
9
+
10
+ keystone = Fog::Identity.new :provider => 'OpenStack',
11
+ :openstack_auth_url => auth_url,
12
+ :openstack_username => username,
13
+ :openstack_api_key => password
14
+ # Optional, self-signed certs
15
+ #:connection_options => { :ssl_verify_peer => false }
16
+
17
+ #
18
+ # Listing keystone tenants
19
+ #
20
+ keystone.tenants.each do |tenant|
21
+ # <Fog::Identity::OpenStack::Tenant
22
+ # id="46b4ab...",
23
+ # description=nil,
24
+ # enabled=1,
25
+ # name="admin@example.net"
26
+ # >
27
+ #pp tenant
28
+ end
29
+
30
+ #
31
+ # List users
32
+ #
33
+ keystone.users.each do |user|
34
+ # <Fog::Identity::OpenStack::User
35
+ # id="c975f...",
36
+ # email="quantum@example.net",
37
+ # enabled=true,
38
+ # name="quantum",
39
+ # tenant_id="00928...",
40
+ # password=nil
41
+ # >
42
+ # ...
43
+ #pp user
44
+ end
45
+
46
+ #
47
+ # Create a new tenant
48
+ #
49
+ tenant = keystone.tenants.create :name => 'rubiojr@example.net',
50
+ :description => 'My foo tenant'
51
+
52
+ #
53
+ # Create a new user
54
+ #
55
+ user = keystone.users.create :name => 'rubiojr@example.net',
56
+ :tenant_id => tenant.id,
57
+ :password => 'rubiojr@example.net',
58
+ :email => 'rubiojr@example.net'
59
+
60
+
61
+ # Find the recently created tenant
62
+ tenant = keystone.tenants.find { |t| t.name == 'rubiojr@example.net' }
63
+ # Destroy the tenant
64
+ tenant.destroy
65
+
66
+ # Find the recently created user
67
+ user = keystone.users.find { |u| u.name == 'rubiojr@example.net' }
68
+ # Destroy the user
69
+ user.destroy
@@ -0,0 +1,423 @@
1
+ require 'fog/compute'
2
+ require 'fog/openstack'
3
+
4
+ module Fog
5
+ module Compute
6
+ class OpenStack < Fog::Service
7
+
8
+ requires :openstack_auth_url
9
+ recognizes :openstack_auth_token, :openstack_management_url,
10
+ :persistent, :openstack_service_type, :openstack_service_name,
11
+ :openstack_tenant,
12
+ :openstack_api_key, :openstack_username, :openstack_identity_endpoint,
13
+ :current_user, :current_tenant, :openstack_region,
14
+ :openstack_endpoint_type
15
+
16
+ ## MODELS
17
+ #
18
+ model_path 'fog/openstack/models/compute'
19
+ model :server
20
+ collection :servers
21
+ model :image
22
+ collection :images
23
+ model :flavor
24
+ collection :flavors
25
+ model :metadatum
26
+ collection :metadata
27
+ model :address
28
+ collection :addresses
29
+ model :security_group
30
+ collection :security_groups
31
+ model :key_pair
32
+ collection :key_pairs
33
+ model :tenant
34
+ collection :tenants
35
+ model :volume
36
+ collection :volumes
37
+ model :network
38
+ collection :networks
39
+ model :snapshot
40
+ collection :snapshots
41
+ model :host
42
+ collection :hosts
43
+
44
+ ## REQUESTS
45
+ #
46
+ request_path 'fog/openstack/requests/compute'
47
+
48
+ # Server CRUD
49
+ request :list_servers
50
+ request :list_servers_detail
51
+ request :create_server
52
+ request :get_server_details
53
+ request :update_server
54
+ request :delete_server
55
+
56
+ # Server Actions
57
+ request :server_actions
58
+ request :server_action
59
+ request :reboot_server
60
+ request :rebuild_server
61
+ request :resize_server
62
+ request :confirm_resize_server
63
+ request :revert_resize_server
64
+ request :pause_server
65
+ request :unpause_server
66
+ request :suspend_server
67
+ request :resume_server
68
+ request :rescue_server
69
+ request :change_server_password
70
+ request :add_fixed_ip
71
+ request :remove_fixed_ip
72
+ request :server_diagnostics
73
+ request :boot_from_snapshot
74
+ request :reset_server_state
75
+
76
+ # Server Extenstions
77
+ request :get_console_output
78
+ request :get_vnc_console
79
+ request :live_migrate_server
80
+ request :migrate_server
81
+
82
+ # Image CRUD
83
+ request :list_images
84
+ request :list_images_detail
85
+ request :create_image
86
+ request :get_image_details
87
+ request :delete_image
88
+
89
+ # Flavor CRUD
90
+ request :list_flavors
91
+ request :list_flavors_detail
92
+ request :get_flavor_details
93
+ request :create_flavor
94
+ request :delete_flavor
95
+
96
+ # Metadata
97
+ request :list_metadata
98
+ request :get_metadata
99
+ request :set_metadata
100
+ request :update_metadata
101
+ request :delete_metadata
102
+
103
+ # Address
104
+ request :list_addresses
105
+ request :list_address_pools
106
+ request :list_all_addresses
107
+ request :list_private_addresses
108
+ request :list_public_addresses
109
+ request :get_address
110
+ request :allocate_address
111
+ request :associate_address
112
+ request :release_address
113
+ request :disassociate_address
114
+
115
+ # Security Group
116
+ request :list_security_groups
117
+ request :get_security_group
118
+ request :create_security_group
119
+ request :create_security_group_rule
120
+ request :delete_security_group
121
+ request :delete_security_group_rule
122
+
123
+ # Key Pair
124
+ request :list_key_pairs
125
+ request :create_key_pair
126
+ request :delete_key_pair
127
+
128
+ # Tenant
129
+ request :list_tenants
130
+ request :set_tenant
131
+ request :get_limits
132
+
133
+ # Volume
134
+ request :list_volumes
135
+ request :create_volume
136
+ request :get_volume_details
137
+ request :delete_volume
138
+ request :attach_volume
139
+ request :detach_volume
140
+ request :get_server_volumes
141
+
142
+ request :create_volume_snapshot
143
+ request :list_snapshots
144
+ request :get_snapshot_details
145
+ request :delete_snapshot
146
+
147
+ # Usage
148
+ request :list_usages
149
+ request :get_usage
150
+
151
+ # Quota
152
+ request :get_quota
153
+ request :get_quota_defaults
154
+ request :update_quota
155
+
156
+ # Hosts
157
+ request :list_hosts
158
+ request :get_host_details
159
+
160
+
161
+ class Mock
162
+ attr_reader :auth_token
163
+ attr_reader :auth_token_expiration
164
+ attr_reader :current_user
165
+ attr_reader :current_tenant
166
+
167
+ def self.data
168
+ @data ||= Hash.new do |hash, key|
169
+ hash[key] = {
170
+ :last_modified => {
171
+ :images => {},
172
+ :servers => {},
173
+ :key_pairs => {},
174
+ :security_groups => {},
175
+ :addresses => {}
176
+ },
177
+ :images => {
178
+ "0e09fbd6-43c5-448a-83e9-0d3d05f9747e" => {
179
+ "id"=>"0e09fbd6-43c5-448a-83e9-0d3d05f9747e",
180
+ "name"=>"cirros-0.3.0-x86_64-blank",
181
+ 'progress' => 100,
182
+ 'status' => "ACTIVE",
183
+ 'updated' => "",
184
+ 'minRam' => 0,
185
+ 'minDisk' => 0,
186
+ 'metadata' => {},
187
+ 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/images/1", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/images/2", "rel"=>"bookmark"}]
188
+ }
189
+ },
190
+ :servers => {},
191
+ :key_pairs => {},
192
+ :security_groups => {
193
+ 0 => {
194
+ "id" => 0,
195
+ "tenant_id" => Fog::Mock.random_hex(8),
196
+ "name" => "default",
197
+ "description" => "default",
198
+ "rules" => [
199
+ { "id" => 0,
200
+ "parent_group_id" => 0,
201
+ "from_port" => 68,
202
+ "to_port" => 68,
203
+ "ip_protocol" => "udp",
204
+ "ip_range" => { "cidr" => "0.0.0.0/0" },
205
+ "group" => {}, },
206
+ ],
207
+ },
208
+ },
209
+ :server_security_group_map => {},
210
+ :addresses => {},
211
+ :quota => {
212
+ 'security_group_rules' => 20,
213
+ 'security_groups' => 10,
214
+ 'injected_file_content_bytes' => 10240,
215
+ 'injected_file_path_bytes' => 256,
216
+ 'injected_files' => 5,
217
+ 'metadata_items' => 128,
218
+ 'floating_ips' => 10,
219
+ 'instances' => 10,
220
+ 'key_pairs' => 10,
221
+ 'gigabytes' => 5000,
222
+ 'volumes' => 10,
223
+ 'cores' => 20,
224
+ 'ram' => 51200
225
+ }
226
+ }
227
+ end
228
+ end
229
+
230
+ def self.reset
231
+ @data = nil
232
+ end
233
+
234
+ def initialize(options={})
235
+ @openstack_username = options[:openstack_username]
236
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
237
+
238
+ @current_tenant = options[:openstack_tenant]
239
+
240
+ @auth_token = Fog::Mock.random_base64(64)
241
+ @auth_token_expiration = (Time.now.utc + 86400).iso8601
242
+
243
+ management_url = URI.parse(options[:openstack_auth_url])
244
+ management_url.port = 8774
245
+ management_url.path = '/v1.1/1'
246
+ @openstack_management_url = management_url.to_s
247
+
248
+ identity_public_endpoint = URI.parse(options[:openstack_auth_url])
249
+ identity_public_endpoint.port = 5000
250
+ @openstack_identity_public_endpoint = identity_public_endpoint.to_s
251
+ end
252
+
253
+ def data
254
+ self.class.data["#{@openstack_username}-#{@current_tenant}"]
255
+ end
256
+
257
+ def reset_data
258
+ self.class.data.delete("#{@openstack_username}-#{@current_tenant}")
259
+ end
260
+
261
+ def credentials
262
+ { :provider => 'openstack',
263
+ :openstack_auth_url => @openstack_auth_uri.to_s,
264
+ :openstack_auth_token => @auth_token,
265
+ :openstack_management_url => @openstack_management_url,
266
+ :openstack_identity_endpoint => @openstack_identity_public_endpoint }
267
+ end
268
+ end
269
+
270
+ class Real
271
+ attr_reader :auth_token
272
+ attr_reader :auth_token_expiration
273
+ attr_reader :current_user
274
+ attr_reader :current_tenant
275
+
276
+ def initialize(options={})
277
+ @openstack_auth_token = options[:openstack_auth_token]
278
+ @auth_token = options[:openstack_auth_token]
279
+ @openstack_identity_public_endpoint = options[:openstack_identity_endpoint]
280
+
281
+ unless @auth_token
282
+ missing_credentials = Array.new
283
+ @openstack_api_key = options[:openstack_api_key]
284
+ @openstack_username = options[:openstack_username]
285
+
286
+ missing_credentials << :openstack_api_key unless @openstack_api_key
287
+ missing_credentials << :openstack_username unless @openstack_username
288
+ raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
289
+ end
290
+
291
+ @openstack_tenant = options[:openstack_tenant]
292
+ @openstack_auth_uri = URI.parse(options[:openstack_auth_url])
293
+ @openstack_management_url = options[:openstack_management_url]
294
+ @openstack_must_reauthenticate = false
295
+ @openstack_service_type = options[:openstack_service_type] || ['nova', 'compute']
296
+ @openstack_service_name = options[:openstack_service_name]
297
+ @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity'
298
+ @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
299
+ @openstack_region = options[:openstack_region]
300
+
301
+ @connection_options = options[:connection_options] || {}
302
+
303
+ @current_user = options[:current_user]
304
+ @current_tenant = options[:current_tenant]
305
+
306
+ authenticate
307
+
308
+ @persistent = options[:persistent] || false
309
+ @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
310
+ end
311
+
312
+ def credentials
313
+ { :provider => 'openstack',
314
+ :openstack_auth_url => @openstack_auth_uri.to_s,
315
+ :openstack_auth_token => @auth_token,
316
+ :openstack_management_url => @openstack_management_url,
317
+ :openstack_identity_endpoint => @openstack_identity_public_endpoint,
318
+ :openstack_region => @openstack_region,
319
+ :current_user => @current_user,
320
+ :current_tenant => @current_tenant }
321
+ end
322
+
323
+ def reload
324
+ @connection.reset
325
+ end
326
+
327
+ def request(params)
328
+ begin
329
+ response = @connection.request(params.merge({
330
+ :headers => {
331
+ 'Content-Type' => 'application/json',
332
+ 'Accept' => 'application/json',
333
+ 'X-Auth-Token' => @auth_token
334
+ }.merge!(params[:headers] || {}),
335
+ :host => @host,
336
+ :path => "#{@path}/#{@tenant_id}/#{params[:path]}",
337
+ :query => params[:query] || ('ignore_awful_caching' << Time.now.to_i.to_s)
338
+ }))
339
+ rescue Excon::Errors::Unauthorized => error
340
+ if error.response.body != 'Bad username or password' # token expiration
341
+ @openstack_must_reauthenticate = true
342
+ authenticate
343
+ retry
344
+ else # Bad Credentials
345
+ raise error
346
+ end
347
+ rescue Excon::Errors::HTTPStatusError => error
348
+ raise case error
349
+ when Excon::Errors::NotFound
350
+ Fog::Compute::OpenStack::NotFound.slurp(error)
351
+ else
352
+ error
353
+ end
354
+ end
355
+
356
+ unless response.body.empty?
357
+ response.body = Fog::JSON.decode(response.body)
358
+ end
359
+
360
+ response
361
+ end
362
+
363
+ private
364
+
365
+ def authenticate
366
+ if !@openstack_management_url || @openstack_must_reauthenticate
367
+ options = {
368
+ :openstack_api_key => @openstack_api_key,
369
+ :openstack_username => @openstack_username,
370
+ :openstack_auth_token => @auth_token,
371
+ :openstack_auth_uri => @openstack_auth_uri,
372
+ :openstack_region => @openstack_region,
373
+ :openstack_tenant => @openstack_tenant,
374
+ :openstack_service_type => @openstack_service_type,
375
+ :openstack_service_name => @openstack_service_name,
376
+ :openstack_identity_service_type => @openstack_identity_service_type,
377
+ :openstack_endpoint_type => @openstack_endpoint_type
378
+ }
379
+
380
+ if @openstack_auth_uri.path =~ /\/v2.0\//
381
+
382
+ credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
383
+ else
384
+ credentials = Fog::OpenStack.authenticate_v1(options, @connection_options)
385
+ end
386
+
387
+ @current_user = credentials[:user]
388
+ @current_tenant = credentials[:tenant]
389
+
390
+ @openstack_must_reauthenticate = false
391
+ @auth_token = credentials[:token]
392
+ @auth_token_expiration = credentials[:expires]
393
+ @openstack_management_url = credentials[:server_management_url]
394
+ @openstack_identity_public_endpoint = credentials[:identity_public_endpoint]
395
+ end
396
+
397
+ uri = URI.parse(@openstack_management_url)
398
+ @host = uri.host
399
+ @path, @tenant_id = uri.path.scan(/(\/.*)\/(.*)/).flatten
400
+
401
+ @path.sub!(/\/$/, '')
402
+ unless @path.match(/1\.1|v2/)
403
+ raise Fog::OpenStack::Errors::ServiceUnavailable.new(
404
+ "OpenStack binding only supports version 2 (a.k.a. 1.1)")
405
+ end
406
+
407
+ @port = uri.port
408
+ @scheme = uri.scheme
409
+
410
+ # Not all implementations have identity service in the catalog
411
+ if @openstack_identity_public_endpoint || @openstack_management_url
412
+ @identity_connection = Fog::Connection.new(
413
+ @openstack_identity_public_endpoint || @openstack_management_url,
414
+ false, @connection_options)
415
+ end
416
+
417
+ true
418
+ end
419
+
420
+ end
421
+ end
422
+ end
423
+ end