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

Merge pull request #1164 from frodenas/openstack-quantum

[openstack|network] Add support for OpenStack Quantum
This commit is contained in:
Nelvin Driz 2012-10-04 19:54:17 -07:00
commit cae2af0806
36 changed files with 1474 additions and 0 deletions

View file

@ -18,4 +18,5 @@ require 'fog/image'
require 'fog/volume'
require 'fog/cdn'
require 'fog/dns'
require 'fog/network'
require 'fog/storage'

View file

@ -7,6 +7,8 @@ class OpenStack < Fog::Bin
Fog::Compute::OpenStack
when :identity
Fog::Identity::OpenStack
when :network
Fog::Network::OpenStack
else
raise ArgumentError, "Unrecognized service: #{key}"
end
@ -21,6 +23,9 @@ class OpenStack < Fog::Bin
when :identity
Fog::Logger.warning("OpenStack[:identity] is not recommended, use Compute[:openstack] for portability")
Fog::Compute.new(:provider => 'OpenStack')
when :network
Fog::Logger.warning("OpenStack[:network] is not recommended, use Network[:openstack] for portability")
Fog::Network.new(:provider => 'OpenStack')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end

26
lib/fog/network.rb Normal file
View file

@ -0,0 +1,26 @@
module Fog
module Network
def self.[](provider)
self.new(:provider => provider)
end
def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
case provider
when :openstack
require 'fog/openstack/network'
Fog::Network::OpenStack.new(attributes)
else
raise ArgumentError.new("#{provider} has no network service")
end
end
def self.providers
Fog.services[:network]
end
end
end

View file

@ -43,6 +43,7 @@ module Fog
service(:compute , 'openstack/compute' , 'Compute' )
service(:identity, 'openstack/identity', 'Identity')
service(:network, 'openstack/network', 'Network')
# legacy v1.0 style auth
def self.authenticate_v1(options, connection_options = {})

View file

@ -0,0 +1,46 @@
require 'fog/core/model'
module Fog
module Network
class OpenStack
class Network < Fog::Model
identity :id
attribute :name
attribute :subnets
attribute :shared
attribute :status
attribute :admin_state_up
attribute :tenant_id
def initialize(attributes)
@connection = attributes[:connection]
super
end
def save
identity ? update : create
end
def create
merge_attributes(connection.create_network(self.attributes).body['network'])
self
end
def update
requires :id
merge_attributes(connection.update_network(self.id,
self.attributes).body['network'])
self
end
def destroy
requires :id
connection.delete_network(self.id)
true
end
end
end
end
end

View file

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

View file

@ -0,0 +1,52 @@
require 'fog/core/model'
module Fog
module Network
class OpenStack
class Port < Fog::Model
identity :id
attribute :name
attribute :network_id
attribute :fixed_ips
attribute :mac_address
attribute :status
attribute :admin_state_up
attribute :device_owner
attribute :device_id
attribute :tenant_id
def initialize(attributes)
@connection = attributes[:connection]
super
end
def save
requires :network_id
identity ? update : create
end
def create
requires :network_id
merge_attributes(connection.create_port(self.network_id,
self.attributes).body['port'])
self
end
def update
requires :id, :network_id
merge_attributes(connection.update_port(self.id,
self.attributes).body['port'])
self
end
def destroy
requires :id
connection.delete_port(self.id)
true
end
end
end
end
end

View file

