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:
parent
b2601eb913
commit
e9a7d8fe80
5 changed files with 72 additions and 0 deletions
|
@ -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
|
||||
|
|
27
lib/fog/rackspace/models/compute_v2/network.rb
Normal file
27
lib/fog/rackspace/models/compute_v2/network.rb
Normal 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
|
23
lib/fog/rackspace/models/compute_v2/networks.rb
Normal file
23
lib/fog/rackspace/models/compute_v2/networks.rb
Normal 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
|
10
tests/rackspace/models/compute_v2/network_tests.rb
Normal file
10
tests/rackspace/models/compute_v2/network_tests.rb
Normal 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
|
10
tests/rackspace/models/compute_v2/networks_tests.rb
Normal file
10
tests/rackspace/models/compute_v2/networks_tests.rb
Normal 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
|
Loading…
Add table
Reference in a new issue