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,114 @@
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 FloatingIpHelper < BaseHelper
25
+ attr_accessor :id, :tenant_id
26
+ attr_accessor :network_id, :port, :router
27
+ attr_accessor :fixed_ip, :floating_ip
28
+
29
+ def self.get_keys()
30
+ return [ "id", "network_id", "port", "router", "fixed_ip", "floating_ip" ]
31
+ end
32
+
33
+ def initialize(connection, foggy = nil)
34
+ super(connection, foggy)
35
+ if foggy.nil?
36
+ return
37
+ end
38
+ @id = foggy.id
39
+ @tenant_id = foggy.tenant_id
40
+ @network_id = foggy.floating_network_id
41
+ @port = foggy.port_id
42
+ @router = foggy.router_id
43
+ @fixed_ip = foggy.fixed_ip_address
44
+ @floating_ip = foggy.floating_ip_address
45
+ end
46
+
47
+ def set_network(value)
48
+ if value.nil?
49
+ netty = Networks.new.external
50
+ if netty.nil?
51
+ set_error("Cannot find an external network")
52
+ return false
53
+ end
54
+ else
55
+ netty = Networks.new.get(value)
56
+ end
57
+ unless netty.is_valid?
58
+ set_error netty.cstatus
59
+ end
60
+ @network_id = netty.id
61
+ end
62
+
63
+ def set_port(value)
64
+ porty = Ports.new.get(value)
65
+ unless porty.is_valid?
66
+ set_error porty.cstatus
67
+ end
68
+ @port = porty.id
69
+ end
70
+
71
+ def ip
72
+ @floating_ip
73
+ end
74
+
75
+ def associate
76
+ @connection.network.associate_floating_ip(@id, @port)
77
+ end
78
+
79
+ def disassociate
80
+ return if @port.nil?
81
+ @connection.network.disassociate_floating_ip(@id)
82
+ end
83
+
84
+ def save
85
+ return false if is_valid? == false
86
+ hsh = {
87
+ :tenant_id => @tenant_id,
88
+ :floating_network_id => @network_id,
89
+ :port_id => @port,
90
+ :fixed_ip_address => @fixed_ip,
91
+ :floating_ip_address => @floating_ip
92
+ }
93
+ if @fog.nil?
94
+ response = @connection.network.create_floating_ip(@network_id, hsh)
95
+ if response.nil?
96
+ set_error("Error creating floating IP")
97
+ return false
98
+ end
99
+ @id = response.body["floatingip"]["id"]
100
+ @floating_ip = response.body["floatingip"]["floating_ip_address"]
101
+ @foggy = response.body["floating_ip"]
102
+ else
103
+ set_error("Floating IP update is not supported")
104
+ return false
105
+ end
106
+ return true
107
+ end
108
+
109
+ def destroy
110
+ @connection.network.delete_floating_ip(@id)
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,42 @@
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/fog_collection'
23
+ require 'hpcloud/port_helper'
24
+
25
+ module HP
26
+ module Cloud
27
+ class FloatingIps < FogCollection
28
+ def initialize
29
+ super("ip address", "an")
30
+ @items = @connection.network.floating_ips
31
+ end
32
+
33
+ def create(item = nil)
34
+ return FloatingIpHelper.new(@connection, item)
35
+ end
36
+
37
+ def matches(arg, item)
38
+ return ((arg == item.id.to_s) || (arg == item.ip.to_s))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,124 @@
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/exceptions/general'
23
+ require 'hpcloud/exceptions/not_found'
24
+
25
+ module HP
26
+ module Cloud
27
+ class FogCollection
28
+ attr_reader :name, :items
29
+
30
+ def initialize(name, article='a')
31
+ @name = name
32
+ @article = article
33
+ @connection = Connection.instance
34
+ end
35
+
36
+ def matches(arg, item)
37
+ return ((arg == item.id.to_s) || (arg == item.name.to_s))
38
+ end
39
+
40
+ def filter(arguments = [], multimatch=true)
41
+ if @ray.nil?
42
+ @ray = []
43
+ @items.each { |x| @ray << create(x) }
44
+ end
45
+ if (arguments.empty?)
46
+ return @ray
47
+ end
48
+ retray = []
49
+ arguments.each { |arg|
50
+ found = []
51
+ @ray.each { |item|
52
+ if matches(arg, item)
53
+ if (multimatch == true)
54
+ found << item
55
+ else
56
+ if found.length == 0
57
+ found << item
58
+ else
59
+ if found[0].respond_to?(:set_error)
60
+ found[0].set_error("More than one #{@name} matches '#{arg}', use the id instead of name.")
61
+ else
62
+ raise HP::Cloud::Exceptions::General.new("More than one #{@name} matches '#{arg}', use the id instead of name.")
63
+ end
64
+ end
65
+ end
66
+ end
67
+ }
68
+ if found.length == 0
69
+ item = create()
70
+ if item.nil?
71
+ raise HP::Cloud::Exceptions::NotFound.new("Cannot find #{@article} #{@name} matching '#{arg}'.")
72
+ end
73
+ if item.respond_to?(:name)
74
+ item.name = arg
75
+ end
76
+ item.set_error("Cannot find #{@article} #{@name} matching '#{arg}'.", :not_found)
77
+ retray << item
78
+ else
79
+ retray += found
80
+ end
81
+ }
82
+ return retray
83
+ end
84
+
85
+ def get(arguments = [], multimatch=true)
86
+ if arguments.kind_of?(Array)
87
+ return filter(arguments, multimatch)
88
+ end
89
+ return filter([arguments], false).first
90
+ end
91
+
92
+ def get_array(arguments = [])
93
+ ray = []
94
+ get(arguments, true).each { |x|
95
+ if x.respond_to?(:to_hash)
96
+ hsh = x.to_hash()
97
+ else
98
+ hsh = Hash[x.attributes.map{ |k, v| [k.to_s, v] }]
99
+ end
100
+ ray << hsh unless hsh.nil?
101
+ }
102
+ return ray
103
+ end
104
+
105
+ def empty?
106
+ return true if @items.nil?
107
+ return @items.empty?
108
+ end
109
+
110
+ def create(item = nil)
111
+ return item
112
+ end
113
+
114
+ def unique(name)
115
+ begin
116
+ get(name)
117
+ raise HP::Cloud::Exceptions::General.new("A #{@name} with the name '#{name}' already exists")
118
+ rescue HP::Cloud::Exceptions::NotFound => e
119
+ end
120
+ return nil
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,111 @@
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/metadata'
23
+
24
+ module HP
25
+ module Cloud
26
+ class ImageHelper < BaseHelper
27
+ OS_TYPES = { :ubuntu => 0,
28
+ :centos => 1,
29
+ :fedora => 2,
30
+ :debian => 3,
31
+ :windows => 4
32
+ }
33
+ attr_reader :meta
34
+ attr_accessor :id, :name, :created_at, :status
35
+
36
+ def self.get_keys()
37
+ return ["id", "name", "created_at", "status"]
38
+ end
39
+
40
+ def initialize(foggy = nil)
41
+ super(nil, foggy)
42
+ if foggy.nil?
43
+ @meta = HP::Cloud::Metadata.new(nil)
44
+ return
45
+ end
46
+ @id = foggy.id
47
+ @name = foggy.name
48
+ @created_at = foggy.created_at
49
+ @status = foggy.status
50
+ @meta = HP::Cloud::Metadata.new(foggy.metadata)
51
+ end
52
+
53
+ def set_server(value)
54
+ @server_name_id = value
55
+ end
56
+
57
+ def save
58
+ if is_valid?
59
+ set_error(@meta.cstatus)
60
+ end
61
+ return false if is_valid? == false
62
+ if @fog.nil?
63
+ server = Servers.new.get(@server_name_id)
64
+ if server.is_valid? == false
65
+ set_error(server.cstatus)
66
+ return false
67
+ end
68
+
69
+ @id = server.create_image(@name , @meta.hsh).id
70
+ if @id.nil?
71
+ set_error(server.cstatus)
72
+ return false
73
+ end
74
+ return true
75
+ end
76
+ raise "Update not implemented"
77
+ end
78
+
79
+ def is_windows?
80
+ return (@meta.hsh['hp_image_license'].nil? == false)
81
+ end
82
+
83
+ def is_private?
84
+ return false if @meta.hsh['owner'].nil?
85
+ return @meta.hsh['owner'].empty? == false
86
+ end
87
+
88
+ def os
89
+ return :windows if is_windows?
90
+ return :ubuntu if name.nil?
91
+ return :windows unless name.match(/[wW][iI][nN][dD][oO][wW]/).nil?
92
+ return :fedora unless name.match(/[fF][eE][dD][oO][rR][aA]/).nil?
93
+ return :centos unless name.match(/[cC][eE][nN][tT][oO][sS]/).nil?
94
+ return :debian unless name.match(/[dD][eE][bB][iI][aA][nN]/).nil?
95
+ return :ubuntu
96
+ end
97
+
98
+ def login
99
+ case os
100
+ when :ubuntu
101
+ return 'ubuntu'
102
+ when :centos, :fedora, :debian
103
+ return 'root'
104
+ when :windows
105
+ return 'Administrator'
106
+ end
107
+ return 'ubuntu'
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,43 @@
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/fog_collection'
23
+ require 'hpcloud/image_helper'
24
+
25
+ module HP
26
+ module Cloud
27
+ class Images < FogCollection
28
+ def initialize()
29
+ super("image")
30
+ @items = @connection.compute.images.all(:details=>true)
31
+ end
32
+
33
+ def create(item = nil)
34
+ return ImageHelper.new(item)
35
+ end
36
+
37
+ def matches(arg, item)
38
+ return (arg == item.id.to_s) if arg.match(/^[0-9]+$/)
39
+ return ((arg == item.id.to_s) || (item.name.to_s.match(arg)))
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,109 @@
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 KeypairHelper < BaseHelper
25
+ attr_accessor :id, :name, :fingerprint, :public_key, :private_key
26
+
27
+ def self.get_keys()
28
+ return [ "name", "fingerprint" ]
29
+ end
30
+
31
+ def initialize(connection, foggy = nil)
32
+ super(connection, foggy)
33
+ return if foggy.nil?
34
+ @id = foggy.name
35
+ @name = foggy.name
36
+ @fingerprint = foggy.fingerprint
37
+ @public_key = foggy.public_key
38
+ @private_key = foggy.private_key
39
+ end
40
+
41
+ def save
42
+ return false if is_valid? == false
43
+ if @fog.nil?
44
+ if @public_key.nil?
45
+ hsh = {:name => @name, :fingerprint => @fingerprint, :private_key => @private_key}
46
+ keypair = @connection.compute.key_pairs.create(hsh)
47
+ else
48
+ keypair = @connection.compute.create_key_pair(@name, @public_key)
49
+ end
50
+ if keypair.nil?
51
+ set_error("Error creating keypair")
52
+ return false
53
+ end
54
+ @fog = keypair
55
+ return true
56
+ else
57
+ raise "Update not implemented"
58
+ end
59
+ end
60
+
61
+ def self.private_directory
62
+ "#{ENV['HOME']}/.hpcloud/keypairs/"
63
+ end
64
+
65
+ def self.private_filename(name)
66
+ "#{KeypairHelper.private_directory}#{name}.pem"
67
+ end
68
+
69
+ def private_read
70
+ filename = KeypairHelper.private_filename(name)
71
+ @private_key = File.read(filename)
72
+ @fog.private_key = @private_key unless @fog.nil?
73
+ @private_key
74
+ end
75
+
76
+ def private_add
77
+ directory = KeypairHelper.private_directory
78
+ FileUtils.mkdir_p(directory)
79
+ FileUtils.chmod(0700, directory)
80
+ filename = KeypairHelper.private_filename(name)
81
+ FileUtils.rm_f(filename)
82
+ if @fog.nil?
83
+ file = File.new(filename, "w")
84
+ file.write(@private_key)
85
+ file.close
86
+ else
87
+ @fog.write(filename)
88
+ end
89
+ FileUtils.chmod(0400, filename)
90
+ return filename
91
+ end
92
+
93
+ def self.private_list
94
+ ray = Dir.entries(KeypairHelper.private_directory)
95
+ ray = ray.delete_if{|x| x == "."}
96
+ ray = ray.delete_if{|x| x == ".."}
97
+ ray = ray.delete_if{|x| x.match(/\.pem$/) == nil }
98
+ ray.collect!{|x| x.gsub(/\.pem$/,'') }
99
+ ray.sort
100
+ end
101
+
102
+ def private_remove
103
+ filename = KeypairHelper.private_filename(name)
104
+ FileUtils.rm(filename)
105
+ filename
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,41 @@
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/fog_collection'
23
+
24
+ module HP
25
+ module Cloud
26
+ class Keypairs < FogCollection
27
+ def initialize()
28
+ super("keypair")
29
+ @items = @connection.compute.key_pairs
30
+ end
31
+
32
+ def create(item = nil)
33
+ return KeypairHelper.new(@connection, item)
34
+ end
35
+
36
+ def matches(arg, item)
37
+ return (arg == item.name.to_s)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
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/fog_collection'
23
+
24
+ module HP
25
+ module Cloud
26
+ class LbAlgorithms < FogCollection
27
+ def initialize
28
+ super("load balancer algorithm")
29
+ @items = @connection.lb.algorithms
30
+ end
31
+
32
+ def matches(arg, item)
33
+ return (arg == item.name.to_s)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
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/fog_collection'
23
+
24
+ module HP
25
+ module Cloud
26
+ class LbLimits < FogCollection
27
+ def initialize
28
+ super("load balancer limit")
29
+ @items = @connection.lb.limits
30
+ end
31
+
32
+ def matches(arg, item)
33
+ return true
34
+ end
35
+ end
36
+ end
37
+ end