@ -0,0 +1,34 @@
require 'fog/core/collection'
require 'fog/openstack/models/network/port'
module Fog
module Network
class OpenStack
class Ports < Fog::Collection
attribute :filters
model Fog::Network::OpenStack::Port
def initialize(attributes)
self.filters ||= {}
super
end
def all(filters = filters)
self.filters = filters
load(connection.list_ports(filters).body['ports'])
end
def get(port_id)
if port = connection.get_port(port_id).body['port']
new(port)
end
rescue Fog::Network::OpenStack::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,55 @@
require 'fog/core/model'
module Fog
module Network
class OpenStack
class Subnet < Fog::Model
identity :id
attribute :name
attribute :network_id
attribute :cidr
attribute :ip_version
attribute :gateway_ip
attribute :allocation_pools
attribute :dns_nameservers
attribute :host_routes
attribute :enable_dhcp
attribute :tenant_id
def initialize(attributes)
@connection = attributes[:connection]
super
end
def save
requires :network_id, :cidr, :ip_version
identity ? update : create
end
def create
requires :network_id, :cidr, :ip_version
merge_attributes(connection.create_subnet(self.network_id,
self.cidr,
self.ip_version,
self.attributes).body['subnet'])
self
end
def update
requires :id, :network_id, :cidr, :ip_version
merge_attributes(connection.update_subnet(self.id,
self.attributes).body['subnet'])
self
end
def destroy
requires :id
connection.delete_subnet(self.id)
true
end
end
end
end
end

View file

