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

deleted old files eg. floatingip.rb

This commit is contained in:
kanetann 2012-12-25 10:42:22 +09:00
parent 9ebd161e03
commit a7df32a8cd
11 changed files with 0 additions and 449 deletions

View file

@ -1,52 +0,0 @@
require 'fog/core/model'
module Fog
module Network
class OpenStack
class Floatingip < Fog::Model
identity :id
attribute :floating_network_id
attribute :port_id
attribute :tenant_id
attribute :fixed_ip_address
def initialize(attributes)
@connection = attributes[:connection]
super
end
def save
requires :floating_network_id
identity ? update : create
end
def create
requires :floating_network_id
merge_attributes(connection.create_floatingip(self.floating_network_id,
self.attributes).body['floatingip'])
self
end
def update
self
end
def destroy
requires :id
connection.delete_floatingip(self.id)
true
end
end
end
end
end

View file

@ -1,34 +0,0 @@
require 'fog/core/collection'
require 'fog/openstack/models/network/floatingip'
module Fog
module Network
class OpenStack
class Floatingips < Fog::Collection
attribute :filters
model Fog::Network::OpenStack::Floatingip
def initialize(attributes)
self.filters ||= {}
super
end
def all(filters = filters)
self.filters = filters
load(connection.list_floatingips(filters).body['floatingips'])
end
def get(floating_network_id)
if floatingip = connection.get_floatingip(floating_network_id).body['floatingip']
new(floatingip)
end
rescue Fog::Network::OpenStack::NotFound
nil
end
end
end
end
end

View file

@ -1,49 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def associate_floatingip(floatingip_id, port_id, options = {})
data = {
'floatingip' => {
'port_id' => port_id,
}
}
vanilla_options = [:fixed_ip_address]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['floatingip'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [200],
:method => 'PUT',
:path => "floatingips/#{floatingip_id}"
)
end
end
class Mock
def associate_floatingip(floatingip_id, port_id, options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => '00000000-0000-0000-0000-000000000000',
'router_id' => '00000000-0000-0000-0000-000000000000',
'tenant_id' => options["tenant_id"],
'floating_network_id' => options["floating_network_id"],
'fixed_ip_address' => options["fixed_ip_address"],
'floating_ip_address' => options["floating_ip_address"],
'port_id' => port_id,
}
self.data[:floatingips][data['floatingip_id']] = data
response.body = { 'floatingip' => data }
response
end
end
end
end
end

View file

@ -1,50 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def create_floatingip(floating_network_id, options = {})
data = {
'floatingip' => {
'floating_network_id' => floating_network_id,
'port_id' => options[:port_id],
'tenant_id' => options[:tenant_id],
'fixed_ip_address' => options[:fixed_ip_address],
}
}
vanilla_options = [:port_id, :tenant_id, :fixed_ip_address ]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['floatingip'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [201],
:method => 'POST',
:path => 'floatingips'
)
end
end
class Mock
def create_floatingip(floating_network_id, options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => floating_network_id,
'floating_network_id' => floating_network_id,
'port_id' => options[:port_id],
'tenant_id' => options[:tenant_id],
'fixed_ip_address' => options[:fixed_ip_address],
'router_id' => nil,
}
self.data[:floatingips][data['id']] = data
response.body = { 'floatingip' => data }
response
end
end
end
end
end

View file

@ -1,30 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def delete_floatingip(floating_network_id)
request(
:expects => 204,
:method => 'DELETE',
:path => "floatingips/#{floating_network_id}"
)
end
end
class Mock
def delete_floatingip(floating_network_id)
response = Excon::Response.new
if list_floatingips.body['floatingips'].map { |r| r['id'] }.include? floating_network_id
self.data[:floatingips].delete(floating_network_id)
response.status = 204
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -1,49 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def disassociate_floatingip(floatingip_id, options = {})
data = {
'floatingip' => {
'port_id' => nil,
}
}
vanilla_options = [:fixed_ip_address]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['floatingip'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [200],
:method => 'PUT',
:path => "floatingips/#{floatingip_id}"
)
end
end
class Mock
def disassociate_floatingip(floatingip_id, options = {})
response = Excon::Response.new
response.status = 200
data = {
'id' => '00000000-0000-0000-0000-000000000000',
'router_id' => nil,
'tenant_id' => options["tenant_id"],
'floating_network_id' => options["floating_network_id"],
'fixed_ip_address' => nil,
'floating_ip_address' => options["floating_ip_address"],
'port_id' => options["port_id"],
}
self.data[:floatingips][data['floatingip_id']] = data
response.body = { 'floatingip' => data }
response
end
end
end
end
end

