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,204 @@
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/accounts'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ map %w(account:add account:setup account:update) => 'account:edit'
29
+
30
+ desc 'account:edit <account_name> [name_value_pair ...]', "Create or edit your account credentials."
31
+ long_desc <<-DESC
32
+ Create or edit your account credentials. If you do not specify an account name on the command line, the default account is updated. If you do not specify name value pairs, you are prompted to input the account values.
33
+
34
+ You need your Access Key Id, Secret Key and Project (aka Tenant) Id from the HP Cloud web site to set up your account. Optionally, you can specify your own endpoint to authorize your identity, but in most cases we recommend you use the default.
35
+
36
+ Availability zones typically have the format 'az-1.region-a.geo-1' or 'region-a.geo-1', depending on the service. See your account API keys page to see your list of activated availability zones: https://console.hpcloud.com/account/api_keys or use the `account:catalog` command to print out your service catalog.
37
+
38
+ You can re-run this command at any time to modify your settings.
39
+
40
+ The interactive mode prompts you for the following values:
41
+
42
+ * Access Key Id
43
+ * Secret Key
44
+ * Project (aka Tenant) Id
45
+ * Identify (Auth) Uri
46
+ * Various zones and regions you have activated
47
+
48
+ The command line mode allows you to set the following values:
49
+ #{Accounts.get_known}
50
+
51
+ Examples:
52
+ hpcloud account:setup # Create or edit the default account interactively
53
+ hpcloud account:edit # Edit the default account settings interactively
54
+ hpcloud account:edit pro auth_uri='https://127.0.0.1/' block_availability_zone='az-2.region-a.geo-1' # Set the account credential authorization URI to `https://127.0.0.1\` and the block availability zone to `az-2.region-a.geo-1`
55
+ hpcloud account:setup rackspace -p rackspace # Create a Rackspace account for migration
56
+
57
+ Aliases: account:add, account:setup, account:update
58
+ DESC
59
+ method_option 'userpass', :type => :boolean,
60
+ :desc => "Use username/password authentication instead of authentication keys"
61
+ method_option 'no-validate', :type => :boolean, :aliases => '-n',
62
+ :default => false,
63
+ :desc => "Don't verify account settings during edit"
64
+ method_option 'provider', :type => :string, :aliases => '-p',
65
+ :desc => "Cloud provider for migration: AWS, Rackspace, or Google"
66
+ define_method "account:edit" do |*args|
67
+ cli_command(options) {
68
+ if args.empty?
69
+ config = Config.new(true)
70
+ name = config.get(:default_account)
71
+ else
72
+ name = args.shift
73
+ end
74
+ accounts = HP::Cloud::Accounts.new()
75
+ if args.empty?
76
+ begin
77
+ acct = accounts.read(name)
78
+ rescue Exception => e
79
+ acct = accounts.create(name)
80
+ end
81
+ acct[:provider] ||= 'hp'
82
+ unless options[:provider].nil?
83
+ provider = options[:provider].downcase
84
+ if provider != acct[:provider]
85
+ acct[:provider] = provider
86
+ acct[:options] = {}
87
+ acct[:credentials] = {}
88
+ acct[:regions] = {}
89
+ end
90
+ end
91
+ cred = acct[:credentials]
92
+
93
+ # ask for credentials
94
+ case acct[:provider]
95
+ when "hp"
96
+ service_name = "HP Cloud Services"
97
+ @log.display "****** Setup your #{service_name} #{name} account ******"
98
+ unless options[:userpass].nil?
99
+ if options[:userpass] == true
100
+ cred[:userpass] = options[:userpass]
101
+ else
102
+ cred[:userpass] = nil
103
+ end
104
+ end
105
+ if cred[:userpass] == true
106
+ cred[:account_id] = ask_with_default 'User name:', "#{cred[:account_id]}"
107
+ cred[:secret_key] = ask_with_default 'Password:', "#{cred[:secret_key]}"
108
+ else
109
+ cred[:account_id] = ask_with_default 'Access Key Id:', "#{cred[:account_id]}"
110
+ cred[:secret_key] = ask_with_default 'Secret Key:', "#{cred[:secret_key]}"
111
+ end
112
+ cred[:tenant_id] = ask_with_default 'Project (aka Tenant) Id:', "#{cred[:tenant_id]}"
113
+ cred[:auth_uri] = ask_with_default 'Identity (Auth) Uri:', "#{cred[:auth_uri]}"
114
+ when "aws"
115
+ service_name = "AWS"
116
+ @log.display "****** Setup your #{service_name} #{name} account ******"
117
+ cred[:aws_access_key_id] = ask_with_default 'Access Key ID:', "#{cred[:aws_access_key_id]}"
118
+ cred[:aws_secret_access_key] = ask_with_default 'Secret Access Key:', "#{cred[:aws_secret_access_key]}"
119
+ acct[:options] = {}
120
+ acct[:regions] = {}
121
+ when "rackspace"
122
+ service_name = "Rackspace"
123
+ @log.display "****** Setup your #{service_name} #{name} account ******"
124
+ cred[:rackspace_username] = ask_with_default 'Username:', "#{cred[:rackspace_username]}"
125
+ cred[:rackspace_api_key] = ask_with_default 'API Key:', "#{cred[:rackspace_api_key]}"
126
+ acct[:options] = {}
127
+ acct[:regions] = {}
128
+ when "google"
129
+ service_name = "Google"
130
+ @log.display "****** Setup your #{service_name} #{name} account ******"
131
+ cred[:google_storage_access_key_id] = ask_with_default 'Storage access key id:', "#{cred[:google_storage_access_key_id]}"
132
+ cred[:google_storage_secret_access_key] = ask_with_default 'Storage secret access key:', "#{cred[:google_storage_secret_access_key]}"
133
+ acct[:options] = {}
134
+ acct[:regions] = {}
135
+ else
136
+ @log.error "Provider '#{acct[:provider]}' not recognized. Supported providers include hp, aws and rackspace."
137
+ @log.fatal "If your provider is not supported, you may manually create an account configuration file in the ~/.hpcloud/accounts directory."
138
+ end
139
+
140
+ # update credentials and stash in config directory
141
+ accounts.set_cred(name, cred)
142
+ accounts.write(name)
143
+
144
+ unless options['no-validate']
145
+ @log.display "Verifying your #{service_name} account..."
146
+ if cred[:auth_uri].nil?
147
+ identifier = cred.to_s
148
+ else
149
+ identifier = cred[:auth_uri]
150
+ end
151
+
152
+ begin
153
+ cata = Connection.instance.catalog(name, [])
154
+ regions = acct[:regions]
155
+ if acct[:provider] == "hp"
156
+ services = []
157
+ cata.keys.each { |x| services << x.to_s }
158
+ services.sort!
159
+ services.each { |service|
160
+ zone = "#{service.downcase}".to_sym
161
+ regs = []
162
+ cata[service.to_sym].keys.each { |x| regs << x.to_s }
163
+ regs.sort!
164
+ default_region = regions[zone] || regs.first.to_s
165
+ az = regs.join(',')
166
+ unless service == "Image Management" || service == "Identity"
167
+ regions[zone] = ask_with_default "#{service} region (#{az}):", "#{default_region}"
168
+ end
169
+ }
170
+ end
171
+ acct[:regions] = regions
172
+ accounts.set_regions(name, regions)
173
+ accounts.write(name)
174
+ rescue Exception => e
175
+ e = ErrorResponse.new(e).to_s
176
+ @log.error "Account verification failed. Error connecting to the service endpoint at: '#{identifier}'. Please verify your account credentials. \n Exception: #{e}"
177
+ end
178
+ end
179
+
180
+ @log.display "Account credentials for #{service_name} have been saved."
181
+ unless acct[:provider] == "hp"
182
+ @log.display "Accounts for providers other than HP are only supported for migration"
183
+ end
184
+ else
185
+ acct = accounts.read(name, true)
186
+ updated = ""
187
+ args.each { |nvp|
188
+ sub_command {
189
+ k, v = Config.split(nvp)
190
+ accounts.set(name, k, v)
191
+ updated += " " if updated.empty? == false
192
+ updated += nvp
193
+ }
194
+ }
195
+ if updated.empty? == false
196
+ accounts.write(name)
197
+ @log.display "Account '#{name}' set " + updated
198
+ end
199
+ end
200
+ }
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,53 @@
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/accounts'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ map %w(account:rm account:delete account:del) => 'account:remove'
29
+
30
+ desc 'account:remove account_name [account_name ...]', "Remove accounts."
31
+ long_desc <<-DESC
32
+ Remove accounts. You may specify one or more account to remove on the command line.
33
+
34
+ Examples:
35
+ hpcloud account:remove useast uswest # Remove the `useast` and `uswest` accounts
36
+
37
+ Aliases: account:rm, account:delete, account:del
38
+ DESC
39
+ define_method "account:remove" do |name, *names|
40
+ cli_command(options) {
41
+ accounts = HP::Cloud::Accounts.new()
42
+ names = [name] + names
43
+ names.each{ |name|
44
+ sub_command {
45
+ accounts.remove(name)
46
+ @log.display("Removed account '#{name}'")
47
+ }
48
+ }
49
+ }
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,40 @@
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/accounts'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ desc 'account:setup <account_name>', "Create or edit your account credentials."
29
+ long_desc <<-DESC
30
+ See account:edit
31
+ DESC
32
+ method_option 'no-validate', :type => :boolean, :aliases => '-n',
33
+ :default => false,
34
+ :desc => "Don't verify account settings during edit"
35
+ define_method "account:setup" do |*args|
36
+ send("account:edit", args)
37
+ end
38
+ end
39
+ end
40
+ 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
+ module HP
23
+ module Cloud
24
+ class CLI < Thor
25
+ desc 'account:tenants', "List the tenants."
26
+ long_desc <<-DESC
27
+ Lists all the tenants associated with this account.
28
+
29
+ Examples:
30
+ hpcloud account:tenants # List all the tenants associated with the account
31
+ DESC
32
+ CLI.add_report_options
33
+ CLI.add_common_options
34
+ define_method "account:tenants" do
35
+ cli_command(options) {
36
+ default_keys = [ "id", "name", "enabled" ]
37
+ ray = Connection.instance.tenants
38
+ Tableizer.new(options, default_keys, ray).print
39
+ }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,46 @@
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/accounts'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ desc 'account:use <account_to_use>', "Set the named account to the default account."
29
+ long_desc <<-DESC
30
+ Use the specified account as your default account. Any command executed without the `-a` account_name option uses this account.
31
+
32
+ Examples:
33
+ hpcloud account:use useast # Set the default account to `useast`
34
+ DESC
35
+ define_method "account:use" do |name|
36
+ cli_command(options) {
37
+ HP::Cloud::Accounts.new().read(name)
38
+ config = Config.new(true)
39
+ config.set(:default_account, name)
40
+ config.write()
41
+ @log.display("Account '#{name}' is now the default")
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,55 @@
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/accounts'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ desc 'account:verify <account_to_verify>', "Verify the credentials of the specified account."
29
+ long_desc <<-DESC
30
+ Verify the credentials of an account.
31
+
32
+ Examples:
33
+ hpcloud account:verify useast # Verify the `useast` account credentials
34
+ DESC
35
+ method_option :debug, :type => :string, :alias => '-x',
36
+ :desc => 'Debug logging 1,2,3,...'
37
+ define_method "account:verify" do |name|
38
+ cli_command(options) {
39
+ HP::Cloud::Accounts.new().read(name)
40
+ @log.display "Verifying '#{name}' account..."
41
+ begin
42
+ Connection.instance.validate_account(name)
43
+ @log.display "Able to connect to valid account '#{name}'."
44
+ rescue Exception => e
45
+ unless options[:debug].nil?
46
+ puts e.backtrace
47
+ end
48
+ e = ErrorResponse.new(e).to_s
49
+ @log.error "Account verification failed. Please verify your account credentials. \n Exception: #{e}"
50
+ end
51
+ }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,67 @@
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/accounts'
23
+ require 'hpcloud/commands/account/catalog'
24
+ require 'hpcloud/commands/account/copy'
25
+ require 'hpcloud/commands/account/edit'
26
+ require 'hpcloud/commands/account/remove'
27
+ require 'hpcloud/commands/account/setup'
28
+ require 'hpcloud/commands/account/tenants'
29
+ require 'hpcloud/commands/account/use'
30
+ require 'hpcloud/commands/account/verify'
31
+
32
+ module HP
33
+ module Cloud
34
+ class CLI < Thor
35
+
36
+ map 'account:list' => 'account'
37
+
38
+ desc 'account [account_name]', "List your accounts and account settings."
39
+ long_desc <<-DESC
40
+ List your accounts and your account settings.
41
+
42
+ Examples:
43
+ hpcloud account # List your accounts and account settings
44
+ hpcloud account:list # List your accounts and account settings
45
+ hpcloud account:list useast # List your accounts and account settings for domain `useast`
46
+
47
+ Aliases: account:list
48
+ DESC
49
+ def account(name=nil)
50
+ cli_command(options) {
51
+ accounts = HP::Cloud::Accounts.new()
52
+ if name.nil?
53
+ config = Config.new(true)
54
+ name = config.get(:default_account)
55
+ listo = accounts.list
56
+ @log.display listo.gsub(/^(#{name})$/, '\1 <= default')
57
+ else
58
+ sub_command {
59
+ acct = accounts.read(name)
60
+ @log.display acct.to_yaml.gsub(/---\n/,'').gsub(/^:/,'').gsub(/^[ ]*:/,' ')
61
+ }
62
+ end
63
+ }
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,59 @@
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/acl_cmd'
23
+
24
+ module HP
25
+ module Cloud
26
+ class CLI < Thor
27
+
28
+ map 'acl:set' => 'acl:grant'
29
+
30
+ desc 'acl:grant <container> <permissions> [user ...]', "Grant the specified permissions."
31
+ long_desc <<-DESC
32
+ Set the access control list (ACL) values for the specified container. The supported permissions are `r` (read), `w` (write), or `rw` (read and write). You may specify one or more user for the given permission. If you do not specify a user, the permissions are set to public. Public write permissions are not allowed.
33
+
34
+ Examples:
35
+ hpcloud acl:grant :my_container r # Allow anyone to read 'my_container'
36
+ hpcloud acl:grant :my_container rw bob@example.com sally@example.com # Allow Bob and Sally to read and write 'my_container'
37
+ hpcloud acl:grant :my_container r billy@example.com # Give Billy read permissions to 'my_container'
38
+
39
+ Aliases: acl:set
40
+ DESC
41
+ CLI.add_common_options
42
+ define_method 'acl:grant' do |name, permissions, *users|
43
+ cli_command(options) {
44
+ acl = HP::Cloud::AclCmd.new(permissions, users)
45
+ if acl.is_valid?
46
+ resource = ResourceFactory.create(Connection.instance.storage, name)
47
+ if resource.grant(acl)
48
+ @log.display "ACL for #{name} updated to #{acl}."
49
+ else
50
+ @log.fatal resource.cstatus
51
+ end
52
+ else
53
+ @log.fatal acl.cstatus
54
+ end
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,52 @@
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
+ desc 'acl:revoke <container> <permissions> [user ...]', "Revoke the specified permissions."
27
+ long_desc <<-DESC
28
+ Revoke the access control list (ACL) values from the specified container. The supported permissions are `r` (read), `w` (write), or `rw` (read and write). You may specify one or more user fo the given permission. If you do not specify a user, the permissions are set to public. Public write permissions are not allowed.
29
+
30
+ Examples:
31
+ hpcloud acl:revoke :my_container public-read # Revoke public read from 'my_container'
32
+ hpcloud acl:revoke :my_container rw bob@example.com # Revoke read and write from bob@example.com from 'my_container'
33
+ DESC
34
+ CLI.add_common_options
35
+ define_method 'acl:revoke' do |name, permissions, *users|
36
+ cli_command(options) {
37
+ acl = AclCmd.new(permissions, users)
38
+ if acl.is_valid?
39
+ resource = ResourceFactory.create(Connection.instance.storage, name)
40
+ if resource.revoke(acl)
41
+ @log.display "Revoked #{acl} from #{name}"
42
+ else
43
+ @log.fatal resource.cstatus
44
+ end
45
+ else
46
+ @log.fatal acl.cstatus
47
+ end
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end