1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|networks] Add networks model and collection.

This commit is contained in:
Brad Gignac 2013-01-31 22:17:51 -05:00
parent b2601eb913
commit e9a7d8fe80
5 changed files with 72 additions and 0 deletions

View file

@ -26,6 +26,8 @@ module Fog
collection :images
model :attachment
collection :attachments
model :network
collection :networks
request_path 'fog/rackspace/requests/compute_v2'
request :list_servers

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class RackspaceV2
class Network < Fog::Model
identity :id
attribute :label
attribute :cidr
def save
requires :label, :cidr
data = service.create_network(label, cidr)
merge_attributes(data.body['network'])
true
end
def destroy
requires :identity
service.delete_network(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/rackspace/models/compute_v2/network'
module Fog
module Compute
class RackspaceV2
class Networks < Fog::Collection
model Fog::Compute::RackspaceV2::Network
def all
data = service.list_networks.body['networks']
load(data)
end
def get(id)
data = service.get_network(id).body['network']
new(data)
rescue Fog::Compute::RackspaceV2::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,10 @@
Shindo.tests('Fog::Compute::RackspaceV2 | network', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
options = {
:label => "fog_network_#{Time.now.to_i.to_s}",
:cidr => '192.168.0.0/24'
}
model_tests(service.networks, options, true)
end

View file

@ -0,0 +1,10 @@
Shindo.tests('Fog::Compute::RackspaceV2 | networks', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
options = {
:label => "fog_network_#{Time.now.to_i.to_s}",
:cidr => '192.168.0.0/24'
}
collection_tests(service.networks, options, true)
end