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,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
|
+
module HP
|
|
23
|
+
module Cloud
|
|
24
|
+
class SubnetHelper < BaseHelper
|
|
25
|
+
attr_accessor :id, :name, :tenant_id
|
|
26
|
+
attr_accessor :network_id, :cidr, :ip_version, :dns_nameservers
|
|
27
|
+
attr_accessor :allocation_pools, :host_routes, :gateway, :dhcp
|
|
28
|
+
attr_accessor :allocation, :routes, :nameservers
|
|
29
|
+
|
|
30
|
+
def self.get_keys()
|
|
31
|
+
return [ "id", "name", "network_id", "cidr", "nameservers", "routes", "gateway", "dhcp" ]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize(connection, foggy = nil)
|
|
35
|
+
super(connection, foggy)
|
|
36
|
+
if foggy.nil?
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
@id = foggy.id
|
|
40
|
+
@name = foggy.name
|
|
41
|
+
@tenant_id = foggy.tenant_id
|
|
42
|
+
@network_id = foggy.network_id
|
|
43
|
+
@cidr = foggy.cidr
|
|
44
|
+
@ip_version = foggy.ip_version
|
|
45
|
+
@dns_nameservers = foggy.dns_nameservers
|
|
46
|
+
@nameservers = ""
|
|
47
|
+
if foggy.dns_nameservers.kind_of? Array
|
|
48
|
+
@nameservers = foggy.dns_nameservers.join(",")
|
|
49
|
+
end
|
|
50
|
+
@allocation_pools = foggy.allocation_pools
|
|
51
|
+
@allocation = ""
|
|
52
|
+
if foggy.allocation_pools.kind_of? Array
|
|
53
|
+
foggy.allocation_pools.each { |hsh|
|
|
54
|
+
if hsh.kind_of? Hash
|
|
55
|
+
@allocation += "," unless @allocation.empty?
|
|
56
|
+
@allocation += "#{hsh['start']}-#{hsh['end']}"
|
|
57
|
+
end
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
@host_routes = foggy.host_routes
|
|
61
|
+
@routes = ""
|
|
62
|
+
if foggy.host_routes.kind_of? Array
|
|
63
|
+
foggy.host_routes.each{ |route|
|
|
64
|
+
if route.kind_of? Hash
|
|
65
|
+
@routes += ';' unless @routes.empty?
|
|
66
|
+
@routes += "#{route['destination']},#{route['nexthop']}"
|
|
67
|
+
end
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
@gateway = foggy.gateway_ip
|
|
71
|
+
@dhcp = foggy.enable_dhcp
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def set_cidr(value)
|
|
75
|
+
require 'ipaddr'
|
|
76
|
+
@cidr = value
|
|
77
|
+
begin
|
|
78
|
+
ipaddr = IPAddr.new(@cidr)
|
|
79
|
+
@ip_version = 6 if ipaddr.ipv6?
|
|
80
|
+
@ip_version = 4 if ipaddr.ipv4?
|
|
81
|
+
rescue Exception => e
|
|
82
|
+
set_error("Invalid CIDR value #{@cidr}", :incorrect_usage)
|
|
83
|
+
return false
|
|
84
|
+
end
|
|
85
|
+
return true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def set_ip_version(value)
|
|
89
|
+
return true if value.nil?
|
|
90
|
+
value = value.to_s
|
|
91
|
+
if value != "4" && value != "6"
|
|
92
|
+
set_error("Invalid IP version '#{value}'", :incorrect_usage)
|
|
93
|
+
return false
|
|
94
|
+
end
|
|
95
|
+
@ip_version = value
|
|
96
|
+
return true
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def set_gateway(value)
|
|
100
|
+
@gateway = value
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def set_dns_nameservers(value)
|
|
104
|
+
return true if value.nil?
|
|
105
|
+
require 'ipaddr'
|
|
106
|
+
@nameserver = value
|
|
107
|
+
begin
|
|
108
|
+
@dns_nameservers = value.split(',')
|
|
109
|
+
@dns_nameservers.each{ |dns|
|
|
110
|
+
IPAddr.new(dns)
|
|
111
|
+
}
|
|
112
|
+
rescue Exception => e
|
|
113
|
+
set_error("Invalid DNS nameserver '#{value}' must be comma separated list of IPs", :incorrect_usage)
|
|
114
|
+
return false
|
|
115
|
+
end
|
|
116
|
+
return true
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def set_host_routes(value)
|
|
120
|
+
return true if value.nil?
|
|
121
|
+
@routes = value
|
|
122
|
+
begin
|
|
123
|
+
@host_routes = []
|
|
124
|
+
value.split(';').each{ |route|
|
|
125
|
+
ray = route.split(',')
|
|
126
|
+
raise Exception.new("not destination,nexthop") if ray.length != 2
|
|
127
|
+
@host_routes << { "destination" => ray[0], "nexthop" => ray[1] }
|
|
128
|
+
}
|
|
129
|
+
rescue Exception => e
|
|
130
|
+
set_error("Invalid host routes '#{value}' must be semicolon separated list of destination,nexthop", :incorrect_usage)
|
|
131
|
+
return false
|
|
132
|
+
end
|
|
133
|
+
return true
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def save
|
|
137
|
+
return false if is_valid? == false
|
|
138
|
+
hsh = {
|
|
139
|
+
:name => @name,
|
|
140
|
+
:tenant_id => @tenant_id,
|
|
141
|
+
:dns_nameservers => @dns_nameservers,
|
|
142
|
+
:allocation_pools => @allocation_pools,
|
|
143
|
+
:host_routes => @host_routes,
|
|
144
|
+
:gateway_ip => @gateway,
|
|
145
|
+
:enable_dhcp => @dhcp.to_s
|
|
146
|
+
}
|
|
147
|
+
if @fog.nil?
|
|
148
|
+
response = @connection.network.create_subnet(@network_id, @cidr, @ip_version, hsh)
|
|
149
|
+
if response.nil?
|
|
150
|
+
set_error("Error creating subnet '#{@name}'")
|
|
151
|
+
return false
|
|
152
|
+
end
|
|
153
|
+
@id = response.body["subnet"]["id"]
|
|
154
|
+
@foggy = response.body["subnet"]
|
|
155
|
+
else
|
|
156
|
+
response = @connection.network.update_subnet(@id, hsh)
|
|
157
|
+
if response.nil?
|
|
158
|
+
set_error("Error updating subnet '#{@name}'")
|
|
159
|
+
return false
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
return true
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def destroy
|
|
166
|
+
@connection.network.delete_subnet(@id)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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/subnet_helper'
|
|
24
|
+
|
|
25
|
+
module HP
|
|
26
|
+
module Cloud
|
|
27
|
+
class Subnets < FogCollection
|
|
28
|
+
def initialize
|
|
29
|
+
super("subnet")
|
|
30
|
+
@items = @connection.network.subnets
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create(item = nil)
|
|
34
|
+
return SubnetHelper.new(@connection, item)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
25
|
+
class Tableizer
|
|
26
|
+
attr_reader :found
|
|
27
|
+
|
|
28
|
+
DEFAULT_REPORT_PAGE_LENGTH = 60
|
|
29
|
+
|
|
30
|
+
def initialize(options, keys, values = [])
|
|
31
|
+
@options = options
|
|
32
|
+
columns = Columns.new(options, keys)
|
|
33
|
+
@keys = columns.keys
|
|
34
|
+
@values = values
|
|
35
|
+
@found = false
|
|
36
|
+
@page_length = Config.new.get_i(:report_page_length, DEFAULT_REPORT_PAGE_LENGTH)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def add(item)
|
|
40
|
+
@found = true
|
|
41
|
+
@values << item
|
|
42
|
+
print if @values.length >= @page_length
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def print
|
|
46
|
+
return if @values.nil?
|
|
47
|
+
return if @values.empty?
|
|
48
|
+
@found = true
|
|
49
|
+
if @options[:separator]
|
|
50
|
+
separator = @options[:separator]
|
|
51
|
+
separator = ',' if separator == "separator"
|
|
52
|
+
@values.each{ |v|
|
|
53
|
+
sep = ''
|
|
54
|
+
line = ''
|
|
55
|
+
@keys.each{ |k|
|
|
56
|
+
line += "#{sep}#{v[k]}"
|
|
57
|
+
sep = separator
|
|
58
|
+
}
|
|
59
|
+
puts line
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
Formatador.display_compact_table(@values, @keys)
|
|
63
|
+
end
|
|
64
|
+
@values = []
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.option_name
|
|
68
|
+
return :separator
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.option_args
|
|
72
|
+
return { :type => :string, :aliases => '-d',
|
|
73
|
+
:desc => 'Use the specified value as the report separator.'}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
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/base'
|
|
23
|
+
|
|
24
|
+
class Thor
|
|
25
|
+
class << self
|
|
26
|
+
|
|
27
|
+
# Prints help information for the given task.
|
|
28
|
+
#
|
|
29
|
+
# ==== Parameters
|
|
30
|
+
# shell<Thor::Shell>
|
|
31
|
+
# task_name<String>
|
|
32
|
+
#
|
|
33
|
+
def task_help(shell, task_name)
|
|
34
|
+
meth = normalize_task_name(task_name)
|
|
35
|
+
task = all_tasks[meth]
|
|
36
|
+
handle_no_task_error(meth) unless task
|
|
37
|
+
|
|
38
|
+
shell.say "Usage:"
|
|
39
|
+
shell.say " #{banner(task)}"
|
|
40
|
+
shell.say
|
|
41
|
+
class_options_help(shell, nil => task.options.map { |_, o| o })
|
|
42
|
+
if task.long_description
|
|
43
|
+
shell.say "Description:"
|
|
44
|
+
shell.say task.long_description
|
|
45
|
+
# elsif nil and task.long_description
|
|
46
|
+
# shell.say "Description:"
|
|
47
|
+
# shell.print_wrapped(task.long_description, :ident => 2)
|
|
48
|
+
else
|
|
49
|
+
shell.say task.description
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
|
|
25
|
+
class TimeParser
|
|
26
|
+
def self.parse(str)
|
|
27
|
+
return nil if str.nil?
|
|
28
|
+
ray = str.scan(/(\d+)(\w)/)
|
|
29
|
+
if ray.nil? || ray[0].nil?
|
|
30
|
+
raise Exception.new("The expected time format contains value and unit like 2d for two days. Supported units are s, m, h, or d")
|
|
31
|
+
end
|
|
32
|
+
case ray[0][1]
|
|
33
|
+
when "s"
|
|
34
|
+
return ray[0][0].to_i
|
|
35
|
+
when "m"
|
|
36
|
+
return ray[0][0].to_i * 60
|
|
37
|
+
when "h"
|
|
38
|
+
return ray[0][0].to_i * 60 * 60
|
|
39
|
+
when "d"
|
|
40
|
+
return ray[0][0].to_i * 60 * 60 * 24
|
|
41
|
+
else
|
|
42
|
+
raise Exception.new("Unrecognized time unit #{ray[0][1]} in #{str} expected s, m, h, or d")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
VERSION = '2.0.0'
|
|
25
|
+
SHA1 = '0f4bee4da6fd6f98be6d85660ff6e91ae71d4116'
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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 VolumeAttachment
|
|
25
|
+
attr_accessor :cstatus
|
|
26
|
+
attr_accessor :id, :device, :serverId, :volumeId, :name, :server
|
|
27
|
+
attr_accessor :meta
|
|
28
|
+
|
|
29
|
+
def self.get_keys()
|
|
30
|
+
return [ "id", "name", "server", "device" ]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(va = nil)
|
|
34
|
+
@cstatus = CliStatus.new
|
|
35
|
+
@fog_va = va
|
|
36
|
+
if va.nil?
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
@id = va["id"]
|
|
40
|
+
@device = va["device"]
|
|
41
|
+
@serverId = va["serverId"]
|
|
42
|
+
@volumeId = va["volumeId"]
|
|
43
|
+
@name = va["name"]
|
|
44
|
+
@server = va["server"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_hash
|
|
48
|
+
hash = {}
|
|
49
|
+
instance_variables.each {|var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
|
50
|
+
hash
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def is_valid?
|
|
54
|
+
return @cstatus.is_success?
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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/volume_helper'
|
|
24
|
+
|
|
25
|
+
module HP
|
|
26
|
+
module Cloud
|
|
27
|
+
class VolumeAttachments < FogCollection
|
|
28
|
+
def initialize(server)
|
|
29
|
+
super("volume_attachment")
|
|
30
|
+
@items = []
|
|
31
|
+
volumes = Volumes.new
|
|
32
|
+
begin
|
|
33
|
+
rsp = @connection.compute.list_server_volumes(server.id.to_s)
|
|
34
|
+
rescue Exception => e
|
|
35
|
+
raise Exception.new("List server volumes call failed")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if rsp.nil? || rsp.body.nil? || rsp.body["volumeAttachments"].nil?
|
|
39
|
+
raise Exception.new("List server volumes should include response body with volumeAttachments")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
rsp.body["volumeAttachments"].each { |hsh|
|
|
43
|
+
hsh["server"] = server.name
|
|
44
|
+
vol = volumes.get(hsh["volumeId"].to_s)
|
|
45
|
+
if vol.is_valid?
|
|
46
|
+
hsh["name"] = vol.name
|
|
47
|
+
end
|
|
48
|
+
@items << hsh
|
|
49
|
+
}
|
|
50
|
+
return
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def create(item = nil)
|
|
54
|
+
return VolumeAttachment.new(item)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
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 VolumeHelper < BaseHelper
|
|
25
|
+
@@serverous = nil
|
|
26
|
+
attr_accessor :id, :name, :size, :type, :created, :status, :description, :servers, :snapshot_id, :imageref, :availability_zone
|
|
27
|
+
attr_accessor :meta
|
|
28
|
+
|
|
29
|
+
def self.get_keys()
|
|
30
|
+
return [ "id", "name", "size", "type", "created", "status", "description", "servers", "availability_zone" ]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(connection, foggy = nil)
|
|
34
|
+
super(connection, foggy)
|
|
35
|
+
if foggy.nil?
|
|
36
|
+
return
|
|
37
|
+
end
|
|
38
|
+
@id = foggy.id
|
|
39
|
+
@name = foggy.name
|
|
40
|
+
@size = foggy.size
|
|
41
|
+
@type = foggy.type
|
|
42
|
+
@created = foggy.created_at
|
|
43
|
+
@status = foggy.status
|
|
44
|
+
@description = foggy.description
|
|
45
|
+
@availability_zone = foggy.availability_zone
|
|
46
|
+
@servers = ''
|
|
47
|
+
@@serverous = Servers.new if @@serverous.nil?
|
|
48
|
+
foggy.attachments.each { |x|
|
|
49
|
+
srv = @@serverous.get(x["server_id"].to_s)
|
|
50
|
+
if srv.is_valid? == false
|
|
51
|
+
next
|
|
52
|
+
end
|
|
53
|
+
if @servers.length > 0
|
|
54
|
+
@servers += ','
|
|
55
|
+
end
|
|
56
|
+
@servers += srv.name
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def save
|
|
61
|
+
return false if is_valid? == false
|
|
62
|
+
if @fog.nil?
|
|
63
|
+
hsh = {:name => @name,
|
|
64
|
+
:description => @description,
|
|
65
|
+
:size => @size}
|
|
66
|
+
hsh[:snapshot_id] = @snapshot_id unless @snapshot_id.nil?
|
|
67
|
+
hsh[:image_id] = @imageref unless @imageref.nil?
|
|
68
|
+
hsh[:availability_zone] = @availability_zone unless @availability_zone.nil?
|
|
69
|
+
volume = @connection.block.volumes.create(hsh)
|
|
70
|
+
if volume.nil?
|
|
71
|
+
set_error("Error creating volume '#{@name}'")
|
|
72
|
+
return false
|
|
73
|
+
end
|
|
74
|
+
@id = volume.id
|
|
75
|
+
@fog = volume
|
|
76
|
+
return true
|
|
77
|
+
else
|
|
78
|
+
raise "Update not implemented"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def attach(server, device)
|
|
83
|
+
begin
|
|
84
|
+
@fog.attach(server.id, device)
|
|
85
|
+
rescue Exception => e
|
|
86
|
+
set_error("Error attaching '#{name}' on server '#{server.name}' to device '#{device}'.")
|
|
87
|
+
return false
|
|
88
|
+
end
|
|
89
|
+
return true
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def detach()
|
|
93
|
+
begin
|
|
94
|
+
@fog.detach
|
|
95
|
+
rescue Exception => e
|
|
96
|
+
set_error("Error detaching '#{name}' from '#{@servers}'.")
|
|
97
|
+
return false
|
|
98
|
+
end
|
|
99
|
+
return true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def self.clear_cache
|
|
103
|
+
@@serverous = nil
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def map_device(device)
|
|
107
|
+
begin
|
|
108
|
+
return "/dev/vda" if device == "0"
|
|
109
|
+
i = device.to_i
|
|
110
|
+
return device if i < 1 || i > 26
|
|
111
|
+
i = i + 96
|
|
112
|
+
return "/dev/vd" + i.chr
|
|
113
|
+
rescue Exception => e
|
|
114
|
+
end
|
|
115
|
+
return device
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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/volume_helper'
|
|
24
|
+
|
|
25
|
+
module HP
|
|
26
|
+
module Cloud
|
|
27
|
+
class Volumes < FogCollection
|
|
28
|
+
def initialize
|
|
29
|
+
super("volume")
|
|
30
|
+
@items = @connection.block.volumes
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create(item = nil)
|
|
34
|
+
return VolumeHelper.new(@connection, item)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|