mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[clodo|compute] Add ip-address management.
This commit is contained in:
parent
065883b066
commit
790454bf54
3 changed files with 129 additions and 0 deletions
49
lib/fog/clodo/requests/compute/add_ip_address.rb
Normal file
49
lib/fog/clodo/requests/compute/add_ip_address.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
|
||||
# Bye new IP-address for specified server
|
||||
# ==== Paramaters
|
||||
# * server_id<~Integer> - Id of server to bye IP for
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>
|
||||
#
|
||||
|
||||
def add_ip_address(server_id)
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'PUT',
|
||||
:path => "servers/#{server_id}/ips"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def add_ip_address(server_id)
|
||||
|
||||
raise Excon::Errors::BadRequest.new(
|
||||
"Invalid image ID"
|
||||
) unless server_id > 0
|
||||
|
||||
data = {
|
||||
'primary_ip' => false,
|
||||
'isp' => false,
|
||||
'ip' => "66.6.#{rand(255)}.#{rand(255)}"
|
||||
}
|
||||
|
||||
raise Excon::Errors::BadRequest unless self.data[:servers][server_id]
|
||||
|
||||
raise Excon::Errors::BadRequest.new "No addresses" unless self.data[:servers][server_id]['addresses']
|
||||
|
||||
self.data[:servers][server_id]['addresses']['public'] << data
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
47
lib/fog/clodo/requests/compute/delete_ip_address.rb
Normal file
47
lib/fog/clodo/requests/compute/delete_ip_address.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
|
||||
# Delete IP-address from specified server
|
||||
# ==== Paramaters
|
||||
# * server_id<~Integer> - Id of server to delete IP from
|
||||
# * ip<~String> - IP-address to delete
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>
|
||||
#
|
||||
|
||||
def delete_ip_address(server_id, ip)
|
||||
data = {'ip' => ip}
|
||||
|
||||
request(
|
||||
:expects => [204],
|
||||
:method => 'DELETE',
|
||||
:path => "servers/#{server_id}/ips",
|
||||
:body => MultiJson.encode(data)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_ip_address(server_id, ip)
|
||||
|
||||
server = self.data[:servers][server_id]
|
||||
|
||||
raise Excon::Errors::BadRequest.new "Server not found" unless server
|
||||
|
||||
pa = server['addresses']['public']
|
||||
|
||||
raise Excon::Errors::BadRequest.new "Address not found" unless pa && pa.reject! {|addr|
|
||||
addr['ip'] == ip
|
||||
}
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/clodo/requests/compute/move_ip_address.rb
Normal file
33
lib/fog/clodo/requests/compute/move_ip_address.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Clodo
|
||||
class Real
|
||||
|
||||
# Move IP-address to specified server.
|
||||
# ==== Paramaters
|
||||
# * server_id<~Integer> - Id of server to move IP to
|
||||
# * ip<~String> - IP-address to move
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>
|
||||
#
|
||||
|
||||
def move_ip(server_id, ip)
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => "servers/#{server_id}/ips/moveip/#{ip}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def move_ip(server_id, ip)
|
||||
response = Excon::Response.new
|
||||
response.status = [200, 203][rand(1)]
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue