зеркало из https://github.com/microsoft/fog.git
Network(s) and Ip(s) models
This commit is contained in:
Родитель
9addf5f9fd
Коммит
7979363d37
|
@ -18,7 +18,8 @@ module Fog
|
|||
@all_request = all_request
|
||||
class_eval <<-EOS, __FILE__, __LINE__
|
||||
def all
|
||||
data = self.class.all_request.call(self).body.links.select do |link|
|
||||
raw_all = self.class.all_request.call(self)
|
||||
data = (raw_all.is_a?(Array) ? raw_all : raw_all.body.links).select do |link|
|
||||
link.type == self.class.vcloud_type
|
||||
end.map { |link| {:href => link.href, :name => link.name } }
|
||||
load(data)
|
||||
|
|
|
@ -31,6 +31,10 @@ module Fog
|
|||
require 'fog/vcloud/terremark/all'
|
||||
require 'fog/vcloud/terremark/ecloud/models/internet_service'
|
||||
require 'fog/vcloud/terremark/ecloud/models/internet_services'
|
||||
require 'fog/vcloud/terremark/ecloud/models/ip'
|
||||
require 'fog/vcloud/terremark/ecloud/models/ips'
|
||||
require 'fog/vcloud/terremark/ecloud/models/network'
|
||||
require 'fog/vcloud/terremark/ecloud/models/networks'
|
||||
require 'fog/vcloud/terremark/ecloud/models/public_ip'
|
||||
require 'fog/vcloud/terremark/ecloud/models/public_ips'
|
||||
require 'fog/vcloud/terremark/ecloud/models/vdc'
|
||||
|
|
|
@ -33,10 +33,15 @@ module Fog
|
|||
raw_results.body.links.detect { |link| link.href.to_s == uri.to_s }
|
||||
end
|
||||
|
||||
def reload
|
||||
super
|
||||
@raw_results = nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def raw_results
|
||||
connection.get_internet_services(self.href)
|
||||
@raw_results ||= connection.get_internet_services(self.href)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
require 'fog/model'
|
||||
|
||||
module Fog
|
||||
module Vcloud
|
||||
module Terremark
|
||||
module Ecloud
|
||||
class Ip < Fog::Vcloud::Model
|
||||
|
||||
identity :name
|
||||
|
||||
attribute :status
|
||||
attribute :server
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module Vcloud
|
||||
module Terremark
|
||||
module Ecloud
|
||||
|
||||
class Ips < Fog::Vcloud::Collection
|
||||
|
||||
model Fog::Vcloud::Terremark::Ecloud::Ip
|
||||
|
||||
undef_method :create
|
||||
|
||||
def all
|
||||
load(connection.get_network_ips(href).body.addresses.
|
||||
map { |address| { :name => address.name, :status => address.status, :server => address.server } })
|
||||
end
|
||||
|
||||
def get_raw(name)
|
||||
raw_results.detect { |address| address.name == name }
|
||||
end
|
||||
|
||||
def reload
|
||||
super
|
||||
@raw_results = nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def raw_results
|
||||
@raw_results ||= connection.get_network_ips(href).body.addresses
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,32 @@
|
|||
require 'fog/model'
|
||||
|
||||
module Fog
|
||||
module Vcloud
|
||||
module Terremark
|
||||
module Ecloud
|
||||
class Network < Fog::Vcloud::Model
|
||||
|
||||
identity :href
|
||||
|
||||
attribute :name
|
||||
attribute :features
|
||||
attribute :configuration
|
||||
attribute :ips_link
|
||||
attribute :type
|
||||
attribute :xmlns
|
||||
|
||||
def ips
|
||||
unless @loaded
|
||||
reload
|
||||
end
|
||||
@ips ||= Fog::Vcloud::Terremark::Ecloud::Ips.
|
||||
new( :connection => connection,
|
||||
:href => ips_link.href )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module Vcloud
|
||||
module Terremark
|
||||
module Ecloud
|
||||
|
||||
module Mock
|
||||
def networks(options = {})
|
||||
@networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
module Real
|
||||
def networks(options = {})
|
||||
@networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
class Networks < Fog::Vcloud::Collection
|
||||
|
||||
undef_method :create
|
||||
|
||||
model Fog::Vcloud::Terremark::Ecloud::Network
|
||||
|
||||
get_request :get_network
|
||||
vcloud_type "application/vnd.vmware.vcloud.network+xml"
|
||||
all_request lambda { |networks| networks.connection.get_vdc(networks.href).body.networks }
|
||||
|
||||
#def all
|
||||
# pp connection.get_vdc(href).body.networks
|
||||
# load(connection.get_vdc(href).body.networks.map { |network| { } } )
|
||||
#end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -27,6 +27,12 @@ module Fog
|
|||
:href => href.to_s.gsub('vdc','extensions/vdc') + "/internetServices" )
|
||||
end
|
||||
|
||||
def networks
|
||||
@networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.
|
||||
new( :connection => connection,
|
||||
:href => href )
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
|
||||
|
||||
describe "Fog::Vcloud::Terremark::Ecloud::Ip", :type => :tmrk_ecloud_model do
|
||||
subject { @vcloud }
|
||||
|
||||
describe :class do
|
||||
subject { Fog::Vcloud::Terremark::Ecloud::Ip }
|
||||
|
||||
it { should have_identity :name }
|
||||
it { should have_only_these_attributes [:name, :status, :server] }
|
||||
end
|
||||
|
||||
context "with no uri" do
|
||||
|
||||
subject { Fog::Vcloud::Terremark::Ecloud::Ip.new() }
|
||||
|
||||
its(:name) { should be_nil }
|
||||
its(:status) { should be_nil }
|
||||
its(:server) { should be_nil }
|
||||
end
|
||||
|
||||
context "as a collection member" do
|
||||
subject { @vcloud.vdcs[0].networks[0].ips[0] }
|
||||
let(:status) { @mock_network[:ips].keys.include?(@vcloud.vdcs[0].networks[0].ips[0].name) ? "Assigned" : nil }
|
||||
let(:server) { @mock_network[:ips][@vcloud.vdcs[0].networks[0].ips[0].name] }
|
||||
|
||||
it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Ip }
|
||||
|
||||
its(:name) { should == IPAddr.new(@mock_network[:name]).to_range.to_a[3].to_s }
|
||||
its(:status) { should == status }
|
||||
its(:server) { should == server }
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
|
||||
|
||||
describe "Fog::Vcloud::Terremark::Ecloud::Ips", :type => :tmrk_ecloud_model do
|
||||
subject { @vcloud }
|
||||
|
||||
it { should_not respond_to :ips }
|
||||
|
||||
describe :class do
|
||||
subject { @vcloud.vdcs[0].networks[0].ips.class }
|
||||
its(:model) { should == Fog::Vcloud::Terremark::Ecloud::Ip }
|
||||
its(:get_request) { should be_nil }
|
||||
its(:all_request) { should be_nil }
|
||||
its(:vcloud_type) { should be_nil }
|
||||
it { should_not respond_to :create }
|
||||
end
|
||||
|
||||
describe :ips do
|
||||
subject { @vcloud.vdcs[0].networks[0].ips }
|
||||
|
||||
it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Ips }
|
||||
|
||||
its(:length) { should == 252 }
|
||||
|
||||
it { should have_members_of_the_right_model }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
|
||||
|
||||
describe "Fog::Vcloud::Terremark::Ecloud::Network", :type => :tmrk_ecloud_model do
|
||||
subject { @vcloud }
|
||||
|
||||
describe :class do
|
||||
subject { Fog::Vcloud::Terremark::Ecloud::Network }
|
||||
|
||||
it { should have_identity :href }
|
||||
it { should have_only_these_attributes [:href, :name, :features, :configuration, :ips_link, :type, :xmlns] }
|
||||
end
|
||||
|
||||
context "with no uri" do
|
||||
|
||||
subject { Fog::Vcloud::Terremark::Ecloud::Network.new() }
|
||||
|
||||
its(:href) { should be_nil }
|
||||
its(:identity) { should be_nil }
|
||||
its(:name) { should be_nil }
|
||||
its(:type) { should be_nil }
|
||||
its(:features) { should be_nil }
|
||||
its(:configuration) { should be_nil }
|
||||
its(:ips_link) { should be_nil }
|
||||
its(:xmlns) { should be_nil }
|
||||
end
|
||||
|
||||
context "as a collection member" do
|
||||
subject { @vcloud.vdcs[0].networks[0] }
|
||||
|
||||
it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Network }
|
||||
|
||||
it_should_behave_like "it has a vcloud v0.8 xmlns"
|
||||
|
||||
its(:href) { should == URI.parse(@mock_network[:href]) }
|
||||
its(:identity) { should == URI.parse(@mock_network[:href]) }
|
||||
its(:name) { should == @mock_network[:name] }
|
||||
its(:type) { should == "application/vnd.vmware.vcloud.network+xml" }
|
||||
|
||||
it { should have(1).features }
|
||||
|
||||
describe :features do
|
||||
let(:feature) { subject.features[0] }
|
||||
specify { feature.should be_an_instance_of Struct::VcloudNetworkFenceMode }
|
||||
specify { feature.mode.should == "isolated" }
|
||||
end
|
||||
|
||||
describe :configurations do
|
||||
let(:configuration) { subject.configuration }
|
||||
specify { configuration.should be_an_instance_of Struct::VcloudNetworkConfiguration }
|
||||
specify { configuration.gateway.should == @mock_network[:gateway] }
|
||||
specify { configuration.netmask.should == @mock_network[:netmask] }
|
||||
specify { configuration.dns.should be_nil }
|
||||
end
|
||||
|
||||
describe :ips_link do
|
||||
let(:ips_link) { subject.ips_link }
|
||||
specify { ips_link.rel.should == "down" }
|
||||
specify { ips_link.href.should == URI.parse(@mock_network[:href] + "/ips") }
|
||||
specify { ips_link.type.should == "application/xml" }
|
||||
specify { ips_link.name.should == "IP Addresses" }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
require File.join(File.dirname(__FILE__),'..','..','..','spec_helper')
|
||||
|
||||
describe "Fog::Vcloud::Terremark::Ecloud::Networks", :type => :tmrk_ecloud_model do
|
||||
subject { @vcloud }
|
||||
|
||||
it { should respond_to :networks }
|
||||
|
||||
describe :class do
|
||||
subject { @vcloud.networks.class }
|
||||
its(:model) { should == Fog::Vcloud::Terremark::Ecloud::Network }
|
||||
its(:get_request) { should == :get_network }
|
||||
its(:all_request) { should be_an_instance_of Proc }
|
||||
its(:vcloud_type) { should == "application/vnd.vmware.vcloud.network+xml" }
|
||||
end
|
||||
|
||||
describe :networks do
|
||||
subject { @vcloud.vdcs[0].networks }
|
||||
|
||||
it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::Networks }
|
||||
|
||||
its(:length) { should == 2 }
|
||||
|
||||
it { should have_members_of_the_right_model }
|
||||
end
|
||||
end
|
||||
|
|
@ -8,8 +8,6 @@ describe "Fog::Vcloud::Terremark::Ecloud::PublicIp", :type => :tmrk_ecloud_model
|
|||
|
||||
subject { @vcloud }
|
||||
|
||||
it { should respond_to :get_public_ip }
|
||||
|
||||
describe :class do
|
||||
subject { Fog::Vcloud::Terremark::Ecloud::PublicIp }
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче