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,288 @@
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 Accounts
27
+ attr_reader :directory
28
+ @@home = nil
29
+
30
+ DEFAULT_ACCOUNT = "default_account"
31
+ TOP_LEVEL = [:username, :provider]
32
+ CREDENTIALS = [:account_id,
33
+ :secret_key,
34
+ :auth_uri,
35
+ :tenant_id,
36
+ :userpass]
37
+ ZONES = [:compute,
38
+ :"object storage",
39
+ :cdn,
40
+ :dns,
41
+ :lbaas,
42
+ :db,
43
+ :network,
44
+ :"block storage"]
45
+ OPTIONS = [:connect_timeout,
46
+ :read_timeout,
47
+ :write_timeout,
48
+ :ssl_verify_peer,
49
+ :ssl_ca_path,
50
+ :ssl_ca_file,
51
+ :preferred_flavor,
52
+ :preferred_win_image,
53
+ :preferred_image]
54
+
55
+ def initialize
56
+ if @@home.nil?
57
+ @@home = ENV['HOME']
58
+ end
59
+ @directory = @@home + "/.hpcloud/accounts/"
60
+ @accts = {}
61
+ end
62
+
63
+ def self.home_directory=(dir)
64
+ @@home = dir
65
+ end
66
+
67
+ def self.get_known
68
+ ret = ""
69
+ CREDENTIALS.each{|key| ret += "\n * " + key.to_s }
70
+ ZONES.each{|key| ret += "\n * " + key.to_s }
71
+ OPTIONS.each{|key| ret += "\n * " + key.to_s }
72
+ return ret
73
+ end
74
+
75
+ def get_file_name(account)
76
+ "#{@directory}#{account.to_s.downcase.gsub(' ', '_')}"
77
+ end
78
+
79
+ def list
80
+ unless File.directory?("#{@directory}")
81
+ return "No such file or directory - #{@directory}\n" +
82
+ "Run account:setup to create accounts."
83
+ end
84
+ ray = Dir.entries("#{@directory}")
85
+ ray.delete_if{|item| File.file?("#{@directory}/#{item}") == false }
86
+ ray.sort!
87
+ return ray.join("\n")
88
+ end
89
+
90
+ def remove(account)
91
+ begin
92
+ file_name = get_file_name(account)
93
+ File.delete(file_name)
94
+ return true
95
+ rescue Exception => e
96
+ raise Exception.new('Error removing account file: ' + file_name)
97
+ end
98
+ return false
99
+ end
100
+
101
+ def copy(src, dest)
102
+ begin
103
+ src_name = get_file_name(src)
104
+ dest_name = get_file_name(dest)
105
+ FileUtils.cp(src_name, dest_name)
106
+ return true
107
+ rescue Exception => e
108
+ raise Exception.new('Error copying ' + src_name + ' to ' + dest_name)
109
+ end
110
+ return false
111
+ end
112
+
113
+ def read(account, createIt=false)
114
+ return @accts[account] if @accts[account].nil? == false
115
+ file_name = get_file_name(account)
116
+ if account == 'hp' && File.exists?(file_name) == false
117
+ migrate
118
+ end
119
+ if File.exists?(file_name)
120
+ begin
121
+ hsh = YAML::load(File.open(file_name))
122
+ hsh[:credentials] = {} if hsh[:credentials].nil?
123
+ if ((hsh[:zones].nil? == false) && (hsh[:regions].nil? == true))
124
+ regions = {}
125
+ zones = hsh[:zones]
126
+ regions[:compute] = zones[:compute_availability_zone] unless zones[:compute_availability_zone].nil?
127
+ regions[:"object storage"] = zones[:storage_availability_zone] unless zones[:storage_availability_zone].nil?
128
+ regions[:cdn] = zones[:cdn_availability_zone] unless zones[:cdn_availability_zone].nil?
129
+ regions[:"block storage"] = zones[:block_availability_zone] unless zones[:block_availability_zone].nil?
130
+ hsh[:zones] = nil
131
+ hsh[:regions] = regions
132
+ end
133
+ hsh[:regions] = {} if hsh[:regions].nil?
134
+ hsh[:options] = {} if hsh[:options].nil?
135
+ @accts[account] = hsh
136
+ rescue Exception => e
137
+ raise Exception.new('Error reading account file: ' + file_name)
138
+ end
139
+ else
140
+ if createIt
141
+ return create(account)
142
+ end
143
+ raise Exception.new('Could not find account file: ' + file_name)
144
+ end
145
+ return @accts[account]
146
+ end
147
+
148
+ def create(account)
149
+ if @accts[account].nil?
150
+ uri = Config.new.get(:default_auth_uri)
151
+ @accts[account] = {:credentials=>{:auth_uri=>uri},
152
+ :regions=>{},
153
+ :options=>{}}
154
+ end
155
+ return @accts[account]
156
+ end
157
+
158
+ def set_cred(account, cred)
159
+ if @accts[account].nil?
160
+ @accts[account] = {:credentials=>{}, :regions=>{}, :options=>{}}
161
+ end
162
+ @accts[account][:credentials] = cred
163
+ unless cred[:hp_auth_uri].nil?
164
+ if cred[:hp_auth_uri].match(/hpcloud.net/)
165
+ @accts[account][:options][:ssl_verify_peer] = false
166
+ end
167
+ end
168
+ end
169
+
170
+ def set_regions(account, regions)
171
+ if @accts[account].nil?
172
+ @accts[account] = {:credentials=>{}, :regions=>{}, :options=>{}}
173
+ end
174
+ @accts[account][:regions] = regions
175
+ end
176
+
177
+ def set(account, key, value)
178
+ hsh = @accts[account]
179
+ return false if hsh.nil?
180
+ key = key.to_sym
181
+ if CREDENTIALS.include?(key)
182
+ hsh[:credentials][key] = value
183
+ elsif ZONES.include?(key)
184
+ hsh[:regions][key] = value
185
+ elsif OPTIONS.include?(key)
186
+ hsh[:options][key] = value
187
+ elsif TOP_LEVEL.include?(key)
188
+ hsh[key] = value
189
+ else
190
+ return false
191
+ end
192
+ return true
193
+ end
194
+
195
+ def get(account)
196
+ hsh = read(account).clone
197
+ settings = Config.new.settings
198
+ hsh[:provider] ||= 'hp'
199
+ hsh[:options][:connect_timeout] ||= settings[:connect_timeout]
200
+ hsh[:options][:read_timeout] ||= settings[:read_timeout]
201
+ hsh[:options][:write_timeout] ||= settings[:write_timeout]
202
+ hsh[:options][:preferred_flavor] ||= settings[:preferred_flavor]
203
+ hsh[:options][:preferred_image] ||= settings[:preferred_image]
204
+ hsh[:options][:connect_timeout] = hsh[:options][:connect_timeout].to_i
205
+ hsh[:options][:read_timeout] = hsh[:options][:read_timeout].to_i
206
+ hsh[:options][:write_timeout] = hsh[:options][:write_timeout].to_i
207
+ if hsh[:options][:ssl_verify_peer].nil?
208
+ hsh[:options][:ssl_verify_peer] = settings[:ssl_verify_peer]
209
+ end
210
+ if hsh[:options][:ssl_verify_peer].to_s == "false" || hsh[:options][:ssl_verify_peer].to_s == "no"
211
+ hsh[:options][:ssl_verify_peer] = false
212
+ else
213
+ hsh[:options][:ssl_verify_peer] = true
214
+ end
215
+ hsh[:options][:ssl_ca_path] ||= settings[:ssl_ca_path]
216
+ hsh[:options][:ssl_ca_path] ||= settings[:ssl_ca_path]
217
+ hsh[:options][:ssl_ca_file] ||= settings[:ssl_ca_file]
218
+ hsh[:options].delete_if{ |k,v| v.nil? }
219
+ return hsh
220
+ end
221
+
222
+ def write(account)
223
+ config = @accts[account]
224
+ if config.nil?
225
+ raise Exception.new("Cannot find account information for #{account}")
226
+ end
227
+ file_name = get_file_name(account)
228
+ begin
229
+ FileUtils.mkpath(@directory)
230
+ File.open(file_name, 'w') do |file|
231
+ file.write config.to_yaml
232
+ end
233
+ rescue Exception => e
234
+ raise Exception.new("Error writing file #{file_name}")
235
+ end
236
+ end
237
+
238
+ def create_options(account_name, zone, avl_zone = nil)
239
+ hsh = get(account_name)
240
+ provider = hsh[:provider] || 'hp'
241
+ provider = provider.downcase
242
+ creds = hsh[:credentials]
243
+ regions = hsh[:regions] || {}
244
+ opts = hsh[:options]
245
+ opts.delete(:preferred_flavor)
246
+ opts.delete(:preferred_image)
247
+ opts.delete(:preferred_win_image)
248
+ opts.delete(:checker_url)
249
+ opts.delete(:checker_deferment)
250
+ unless zone.nil?
251
+ avl_zone = avl_zone || regions[zone.to_s.downcase.to_sym]
252
+ end
253
+
254
+ options = {}
255
+ if provider == 'hp'
256
+ options[:hp_access_key] = creds[:account_id] || creds[:hp_access_key] || creds[:hp_account_id]
257
+ options[:hp_secret_key] = creds[:secret_key] || creds[:hp_secret_key]
258
+ options[:hp_use_upass_auth_style] = true if creds[:userpass] == true
259
+ options[:hp_auth_uri] = creds[:auth_uri] || creds[:hp_auth_uri]
260
+ options[:hp_tenant_id ] = creds[:tenant_id] || creds[:hp_tenant_id]
261
+ options[:hp_avl_zone] = avl_zone
262
+ options[:connection_options] = opts
263
+ options[:user_agent] = "HPCloud-UnixCLI/#{HP::Cloud::VERSION}"
264
+ else
265
+ options = creds
266
+ end
267
+ options[:provider] = provider
268
+
269
+ return options
270
+ end
271
+
272
+ def migrate
273
+ ray = list
274
+ return false if ray.index('default').nil?
275
+ return false unless ray.index('hp').nil?
276
+ warn "Renaming account 'default' to 'hp'..."
277
+ return false unless copy('default', 'hp')
278
+ remove('default')
279
+
280
+ config = Config.new(true)
281
+ config.set(:default_account, 'hp')
282
+ config.write()
283
+ warn "Account 'hp' is now the default"
284
+ return true
285
+ end
286
+ end
287
+ end
288
+ end
@@ -0,0 +1,112 @@
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 Acl
25
+ ALL = ".r:*,.rlistings"
26
+
27
+ attr_reader :cstatus, :public, :users
28
+
29
+ def initialize(key, hash)
30
+ @key = key
31
+ @cstatus = CliStatus.new
32
+ hash = {} if hash.nil?
33
+ @users = parse_acl(hash[key])
34
+ @public = parse_public(hash[key])
35
+ end
36
+
37
+ def parse_acl(header)
38
+ return nil if header.nil?
39
+ return [] if header.start_with?(".r:*")
40
+ ray = []
41
+ header.split(",").each {|x|
42
+ if x.index(":")
43
+ u = x.split(":")[1]
44
+ ray << u unless u.nil?
45
+ else
46
+ ray << x
47
+ end
48
+ }
49
+ return nil if ray.empty?
50
+ return ray
51
+ end
52
+
53
+ def parse_public(header)
54
+ return "no" if header.nil?
55
+ return header.start_with?(".r:*")?"yes":"no"
56
+ end
57
+
58
+ def is_valid?
59
+ return @cstatus.is_success?
60
+ end
61
+
62
+ def to_hash
63
+ return { } if @users.nil?
64
+ return { @key => ALL } if @users.empty?
65
+ return { @key => "*:" + @users.join(",*:") }
66
+ end
67
+
68
+ def grant(ray)
69
+ return true if ray.nil?
70
+ @users = ray
71
+ return true
72
+ end
73
+
74
+ def revoke(ray)
75
+ if ray.nil?
76
+ @users = nil
77
+ return true
78
+ end
79
+ return true if ray.empty?
80
+ not_found = []
81
+ if @users.nil?
82
+ not_found << ray
83
+ else
84
+ ray.each{ |x|
85
+ if @users.delete(x).nil?
86
+ rc = false
87
+ not_found << x
88
+ end
89
+ }
90
+ end
91
+ @users = nil if @users.nil? || @users.empty?
92
+ return true if not_found.empty?
93
+ @cstatus = CliStatus.new("Revoke failed invalid user: #{not_found.join(',')}", :not_found)
94
+ return false
95
+ end
96
+ end
97
+
98
+ class AclReader < Acl
99
+ KEY = 'X-Container-Read'
100
+ def initialize(hash)
101
+ super(KEY, hash)
102
+ end
103
+ end
104
+
105
+ class AclWriter < Acl
106
+ KEY = 'X-Container-Write'
107
+ def initialize(hash)
108
+ super(KEY, hash)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,81 @@
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 AclCmd
25
+ VALID_ACLS = ["r", "rw", "w"]
26
+
27
+ attr_reader :permissions, :users
28
+ attr_reader :cstatus
29
+
30
+ def initialize(permissions, users)
31
+ @cstatus = CliStatus.new
32
+ @permissions = permissions.downcase
33
+ @permissions = "r" if @permissions == "public-read"
34
+ @users = users
35
+
36
+ if @permissions == "private"
37
+ @cstatus = CliStatus.new("Use the acl:revoke command to revoke public read permissions", :incorrect_usage)
38
+ return
39
+ end
40
+ unless VALID_ACLS.include?(@permissions)
41
+ @cstatus = CliStatus.new("Your permissions '#{@permissions}' are not valid.\nValid settings are: #{VALID_ACLS.join(', ')}", :incorrect_usage)
42
+ return
43
+ end
44
+ @permissions = "pr" if is_public? && @permissions == "r"
45
+ if is_public? && @permissions != "pr"
46
+ @cstatus = CliStatus.new("You may not make an object writable by everyone", :not_supported)
47
+ return
48
+ end
49
+ end
50
+
51
+ def is_public?
52
+ return false if @users.nil?
53
+ return true if @users.empty?
54
+ return false
55
+ end
56
+
57
+ def is_valid?
58
+ return @cstatus.is_success?
59
+ end
60
+
61
+ def readers
62
+ return [] if @permissions == "pr"
63
+ return @users if @permissions == "r"
64
+ return @users if @permissions == "rw"
65
+ return nil
66
+ end
67
+
68
+ def writers
69
+ return @users if @permissions == "w"
70
+ return @users if @permissions == "rw"
71
+ return nil
72
+ end
73
+
74
+ def to_s
75
+ return "public-read" if @permissions == "pr"
76
+ return (@permissions + " for " + @users.join(",")) unless @users.nil?
77
+ return @permissions
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,63 @@
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 AddressHelper < BaseHelper
25
+ attr_accessor :id, :ip, :fixed_ip, :instance_id
26
+
27
+ def self.get_keys()
28
+ return [ "id", "ip", "fixed_ip", "instance_id" ]
29
+ end
30
+
31
+ def initialize(connection, foggy = nil)
32
+ super(connection, foggy)
33
+ return if foggy.nil?
34
+ @id = foggy.id
35
+ @ip = foggy.ip
36
+ @fixed_ip = foggy.fixed_ip
37
+ @instance_id = foggy.instance_id
38
+ end
39
+
40
+ def save
41
+ return false if is_valid? == false
42
+ if @fog.nil?
43
+ address = @connection.compute.addresses.create
44
+ if address.nil?
45
+ set_error("Error creating ip address")
46
+ return false
47
+ end
48
+ @id = address.id
49
+ @ip = address.ip
50
+ @fixed_ip = address.fixed_ip
51
+ @fog = address
52
+ return true
53
+ else
54
+ raise "Update not implemented"
55
+ end
56
+ end
57
+
58
+ def name=(value)
59
+ ip = value
60
+ end
61
+ end
62
+ end
63
+ 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/address_helper'
24
+
25
+ module HP
26
+ module Cloud
27
+ class Addresses < FogCollection
28
+ def initialize()
29
+ super("ip address", "an")
30
+ @items = @connection.compute.addresses
31
+ end
32
+
33
+ def create(item = nil)
34
+ return AddressHelper.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