mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|network] Add the request methods for routers.
This commit is contained in:
parent
8766c7b8f4
commit
e2ae80c867
8 changed files with 409 additions and 8 deletions
|
@ -12,29 +12,35 @@ module Fog
|
|||
secrets :hp_secret_key
|
||||
|
||||
request_path 'fog/hp/requests/network'
|
||||
request :add_router_interface
|
||||
request :associate_floating_ip
|
||||
request :create_floating_ip
|
||||
request :create_port
|
||||
request :create_network
|
||||
request :create_port
|
||||
request :create_router
|
||||
request :create_subnet
|
||||
request :disassociate_floating_ip
|
||||
request :delete_floating_ip
|
||||
request :delete_port
|
||||
request :delete_network
|
||||
request :delete_port
|
||||
request :delete_router
|
||||
request :delete_subnet
|
||||
request :get_floating_ip
|
||||
request :get_port
|
||||
request :get_network
|
||||
request :get_port
|
||||
request :get_router
|
||||
request :get_subnet
|
||||
request :list_floating_ips
|
||||
request :list_ports
|
||||
request :list_networks
|
||||
request :list_ports
|
||||
request :list_routers
|
||||
request :list_subnets
|
||||
request :update_port
|
||||
request :remove_router_interface
|
||||
request :update_network
|
||||
request :update_port
|
||||
request :update_router
|
||||
request :update_subnet
|
||||
|
||||
|
||||
module Utils
|
||||
|
||||
end
|
||||
|
@ -45,10 +51,11 @@ module Fog
|
|||
def self.data
|
||||
@data ||= Hash.new do |hash, key|
|
||||
hash[key] = {
|
||||
:floating_ips => {},
|
||||
:networks => {},
|
||||
:subnets => {},
|
||||
:ports => {},
|
||||
:floating_ips => {}
|
||||
:routers => {},
|
||||
:subnets => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
75
lib/fog/hp/requests/network/add_router_interface.rb
Normal file
75
lib/fog/hp/requests/network/add_router_interface.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Add an internal router interface, thus attaching a subnet or a port to an existing router
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'router_id'<~String>: - UUId for the router
|
||||
# * 'subnet_id'<~String>: - UUId for the subnet (Either a subnet or a port can be passed, not both)
|
||||
# * 'port_id'<~String>: - UUId for the port (Either a subnet or a port can be passed, not both)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'subnet_id'<~String>: - UUId for the subnet
|
||||
# * 'port_id'<~String>: - UUId for the port
|
||||
def add_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
|
||||
# Either a subnet or a port can be passed, not both
|
||||
if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?)
|
||||
raise ArgumentError.new('Either a subnet or a port can be passed, not both')
|
||||
end
|
||||
if subnet_id
|
||||
data = { 'subnet_id' => subnet_id }
|
||||
elsif port_id
|
||||
data = { 'port_id' => port_id }
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}/add_router_interface"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def add_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
|
||||
response = Excon::Response.new
|
||||
if list_routers.body['routers'].detect {|_| _['id'] == router_id}
|
||||
# Either a subnet or a port can be passed, not both
|
||||
if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?)
|
||||
raise ArgumentError.new('Either a subnet or a port can be passed, not both')
|
||||
end
|
||||
|
||||
if port_id.nil?
|
||||
# create a new port
|
||||
resp = create_port(Fog::HP::Mock.uuid.to_s, {:name => "New Port #{rand(10)}"})
|
||||
port_id = resp.body['port']['id']
|
||||
end
|
||||
|
||||
data = {
|
||||
'subnet_id' => subnet_id || Fog::HP::Mock.uuid.to_s,
|
||||
'port_id' => port_id
|
||||
}
|
||||
|
||||
# so either way if I pass a subnet or a port,
|
||||
# it basically adds the router uuid to the port's device_id
|
||||
# and sets device_owner to network:router_interface
|
||||
self.data[:ports][port_id]['device_id'] = router_id
|
||||
self.data[:ports][port_id]['device_owner'] = 'network:router_interface'
|
||||
|
||||
response.status = 200
|
||||
response.body = data
|
||||
response
|
||||
else
|
||||
raise Fog::HP::Network::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/hp/requests/network/create_router.rb
Normal file
64
lib/fog/hp/requests/network/create_router.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Create a new router
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of the router
|
||||
# * 'admin_state_up'<~Boolean> - The administrative state of the router, true or false
|
||||
# * 'tenant_id'<~String> - TenantId different than the current user, that should own the network. Only allowed if user has 'admin' role.
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * router<~Array>:
|
||||
# * 'id'<~String>: - UUId for the router
|
||||
# * 'name'<~String>: - Name of the router
|
||||
# * 'tenant_id'<~String>: - TenantId that owns the router
|
||||
# * 'status'<~String>: - Status of the router i.e. ACTIVE
|
||||
# * 'admin_state_up'<~Boolean>: - true or false
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
def create_router(options = {})
|
||||
data = { 'router' => {} }
|
||||
|
||||
l_options = [:name, :admin_state_up, :tenant_id, :external_gateway_info]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 201,
|
||||
:method => 'POST',
|
||||
:path => 'routers'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_router(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
data = {
|
||||
'id' => Fog::HP::Mock.uuid.to_s,
|
||||
'name' => options[:name] || "",
|
||||
'status' => 'ACTIVE',
|
||||
'external_gateway_info' => options[:external_gateway_info] || nil,
|
||||
'admin_state_up' => options[:admin_state_up] || true,
|
||||
'tenant_id' => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s
|
||||
}
|
||||
self.data[:routers][data['id']] = data
|
||||
response.body = { 'router' => data }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/hp/requests/network/delete_router.rb
Normal file
34
lib/fog/hp/requests/network/delete_router.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Delete an existing router
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'router_id'<~String> - UUId for the router to delete
|
||||
def delete_router(router_id)
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "routers/#{router_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_router(router_id)
|
||||
response = Excon::Response.new
|
||||
if list_routers.body['routers'].detect {|_| _['id'] == router_id}
|
||||
self.data[:routers].delete(router_id)
|
||||
response.status = 204
|
||||
response
|
||||
else
|
||||
raise Fog::HP::Network::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
46
lib/fog/hp/requests/network/get_router.rb
Normal file
46
lib/fog/hp/requests/network/get_router.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Get details for an existing router by id
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'router_id'<~String>: - UUId for the router to get details for
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * router<~Array>:
|
||||
# * 'id'<~String>: - UUId for the router
|
||||
# * 'name'<~String>: - Name of the router
|
||||
# * 'tenant_id'<~String>: - TenantId that owns the router
|
||||
# * 'status'<~String>: - Status of the router i.e. ACTIVE
|
||||
# * 'admin_state_up'<~Boolean>: - true or false
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
def get_router(router_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "routers/#{router_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_router(router_id)
|
||||
response = Excon::Response.new
|
||||
if router = list_routers.body['routers'].detect {|_| _['id'] == router_id}
|
||||
response.status = 200
|
||||
response.body = { 'router' => router }
|
||||
response
|
||||
else
|
||||
raise Fog::HP::Network::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
45
lib/fog/hp/requests/network/list_routers.rb
Normal file
45
lib/fog/hp/requests/network/list_routers.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# List existing routers
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash>:
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * routers<~Array>:
|
||||
# * 'id'<~String>: - UUId for the router
|
||||
# * 'name'<~String>: - Name of the router
|
||||
# * 'tenant_id'<~String>: - TenantId that owns the router
|
||||
# * 'status'<~String>: - Status of the router i.e. ACTIVE
|
||||
# * 'admin_state_up'<~Boolean>: - true or false
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
def list_routers(options = {})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'routers',
|
||||
:query => options
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_routers(options = {})
|
||||
response = Excon::Response.new
|
||||
|
||||
routers = self.data[:routers].values
|
||||
response.status = 200
|
||||
response.body = { 'routers' => routers }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
68
lib/fog/hp/requests/network/remove_router_interface.rb
Normal file
68
lib/fog/hp/requests/network/remove_router_interface.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Remove an internal router interface, thus detaching a subnet or a port from an existing router
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'router_id'<~String>: - UUId for the router
|
||||
# * 'subnet_id'<~String>: - UUId for the subnet (Either a subnet or a port can be passed, not both)
|
||||
# * 'port_id'<~String>: - UUId for the port (Either a subnet or a port can be passed, not both)
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'subnet_id'<~String>: - UUId for the subnet
|
||||
# * 'port_id'<~String>: - UUId for the port
|
||||
def remove_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
|
||||
# Either a subnet or a port can be passed, not both
|
||||
if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?)
|
||||
raise ArgumentError.new('Either a subnet or a port can be passed, not both')
|
||||
end
|
||||
if subnet_id
|
||||
data = { 'subnet_id' => subnet_id }
|
||||
elsif port_id
|
||||
data = { 'port_id' => port_id }
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}/remove_router_interface"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def remove_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
|
||||
response = Excon::Response.new
|
||||
if list_routers.body['routers'].detect {|_| _['id'] == router_id}
|
||||
# Either a subnet or a port can be passed, not both
|
||||
if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?)
|
||||
raise ArgumentError.new('Either a subnet or a port can be passed, not both')
|
||||
end
|
||||
|
||||
# set the device_id and device_owner back to ""
|
||||
if port_id
|
||||
self.data[:ports][port_id]['device_id'] = ""
|
||||
self.data[:ports][port_id]['device_owner'] = ""
|
||||
elsif subnet_id
|
||||
ports = self.data[:ports].select {|p| self.data[:ports]["#{p}"]['device_id'] == router_id}
|
||||
ports.each do |key, _|
|
||||
self.data[:ports][key]['device_id'] = ""
|
||||
self.data[:ports][key]['device_owner'] = ""
|
||||
end
|
||||
end
|
||||
response.status = 200
|
||||
response
|
||||
else
|
||||
raise Fog::HP::Network::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
62
lib/fog/hp/requests/network/update_router.rb
Normal file
62
lib/fog/hp/requests/network/update_router.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Real
|
||||
# Update an existing router by id
|
||||
#
|
||||
# ==== Parameters
|
||||
# * 'router_id'<~String>: - UUId for the router
|
||||
# * options<~Hash>:
|
||||
# * 'name'<~String> - Name of the router
|
||||
# * 'admin_state_up'<~Boolean> - The administrative state of the router, true or false
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * router<~Array>:
|
||||
# * 'id'<~String>: - UUId for the router
|
||||
# * 'name'<~String>: - Name of the router
|
||||
# * 'tenant_id'<~String>: - TenantId that owns the router
|
||||
# * 'status'<~String>: - Status of the router i.e. ACTIVE
|
||||
# * 'admin_state_up'<~Boolean>: - true or false
|
||||
# * 'external_gateway_info'<~Hash>: - External gateway info.
|
||||
# * 'network_id'<~String>: - UUId of the external network
|
||||
def update_router(router_id, options = {})
|
||||
data = { 'router' => {} }
|
||||
|
||||
l_options = [:name, :admin_state_up, :external_gateway_info]
|
||||
l_options.select{|o| options[o]}.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_router(router_id, options = {})
|
||||
response = Excon::Response.new
|
||||
if router = list_routers.body['routers'].detect {|_| _['id'] == router_id}
|
||||
router['name'] = options[:name]
|
||||
router['admin_state_up'] = options[:admin_state_up]
|
||||
router['external_gateway_info'] = options[:external_gateway_info]
|
||||
response.body = { 'router' => router }
|
||||
response.status = 200
|
||||
response
|
||||
else
|
||||
raise Fog::HP::Network::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue