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 network, along with tests.

This commit is contained in:
Rupak Ganguly 2013-03-28 18:13:49 -04:00
parent 8c9a2c7043
commit 9036dd0ef0
5 changed files with 124 additions and 0 deletions

View file

@ -0,0 +1,42 @@
require 'fog/core/model'
module Fog
module HP
class Network
class Network < Fog::Model
identity :id
attribute :name
attribute :tenant_id
attribute :status
attribute :subnets
attribute :shared
attribute :admin_state_up
attribute :router_external, :aliases => 'router:external'
def destroy
requires :id
service.delete_network(id)
true
end
def save
identity ? update : create
end
def create
merge_attributes(service.create_network(attributes).body['network'])
self
end
def update
requires :id
merge_attributes(service.update_network(id, attributes).body['network'])
self
end
end
end
end
end

View file

@ -0,0 +1,35 @@
require 'fog/core/collection'
require 'fog/hp/models/network/network'
module Fog
module HP
class Network
class Networks < Fog::Collection
attribute :filters
model Fog::HP::Network::Network
def initialize(attributes)
self.filters ||= {}
super
end
def all(filters = filters)
self.filters = filters
load(service.list_networks(filters).body['networks'])
end
def get(network_id)
if network = service.get_network(network_id).body['network']
new(network)
end
rescue Fog::HP::Network::NotFound
nil
end
end
end
end
end

View file

@ -11,6 +11,10 @@ module Fog
secrets :hp_secret_key
model_path 'fog/hp/models/network'
model :network
collection :networks
request_path 'fog/hp/requests/network'
request :add_router_interface
request :associate_floating_ip

View file

@ -0,0 +1,25 @@
Shindo.tests('HP::Network | networking network model', ['hp', 'networking', 'network']) do
model_tests(HP[:network].networks, {:name => 'fognetwork'}, true)
tests('success') do
tests('#create').succeeds do
attributes = {:name => 'my_network', :admin_state_up => true, :shared => false}
@network = HP[:network].networks.create(attributes)
@network.wait_for { ready? } unless Fog.mocking?
!@network.id.nil?
end
tests('#update').succeeds do
@network.name = 'my_network_upd'
@network.update
end
tests('#destroy').succeeds do
@network.destroy
end
end
end

View file

@ -0,0 +1,18 @@
Shindo.tests('HP::Network | networking networks model', ['hp', 'networking', 'network']) do
attributes = {:name => 'my_network', :admin_state_up => true, :shared => false}
collection_tests(HP[:network].networks, attributes, true)
@network = HP[:network].networks.create(attributes)
tests('success') do
tests('#all(filter)').succeeds do
networks = HP[:network].networks.all({'router:external'=>true})
networks.first.router_external == true
end
end
@network.destroy
end