hpcloud 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +127 -0
- data/LICENSE +1 -0
- data/README.rdoc +59 -0
- data/bin/hpcloud +11 -0
- data/completion/hpcloud +372 -0
- data/lib/hpcloud/accounts.rb +288 -0
- data/lib/hpcloud/acl.rb +112 -0
- data/lib/hpcloud/acl_cmd.rb +81 -0
- data/lib/hpcloud/address_helper.rb +63 -0
- data/lib/hpcloud/addresses.rb +42 -0
- data/lib/hpcloud/auth_cache.rb +128 -0
- data/lib/hpcloud/base_helper.rb +56 -0
- data/lib/hpcloud/checker.rb +104 -0
- data/lib/hpcloud/cli.rb +170 -0
- data/lib/hpcloud/cli_status.rb +80 -0
- data/lib/hpcloud/columns.rb +46 -0
- data/lib/hpcloud/commands/account/catalog.rb +57 -0
- data/lib/hpcloud/commands/account/copy.rb +44 -0
- data/lib/hpcloud/commands/account/edit.rb +204 -0
- data/lib/hpcloud/commands/account/remove.rb +53 -0
- data/lib/hpcloud/commands/account/setup.rb +40 -0
- data/lib/hpcloud/commands/account/tenants.rb +43 -0
- data/lib/hpcloud/commands/account/use.rb +46 -0
- data/lib/hpcloud/commands/account/verify.rb +55 -0
- data/lib/hpcloud/commands/account.rb +67 -0
- data/lib/hpcloud/commands/acl/grant.rb +59 -0
- data/lib/hpcloud/commands/acl/revoke.rb +52 -0
- data/lib/hpcloud/commands/acl.rb +63 -0
- data/lib/hpcloud/commands/addresses/add.rb +67 -0
- data/lib/hpcloud/commands/addresses/associate.rb +63 -0
- data/lib/hpcloud/commands/addresses/disassociate.rb +58 -0
- data/lib/hpcloud/commands/addresses/remove.rb +57 -0
- data/lib/hpcloud/commands/addresses.rb +63 -0
- data/lib/hpcloud/commands/cdn_containers/add.rb +56 -0
- data/lib/hpcloud/commands/cdn_containers/get.rb +70 -0
- data/lib/hpcloud/commands/cdn_containers/location.rb +61 -0
- data/lib/hpcloud/commands/cdn_containers/remove.rb +55 -0
- data/lib/hpcloud/commands/cdn_containers/set.rb +63 -0
- data/lib/hpcloud/commands/cdn_containers.rb +72 -0
- data/lib/hpcloud/commands/complete.rb +60 -0
- data/lib/hpcloud/commands/config/set.rb +63 -0
- data/lib/hpcloud/commands/config.rb +46 -0
- data/lib/hpcloud/commands/containers/add.rb +67 -0
- data/lib/hpcloud/commands/containers/remove.rb +63 -0
- data/lib/hpcloud/commands/containers/sync.rb +59 -0
- data/lib/hpcloud/commands/containers.rb +24 -0
- data/lib/hpcloud/commands/copy.rb +78 -0
- data/lib/hpcloud/commands/dns/add.rb +56 -0
- data/lib/hpcloud/commands/dns/records/add.rb +50 -0
- data/lib/hpcloud/commands/dns/records/remove.rb +53 -0
- data/lib/hpcloud/commands/dns/records/update.rb +50 -0
- data/lib/hpcloud/commands/dns/records.rb +57 -0
- data/lib/hpcloud/commands/dns/remove.rb +57 -0
- data/lib/hpcloud/commands/dns/servers.rb +57 -0
- data/lib/hpcloud/commands/dns/update.rb +58 -0
- data/lib/hpcloud/commands/dns.rb +65 -0
- data/lib/hpcloud/commands/flavors.rb +59 -0
- data/lib/hpcloud/commands/get.rb +58 -0
- data/lib/hpcloud/commands/images/add.rb +54 -0
- data/lib/hpcloud/commands/images/metadata/add.rb +54 -0
- data/lib/hpcloud/commands/images/metadata/remove.rb +56 -0
- data/lib/hpcloud/commands/images/metadata.rb +54 -0
- data/lib/hpcloud/commands/images/remove.rb +58 -0
- data/lib/hpcloud/commands/images.rb +67 -0
- data/lib/hpcloud/commands/info.rb +41 -0
- data/lib/hpcloud/commands/keypairs/add.rb +73 -0
- data/lib/hpcloud/commands/keypairs/import.rb +62 -0
- data/lib/hpcloud/commands/keypairs/private/add.rb +44 -0
- data/lib/hpcloud/commands/keypairs/private/location.rb +50 -0
- data/lib/hpcloud/commands/keypairs/private/remove.rb +52 -0
- data/lib/hpcloud/commands/keypairs/private.rb +47 -0
- data/lib/hpcloud/commands/keypairs/public_key.rb +51 -0
- data/lib/hpcloud/commands/keypairs/remove.rb +58 -0
- data/lib/hpcloud/commands/keypairs.rb +64 -0
- data/lib/hpcloud/commands/lb/add.rb +92 -0
- data/lib/hpcloud/commands/lb/algorithms.rb +55 -0
- data/lib/hpcloud/commands/lb/limits.rb +55 -0
- data/lib/hpcloud/commands/lb/nodes/add.rb +47 -0
- data/lib/hpcloud/commands/lb/nodes/remove.rb +54 -0
- data/lib/hpcloud/commands/lb/nodes/update.rb +47 -0
- data/lib/hpcloud/commands/lb/nodes.rb +55 -0
- data/lib/hpcloud/commands/lb/protocols.rb +55 -0
- data/lib/hpcloud/commands/lb/remove.rb +54 -0
- data/lib/hpcloud/commands/lb/update.rb +46 -0
- data/lib/hpcloud/commands/lb/versions.rb +55 -0
- data/lib/hpcloud/commands/lb/virtualips.rb +51 -0
- data/lib/hpcloud/commands/lb.rb +73 -0
- data/lib/hpcloud/commands/list.rb +114 -0
- data/lib/hpcloud/commands/location.rb +56 -0
- data/lib/hpcloud/commands/metadata/set.rb +61 -0
- data/lib/hpcloud/commands/metadata.rb +60 -0
- data/lib/hpcloud/commands/migrate.rb +61 -0
- data/lib/hpcloud/commands/move.rb +73 -0
- data/lib/hpcloud/commands/networks/add.rb +55 -0
- data/lib/hpcloud/commands/networks/remove.rb +57 -0
- data/lib/hpcloud/commands/networks/update.rb +54 -0
- data/lib/hpcloud/commands/networks.rb +63 -0
- data/lib/hpcloud/commands/ports/add.rb +81 -0
- data/lib/hpcloud/commands/ports/remove.rb +57 -0
- data/lib/hpcloud/commands/ports/update.rb +67 -0
- data/lib/hpcloud/commands/ports.rb +63 -0
- data/lib/hpcloud/commands/remove.rb +75 -0
- data/lib/hpcloud/commands/routers/add.rb +67 -0
- data/lib/hpcloud/commands/routers/interface/add.rb +59 -0
- data/lib/hpcloud/commands/routers/interface/remove.rb +66 -0
- data/lib/hpcloud/commands/routers/remove.rb +54 -0
- data/lib/hpcloud/commands/routers/update.rb +66 -0
- data/lib/hpcloud/commands/routers.rb +66 -0
- data/lib/hpcloud/commands/securitygroups/add.rb +52 -0
- data/lib/hpcloud/commands/securitygroups/remove.rb +57 -0
- data/lib/hpcloud/commands/securitygroups/rules/add.rb +126 -0
- data/lib/hpcloud/commands/securitygroups/rules/remove.rb +51 -0
- data/lib/hpcloud/commands/securitygroups/rules.rb +56 -0
- data/lib/hpcloud/commands/securitygroups.rb +62 -0
- data/lib/hpcloud/commands/servers/add.rb +100 -0
- data/lib/hpcloud/commands/servers/console.rb +81 -0
- data/lib/hpcloud/commands/servers/limits.rb +46 -0
- data/lib/hpcloud/commands/servers/metadata/add.rb +56 -0
- data/lib/hpcloud/commands/servers/metadata/remove.rb +57 -0
- data/lib/hpcloud/commands/servers/metadata.rb +56 -0
- data/lib/hpcloud/commands/servers/password.rb +47 -0
- data/lib/hpcloud/commands/servers/ratelimits.rb +46 -0
- data/lib/hpcloud/commands/servers/reboot.rb +61 -0
- data/lib/hpcloud/commands/servers/rebuild.rb +59 -0
- data/lib/hpcloud/commands/servers/remove.rb +58 -0
- data/lib/hpcloud/commands/servers/securitygroups/add.rb +47 -0
- data/lib/hpcloud/commands/servers/securitygroups/remove.rb +47 -0
- data/lib/hpcloud/commands/servers/ssh.rb +92 -0
- data/lib/hpcloud/commands/servers.rb +92 -0
- data/lib/hpcloud/commands/snapshots/add.rb +62 -0
- data/lib/hpcloud/commands/snapshots/remove.rb +58 -0
- data/lib/hpcloud/commands/snapshots.rb +62 -0
- data/lib/hpcloud/commands/subnets/add.rb +78 -0
- data/lib/hpcloud/commands/subnets/remove.rb +57 -0
- data/lib/hpcloud/commands/subnets/update.rb +70 -0
- data/lib/hpcloud/commands/subnets.rb +63 -0
- data/lib/hpcloud/commands/tempurl.rb +62 -0
- data/lib/hpcloud/commands/volumes/add.rb +88 -0
- data/lib/hpcloud/commands/volumes/attach.rb +59 -0
- data/lib/hpcloud/commands/volumes/detach.rb +57 -0
- data/lib/hpcloud/commands/volumes/metadata/add.rb +54 -0
- data/lib/hpcloud/commands/volumes/metadata.rb +55 -0
- data/lib/hpcloud/commands/volumes/remove.rb +57 -0
- data/lib/hpcloud/commands/volumes/server.rb +64 -0
- data/lib/hpcloud/commands/volumes.rb +65 -0
- data/lib/hpcloud/config.rb +205 -0
- data/lib/hpcloud/connection.rb +290 -0
- data/lib/hpcloud/container_resource.rb +175 -0
- data/lib/hpcloud/database_helper.rb +70 -0
- data/lib/hpcloud/databases.rb +38 -0
- data/lib/hpcloud/dns_helper.rb +125 -0
- data/lib/hpcloud/dnss.rb +38 -0
- data/lib/hpcloud/error_response.rb +89 -0
- data/lib/hpcloud/exceptions/base.rb +35 -0
- data/lib/hpcloud/exceptions/general.rb +34 -0
- data/lib/hpcloud/exceptions/not_found.rb +34 -0
- data/lib/hpcloud/flavors.rb +40 -0
- data/lib/hpcloud/floating_ip_helper.rb +114 -0
- data/lib/hpcloud/floating_ips.rb +42 -0
- data/lib/hpcloud/fog_collection.rb +124 -0
- data/lib/hpcloud/image_helper.rb +111 -0
- data/lib/hpcloud/images.rb +43 -0
- data/lib/hpcloud/keypair_helper.rb +109 -0
- data/lib/hpcloud/keypairs.rb +41 -0
- data/lib/hpcloud/lb_algorithms.rb +37 -0
- data/lib/hpcloud/lb_limits.rb +37 -0
- data/lib/hpcloud/lb_nodes.rb +42 -0
- data/lib/hpcloud/lb_protocols.rb +37 -0
- data/lib/hpcloud/lb_versions.rb +37 -0
- data/lib/hpcloud/lb_virtualips.rb +42 -0
- data/lib/hpcloud/lbs.rb +38 -0
- data/lib/hpcloud/local_resource.rb +183 -0
- data/lib/hpcloud/log.rb +55 -0
- data/lib/hpcloud/metadata.rb +118 -0
- data/lib/hpcloud/monkey.rb +22 -0
- data/lib/hpcloud/network_helper.rb +88 -0
- data/lib/hpcloud/networks.rb +47 -0
- data/lib/hpcloud/object_store.rb +66 -0
- data/lib/hpcloud/port_helper.rb +150 -0
- data/lib/hpcloud/ports.rb +38 -0
- data/lib/hpcloud/progress.rb +53 -0
- data/lib/hpcloud/remote_resource.rb +512 -0
- data/lib/hpcloud/resource.rb +264 -0
- data/lib/hpcloud/resource_factory.rb +110 -0
- data/lib/hpcloud/routers.rb +56 -0
- data/lib/hpcloud/rule_helper.rb +70 -0
- data/lib/hpcloud/rules.rb +41 -0
- data/lib/hpcloud/security_group_helper.rb +59 -0
- data/lib/hpcloud/security_groups.rb +37 -0
- data/lib/hpcloud/server_helper.rb +318 -0
- data/lib/hpcloud/servers.rb +47 -0
- data/lib/hpcloud/shared_resource.rb +172 -0
- data/lib/hpcloud/snapshot_helper.rb +78 -0
- data/lib/hpcloud/snapshots.rb +38 -0
- data/lib/hpcloud/subnet_helper.rb +170 -0
- data/lib/hpcloud/subnets.rb +38 -0
- data/lib/hpcloud/tableizer.rb +77 -0
- data/lib/hpcloud/thor_ext/thor.rb +54 -0
- data/lib/hpcloud/time_parser.rb +47 -0
- data/lib/hpcloud/version.rb +27 -0
- data/lib/hpcloud/volume_attachment.rb +58 -0
- data/lib/hpcloud/volume_attachments.rb +58 -0
- data/lib/hpcloud/volume_helper.rb +119 -0
- data/lib/hpcloud/volumes.rb +38 -0
- data/lib/hpcloud.rb +112 -0
- data/lib/monkey/hp/lb.rb +188 -0
- data/lib/monkey/hp/models/lb/algorithm.rb +32 -0
- data/lib/monkey/hp/models/lb/algorithms.rb +46 -0
- data/lib/monkey/hp/models/lb/limit.rb +38 -0
- data/lib/monkey/hp/models/lb/limits.rb +50 -0
- data/lib/monkey/hp/models/lb/load_balancer.rb +70 -0
- data/lib/monkey/hp/models/lb/load_balancers.rb +46 -0
- data/lib/monkey/hp/models/lb/node.rb +69 -0
- data/lib/monkey/hp/models/lb/nodes.rb +47 -0
- data/lib/monkey/hp/models/lb/protocol.rb +33 -0
- data/lib/monkey/hp/models/lb/protocols.rb +46 -0
- data/lib/monkey/hp/models/lb/version.rb +34 -0
- data/lib/monkey/hp/models/lb/versions.rb +47 -0
- data/lib/monkey/hp/models/lb/virtual_ip.rb +37 -0
- data/lib/monkey/hp/models/lb/virtual_ips.rb +47 -0
- data/lib/monkey/hp/requests/lb/create_load_balancer.rb +64 -0
- data/lib/monkey/hp/requests/lb/create_load_balancer_node.rb +58 -0
- data/lib/monkey/hp/requests/lb/delete_load_balancer.rb +54 -0
- data/lib/monkey/hp/requests/lb/delete_load_balancer_node.rb +60 -0
- data/lib/monkey/hp/requests/lb/get_load_balancer.rb +88 -0
- data/lib/monkey/hp/requests/lb/get_load_balancer_node.rb +60 -0
- data/lib/monkey/hp/requests/lb/get_version.rb +68 -0
- data/lib/monkey/hp/requests/lb/get_virtual_ips.rb +48 -0
- data/lib/monkey/hp/requests/lb/list_algorithms.rb +51 -0
- data/lib/monkey/hp/requests/lb/list_limits.rb +60 -0
- data/lib/monkey/hp/requests/lb/list_load_balancer_nodes.rb +79 -0
- data/lib/monkey/hp/requests/lb/list_load_balancer_virtual_ips.rb +76 -0
- data/lib/monkey/hp/requests/lb/list_load_balancers.rb +69 -0
- data/lib/monkey/hp/requests/lb/list_protocols.rb +51 -0
- data/lib/monkey/hp/requests/lb/list_versions.rb +51 -0
- data/lib/monkey/hp/requests/lb/update_load_balancer.rb +46 -0
- data/lib/monkey/hp/requests/lb/update_load_balancer_node.rb +50 -0
- metadata +368 -0
|
@@ -0,0 +1,128 @@
|
|
|
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 AuthCache
|
|
27
|
+
attr_reader :directory
|
|
28
|
+
@@home = nil
|
|
29
|
+
|
|
30
|
+
def initialize
|
|
31
|
+
if @@home.nil?
|
|
32
|
+
@@home = ENV['HOME']
|
|
33
|
+
end
|
|
34
|
+
@directory = @@home + "/.hpcloud/accounts/.cache/"
|
|
35
|
+
@aucas = {}
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.home_directory=(dir)
|
|
39
|
+
@@home = dir
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def get_name(opts)
|
|
43
|
+
begin
|
|
44
|
+
"#{opts[:hp_access_key]}:#{opts[:hp_tenant_id]}"
|
|
45
|
+
rescue
|
|
46
|
+
"default"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def get_file_name(opts)
|
|
51
|
+
return "#{@directory}" if opts.nil?
|
|
52
|
+
"#{@directory}#{get_name(opts)}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def remove(opts = nil)
|
|
56
|
+
if opts.nil?
|
|
57
|
+
begin
|
|
58
|
+
dirname = get_file_name(nil)
|
|
59
|
+
dir = Dir.new(dirname)
|
|
60
|
+
dir.entries.each { |x|
|
|
61
|
+
file_name = dirname + x
|
|
62
|
+
begin
|
|
63
|
+
unless (x == "." || x == "..")
|
|
64
|
+
File.delete(file_name)
|
|
65
|
+
end
|
|
66
|
+
rescue
|
|
67
|
+
warn "Error deleting cache file: #{file_name}"
|
|
68
|
+
end
|
|
69
|
+
}
|
|
70
|
+
rescue
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
file_name = get_file_name(opts)
|
|
74
|
+
begin
|
|
75
|
+
File.delete(file_name)
|
|
76
|
+
rescue
|
|
77
|
+
return false
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
return true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def read(opts)
|
|
84
|
+
account = get_name(opts)
|
|
85
|
+
return @aucas[account] if @aucas[account].nil? == false
|
|
86
|
+
file_name = get_file_name(opts)
|
|
87
|
+
if File.exists?(file_name)
|
|
88
|
+
begin
|
|
89
|
+
@aucas[account] = YAML::load(File.open(file_name))
|
|
90
|
+
rescue Exception => e
|
|
91
|
+
raise Exception.new('Error reading cache file: ' + file_name)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
return @aucas[account]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def write(opts, creds)
|
|
98
|
+
account = get_name(opts)
|
|
99
|
+
@aucas[account] = creds;
|
|
100
|
+
config = @aucas[account]
|
|
101
|
+
if config.nil?
|
|
102
|
+
remove(opts)
|
|
103
|
+
return
|
|
104
|
+
end
|
|
105
|
+
file_name = get_file_name(opts)
|
|
106
|
+
begin
|
|
107
|
+
FileUtils.mkpath(@directory)
|
|
108
|
+
File.open(file_name, 'w') do |file|
|
|
109
|
+
file.write config.to_yaml
|
|
110
|
+
end
|
|
111
|
+
rescue Exception => e
|
|
112
|
+
raise Exception.new("Error writing file #{file_name}")
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def default_zone(opts, service)
|
|
117
|
+
creds = read(opts)
|
|
118
|
+
return nil if creds.nil?
|
|
119
|
+
catalog = creds[:service_catalog]
|
|
120
|
+
return nil if catalog.nil?
|
|
121
|
+
return nil if catalog[service.to_sym].nil?
|
|
122
|
+
keys = []
|
|
123
|
+
catalog[service.to_sym].keys.each { |x| keys << x.to_s }
|
|
124
|
+
return keys.sort.first.to_s
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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 BaseHelper
|
|
25
|
+
attr_accessor :fog, :connection, :cstatus
|
|
26
|
+
|
|
27
|
+
def initialize(connection, foggy = nil)
|
|
28
|
+
@connection = connection
|
|
29
|
+
@cstatus = CliStatus.new
|
|
30
|
+
@fog = foggy
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_hash
|
|
34
|
+
return nil unless is_valid?
|
|
35
|
+
hash = {}
|
|
36
|
+
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
|
37
|
+
hash
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_error(noo, status = :general_error)
|
|
41
|
+
unless noo.is_a?(CliStatus)
|
|
42
|
+
noo = CliStatus.new(noo, status)
|
|
43
|
+
end
|
|
44
|
+
@cstatus.set(noo)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def is_valid?
|
|
48
|
+
return @cstatus.is_success?
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def destroy
|
|
52
|
+
@fog.destroy unless @fog.nil?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
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 'open-uri'
|
|
23
|
+
|
|
24
|
+
module HP
|
|
25
|
+
module Cloud
|
|
26
|
+
class Checker
|
|
27
|
+
attr_accessor :url, :deferment, :file, :latest
|
|
28
|
+
|
|
29
|
+
@@home = nil
|
|
30
|
+
|
|
31
|
+
def initialize
|
|
32
|
+
if @@home.nil?
|
|
33
|
+
@@home = ENV['HOME']
|
|
34
|
+
end
|
|
35
|
+
@directory = @@home + "/.hpcloud/"
|
|
36
|
+
@file = @directory + ".checker"
|
|
37
|
+
config = Config.new
|
|
38
|
+
@url = config.get(:checker_url)
|
|
39
|
+
@deferment = config.get(:checker_deferment)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.home_directory=(dir)
|
|
43
|
+
@@home = dir
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.split(value)
|
|
47
|
+
value = value.strip.split('.')
|
|
48
|
+
major = value[0] if value.length > 0
|
|
49
|
+
minor = value[1] if value.length > 1
|
|
50
|
+
build = value[2] if value.length > 2
|
|
51
|
+
return major, minor, build
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def comparo(latest)
|
|
55
|
+
lmajor, lminor, lbuild = Checker.split(latest)
|
|
56
|
+
major, minor, build = Checker.split(HP::Cloud::VERSION)
|
|
57
|
+
lmajor = lmajor.to_i
|
|
58
|
+
lminor = lminor.to_i
|
|
59
|
+
lbuild = lbuild.to_i
|
|
60
|
+
major = major.to_i
|
|
61
|
+
minor = minor.to_i
|
|
62
|
+
build = build.to_i
|
|
63
|
+
return true if lmajor > major
|
|
64
|
+
return false if lmajor < major
|
|
65
|
+
return true if lminor > minor
|
|
66
|
+
return false if lminor < minor
|
|
67
|
+
return true if lbuild > build
|
|
68
|
+
return false
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def process
|
|
72
|
+
return false if @deferment == 0
|
|
73
|
+
return false if @url.nil?
|
|
74
|
+
if File.exists?(@file)
|
|
75
|
+
begin
|
|
76
|
+
mtime = File.new(@file).mtime
|
|
77
|
+
now = Time.now
|
|
78
|
+
rescue
|
|
79
|
+
return false
|
|
80
|
+
end
|
|
81
|
+
return false if ((now - mtime) < @deferment)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
begin
|
|
85
|
+
FileUtils.mkdir_p(@directory)
|
|
86
|
+
FileUtils.touch(@file)
|
|
87
|
+
rescue
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
begin
|
|
91
|
+
@latest = open(@url).read.strip
|
|
92
|
+
return false unless comparo(@latest)
|
|
93
|
+
rescue
|
|
94
|
+
return false
|
|
95
|
+
end
|
|
96
|
+
return true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def reset
|
|
100
|
+
FileUtils.rm_rf(@file)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
data/lib/hpcloud/cli.rb
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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 'thor'
|
|
23
|
+
require 'thor/group'
|
|
24
|
+
require 'hpcloud/thor_ext/thor'
|
|
25
|
+
require 'hpcloud/exceptions/base'
|
|
26
|
+
|
|
27
|
+
module HP
|
|
28
|
+
module Cloud
|
|
29
|
+
class CLI < Thor
|
|
30
|
+
attr_accessor :exit_status
|
|
31
|
+
|
|
32
|
+
GOPTS = {:availability_zone => {:type => :string, :aliases => '-z',
|
|
33
|
+
:desc => 'Set the availability zone.'},
|
|
34
|
+
:debug => {:type => :string, :aliases => '-x',
|
|
35
|
+
:desc => 'Debug logging 1,2,3,...'},
|
|
36
|
+
:tenantid => {:type => :string,
|
|
37
|
+
:desc => 'Tenant id for account.'},
|
|
38
|
+
:account_name => {:type => :string, :aliases => '-a',
|
|
39
|
+
:desc => 'Select account.'}}
|
|
40
|
+
|
|
41
|
+
def initialize(*args)
|
|
42
|
+
super
|
|
43
|
+
@@debugging = false
|
|
44
|
+
@@error = nil
|
|
45
|
+
@exit_status = HP::Cloud::CliStatus.new
|
|
46
|
+
@log = HP::Cloud::Log.new(self)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
def self.add_common_options
|
|
51
|
+
GOPTS.each { |k,v| method_option(k, v) }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.add_report_options
|
|
55
|
+
method_option(Columns.option_name, Columns.option_args)
|
|
56
|
+
method_option(Tableizer.option_name, Tableizer.option_args)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# name of the running CLI script
|
|
60
|
+
def selfname
|
|
61
|
+
ENV['HPCLOUD_CLI_NAME'] || 'hpcloud'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
class << self
|
|
65
|
+
def exit_on_failure?
|
|
66
|
+
true
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
### Thor extensions
|
|
71
|
+
|
|
72
|
+
def ask_with_default(statement, default, color = nil)
|
|
73
|
+
response = ask("#{statement} [#{default}]")
|
|
74
|
+
return response.empty? ? default : response
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def cli_command(options)
|
|
78
|
+
unless options[:debug].nil?
|
|
79
|
+
if options[:debug] > '1'
|
|
80
|
+
ENV['EXCON_STANDARD_INSTRUMENTOR']='1'
|
|
81
|
+
end
|
|
82
|
+
@@debugging = true
|
|
83
|
+
end
|
|
84
|
+
Connection.instance.set_options(options)
|
|
85
|
+
sub_command { yield }
|
|
86
|
+
checker = Checker.new
|
|
87
|
+
if checker.process
|
|
88
|
+
warn "A new version v#{checker.latest} of the Unix CLI is available at https://docs.hpcloud.com/cli/unix/install"
|
|
89
|
+
end
|
|
90
|
+
exit @exit_status.get
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def sub_command(action=nil)
|
|
94
|
+
error_status = nil
|
|
95
|
+
begin
|
|
96
|
+
yield
|
|
97
|
+
rescue HP::Cloud::Exceptions::Base => error
|
|
98
|
+
@@error = error.to_s
|
|
99
|
+
error_status = error.status
|
|
100
|
+
rescue Excon::Errors::BadRequest => error
|
|
101
|
+
@@error = ErrorResponse.new(error).to_s
|
|
102
|
+
error_status = :incorrect_usage
|
|
103
|
+
rescue Excon::Errors::InternalServerError => error
|
|
104
|
+
@@error = ErrorResponse.new(error).to_s
|
|
105
|
+
error_status = :general_error
|
|
106
|
+
rescue Fog::HP::Errors::ServiceError => error
|
|
107
|
+
@@error = error
|
|
108
|
+
error_status = :general_error
|
|
109
|
+
rescue Fog::HP::BlockStorage::NotFound => error
|
|
110
|
+
@@error = error
|
|
111
|
+
error_status = :not_found
|
|
112
|
+
rescue Fog::CDN::HP::NotFound => error
|
|
113
|
+
@@error = error
|
|
114
|
+
error_status = :not_found
|
|
115
|
+
rescue Fog::Compute::HP::NotFound => error
|
|
116
|
+
@@error = error
|
|
117
|
+
error_status = :not_found
|
|
118
|
+
rescue Fog::Storage::HP::NotFound => error
|
|
119
|
+
@@error = error
|
|
120
|
+
error_status = :not_found
|
|
121
|
+
rescue Fog::HP::BlockStorage::Error => error
|
|
122
|
+
@@error = error
|
|
123
|
+
error_status = :general_error
|
|
124
|
+
rescue Fog::CDN::HP::Error => error
|
|
125
|
+
@@error = error
|
|
126
|
+
error_status = :general_error
|
|
127
|
+
rescue Fog::Compute::HP::Error => error
|
|
128
|
+
@@error = error
|
|
129
|
+
error_status = :general_error
|
|
130
|
+
rescue Fog::Storage::HP::Error => error
|
|
131
|
+
@@error = error
|
|
132
|
+
error_status = :general_error
|
|
133
|
+
rescue Excon::Errors::Unauthorized, Excon::Errors::Forbidden => error
|
|
134
|
+
@@error = ErrorResponse.new(error).to_s
|
|
135
|
+
error_status = :permission_denied
|
|
136
|
+
rescue Excon::Errors::Conflict => error
|
|
137
|
+
@@error = ErrorResponse.new(error).to_s
|
|
138
|
+
error_status = :conflicted
|
|
139
|
+
rescue Excon::Errors::NotFound => error
|
|
140
|
+
@@error = ErrorResponse.new(error).to_s
|
|
141
|
+
error_status = :not_found
|
|
142
|
+
rescue Excon::Errors::RequestEntityTooLarge => error
|
|
143
|
+
@@error = ErrorResponse.new(error).to_s
|
|
144
|
+
error_status = :rate_limited
|
|
145
|
+
rescue SystemExit => error
|
|
146
|
+
@@error = error
|
|
147
|
+
rescue Exception => error
|
|
148
|
+
@@error = error
|
|
149
|
+
error_status = :general_error
|
|
150
|
+
end
|
|
151
|
+
unless error_status.nil?
|
|
152
|
+
if action.nil?
|
|
153
|
+
@log.error(@@error, error_status)
|
|
154
|
+
else
|
|
155
|
+
@@error = "Error #{action}: #{@@error.to_s}"
|
|
156
|
+
@log.error(@@error, error_status)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
if @@debugging == true
|
|
160
|
+
unless @@error.nil?
|
|
161
|
+
if @@error.kind_of?(Exception)
|
|
162
|
+
puts @@error.backtrace
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
@exit_status.get
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
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 CliStatus
|
|
25
|
+
attr_accessor :message, :exit_code, :error_code
|
|
26
|
+
|
|
27
|
+
TYPES = { :success => 0,
|
|
28
|
+
:general_error => 1,
|
|
29
|
+
:not_supported => 3,
|
|
30
|
+
:not_found => 4,
|
|
31
|
+
:conflicted => 5,
|
|
32
|
+
:incorrect_usage => 64,
|
|
33
|
+
:permission_denied => 77,
|
|
34
|
+
:rate_limited => 88,
|
|
35
|
+
:partial_error => 98,
|
|
36
|
+
:unknown_status => 99
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def initialize(message = nil, code = :success)
|
|
40
|
+
@message = message
|
|
41
|
+
@error_code = :success
|
|
42
|
+
@exit_code = 0
|
|
43
|
+
set(code)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def set(code)
|
|
47
|
+
unless code.is_a?(Symbol)
|
|
48
|
+
if code.is_a?(CliStatus)
|
|
49
|
+
@message = code.message
|
|
50
|
+
code = code.error_code
|
|
51
|
+
else
|
|
52
|
+
warn "Incorrect error code: #{code.to_s}"
|
|
53
|
+
code = :unknown_status
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
exit_code = TYPES[code]
|
|
57
|
+
if exit_code.nil?
|
|
58
|
+
warn "Unknown error code: #{code.to_s}"
|
|
59
|
+
exit_code = TYPES[:unknown_status]
|
|
60
|
+
end
|
|
61
|
+
if exit_code > @exit_code
|
|
62
|
+
@error_code = code
|
|
63
|
+
@exit_code = exit_code
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def is_success?
|
|
68
|
+
return @error_code == :success
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def get
|
|
72
|
+
return @exit_code
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def to_s
|
|
76
|
+
return @message.to_s
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
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
|
+
module HP
|
|
23
|
+
module Cloud
|
|
24
|
+
class Columns
|
|
25
|
+
|
|
26
|
+
attr_reader :keys
|
|
27
|
+
|
|
28
|
+
def initialize(options, keys)
|
|
29
|
+
if options[:columns].nil?
|
|
30
|
+
@keys = keys
|
|
31
|
+
else
|
|
32
|
+
@keys = options[:columns].split(',')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.option_name
|
|
37
|
+
return :columns
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.option_args
|
|
41
|
+
return { :type => :string, :aliases => '-c',
|
|
42
|
+
:desc => 'Comma separated list of columns in report.'}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
#
|
|
3
|
+
# © Copyright 2013 Hewlett-Packard Development Company, L.P.
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
# copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
# SOFTWARE.
|
|
21
|
+
|
|
22
|
+
require 'yaml'
|
|
23
|
+
require 'hpcloud/accounts'
|
|
24
|
+
|
|
25
|
+
module HP
|
|
26
|
+
module Cloud
|
|
27
|
+
class CLI < Thor
|
|
28
|
+
|
|
29
|
+
desc 'account:catalog <account_to_catalog> [service]', "Print the service catalog of the specified account."
|
|
30
|
+
long_desc <<-DESC
|
|
31
|
+
Print the service catalog of the specified account. Optionally, you may specify a particular service to print such as `Compute`.
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
hpcloud account:catalog useast # Print the service catalog of `useast`:
|
|
35
|
+
hpcloud account:catalog useast Compute # Print the compute catalog of `useast`:
|
|
36
|
+
DESC
|
|
37
|
+
method_option :debug, :type => :string, :alias => '-x',
|
|
38
|
+
:desc => 'Debug logging 1,2,3,...'
|
|
39
|
+
define_method "account:catalog" do |name, *service|
|
|
40
|
+
cli_command(options) {
|
|
41
|
+
@log.display "Service catalog '#{name}':"
|
|
42
|
+
HP::Cloud::Accounts.new().read(name)
|
|
43
|
+
begin
|
|
44
|
+
cata = Connection.instance.catalog(name, service)
|
|
45
|
+
@log.display cata.to_yaml.gsub(/--- \n/,'').gsub(/\{\}/,'').gsub(/\n\n/, "\n")
|
|
46
|
+
rescue Exception => e
|
|
47
|
+
unless options[:debug].nil?
|
|
48
|
+
puts e.backtrace
|
|
49
|
+
end
|
|
50
|
+
e = ErrorResponse.new(e).to_s
|
|
51
|
+
@log.error "Account verification failed. Please check your account credentials. \n Exception: #{e}"
|
|
52
|
+
end
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
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:copy <from_account> <to_account>', "Copy account data to the specified account."
|
|
29
|
+
long_desc <<-DESC
|
|
30
|
+
The copy command overwrites the destination account with the source account information.
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
hpcloud account:copy useast backup # Copy account `useast` to account `backup`
|
|
34
|
+
DESC
|
|
35
|
+
define_method "account:copy" do |src, dest|
|
|
36
|
+
cli_command(options) {
|
|
37
|
+
accounts = HP::Cloud::Accounts.new()
|
|
38
|
+
accounts.copy(src, dest)
|
|
39
|
+
@log.display("Account '#{src}' copied to '#{dest}'")
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|