mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|network] Add models for subnets, along with tests.
This commit is contained in:
parent
256d48ef30
commit
b282f5d5a0
5 changed files with 138 additions and 0 deletions
49
lib/fog/hp/models/network/subnet.rb
Normal file
49
lib/fog/hp/models/network/subnet.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Subnet < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :network_id
|
||||
attribute :cidr
|
||||
attribute :ip_version
|
||||
attribute :tenant_id
|
||||
attribute :dns_nameservers
|
||||
attribute :allocation_pools
|
||||
attribute :host_routes
|
||||
attribute :gateway_ip
|
||||
attribute :enable_dhcp
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_subnet(id)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
requires :network_id, :cidr, :ip_version
|
||||
identity ? update : create
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create
|
||||
requires :network_id, :cidr, :ip_version
|
||||
merge_attributes(service.create_subnet(network_id, cidr, ip_version, attributes).body['subnet'])
|
||||
true
|
||||
end
|
||||
|
||||
def update
|
||||
requires :id
|
||||
merge_attributes(service.update_subnet(id, attributes).body['subnet'])
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
35
lib/fog/hp/models/network/subnets.rb
Normal file
35
lib/fog/hp/models/network/subnets.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/hp/models/network/subnet'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class Network
|
||||
|
||||
class Subnets < Fog::Collection
|
||||
|
||||
attribute :filters
|
||||
|
||||
model Fog::HP::Network::Subnet
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
def all(filters = filters)
|
||||
self.filters = filters
|
||||
load(service.list_subnets(filters).body['subnets'])
|
||||
end
|
||||
|
||||
def get(subnet_id)
|
||||
if subnet = service.get_subnet(subnet_id).body['subnet']
|
||||
new(subnet)
|
||||
end
|
||||
rescue Fog::HP::Network::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,6 +14,8 @@ module Fog
|
|||
model_path 'fog/hp/models/network'
|
||||
model :network
|
||||
collection :networks
|
||||
model :subnet
|
||||
collection :subnets
|
||||
|
||||
request_path 'fog/hp/requests/network'
|
||||
request :add_router_interface
|
||||
|
|
30
tests/hp/models/network/subnet_tests.rb
Normal file
30
tests/hp/models/network/subnet_tests.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
Shindo.tests('HP::Network | networking subnet model', ['hp', 'networking', 'subnet']) do
|
||||
|
||||
@network = HP[:network].networks.create(:name => 'my_network')
|
||||
|
||||
attributes = {:name => 'fogsubnet', :network_id => @network.id, :cidr => '11.11.11.11/11', :ip_version => 4}
|
||||
model_tests(HP[:network].subnets, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#create').succeeds do
|
||||
attributes = {:name => 'my_subnet', :network_id => @network.id, :cidr => '12.12.12.12/12', :ip_version => 4}
|
||||
@subnet = HP[:network].subnets.create(attributes)
|
||||
@subnet.wait_for { ready? } unless Fog.mocking?
|
||||
!@subnet.id.nil?
|
||||
end
|
||||
|
||||
tests('#save').succeeds do
|
||||
@subnet.name = 'my_subnet_upd'
|
||||
@subnet.save
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@subnet.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@network.destroy
|
||||
|
||||
end
|
22
tests/hp/models/network/subnets_tests.rb
Normal file
22
tests/hp/models/network/subnets_tests.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
Shindo.tests('HP::Network | networking subnets model', ['hp', 'networking', 'subnet']) do
|
||||
|
||||
@network = HP[:network].networks.create(:name => 'my_network')
|
||||
|
||||
attributes = {:name => 'my_subnet', :network_id => @network.id, :cidr => '11.11.11.11/11', :ip_version => 4}
|
||||
collection_tests(HP[:network].subnets, attributes, true)
|
||||
|
||||
tests('success') do
|
||||
|
||||
attributes = {:name => 'fogsubnet', :network_id => @network.id, :cidr => '12.12.12.12/12', :ip_version => 4}
|
||||
@subnet = HP[:network].subnets.create(attributes)
|
||||
|
||||
tests('#all(filter)').succeeds do
|
||||
subnets = HP[:network].subnets.all({:cidr => '12.12.12.12/12'})
|
||||
subnets.first.cidr == '12.12.12.12/12'
|
||||
end
|
||||
|
||||
@subnet.destroy
|
||||
end
|
||||
|
||||
@network.destroy
|
||||
end
|
Loading…
Reference in a new issue