hpcloud 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/CHANGELOG +127 -0
  2. data/LICENSE +1 -0
  3. data/README.rdoc +59 -0
  4. data/bin/hpcloud +11 -0
  5. data/completion/hpcloud +372 -0
  6. data/lib/hpcloud/accounts.rb +288 -0
  7. data/lib/hpcloud/acl.rb +112 -0
  8. data/lib/hpcloud/acl_cmd.rb +81 -0
  9. data/lib/hpcloud/address_helper.rb +63 -0
  10. data/lib/hpcloud/addresses.rb +42 -0
  11. data/lib/hpcloud/auth_cache.rb +128 -0
  12. data/lib/hpcloud/base_helper.rb +56 -0
  13. data/lib/hpcloud/checker.rb +104 -0
  14. data/lib/hpcloud/cli.rb +170 -0
  15. data/lib/hpcloud/cli_status.rb +80 -0
  16. data/lib/hpcloud/columns.rb +46 -0
  17. data/lib/hpcloud/commands/account/catalog.rb +57 -0
  18. data/lib/hpcloud/commands/account/copy.rb +44 -0
  19. data/lib/hpcloud/commands/account/edit.rb +204 -0
  20. data/lib/hpcloud/commands/account/remove.rb +53 -0
  21. data/lib/hpcloud/commands/account/setup.rb +40 -0
  22. data/lib/hpcloud/commands/account/tenants.rb +43 -0
  23. data/lib/hpcloud/commands/account/use.rb +46 -0
  24. data/lib/hpcloud/commands/account/verify.rb +55 -0
  25. data/lib/hpcloud/commands/account.rb +67 -0
  26. data/lib/hpcloud/commands/acl/grant.rb +59 -0
  27. data/lib/hpcloud/commands/acl/revoke.rb +52 -0
  28. data/lib/hpcloud/commands/acl.rb +63 -0
  29. data/lib/hpcloud/commands/addresses/add.rb +67 -0
  30. data/lib/hpcloud/commands/addresses/associate.rb +63 -0
  31. data/lib/hpcloud/commands/addresses/disassociate.rb +58 -0
  32. data/lib/hpcloud/commands/addresses/remove.rb +57 -0
  33. data/lib/hpcloud/commands/addresses.rb +63 -0
  34. data/lib/hpcloud/commands/cdn_containers/add.rb +56 -0
  35. data/lib/hpcloud/commands/cdn_containers/get.rb +70 -0
  36. data/lib/hpcloud/commands/cdn_containers/location.rb +61 -0
  37. data/lib/hpcloud/commands/cdn_containers/remove.rb +55 -0
  38. data/lib/hpcloud/commands/cdn_containers/set.rb +63 -0
  39. data/lib/hpcloud/commands/cdn_containers.rb +72 -0
  40. data/lib/hpcloud/commands/complete.rb +60 -0
  41. data/lib/hpcloud/commands/config/set.rb +63 -0
  42. data/lib/hpcloud/commands/config.rb +46 -0
  43. data/lib/hpcloud/commands/containers/add.rb +67 -0
  44. data/lib/hpcloud/commands/containers/remove.rb +63 -0
  45. data/lib/hpcloud/commands/containers/sync.rb +59 -0
  46. data/lib/hpcloud/commands/containers.rb +24 -0
  47. data/lib/hpcloud/commands/copy.rb +78 -0
  48. data/lib/hpcloud/commands/dns/add.rb +56 -0
  49. data/lib/hpcloud/commands/dns/records/add.rb +50 -0
  50. data/lib/hpcloud/commands/dns/records/remove.rb +53 -0
  51. data/lib/hpcloud/commands/dns/records/update.rb +50 -0
  52. data/lib/hpcloud/commands/dns/records.rb +57 -0
  53. data/lib/hpcloud/commands/dns/remove.rb +57 -0
  54. data/lib/hpcloud/commands/dns/servers.rb +57 -0
  55. data/lib/hpcloud/commands/dns/update.rb +58 -0
  56. data/lib/hpcloud/commands/dns.rb +65 -0
  57. data/lib/hpcloud/commands/flavors.rb +59 -0
  58. data/lib/hpcloud/commands/get.rb +58 -0
  59. data/lib/hpcloud/commands/images/add.rb +54 -0
  60. data/lib/hpcloud/commands/images/metadata/add.rb +54 -0
  61. data/lib/hpcloud/commands/images/metadata/remove.rb +56 -0
  62. data/lib/hpcloud/commands/images/metadata.rb +54 -0
  63. data/lib/hpcloud/commands/images/remove.rb +58 -0
  64. data/lib/hpcloud/commands/images.rb +67 -0
  65. data/lib/hpcloud/commands/info.rb +41 -0
  66. data/lib/hpcloud/commands/keypairs/add.rb +73 -0
  67. data/lib/hpcloud/commands/keypairs/import.rb +62 -0
  68. data/lib/hpcloud/commands/keypairs/private/add.rb +44 -0
  69. data/lib/hpcloud/commands/keypairs/private/location.rb +50 -0
  70. data/lib/hpcloud/commands/keypairs/private/remove.rb +52 -0
  71. data/lib/hpcloud/commands/keypairs/private.rb +47 -0
  72. data/lib/hpcloud/commands/keypairs/public_key.rb +51 -0
  73. data/lib/hpcloud/commands/keypairs/remove.rb +58 -0
  74. data/lib/hpcloud/commands/keypairs.rb +64 -0
  75. data/lib/hpcloud/commands/lb/add.rb +92 -0
  76. data/lib/hpcloud/commands/lb/algorithms.rb +55 -0
  77. data/lib/hpcloud/commands/lb/limits.rb +55 -0
  78. data/lib/hpcloud/commands/lb/nodes/add.rb +47 -0
  79. data/lib/hpcloud/commands/lb/nodes/remove.rb +54 -0
  80. data/lib/hpcloud/commands/lb/nodes/update.rb +47 -0
  81. data/lib/hpcloud/commands/lb/nodes.rb +55 -0
  82. data/lib/hpcloud/commands/lb/protocols.rb +55 -0
  83. data/lib/hpcloud/commands/lb/remove.rb +54 -0
  84. data/lib/hpcloud/commands/lb/update.rb +46 -0
  85. data/lib/hpcloud/commands/lb/versions.rb +55 -0
  86. data/lib/hpcloud/commands/lb/virtualips.rb +51 -0
  87. data/lib/hpcloud/commands/lb.rb +73 -0
  88. data/lib/hpcloud/commands/list.rb +114 -0
  89. data/lib/hpcloud/commands/location.rb +56 -0
  90. data/lib/hpcloud/commands/metadata/set.rb +61 -0
  91. data/lib/hpcloud/commands/metadata.rb +60 -0
  92. data/lib/hpcloud/commands/migrate.rb +61 -0
  93. data/lib/hpcloud/commands/move.rb +73 -0
  94. data/lib/hpcloud/commands/networks/add.rb +55 -0
  95. data/lib/hpcloud/commands/networks/remove.rb +57 -0
  96. data/lib/hpcloud/commands/networks/update.rb +54 -0
  97. data/lib/hpcloud/commands/networks.rb +63 -0
  98. data/lib/hpcloud/commands/ports/add.rb +81 -0
  99. data/lib/hpcloud/commands/ports/remove.rb +57 -0
  100. data/lib/hpcloud/commands/ports/update.rb +67 -0
  101. data/lib/hpcloud/commands/ports.rb +63 -0
  102. data/lib/hpcloud/commands/remove.rb +75 -0
  103. data/lib/hpcloud/commands/routers/add.rb +67 -0
  104. data/lib/hpcloud/commands/routers/interface/add.rb +59 -0
  105. data/lib/hpcloud/commands/routers/interface/remove.rb +66 -0
  106. data/lib/hpcloud/commands/routers/remove.rb +54 -0
  107. data/lib/hpcloud/commands/routers/update.rb +66 -0
  108. data/lib/hpcloud/commands/routers.rb +66 -0
  109. data/lib/hpcloud/commands/securitygroups/add.rb +52 -0
  110. data/lib/hpcloud/commands/securitygroups/remove.rb +57 -0
  111. data/lib/hpcloud/commands/securitygroups/rules/add.rb +126 -0
  112. data/lib/hpcloud/commands/securitygroups/rules/remove.rb +51 -0
  113. data/lib/hpcloud/commands/securitygroups/rules.rb +56 -0
  114. data/lib/hpcloud/commands/securitygroups.rb +62 -0
  115. data/lib/hpcloud/commands/servers/add.rb +100 -0
  116. data/lib/hpcloud/commands/servers/console.rb +81 -0
  117. data/lib/hpcloud/commands/servers/limits.rb +46 -0
  118. data/lib/hpcloud/commands/servers/metadata/add.rb +56 -0
  119. data/lib/hpcloud/commands/servers/metadata/remove.rb +57 -0
  120. data/lib/hpcloud/commands/servers/metadata.rb +56 -0
  121. data/lib/hpcloud/commands/servers/password.rb +47 -0
  122. data/lib/hpcloud/commands/servers/ratelimits.rb +46 -0
  123. data/lib/hpcloud/commands/servers/reboot.rb +61 -0
  124. data/lib/hpcloud/commands/servers/rebuild.rb +59 -0
  125. data/lib/hpcloud/commands/servers/remove.rb +58 -0
  126. data/lib/hpcloud/commands/servers/securitygroups/add.rb +47 -0
  127. data/lib/hpcloud/commands/servers/securitygroups/remove.rb +47 -0
  128. data/lib/hpcloud/commands/servers/ssh.rb +92 -0
  129. data/lib/hpcloud/commands/servers.rb +92 -0
  130. data/lib/hpcloud/commands/snapshots/add.rb +62 -0
  131. data/lib/hpcloud/commands/snapshots/remove.rb +58 -0
  132. data/lib/hpcloud/commands/snapshots.rb +62 -0
  133. data/lib/hpcloud/commands/subnets/add.rb +78 -0
  134. data/lib/hpcloud/commands/subnets/remove.rb +57 -0
  135. data/lib/hpcloud/commands/subnets/update.rb +70 -0
  136. data/lib/hpcloud/commands/subnets.rb +63 -0
  137. data/lib/hpcloud/commands/tempurl.rb +62 -0
  138. data/lib/hpcloud/commands/volumes/add.rb +88 -0
  139. data/lib/hpcloud/commands/volumes/attach.rb +59 -0
  140. data/lib/hpcloud/commands/volumes/detach.rb +57 -0
  141. data/lib/hpcloud/commands/volumes/metadata/add.rb +54 -0
  142. data/lib/hpcloud/commands/volumes/metadata.rb +55 -0
  143. data/lib/hpcloud/commands/volumes/remove.rb +57 -0
  144. data/lib/hpcloud/commands/volumes/server.rb +64 -0
  145. data/lib/hpcloud/commands/volumes.rb +65 -0
  146. data/lib/hpcloud/config.rb +205 -0
  147. data/lib/hpcloud/connection.rb +290 -0
  148. data/lib/hpcloud/container_resource.rb +175 -0
  149. data/lib/hpcloud/database_helper.rb +70 -0
  150. data/lib/hpcloud/databases.rb +38 -0
  151. data/lib/hpcloud/dns_helper.rb +125 -0
  152. data/lib/hpcloud/dnss.rb +38 -0
  153. data/lib/hpcloud/error_response.rb +89 -0
  154. data/lib/hpcloud/exceptions/base.rb +35 -0
  155. data/lib/hpcloud/exceptions/general.rb +34 -0
  156. data/lib/hpcloud/exceptions/not_found.rb +34 -0
  157. data/lib/hpcloud/flavors.rb +40 -0
  158. data/lib/hpcloud/floating_ip_helper.rb +114 -0
  159. data/lib/hpcloud/floating_ips.rb +42 -0
  160. data/lib/hpcloud/fog_collection.rb +124 -0
  161. data/lib/hpcloud/image_helper.rb +111 -0
  162. data/lib/hpcloud/images.rb +43 -0
  163. data/lib/hpcloud/keypair_helper.rb +109 -0
  164. data/lib/hpcloud/keypairs.rb +41 -0
  165. data/lib/hpcloud/lb_algorithms.rb +37 -0
  166. data/lib/hpcloud/lb_limits.rb +37 -0
  167. data/lib/hpcloud/lb_nodes.rb +42 -0
  168. data/lib/hpcloud/lb_protocols.rb +37 -0
  169. data/lib/hpcloud/lb_versions.rb +37 -0
  170. data/lib/hpcloud/lb_virtualips.rb +42 -0
  171. data/lib/hpcloud/lbs.rb +38 -0
  172. data/lib/hpcloud/local_resource.rb +183 -0
  173. data/lib/hpcloud/log.rb +55 -0
  174. data/lib/hpcloud/metadata.rb +118 -0
  175. data/lib/hpcloud/monkey.rb +22 -0
  176. data/lib/hpcloud/network_helper.rb +88 -0
  177. data/lib/hpcloud/networks.rb +47 -0
  178. data/lib/hpcloud/object_store.rb +66 -0
  179. data/lib/hpcloud/port_helper.rb +150 -0
  180. data/lib/hpcloud/ports.rb +38 -0
  181. data/lib/hpcloud/progress.rb +53 -0
  182. data/lib/hpcloud/remote_resource.rb +512 -0
  183. data/lib/hpcloud/resource.rb +264 -0
  184. data/lib/hpcloud/resource_factory.rb +110 -0
  185. data/lib/hpcloud/routers.rb +56 -0
  186. data/lib/hpcloud/rule_helper.rb +70 -0
  187. data/lib/hpcloud/rules.rb +41 -0
  188. data/lib/hpcloud/security_group_helper.rb +59 -0
  189. data/lib/hpcloud/security_groups.rb +37 -0
  190. data/lib/hpcloud/server_helper.rb +318 -0
  191. data/lib/hpcloud/servers.rb +47 -0
  192. data/lib/hpcloud/shared_resource.rb +172 -0
  193. data/lib/hpcloud/snapshot_helper.rb +78 -0
  194. data/lib/hpcloud/snapshots.rb +38 -0
  195. data/lib/hpcloud/subnet_helper.rb +170 -0
  196. data/lib/hpcloud/subnets.rb +38 -0
  197. data/lib/hpcloud/tableizer.rb +77 -0
  198. data/lib/hpcloud/thor_ext/thor.rb +54 -0
  199. data/lib/hpcloud/time_parser.rb +47 -0
  200. data/lib/hpcloud/version.rb +27 -0
  201. data/lib/hpcloud/volume_attachment.rb +58 -0
  202. data/lib/hpcloud/volume_attachments.rb +58 -0
  203. data/lib/hpcloud/volume_helper.rb +119 -0
  204. data/lib/hpcloud/volumes.rb +38 -0
  205. data/lib/hpcloud.rb +112 -0
  206. data/lib/monkey/hp/lb.rb +188 -0
  207. data/lib/monkey/hp/models/lb/algorithm.rb +32 -0
  208. data/lib/monkey/hp/models/lb/algorithms.rb +46 -0
  209. data/lib/monkey/hp/models/lb/limit.rb +38 -0
  210. data/lib/monkey/hp/models/lb/limits.rb +50 -0
  211. data/lib/monkey/hp/models/lb/load_balancer.rb +70 -0
  212. data/lib/monkey/hp/models/lb/load_balancers.rb +46 -0
  213. data/lib/monkey/hp/models/lb/node.rb +69 -0
  214. data/lib/monkey/hp/models/lb/nodes.rb +47 -0
  215. data/lib/monkey/hp/models/lb/protocol.rb +33 -0
  216. data/lib/monkey/hp/models/lb/protocols.rb +46 -0
  217. data/lib/monkey/hp/models/lb/version.rb +34 -0
  218. data/lib/monkey/hp/models/lb/versions.rb +47 -0
  219. data/lib/monkey/hp/models/lb/virtual_ip.rb +37 -0
  220. data/lib/monkey/hp/models/lb/virtual_ips.rb +47 -0
  221. data/lib/monkey/hp/requests/lb/create_load_balancer.rb +64 -0
  222. data/lib/monkey/hp/requests/lb/create_load_balancer_node.rb +58 -0
  223. data/lib/monkey/hp/requests/lb/delete_load_balancer.rb +54 -0
  224. data/lib/monkey/hp/requests/lb/delete_load_balancer_node.rb +60 -0
  225. data/lib/monkey/hp/requests/lb/get_load_balancer.rb +88 -0
  226. data/lib/monkey/hp/requests/lb/get_load_balancer_node.rb +60 -0
  227. data/lib/monkey/hp/requests/lb/get_version.rb +68 -0
  228. data/lib/monkey/hp/requests/lb/get_virtual_ips.rb +48 -0
  229. data/lib/monkey/hp/requests/lb/list_algorithms.rb +51 -0
  230. data/lib/monkey/hp/requests/lb/list_limits.rb +60 -0
  231. data/lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb +79 -0
  232. data/lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb +76 -0
  233. data/lib/monkey/hp/requests/lb/list_load_balancers.rb +69 -0
  234. data/lib/monkey/hp/requests/lb/list_protocols.rb +51 -0
  235. data/lib/monkey/hp/requests/lb/list_versions.rb +51 -0
  236. data/lib/monkey/hp/requests/lb/update_load_balancer.rb +46 -0
  237. data/lib/monkey/hp/requests/lb/update_load_balancer_node.rb +50 -0
  238. metadata +368 -0
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ #
3
+ # © Copyright 2013 Hewlett-Packard Development Company, L.P.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ module HP
23
+ module Cloud
24
+ class CLI < Thor
25
+
26
+ map %w(volumes:rm volumes:delete volumes:del) => 'volumes:remove'
27
+
28
+ desc "volumes:remove name_or_id [name_or_id ...]", "Remove a volume or volumes (specified by name or ID)."
29
+ long_desc <<-DESC
30
+ Remove volumes by specifying their names or ID. You may specify more than one volume name or ID on a command line. Optionally, you can specify an availability zone.
31
+
32
+ Examples:
33
+ hpcloud volumes:remove tome treatise # Delete the volumes 'tome' and 'treatise'
34
+ hpcloud volumes:remove 038d0e77 # Delete the volume with ID 038d0e77
35
+
36
+ Aliases: volumes:rm, volumes:delete, volumes:del
37
+ DESC
38
+ CLI.add_common_options
39
+ define_method "volumes:remove" do |name_or_id, *name_or_ids|
40
+ cli_command(options) {
41
+ name_or_ids = [name_or_id] + name_or_ids
42
+ volumes = Volumes.new.get(name_or_ids, false)
43
+ volumes.each { |volume|
44
+ sub_command("removing volume") {
45
+ if volume.is_valid?
46
+ volume.destroy
47
+ @log.display "Removed volume '#{volume.name}'."
48
+ else
49
+ @log.error volume.cstatus
50
+ end
51
+ }
52
+ }
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ #
3
+ # © Copyright 2013 Hewlett-Packard Development Company, L.P.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ module HP
23
+ module Cloud
24
+ class CLI < Thor
25
+
26
+ map 'volumes:servers' => 'volumes:server'
27
+
28
+ desc "volumes:server [server]", "List the volumes on server."
29
+ long_desc <<-DESC
30
+ List the volumes attached to servers with the device they are using. Optionally, you may filter by specifying the server name or ID on the command line.
31
+
32
+ Examples:
33
+ hpcloud volumes:server # List all the attached volumes
34
+ hpcloud volumes:server myServer # List the volumes on server `myServer`
35
+ hpcloud volumes:server f9520651 # List the volumes on server `f9520651`
36
+ DESC
37
+ CLI.add_report_options
38
+ CLI.add_common_options
39
+ define_method "volumes:server" do |*arguments|
40
+ cli_command(options) {
41
+ rayray = []
42
+ servers = Servers.new.get(arguments)
43
+ servers.each { |server|
44
+ if server.is_valid? == false
45
+ @log.error server.cstatus
46
+ next
47
+ end
48
+ ray = VolumeAttachments.new(server).get_array()
49
+ if ray.empty?
50
+ unless arguments.empty?
51
+ @log.error "Cannot find any volumes for '#{server.name}'.", :not_found
52
+ end
53
+ next
54
+ end
55
+ rayray += ray
56
+ }
57
+ if rayray.empty? == false
58
+ Tableizer.new(options, VolumeAttachment.get_keys(), rayray).print
59
+ end
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ #
3
+ # © Copyright 2013 Hewlett-Packard Development Company, L.P.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ require 'hpcloud/commands/volumes/add'
23
+ require 'hpcloud/commands/volumes/attach'
24
+ require 'hpcloud/commands/volumes/detach'
25
+ require 'hpcloud/commands/volumes/remove'
26
+ require 'hpcloud/commands/volumes/server'
27
+ require 'hpcloud/volumes'
28
+
29
+ module HP
30
+ module Cloud
31
+ class CLI < Thor
32
+
33
+ map 'volumes:list' => 'volumes'
34
+
35
+ desc 'volumes [name_or_id ...]', "List the available block devices."
36
+ long_desc <<-DESC
37
+ Lists all the block volumes that are associated with the account on the server. The list begins with identifier and contains name, size, type, create date, status, description and servers on which it is attached. Optionally, you can filter the list by specifying name or ID.
38
+
39
+ Examples:
40
+ hpcloud volumes # List all volumes
41
+ hpcloud volumes b8e90a48 # List the details for volume `b8e90a48`
42
+ hpcloud volumes testvol # List the details for volume `testvol`
43
+
44
+ Aliases: volumes:list
45
+ DESC
46
+ CLI.add_report_options
47
+ CLI.add_common_options
48
+ def volumes(*arguments)
49
+ cli_command(options) {
50
+ volumes = Volumes.new
51
+ if volumes.empty?
52
+ @log.display "You currently have no block volume devices, use `#{selfname} volumes:add <name>` to create one."
53
+ else
54
+ ray = volumes.get_array(arguments)
55
+ if ray.empty?
56
+ @log.display "There are no volumes that match the provided arguments"
57
+ else
58
+ Tableizer.new(options, VolumeHelper.get_keys(), ray).print
59
+ end
60
+ end
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+ #
3
+ # © Copyright 2013 Hewlett-Packard Development Company, L.P.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ require 'yaml'
23
+
24
+ module HP
25
+ module Cloud
26
+ class Config
27
+ @@home = nil
28
+ attr_reader :directory, :file, :settings
29
+ KNOWN = [ :default_auth_uri,
30
+ :connect_timeout,
31
+ :read_timeout,
32
+ :write_timeout,
33
+ :preferred_flavor,
34
+ :preferred_image,
35
+ :ssl_verify_peer,
36
+ :ssl_ca_path,
37
+ :ssl_ca_file,
38
+ :default_account,
39
+ :storage_page_length,
40
+ :storage_segment_size,
41
+ :storage_chunk_size,
42
+ :storage_max_size,
43
+ :report_page_length,
44
+ :checker_url,
45
+ :checker_deferment
46
+ ]
47
+
48
+ def initialize(ignore=false)
49
+ if @@home.nil?
50
+ @@home = ENV['HOME']
51
+ end
52
+ @directory = @@home + "/.hpcloud/"
53
+ @file = @directory + "config.yml"
54
+ @file_settings = {}
55
+ @settings = {}
56
+ begin
57
+ read()
58
+ rescue Exception => e
59
+ if ignore
60
+ warn e.to_s
61
+ else
62
+ raise e
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.home_directory=(dir)
68
+ @@home = dir
69
+ end
70
+
71
+ def self.default_config
72
+ return { :default_auth_uri => 'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/',
73
+ :default_account => 'hp'
74
+ }
75
+ end
76
+
77
+ def self.default_options
78
+ return { :connect_timeout => 30,
79
+ :read_timeout => 240,
80
+ :write_timeout => 240,
81
+ :preferred_flavor => 100,
82
+ :ssl_verify_peer => true,
83
+ :ssl_ca_path => nil,
84
+ :ssl_ca_file => nil,
85
+ :default_account => 'hp',
86
+ :checker_url => 'https://region-a.geo-1.objects.hpcloudsvc.com:443/v1/89388614989714/documentation-downloads/unixcli/latest',
87
+ :checker_deferment => 604800,
88
+ }
89
+ end
90
+
91
+ def self.get_known
92
+ ret = ""
93
+ KNOWN.each{|key| ret += "\n" + key.to_s }
94
+ return ret
95
+ end
96
+
97
+ def self.split(nvp)
98
+ begin
99
+ kv = nvp.split('=')
100
+ if kv.length == 2
101
+ return kv[0], kv[1]
102
+ end
103
+ if nvp[-1,1] == '='
104
+ return kv[0], ''
105
+ end
106
+ rescue Exception => e
107
+ end
108
+ raise Exception.new("Invalid name value pair: '#{nvp}'")
109
+ end
110
+
111
+ def list
112
+ return @settings.to_yaml.gsub(/---\n/,'').gsub(/^:/,'')
113
+ end
114
+
115
+ def read
116
+ cfg = Config.default_config()
117
+ if File.exists?(@file)
118
+ begin
119
+ @file_settings = YAML::load(File.open(@file))
120
+ @settings = @file_settings.clone
121
+ raise Exception.new("File parse error") unless @settings.kind_of?(Hash)
122
+ rescue Exception => e
123
+ @settings = cfg
124
+ raise Exception.new("Error reading configuration file: #{@file}\n" + e.to_s)
125
+ end
126
+ else
127
+ @settings = cfg
128
+ end
129
+ options = Config.default_options()
130
+ @settings[:connect_timeout] ||= options[:connect_timeout]
131
+ @settings[:read_timeout] ||= options[:read_timeout]
132
+ @settings[:write_timeout] ||= options[:write_timeout]
133
+ @settings[:preferred_flavor] ||= options[:preferred_flavor]
134
+ @settings[:connect_timeout] = @settings[:connect_timeout].to_i
135
+ @settings[:read_timeout] = @settings[:read_timeout].to_i
136
+ @settings[:write_timeout] = @settings[:write_timeout].to_i
137
+ if @settings[:ssl_verify_peer].nil?
138
+ @settings[:ssl_verify_peer] = options[:ssl_verify_peer]
139
+ end
140
+ if @settings[:ssl_verify_peer].to_s == "false" || @settings[:ssl_verify_peer].to_s == "no"
141
+ @settings[:ssl_verify_peer] = false
142
+ else
143
+ @settings[:ssl_verify_peer] = true
144
+ end
145
+ @settings[:ssl_ca_path] ||= options[:ssl_ca_path]
146
+ @settings[:ssl_ca_file] ||= options[:ssl_ca_file]
147
+ @settings[:default_account] ||= options[:default_account]
148
+ @settings[:checker_url] ||= options[:checker_url]
149
+ @settings[:checker_deferment] ||= options[:checker_deferment]
150
+ @settings[:checker_deferment] = @settings[:checker_deferment].to_i
151
+ @settings.delete_if { |k,v| v.nil? }
152
+ end
153
+
154
+ def get(key)
155
+ return @settings[key.to_sym]
156
+ end
157
+
158
+ def get_i(key, default_value)
159
+ begin
160
+ value = @settings[key.to_sym].to_i
161
+ return default_value if value == 0
162
+ return value
163
+ rescue
164
+ end
165
+ return default_value
166
+ end
167
+
168
+ def set(key, value)
169
+ key = key.to_sym
170
+ if KNOWN.include?(key) == false
171
+ raise Exception.new("Unknown configuration key value '#{key.to_s}'")
172
+ end
173
+ value = value.to_s
174
+ if value.empty?
175
+ @file_settings.delete(key)
176
+ @settings.delete(key)
177
+ else
178
+ if key.to_s == 'ssl_verify_peer'
179
+ if value.to_s == "false" || value.to_s == "no"
180
+ value = false
181
+ else
182
+ value = true
183
+ end
184
+ end
185
+ @file_settings[key] = value
186
+ @settings[key] = value
187
+ end
188
+ return true
189
+ end
190
+
191
+ def write()
192
+ begin
193
+ Dir.mkdir(@directory) unless File.directory?(@directory)
194
+ @file_settings.delete_if { |k,v| v.nil? }
195
+ File.open("#{@file}", 'w') do |file|
196
+ file.write @file_settings.to_yaml
197
+ end
198
+ rescue
199
+ raise Exception.new('Error writing configuration file: ' + @file)
200
+ end
201
+ return true
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,290 @@
1
+ # encoding: utf-8
2
+ #
3
+ # © Copyright 2013 Hewlett-Packard Development Company, L.P.
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ require 'fog/hp'
23
+ require 'hpcloud/auth_cache'
24
+
25
+ module HP
26
+ module Cloud
27
+ class Connection
28
+
29
+ def initialize
30
+ @storage_connection = {}
31
+ @compute_connection = {}
32
+ @block_connection = {}
33
+ @cdn_connection = {}
34
+ @network_connection = {}
35
+ @dns_connection = {}
36
+ @lb_connection = {}
37
+ @authcache = HP::Cloud::AuthCache.new
38
+ @options = {}
39
+ end
40
+ @@instance = Connection.new
41
+ private_class_method :new
42
+
43
+ def self.instance
44
+ return @@instance
45
+ end
46
+
47
+ VALID_SERVICES = ['storage','compute','cdn', 'block']
48
+
49
+ def self.is_service(name)
50
+ return VALID_SERVICES.include?(name)
51
+ end
52
+
53
+ def self.get_services()
54
+ return VALID_SERVICES.join(', ')
55
+ end
56
+
57
+ def reset_connections
58
+ @storage_connection = {}
59
+ @compute_connection = {}
60
+ @block_connection = {}
61
+ @cdn_connection = {}
62
+ @network_connection = {}
63
+ @dns_connection = {}
64
+ @lb_connection = {}
65
+ end
66
+
67
+ def set_options(options)
68
+ if options.nil?
69
+ @options = {}
70
+ return
71
+ end
72
+ if (@options[:availability_zone] != options[:availability_zone])
73
+ reset_connections()
74
+ end
75
+ @options = options
76
+ end
77
+
78
+ def clear_options()
79
+ @options = {}
80
+ reset_connections()
81
+ end
82
+
83
+ def read_creds(account, opts, service)
84
+ creds = @authcache.read(opts)
85
+ if creds.nil?
86
+ return unless opts[:provider] == "hp"
87
+ creds = validate_account(account)
88
+ return if creds.nil?
89
+ @authcache.write(opts, creds)
90
+ end
91
+ if opts[:hp_avl_zone].nil?
92
+ opts[:hp_avl_zone] = @authcache.default_zone(opts, service)
93
+ end
94
+ opts[:credentials] = creds
95
+ end
96
+
97
+ def write_creds(opts, connection)
98
+ if connection.respond_to? :credentials
99
+ @authcache.write(opts, connection.credentials)
100
+ end
101
+ end
102
+
103
+ def storage(account_name=nil)
104
+ account = get_account(account_name)
105
+ return @storage_connection[account] unless @storage_connection[account].nil?
106
+ opts = create_options(account, 'Object Storage')
107
+ read_creds(account, opts, 'Object Storage')
108
+ begin
109
+ @storage_connection[account] = Fog::Storage.new(opts)
110
+ write_creds(opts, @storage_connection[account])
111
+ rescue Exception => e
112
+ @authcache.remove(opts)
113
+ respo = ErrorResponse.new(e).to_s
114
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'Storage' service is activated for the appropriate availability zone.\n Exception: #{respo}\n Print the service catalog: hpcloud account:catalog #{account}"
115
+ end
116
+ return @storage_connection[account]
117
+ end
118
+
119
+ def compute
120
+ account = get_account()
121
+ return @compute_connection[account] unless @compute_connection[account].nil?
122
+ opts = create_options(account, 'Compute')
123
+ opts[:version] = :v2
124
+ read_creds(account, opts, 'Compute')
125
+ begin
126
+ @compute_connection[account] = Fog::Compute.new(opts)
127
+ write_creds(opts, @compute_connection[account])
128
+ rescue Exception => e
129
+ @authcache.remove(opts)
130
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'Compute' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
131
+ end
132
+ return @compute_connection[account]
133
+ end
134
+
135
+ def block
136
+ account = get_account()
137
+ return @block_connection[account] unless @block_connection[account].nil?
138
+ opts = create_options(account, 'Block Storage')
139
+ opts.delete(:provider)
140
+ read_creds(account, opts, 'Block Storage')
141
+ begin
142
+ @block_connection[account] = Fog::HP::BlockStorageV2.new(opts)
143
+ write_creds(opts, @block_connection[account])
144
+ rescue Exception => e
145
+ @authcache.remove(opts)
146
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'BlockStorage' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
147
+ end
148
+ return @block_connection[account]
149
+ end
150
+
151
+ def cdn
152
+ account = get_account()
153
+ return @cdn_connection[account] unless @cdn_connection[account].nil?
154
+ opts = create_options(account, 'CDN')
155
+ read_creds(account, opts, 'CDN')
156
+ begin
157
+ @cdn_connection[account] = Fog::CDN.new(opts)
158
+ write_creds(opts, @cdn_connection[account])
159
+ rescue Exception => e
160
+ @authcache.remove(opts)
161
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'CDN' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
162
+ end
163
+ return @cdn_connection[account]
164
+ end
165
+
166
+ def network
167
+ account = get_account()
168
+ return @network_connection[account] unless @network_connection[account].nil?
169
+ opts = create_options(account, 'Networking')
170
+ read_creds(account, opts, 'Networking')
171
+ begin
172
+ opts.delete(:provider)
173
+ @network_connection[account] = Fog::HP::Network.new(opts)
174
+ write_creds(opts, @network_connection[account])
175
+ rescue Exception => e
176
+ @authcache.remove(opts)
177
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'Network' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
178
+ end
179
+ return @network_connection[account]
180
+ end
181
+
182
+ def dns
183
+ account = get_account()
184
+ return @dns_connection[account] unless @dns_connection[account].nil?
185
+ opts = create_options(account, 'DNS')
186
+ read_creds(account, opts, 'DNS')
187
+ begin
188
+ opts.delete(:provider)
189
+ @dns_connection[account] = Fog::HP::DNS.new(opts)
190
+ write_creds(opts, @dns_connection[account])
191
+ rescue Exception => e
192
+ @authcache.remove(opts)
193
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'DNS' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
194
+ end
195
+ return @dns_connection[account]
196
+ end
197
+
198
+ def lb
199
+ account = get_account()
200
+ return @lb_connection[account] unless @lb_connection[account].nil?
201
+ opts = create_options(account, 'Load Balancer')
202
+ read_creds(account, opts, 'Load Balancer')
203
+ begin
204
+ opts.delete(:provider)
205
+ @lb_connection[account] = Fog::HP::LB.new(opts)
206
+ write_creds(opts, @lb_connection[account])
207
+ rescue Exception => e
208
+ @authcache.remove(opts)
209
+ raise Fog::HP::Errors::ServiceError, "Please check your HP Cloud Services account to make sure the 'Load Balancer' service is activated for the appropriate availability zone.\n Exception: #{e}\n Print the service catalog: hpcloud account:catalog #{account}"
210
+ end
211
+ return @lb_connection[account]
212
+ end
213
+
214
+ def get_account(account_name = nil)
215
+ return account_name unless account_name.nil?
216
+ return @options[:account_name] || Config.new.get(:default_account) || 'hp'
217
+ end
218
+
219
+ def create_options(account_name, zone)
220
+ opts = Accounts.new.create_options(account_name, zone, @options[:availability_zone])
221
+ opts[:hp_tenant_id] = @options[:tenantid] unless @options[:tenantid].nil?
222
+ return opts
223
+ end
224
+
225
+ def zones(service)
226
+ name = get_account(nil)
227
+ cata = catalog(name, service)
228
+ hsh = YAML::load(cata)
229
+ hsh[service.to_sym].keys
230
+ end
231
+
232
+ def catalog(name, service)
233
+ rsp = validate_account(name)
234
+ cata = rsp[:service_catalog]
235
+ unless service.empty?
236
+ hsh = {}
237
+ service.each{ |x|
238
+ hsh[x.to_sym] = cata[x.to_sym]
239
+ }
240
+ cata = hsh
241
+ end
242
+ return cata
243
+ end
244
+
245
+ def validate_account(account_name)
246
+ options = create_options(account_name, nil)
247
+ case options[:provider]
248
+ when "hp"
249
+ unless options[:connection_options].nil?
250
+ options[:ssl_verify_peer] = options[:connection_options][:ssl_verify_peer]
251
+ end
252
+ Fog::HP.authenticate_v2(options, options[:connection_options])
253
+ else
254
+ Fog::Storage.new(options).directories
255
+ return true
256
+ end
257
+ end
258
+
259
+ def tenants(account_name = nil)
260
+ account = get_account(account_name)
261
+ opts = create_options(account, nil)
262
+ creds = read_creds(account, opts, 'whatever')
263
+ service_url = "#{opts[:hp_auth_uri]}tenants/"
264
+ connection_options = opts[:connection_options]
265
+ connection = Fog::Connection.new(service_url, false, connection_options)
266
+ endpoint = URI.parse(opts[:hp_auth_uri])
267
+ scheme = endpoint.scheme
268
+ host = endpoint.host
269
+ port = endpoint.port.to_s
270
+ path = endpoint.path.slice(1, endpoint.path.length) + 'tenants'
271
+ request_body = {}
272
+ auth_token = creds[:auth_token]
273
+
274
+ response = connection.request(
275
+ {
276
+ :expects => 200,
277
+ :headers => {
278
+ 'X-Auth-Token' => auth_token
279
+ },
280
+ :host => host,
281
+ :port => port,
282
+ :method => 'GET',
283
+ :path => path,
284
+ }
285
+ )
286
+ YAML::load(response.body.to_s)["tenants"]
287
+ end
288
+ end
289
+ end
290
+ end