View file

@ -1,41 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def get_floatingip(floating_network_id)
request(
:expects => [200],
:method => 'GET',
:path => "floatingips/#{floating_network_id}"
)
end
end
class Mock
def get_floatingip(floating_network_id)
response = Excon::Response.new
if data = self.data[:floatingips][floating_network_id]
response.status = 200
response.body = {
"floatingip" => {
"id" => "00000000-0000-0000-0000-000000000000",
"floating_network_id" => floating_network_id,
"port_id" => data["port_id"],
"tenant_id" => data["tenant_id"],
"fixed_ip_address" => data["fixed_ip_address"],
"router_id" => "00000000-0000-0000-0000-000000000000",
"floating_ip_address" => data["floating_ip_address"],
}
}
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -1,27 +0,0 @@
module Fog
module Network
class OpenStack
class Real
def list_floatingips(filters = {})
request(
:expects => 200,
:method => 'GET',
:path => 'floatingips',
:query => filters
)
end
end
class Mock
def list_floatingips(filters = {})
Excon::Response.new(
:body => { 'floatingips' => self.data[:floatingips].values },
:status => 200
)
end
end
end
end
end

View file

@ -1,30 +0,0 @@
Shindo.tests("Fog::Network[:openstack] | floatingip", ['openstack']) do
tests('success') do
tests('#create').succeeds do
@instance = Fog::Network[:openstack].floatingips.create(:floating_network_id => 'f0000000-0000-0000-0000-000000000000')
!@instance.id.nil?
end
tests('#update').succeeds do
@instance.port_id = 'p0000000-0000-0000-0000-000000000000'
@instance.update
end
tests('#destroy').succeeds do
@instance.destroy == true
end
end
end

View file

@ -1,27 +0,0 @@
Shindo.tests("Fog::Network[:openstack] | floatingips", ['openstack']) do
@floatingip = Fog::Network[:openstack].floatingips.create(:floating_network_id => 'f0000000-0000-0000-0000-000000000000')
@floatingips = Fog::Network[:openstack].floatingips
tests('success') do
tests('#all').succeeds do
@floatingips.all
end
tests('#get').succeeds do
@floatingips.get @floatingip.id
end
end
@floatingip.destroy
end

View file

@ -1,60 +0,0 @@
Shindo.tests('Fog::Network[:openstack] | floating_ip requests', ['openstack']) do
@floating_ip_format = {
'id' => String,
'floating_network_id' => Fog::Nullable::String,
'port_id' => Fog::Nullable::String,
'tenant_id' => Fog::Nullable::String,
'fixed_ip_address' => Fog::Nullable::String,
'router_id' => Fog::Nullable::String,
'floating_ip_address' => Fog::Nullable::String,
}
tests('success') do
tests('#create_floating_ip').formats({'floating_ip' => @floating_ip_format}) do
floating_network_id = 'f0000000-0000-0000-0000-000000000000'
attributes = {:port_id => 'p0000000-0000-0000-0000-000000000000',
:tenant_id => 't0000000-0000-0000-0000-000000000000',
:fixed_ip_address => '192.168.0.1' }
Fog::Network[:openstack].create_floating_ip(floating_network_id, attributes).body
end
tests('#list_floating_ip').formats({'floating_ips' => [@floating_ip_format]}) do
Fog::Network[:openstack].list_floating_ips.body
end
tests('#get_floating_ip').formats({'floating_ip' => @floating_ip_format}) do
floating_ip_id = Fog::Network[:openstack].floating_ips.all.first.id
Fog::Network[:openstack].get_floating_ip(floating_ip_id).body
end
tests('#associate_floating_ip').succeeds do
floating_ip_id = Fog::Network[:openstack].floating_ips.all.first.id
port_id = 'p00000000-0000-0000-0000-000000000000'
Fog::Network[:openstack].associate_floating_ip(floating_ip_id, port_id).body
end
tests('#disassociate_floating_ip').succeeds do
floating_ip_id = Fog::Network[:openstack].floating_ips.all.first.id
Fog::Network[:openstack].disassociate_floating_ip(floating_ip_id).body
end
tests('#delete_floating_ip').succeeds do
floating_ip_id = Fog::Network[:openstack].floating_ips.all.first.id
Fog::Network[:openstack].delete_floating_ip(floating_ip_id).body
end
end
tests('failure') do
tests('#get_floating_ip').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].get_floating_ip(0)
end
tests('#delete_floating_ip').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].delete_floating_ip(0)
end
end
end