@ -0,0 +1,34 @@
require 'fog/core/collection'
require 'fog/openstack/models/network/subnet'
module Fog
module Network
class OpenStack
class Subnets < Fog::Collection
attribute :filters
model Fog::Network::OpenStack::Subnet
def initialize(attributes)
self.filters ||= {}
super
end
def all(filters = filters)
self.filters = filters
load(connection.list_subnets(filters).body['subnets'])
end
def get(subnet_id)
if subnet = connection.get_subnet(subnet_id).body['subnet']
new(subnet)
end
rescue Fog::Network::OpenStack::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,234 @@
require 'fog/openstack'
module Fog
module Network
class OpenStack < Fog::Service
requires :openstack_auth_url
recognizes :openstack_auth_token, :openstack_management_url, :persistent,
:openstack_service_name, :openstack_tenant,
:openstack_api_key, :openstack_username,
:current_user, :current_tenant
## MODELS
#
model_path 'fog/openstack/models/network'
model :network
collection :networks
model :port
collection :ports
model :subnet
collection :subnets
## REQUESTS
#
request_path 'fog/openstack/requests/network'
# Network CRUD
request :list_networks
request :create_network
request :delete_network
request :get_network
request :update_network
# Port CRUD
request :list_ports
request :create_port
request :delete_port
request :get_port
request :update_port
# Subnet CRUD
request :list_subnets
request :create_subnet
request :delete_subnet
request :get_subnet
request :update_subnet
# Tenant
request :set_tenant
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:networks => {},
:ports => {},
:subnets => {},
}
end
end
def self.reset
@data = nil
end
def initialize(options={})
@openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant]
end
def data
self.class.data["#{@openstack_username}-#{@openstack_tenant}"]
end
def reset_data
self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}")
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url }
end
end
class Real
attr_reader :current_user
attr_reader :current_tenant
def initialize(options={})
require 'multi_json'
@openstack_auth_token = options[:openstack_auth_token]
unless @openstack_auth_token
missing_credentials = Array.new
@openstack_api_key = options[:openstack_api_key]
@openstack_username = options[:openstack_username]
missing_credentials << :openstack_api_key unless @openstack_api_key
missing_credentials << :openstack_username unless @openstack_username
raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
end
@openstack_tenant = options[:openstack_tenant]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@openstack_management_url = options[:openstack_management_url]
@openstack_must_reauthenticate = false
@openstack_service_name = options[:openstack_service_name] || ['network']
@connection_options = options[:connection_options] || {}
@current_user = options[:current_user]
@current_tenant = options[:current_tenant]
authenticate
@persistent = options[:persistent] || false
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:current_user => @current_user,
:current_tenant => @current_tenant }
end
def reload
@connection.reset
end
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"#,
# Causes errors for some requests like tenants?limit=1
# :query => ('ignore_awful_caching' << Time.now.to_i.to_s)
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password' # token expiration
@openstack_must_reauthenticate = true
authenticate
retry
else # bad credentials
raise error
end
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Network::OpenStack::NotFound.slurp(error)
else
error
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
end
response
end
private
def authenticate
if @openstack_must_reauthenticate || @openstack_auth_token.nil?
options = {
:openstack_tenant => @openstack_tenant,
:openstack_api_key => @openstack_api_key,
:openstack_username => @openstack_username,
:openstack_auth_uri => @openstack_auth_uri,
:openstack_auth_token => @openstack_auth_token,
:openstack_service_name => @openstack_service_name,
:openstack_endpoint_type => 'adminURL'
}
credentials = Fog::OpenStack.authenticate_v2(options, @connection_options)
@current_user = credentials[:user]
@current_tenant = credentials[:tenant]
@openstack_must_reauthenticate = false
@auth_token = credentials[:token]
@openstack_management_url = credentials[:server_management_url]
uri = URI.parse(@openstack_management_url)
else
@auth_token = @openstack_auth_token
uri = URI.parse(@openstack_management_url)
end
@host = uri.host
@path = uri.path
@path.sub!(/\/$/, '')
unless @path.match(/^\/v(\d)+(\.)?(\d)*$/)
@path = "/" + retrieve_current_version(uri)
end
@port = uri.port
@scheme = uri.scheme
true
end
def retrieve_current_version(uri)
response = Fog::Connection.new(
"#{uri.scheme}://#{uri.host}:#{uri.port}", false, @connection_options).request({
:expects => [200, 204],
:headers => {'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token},
:host => uri.host,
:method => 'GET'
})
body = Fog::JSON.decode(response.body)
version = nil
unless body['versions'].empty?
current_version = body['versions'].detect { |x| x["status"] == "CURRENT" }
version = current_version["id"]
end
raise Errors::NotFound.new('No API versions found') if version.nil?
version
end
end
end
end
end

View file

@ -0,0 +1,44 @@
module Fog
module Network
class OpenStack
class Real
def create_network(options = {})
data = { 'network' => {} }
vanilla_options = [:name, :shared, :admin_state_up, :tenant_id]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['network'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [201],
:method => 'POST',
:path => 'networks'
)
end
end
class Mock
def create_network(options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => Fog::Mock.random_numbers(6).to_s,
'name' => options[:name],
'shared' => options[:shared],
'subnets' => [],
'status' => 'ACTIVE',
'admin_state_up' => options[:admin_state_up],
'tenant_id' => options[:tenant_id],
}
self.data[:networks][data['id']] = data
response.body = { 'network' => data }
response
end
end
end
end
end

View file

@ -0,0 +1,52 @@
module Fog
module Network
class OpenStack
class Real
def create_port(network_id, options = {})
data = {
'port' => {
'network_id' => network_id,
}
}
vanilla_options = [:name, :fixed_ips, :mac_address, :admin_state_up,
:device_owner, :device_id, :tenant_id]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['port'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [201],
:method => 'POST',
:path => 'ports'
)
end
end
class Mock
def create_port(network_id, options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => Fog::Mock.random_numbers(6).to_s,
'name' => options[:name],
'network_id' => network_id,
'fixed_ips' => options[:fixed_ips],
'mac_address' => options[:mac_address],
'status' => 'ACTIVE',
'admin_state_up' => options[:admin_state_up],
'device_owner' => options[:device_owner],
'device_id' => options[:device_id],
'tenant_id' => options[:tenant_id],
}
self.data[:ports][data['id']] = data
response.body = { 'port' => data }
response
end
end
end
end
end

View file

@ -0,0 +1,56 @@
module Fog
module Network
class OpenStack
class Real
def create_subnet(network_id, cidr, ip_version, options = {})
data = {
'subnet' => {
'network_id' => network_id,
'cidr' => cidr,
'ip_version' => ip_version,
}
}
vanilla_options = [:name, :gateway_ip, :allocation_pools,
:dns_nameservers, :host_routes, :enable_dhcp,
:tenant_id]
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['subnet'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => [201],
:method => 'POST',
:path => 'subnets'
)
end
end
class Mock
def create_subnet(network_id, cidr, ip_version, options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => Fog::Mock.random_numbers(6).to_s,
'name' => options[:name],
'network_id' => network_id,
'cidr' => cidr,
'ip_version' => ip_version,
'gateway_ip' => options[:gateway_ip],
'allocation_pools' => options[:allocation_pools],
'dns_nameservers' => options[:dns_nameservers],
'host_routes' => options[:host_routes],
'enable_dhcp' => options[:enable_dhcp],
'tenant_id' => options[:tenant_id],
}
self.data[:subnets][data['id']] = data
response.body = { 'subnet' => data }
response
end
end
end
end
end

View file

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

View file

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

View file

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

View file

@ -0,0 +1,42 @@
module Fog
module Network
class OpenStack
class Real
def get_network(network_id)
request(
:expects => [200],
:method => 'GET',
:path => "networks/#{network_id}"
)
end
end
class Mock
def get_network(network_id)
response = Excon::Response.new
if data = self.data[:networks][network_id]
response.status = 200
response.body = {
'network' => {
'id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb',
'name' => 'network_1',
'subnets' => [
'2e4ec6a4-0150-47f5-8523-e899ac03026e'
],
'shared' => false,
'status' => 'ACTIVE',
'admin_state_up' => true,
'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9',
}
}
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -0,0 +1,48 @@
module Fog
module Network
class OpenStack
class Real
def get_port(port_id)
request(
:expects => [200],
:method => 'GET',
:path => "ports/#{port_id}"
)
end
end
class Mock
def get_port(port_id)
response = Excon::Response.new
if data = self.data[:ports][port_id]
response.status = 200
response.body = {
'port' => {
'id' => '5c81d975-5fea-4674-9c1f-b8aa10bf9a79',
'name' => 'port_1',
'network_id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb',
'fixed_ips' => [
{
'ip_address' => '10.2.2.2',
'subnet_id' => '2e4ec6a4-0150-47f5-8523-e899ac03026e',
}
],
'mac_address' => 'fa:16:3e:62:91:7f',
'status' => 'ACTIVE',
'admin_state_up' => true,
'device_id' => 'dhcp724fc160-2b2e-597e-b9ed-7f65313cd73f-e624a36d-762b-481f-9b50-4154ceb78bbb',
'device_owner' => 'network:dhcp',
'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9',
}
}
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -0,0 +1,49 @@
module Fog
module Network
class OpenStack
class Real
def get_subnet(subnet_id)
request(
:expects => [200],
:method => 'GET',
:path => "subnets/#{subnet_id}"
)
end
end
class Mock
def get_subnet(subnet_id)
response = Excon::Response.new
if data = self.data[:subnets][subnet_id]
response.status = 200
response.body = {
"subnet" => {
"id" => "2e4ec6a4-0150-47f5-8523-e899ac03026e",
"name" => "subnet_1",
"network_id" => "e624a36d-762b-481f-9b50-4154ceb78bbb",
"cidr" => "10.2.2.0/24",
"ip_version" => 4,
"gateway_ip" => "10.2.2.1",
"allocation_pools" => [
{
"start" => "10.2.2.2",
"end" => "10.2.2.254"
}
],
"dns_nameservers" => [],
"host_routes" => [],
"enable_dhcp" => true,
"tenant_id" => "f8b26a6032bc47718a7702233ac708b9",
}
}
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

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

View file

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

View file

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

View file

@ -0,0 +1,21 @@
module Fog
module Network
class OpenStack
class Real
def set_tenant(tenant)
@openstack_must_reauthenticate = true
@openstack_tenant = tenant.to_s
authenticate
end
end
class Mock
def set_tenant(tenant)
true
end
end
end
end
end

View file

@ -0,0 +1,41 @@
module Fog
module Network
class OpenStack
class Real
def update_network(network_id, options = {})
data = { 'network' => {} }
vanilla_options = [:name, :shared, :admin_state_up]
vanilla_options.select{ |o| options.has_key?(o) }.each do |key|
data['network'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => 200,
:method => 'PUT',
:path => "networks/#{network_id}.json"
)
end
end
class Mock
def update_network(network_id, options = {})
response = Excon::Response.new
if network = list_networks.body['networks'].detect { |_| _['id'] == network_id }
network['name'] = options[:name]
network['shared'] = options[:shared]
network['admin_state_up'] = options[:admin_state_up]
response.body = { 'network' => network }
response.status = 200
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -0,0 +1,44 @@
module Fog
module Network
class OpenStack
class Real
def update_port(port_id, options = {})
data = { 'port' => {} }
vanilla_options = [:name, :fixed_ips, :admin_state_up, :device_owner,
:device_id]
vanilla_options.select{ |o| options.has_key?(o) }.each do |key|
data['port'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => 200,
:method => 'PUT',
:path => "ports/#{port_id}.json"
)
end
end
class Mock
def update_port(port_id, options = {})
response = Excon::Response.new
if port = list_ports.body['ports'].detect { |_| _['id'] == port_id }
port['name'] = options[:name]
port['fixed_ips'] = options[:fixed_ips]
port['admin_state_up'] = options[:admin_state_up]
port['device_owner'] = options[:device_owner]
port['device_id'] = options[:device_id]
response.body = { 'port' => port }
response.status = 200
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -0,0 +1,44 @@
module Fog
module Network
class OpenStack
class Real
def update_subnet(subnet_id, options = {})
data = { 'subnet' => {} }
vanilla_options = [:name, :gateway_ip, :dns_nameservers,
:host_routes, :enable_dhcp]
vanilla_options.select{ |o| options.has_key?(o) }.each do |key|
data['subnet'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => 200,
:method => 'PUT',
:path => "subnets/#{subnet_id}"
)
end
end
class Mock
def update_subnet(subnet_id, options = {})
response = Excon::Response.new
if subnet = list_subnets.body['subnets'].detect { |_| _['id'] == subnet_id }
subnet['name'] = options[:name]
subnet['gateway_ip'] = options[:gateway_ip]
subnet['dns_nameservers'] = options[:dns_nameservers]
subnet['host_routes'] = options[:host_routes]
subnet['enable_dhcp'] = options[:enable_dhcp]
response.body = { 'subnet' => subnet }
response.status = 200
response
else
raise Fog::Network::OpenStack::NotFound
end
end
end
end
end
end

View file

@ -0,0 +1,24 @@
Shindo.tests("Fog::Network[:openstack] | network", ['openstack']) do
tests('success') do
tests('#create').succeeds do
@instance = Fog::Network[:openstack].networks.create(:name => 'net_name',
:shared => false,
:admin_state_up => true,
:tenant_id => 'tenant_id')
!@instance.id.nil?
end
tests('#update').succeeds do
@instance.name = 'new_net_name'
@instance.update
end
tests('#destroy').succeeds do
@instance.destroy == true
end
end
end

View file

@ -0,0 +1,21 @@
Shindo.tests("Fog::Network[:openstack] | networks", ['openstack']) do
@network = Fog::Network[:openstack].networks.create(:name => 'net_name',
:shared => false,
:admin_state_up => true,
:tenant_id => 'tenant_id')
@networks = Fog::Network[:openstack].networks
tests('success') do
tests('#all').succeeds do
@networks.all
end
tests('#get').succeeds do
@networks.get @network.id
end
end
@network.destroy
end

View file

@ -0,0 +1,28 @@
Shindo.tests("Fog::Network[:openstack] | port", ['openstack']) do
tests('success') do
tests('#create').succeeds do
@instance = Fog::Network[:openstack].ports.create(:name => 'port_name',
:network_id => 'net_id',
:fixed_ips => [],
:mac_address => 'fa:16:3e:62:91:7f',
:admin_state_up => true,
:device_owner => 'device_owner',
:device_id => 'device_id',
:tenant_id => 'tenant_id')
!@instance.id.nil?
end
tests('#update').succeeds do
@instance.name = 'new_port_name'
@instance.update
end
tests('#destroy').succeeds do
@instance.destroy == true
end
end
end

View file

@ -0,0 +1,25 @@
Shindo.tests("Fog::Network[:openstack] | ports", ['openstack']) do
@port = Fog::Network[:openstack].ports.create(:name => 'port_name',
:network_id => 'net_id',
:fixed_ips => [],
:mac_address => 'fa:16:3e:62:91:7f',
:admin_state_up => true,
:device_owner => 'device_owner',
:device_id => 'device_id',
:tenant_id => 'tenant_id')
@ports = Fog::Network[:openstack].ports
tests('success') do
tests('#all').succeeds do
@ports.all
end
tests('#get').succeeds do
@ports.get @port.id
end
end
@port.destroy
end

View file

@ -0,0 +1,30 @@
Shindo.tests("Fog::Network[:openstack] | subnet", ['openstack']) do
tests('success') do
tests('#create').succeeds do
@instance = Fog::Network[:openstack].subnets.create(:name => 'subnet_name',
:network_id => 'net_id',
:cidr => '10.2.2.0/24',
:ip_version => 4,
:gateway_ip => '10.2.2.1',
:allocation_pools => [],
:dns_nameservers => [],
:host_routes => [],
:enable_dhcp => true,
:tenant_id => 'tenant_id')
!@instance.id.nil?
end
tests('#update').succeeds do
@instance.name = 'new_subnet_name'
@instance.update
end
tests('#destroy').succeeds do
@instance.destroy == true
end
end
end

View file

@ -0,0 +1,27 @@
Shindo.tests("Fog::Network[:openstack] | subnets", ['openstack']) do
@subnet = Fog::Network[:openstack].subnets.create(:name => 'subnet_name',
:network_id => 'net_id',
:cidr => '10.2.2.0/24',
:ip_version => 4,
:gateway_ip => '10.2.2.1',
:allocation_pools => [],
:dns_nameservers => [],
:host_routes => [],
:enable_dhcp => true,
:tenant_id => 'tenant_id')
@subnets = Fog::Network[:openstack].subnets
tests('success') do
tests('#all').succeeds do
@subnets.all
end
tests('#get').succeeds do
@subnets.get @subnet.id
end
end
@subnet.destroy
end

View file

@ -0,0 +1,56 @@
Shindo.tests('Fog::Network[:openstack] | network requests', ['openstack']) do
@network_format = {
'id' => String,
'name' => String,
'subnets' => Array,
'shared' => Fog::Boolean,
'status' => String,
'admin_state_up' => Fog::Boolean,
'tenant_id' => String,
}
tests('success') do
tests('#create_network').formats({'network' => @network_format}) do
attributes = {:name => 'net_name', :shared => false,
:admin_state_up => true, :tenant_id => 'tenant_id'}
Fog::Network[:openstack].create_network(attributes).body
end
tests('#list_networks').formats({'networks' => [@network_format]}) do
Fog::Network[:openstack].list_networks.body
end
tests('#get_network').formats({'network' => @network_format}) do
network_id = Fog::Network[:openstack].networks.all.first.id
Fog::Network[:openstack].get_network(network_id).body
end
tests('#update_network').formats({'network' => @network_format}) do
network_id = Fog::Network[:openstack].networks.all.first.id
attributes = {:name => 'net_name', :shared => false,
:admin_state_up => true}
Fog::Network[:openstack].update_network(network_id, attributes).body
end
tests('#delete_network').succeeds do
network_id = Fog::Network[:openstack].networks.all.first.id
Fog::Network[:openstack].delete_network(network_id)
end
end
tests('failure') do
tests('#get_network').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].get_network(0)
end
tests('#update_network').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].update_network(0, {})
end
tests('#delete_network').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].delete_network(0)
end
end
end

