1
0
Fork 0
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:
Rupak Ganguly 2013-03-29 14:37:05 -04:00
parent 256d48ef30
commit b282f5d5a0
5 changed files with 138 additions and 0 deletions

View 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

View 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

View file

@ -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

View 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

View 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