View file

@ -0,0 +1,63 @@
Shindo.tests('Fog::Network[:openstack] | port requests', ['openstack']) do
@port_format = {
'id' => String,
'name' => String,
'network_id' => String,
'fixed_ips' => Array,
'mac_address' => String,
'status' => String,
'admin_state_up' => Fog::Boolean,
'device_owner' => String,
'device_id' => String,
'tenant_id' => String,
}
tests('success') do
tests('#create_port').formats({'port' => @port_format}) do
network_id = 'net_id'
attributes = {:name => 'port_name', :fixed_ips => [],
:mac_address => 'fa:16:3e:62:91:7f', :admin_state_up => true,
:device_owner => 'device_owner', :device_id => 'device_id',
:tenant_id => 'tenant_id'}
Fog::Network[:openstack].create_port(network_id, attributes).body
end
tests('#list_port').formats({'ports' => [@port_format]}) do
Fog::Network[:openstack].list_ports.body
end
tests('#get_port').formats({'port' => @port_format}) do
port_id = Fog::Network[:openstack].ports.all.first.id
Fog::Network[:openstack].get_port(port_id).body
end
tests('#update_port').formats({'port' => @port_format}) do
port_id = Fog::Network[:openstack].ports.all.first.id
attributes = {:name => 'port_name', :fixed_ips => [],
:admin_state_up => true, :device_owner => 'device_owner',
:device_id => 'device_id'}
Fog::Network[:openstack].update_port(port_id, attributes).body
end
tests('#delete_port').succeeds do
port_id = Fog::Network[:openstack].ports.all.first.id
Fog::Network[:openstack].delete_port(port_id)
end
end
tests('failure') do
tests('#get_port').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].get_port(0)
end
tests('#update_port').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].update_port(0, {})
end
tests('#delete_port').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].delete_port(0)
end
end
end

View file

@ -0,0 +1,66 @@
Shindo.tests('Fog::Network[:openstack] | subnet requests', ['openstack']) do
@subnet_format = {
'id' => String,
'name' => String,
'network_id' => String,
'cidr' => String,
'ip_version' => Integer,
'gateway_ip' => String,
'allocation_pools' => Array,
'dns_nameservers' => Array,
'host_routes' => Array,
'enable_dhcp' => Fog::Boolean,
'tenant_id' => String,
}
tests('success') do
tests('#create_subnet').formats({'subnet' => @subnet_format}) do
network_id = 'net_id'
cidr = '10.2.2.0/24'
ip_version = 4
attributes = {:name => 'subnet_name', :gateway_ip => '10.2.2.1',
:allocation_pools => [], :dns_nameservers => [],
:host_routes => [], :enable_dhcp => true,
:tenant_id => 'tenant_id'}
Fog::Network[:openstack].create_subnet(network_id, cidr, ip_version, attributes).body
end
tests('#list_subnet').formats({'subnets' => [@subnet_format]}) do
Fog::Network[:openstack].list_subnets.body
end
tests('#get_subnet').formats({'subnet' => @subnet_format}) do
subnet_id = Fog::Network[:openstack].subnets.all.first.id
Fog::Network[:openstack].get_subnet(subnet_id).body
end
tests('#update_subnet').formats({'subnet' => @subnet_format}) do
subnet_id = Fog::Network[:openstack].subnets.all.first.id
attributes = {:name => 'subnet_name', :gateway_ip => '10.2.2.1',
:dns_nameservers => [], :host_routes => [],
:enable_dhcp => true}
Fog::Network[:openstack].update_subnet(subnet_id, attributes).body
end
tests('#delete_subnet').succeeds do
subnet_id = Fog::Network[:openstack].subnets.all.first.id
Fog::Network[:openstack].delete_subnet(subnet_id)
end
end
tests('failure') do
tests('#get_subnet').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].get_subnet(0)
end
tests('#update_subnet').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].update_subnet(0, {})
end
tests('#delete_subnet').raises(Fog::Network::OpenStack::NotFound) do
Fog::Network[:openstack].delete_subnet(0)
end
end
end