mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge branch 'master' of github.com:fog/fog into cbs_docs
This commit is contained in:
commit
353c3e6e4f
26 changed files with 861 additions and 28 deletions
|
@ -32,6 +32,33 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_server_certificate(server_certificate_name, options = {})
|
||||
new_server_certificate_name = options['NewServerCertificateName']
|
||||
if self.data[:server_certificates][new_server_certificate_name]
|
||||
raise Fog::AWS::IAM::EntityAlreadyExists.new("The Server Certificate with name #{server_certificate_name} already exists.")
|
||||
end
|
||||
unless certificate = self.data[:server_certificates].delete(server_certificate_name)
|
||||
raise Fog::AWS::IAM::NotFound.new("The Server Certificate with name #{server_certificate_name} cannot be found.")
|
||||
end
|
||||
|
||||
if new_server_certificate_name
|
||||
certificate['ServerCertificateName'] = new_server_certificate_name
|
||||
end
|
||||
|
||||
if new_path = options['NewPath']
|
||||
certificate['Path'] = new_path
|
||||
end
|
||||
|
||||
self.data[:server_certificates][certificate['ServerCertificateName']] = certificate
|
||||
|
||||
Excon::Response.new.tap do |response|
|
||||
response.body = { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||
response.status = 200
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ module Fog
|
|||
raise ArgumentError.new(':key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH')
|
||||
end
|
||||
|
||||
options[:timeout] = 30
|
||||
options[:timeout] ||= 30
|
||||
if options[:key_data] || options[:keys]
|
||||
options[:keys_only] = true
|
||||
#Explicitly set these so net-ssh doesn't add the default keys
|
||||
|
|
|
@ -14,7 +14,7 @@ module Fog
|
|||
node_hash[:uri] = client.uri
|
||||
xml = client.sys_info rescue nil
|
||||
[:uuid, :manufacturer, :product, :serial].each do |attr|
|
||||
node_hash[attr] = node_attr(attr, xml)
|
||||
node_hash[attr] = node_attr(attr, xml) rescue nil
|
||||
end if xml
|
||||
|
||||
node_hash[:hostname] = client.hostname
|
||||
|
|
77
lib/fog/openstack/examples/image/upload-test-image.rb
Normal file
77
lib/fog/openstack/examples/image/upload-test-image.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
require 'securerandom'
|
||||
require 'rubygems/package'
|
||||
require 'zlib'
|
||||
require 'fog'
|
||||
|
||||
#
|
||||
# Download CirrOS 0.3.0 image from launchpad (~6.5MB) to /tmp
|
||||
# and upload it to Glance (the OpenStack Image Service).
|
||||
#
|
||||
# You will need to source OpenStack credentials since the script
|
||||
# reads the following envionment variables:
|
||||
#
|
||||
# OS_PASSWORD
|
||||
# OS_USERNAME
|
||||
# OS_AUTH_URL
|
||||
# OS_TENANT_NAME
|
||||
#
|
||||
# Should work with Fog >= 1.9, ruby 1.8.7 and 2.0
|
||||
#
|
||||
image_url = "https://launchpadlibrarian.net/83305869/cirros-0.3.0-x86_64-uec.tar.gz"
|
||||
image_out = File.open("/tmp/cirros-image-#{SecureRandom.hex}", 'wb')
|
||||
extract_path = "/tmp/cirros-#{SecureRandom.hex}-dir"
|
||||
ami = "#{extract_path}/cirros-0.3.0-x86_64-blank.img"
|
||||
aki = "#{extract_path}/cirros-0.3.0-x86_64-vmlinuz"
|
||||
ari = "#{extract_path}/cirros-0.3.0-x86_64-initrd"
|
||||
|
||||
FileUtils.mkdir_p extract_path
|
||||
|
||||
# Efficient image write
|
||||
puts "Downloading Cirros image..."
|
||||
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
||||
image_out.write chunk
|
||||
end
|
||||
Excon.get image_url, :response_block => streamer
|
||||
image_out.close
|
||||
puts "Image downloaded to #{image_out.path}"
|
||||
|
||||
puts "Extracting image contents to #{extract_path}..."
|
||||
Gem::Package::TarReader.new(Zlib::GzipReader.open(image_out.path)).each do |entry|
|
||||
FileUtils.mkdir_p "#{extract_path}/#{File.dirname(entry.full_name)}"
|
||||
File.open "#{extract_path}/#{entry.full_name}", 'w' do |f|
|
||||
f.write entry.read
|
||||
end
|
||||
end
|
||||
|
||||
image_service = Fog::Image.new({
|
||||
:provider => 'OpenStack',
|
||||
:openstack_api_key => ENV['OS_PASSWORD'],
|
||||
:openstack_username => ENV["OS_USERNAME"],
|
||||
:openstack_auth_url => ENV["OS_AUTH_URL"] + "/tokens",
|
||||
:openstack_tenant => ENV["OS_TENANT_NAME"]
|
||||
})
|
||||
|
||||
puts "Uploading AKI..."
|
||||
aki = image_service.images.create :name => 'cirros-0.3.0-amd64-aki',
|
||||
:size => File.size(aki),
|
||||
:disk_format => 'aki',
|
||||
:container_format => 'aki',
|
||||
:location => aki
|
||||
|
||||
puts "Uploading ARI..."
|
||||
ari = image_service.images.create :name => 'cirros-0.3.0-amd64-ari',
|
||||
:size => File.size(ari),
|
||||
:disk_format => 'ari',
|
||||
:container_format => 'ari',
|
||||
:location => ari
|
||||
|
||||
puts "Uploading AMI..."
|
||||
image_service.images.create :name => 'cirros-0.3.0-amd64',
|
||||
:size => File.size(ami),
|
||||
:disk_format => 'ami',
|
||||
:container_format => 'ami',
|
||||
:location => ami,
|
||||
:properties => {
|
||||
'kernel_id' => aki.id,
|
||||
'ramdisk_id' => ari.id
|
||||
}
|
|
@ -40,7 +40,7 @@ module Fog
|
|||
attribute :os_ext_sts_vm_state, :aliases => 'OS-EXT-STS:vm_state'
|
||||
|
||||
attr_reader :password
|
||||
attr_writer :image_ref, :flavor_ref, :os_scheduler_hints
|
||||
attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints
|
||||
|
||||
|
||||
def initialize(attributes={})
|
||||
|
@ -50,6 +50,7 @@ module Fog
|
|||
self.security_groups = attributes.delete(:security_groups)
|
||||
self.min_count = attributes.delete(:min_count)
|
||||
self.max_count = attributes.delete(:max_count)
|
||||
self.nics = attributes.delete(:nics)
|
||||
self.os_scheduler_hints = attributes.delete(:os_scheduler_hints)
|
||||
|
||||
super
|
||||
|
@ -256,7 +257,8 @@ module Fog
|
|||
'security_groups' => @security_groups,
|
||||
'min_count' => @min_count,
|
||||
'max_count' => @max_count,
|
||||
'os:scheduler_hints' => @os_scheduler_hints
|
||||
'nics' => @nics,
|
||||
'os:scheduler_hints' => @os_scheduler_hints,
|
||||
}
|
||||
options['metadata'] = metadata.to_hash unless @metadata.nil?
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
|
||||
def create
|
||||
requires :floating_network_id
|
||||
merge_attributes(connection.create_floating_ip(self.floating_network_id,
|
||||
merge_attributes(service.create_floating_ip(self.floating_network_id,
|
||||
|
||||
|
||||
self.attributes).body['floatingip'])
|
||||
|
@ -42,7 +42,7 @@ module Fog
|
|||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_floating_ip(self.id)
|
||||
service.delete_floating_ip(self.id)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ module Fog
|
|||
|
||||
def all(filters = filters)
|
||||
self.filters = filters
|
||||
load(connection.list_floating_ips(filters).body['floatingips'])
|
||||
load(service.list_floating_ips(filters).body['floatingips'])
|
||||
end
|
||||
|
||||
def get(floating_network_id)
|
||||
|
|
56
lib/fog/openstack/models/network/router.rb
Normal file
56
lib/fog/openstack/models/network/router.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
# The Layer-3 Networking Extensions (router)
|
||||
#
|
||||
# A logical entity for forwarding packets across internal
|
||||
# subnets and NATting them on external networks through
|
||||
# an appropriate external gateway.
|
||||
#
|
||||
# @see http://docs.openstack.org/api/openstack-network/2.0/content/router_ext.html
|
||||
class Router < Fog::Model
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :admin_state_up
|
||||
attribute :tenant_id
|
||||
attribute :external_gateway_info
|
||||
attribute :status
|
||||
|
||||
def initialize(attributes)
|
||||
# Old 'connection' is renamed as service and should be used instead
|
||||
prepare_service_value(attributes)
|
||||
super
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name
|
||||
identity ? update : create
|
||||
end
|
||||
|
||||
def create
|
||||
requires :name
|
||||
merge_attributes(service.create_router(self.name,
|
||||
self.attributes).body['router'])
|
||||
self
|
||||
end
|
||||
|
||||
def update
|
||||
requires :id
|
||||
merge_attributes(service.update_router(self.id,
|
||||
self.attributes).body['router'])
|
||||
self
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_router(self.id)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
lib/fog/openstack/models/network/routers.rb
Normal file
34
lib/fog/openstack/models/network/routers.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/openstack/models/network/router'
|
||||
|
||||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
class Routers < Fog::Collection
|
||||
|
||||
attribute :filters
|
||||
|
||||
model Fog::Network::OpenStack::Router
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
def all(filters = filters)
|
||||
self.filters = filters
|
||||
load(service.list_routers(filters).body['routers'])
|
||||
end
|
||||
|
||||
def get(router_id)
|
||||
if router = service.get_router(router_id).body['router']
|
||||
new(router)
|
||||
end
|
||||
rescue Fog::Network::OpenStack::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,6 +21,8 @@ module Fog
|
|||
collection :subnets
|
||||
model :floating_ip
|
||||
collection :floating_ips
|
||||
model :router
|
||||
collection :routers
|
||||
|
||||
## REQUESTS
|
||||
#
|
||||
|
@ -55,6 +57,15 @@ module Fog
|
|||
request :associate_floating_ip
|
||||
request :disassociate_floating_ip
|
||||
|
||||
# Router CRUD
|
||||
request :list_routers
|
||||
request :create_router
|
||||
request :delete_router
|
||||
request :get_router
|
||||
request :update_router
|
||||
request :add_router_interface
|
||||
request :remove_router_interface
|
||||
|
||||
# Tenant
|
||||
request :set_tenant
|
||||
|
||||
|
@ -66,6 +77,7 @@ module Fog
|
|||
:ports => {},
|
||||
:subnets => {},
|
||||
:floating_ips => {},
|
||||
:routers => {},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,6 +41,17 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
if options['nics']
|
||||
data['server']['networks'] =
|
||||
Array(options['nics']).map do |nic|
|
||||
{
|
||||
'uuid' => nic['net_id'],
|
||||
'fixed_ip' => nic['v4_fixed_ip'],
|
||||
'port' => nic['port_id']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if options['os:scheduler_hints']
|
||||
data['os:scheduler_hints'] = options['os:scheduler_hints']
|
||||
end
|
||||
|
|
48
lib/fog/openstack/requests/network/add_router_interface.rb
Normal file
48
lib/fog/openstack/requests/network/add_router_interface.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def add_router_interface(router_id, subnet_id, options = {})
|
||||
data = {
|
||||
'subnet_id' => subnet_id,
|
||||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [200],
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}/add_router_interface"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def add_router_interface(router_id, subnet_id, options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
data = {
|
||||
'status' => 'ACTIVE',
|
||||
'name' => '',
|
||||
'admin_state_up' => true,
|
||||
'network_id' => '5307648b-e836-4658-8f1a-ff7536870c64',
|
||||
'tenant_id' => '6b96ff0cb17a4b859e1e575d221683d3',
|
||||
'device_owner' => 'network:router_interface',
|
||||
'mac_address' => 'fa:16:3e:f7:d1:9c',
|
||||
'fixed_ips' => {
|
||||
'subnet_id' => 'a2f1f29d-571b-4533-907f-5803ab96ead1',
|
||||
'ip_address' => '10.1.1.1'
|
||||
},
|
||||
'id' => '3a44f4e5-1694-493a-a1fb-393881c673a4',
|
||||
'device_id' => '7177abc4-5ae9-4bb7-b0d4-89e94a4abf3b'
|
||||
}
|
||||
|
||||
self.data[:routers][data['router_id']] = data
|
||||
response.body = { 'router' => data }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,11 +6,45 @@ module Fog
|
|||
def create_network(options = {})
|
||||
data = { 'network' => {} }
|
||||
|
||||
vanilla_options = [:name, :shared, :admin_state_up, :tenant_id]
|
||||
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
|
||||
|
||||
# Advanced Features through API Extensions
|
||||
#
|
||||
# Not strictly required but commonly found in OpenStack
|
||||
# installs with Quantum networking.
|
||||
#
|
||||
# @see http://docs.openstack.org/trunk/openstack-network/admin/content/provider_attributes.html
|
||||
provider_options = [
|
||||
:router_external,
|
||||
:provider_network_type,
|
||||
:provider_segmentation_id,
|
||||
:provider_physical_network
|
||||
]
|
||||
|
||||
# Map Fog::Network::OpenStack::Network
|
||||
# model attributes to OpenStack provider attributes
|
||||
aliases = {
|
||||
:provider_network_type => 'provider:network_type',
|
||||
# Not applicable to the "local" or "gre" network types
|
||||
:provider_physical_network => 'provider:physical_network',
|
||||
:provider_segmentation_id => 'provider:segmentation_id',
|
||||
:router_external => 'router:external'
|
||||
}
|
||||
|
||||
provider_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
aliased_key = aliases[key] || key
|
||||
data['network'][aliased_key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [201],
|
||||
|
@ -33,6 +67,27 @@ module Fog
|
|||
'admin_state_up' => options[:admin_state_up],
|
||||
'tenant_id' => options[:tenant_id],
|
||||
}
|
||||
|
||||
# Add provider specific attributes when found
|
||||
#
|
||||
provider_options = [
|
||||
:router_external,
|
||||
:provider_network_type,
|
||||
:provider_segmentation_id,
|
||||
:provider_physical_network
|
||||
]
|
||||
aliases = {
|
||||
:provider_network_type => 'provider:network_type',
|
||||
# Not applicable to the "local" or "gre" network types
|
||||
:provider_physical_network => 'provider:physical_network',
|
||||
:provider_segmentation_id => 'provider:segmentation_id',
|
||||
:router_external => 'router:external'
|
||||
}
|
||||
provider_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
aliased_key = aliases[key] || key
|
||||
data[aliased_key] = options[key]
|
||||
end
|
||||
|
||||
self.data[:networks][data['id']] = data
|
||||
response.body = { 'network' => data }
|
||||
response
|
||||
|
@ -41,4 +96,4 @@ module Fog
|
|||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
58
lib/fog/openstack/requests/network/create_router.rb
Normal file
58
lib/fog/openstack/requests/network/create_router.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def create_router(name, options = {})
|
||||
data = {
|
||||
'router' => {
|
||||
'name' => name,
|
||||
}
|
||||
}
|
||||
|
||||
vanilla_options = [
|
||||
:admin_state_up,
|
||||
:tenant_id,
|
||||
:network_id,
|
||||
:external_gateway_info,
|
||||
:status,
|
||||
:subnet_id
|
||||
]
|
||||
|
||||
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [201],
|
||||
:method => 'POST',
|
||||
:path => 'routers'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_router(name, options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
data = {
|
||||
'router' => {
|
||||
'status' => 'ACTIVE',
|
||||
'external_gateway_info' => nil,
|
||||
'name' => 'another_router',
|
||||
'admin_state_up' => true,
|
||||
'tenant_id' => '6b96ff0cb17a4b859e1e575d221683d3',
|
||||
'id' => '8604a0de-7f6b-409a-a47c-a1cc7bc77b2e'
|
||||
}
|
||||
}
|
||||
self.data['routers'] ||= []
|
||||
self.data['routers'] << data['router']
|
||||
response.body = data
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/openstack/requests/network/delete_router.rb
Normal file
30
lib/fog/openstack/requests/network/delete_router.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def delete_router(router_id)
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "routers/#{router_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_router(router_id)
|
||||
response = Excon::Response.new
|
||||
if list_routers.body['routers'].map { |r| r['id'] }.include? router_id
|
||||
self.data[:routers].delete(router_id)
|
||||
response.status = 204
|
||||
response
|
||||
else
|
||||
raise Fog::Network::OpenStack::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/openstack/requests/network/get_router.rb
Normal file
41
lib/fog/openstack/requests/network/get_router.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def get_router(router_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "routers/#{router_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_router(router_id)
|
||||
response = Excon::Response.new
|
||||
if data = (self.data['routers'].find { |r| r['id'] == router_id })
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'router' => {
|
||||
'status' => 'ACTIVE',
|
||||
'external_gateway_info' => {
|
||||
'network_id' => '3c5bcddd-6af9-4e6b-9c3e-c153e521cab8'
|
||||
},
|
||||
'name' => 'router1',
|
||||
'admin_state_up' => true,
|
||||
'tenant_id' => '33a40233088643acb66ff6eb0ebea679',
|
||||
'id' => 'a9254bdb-2613-4a13-ac4c-adc581fba50d'
|
||||
}
|
||||
}
|
||||
response
|
||||
else
|
||||
raise Fog::Network::OpenStack::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/openstack/requests/network/list_routers.rb
Normal file
27
lib/fog/openstack/requests/network/list_routers.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def list_routers(filters = {})
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => 'routers',
|
||||
:query => filters
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_routers(filters = {})
|
||||
Excon::Response.new(
|
||||
:body => { 'routers' => self.data['routers'] },
|
||||
:status => 200
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
def remove_router_interface(router_id, subnet_id, options = {})
|
||||
data = {
|
||||
'subnet_id' => subnet_id,
|
||||
}
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [200],
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}/remove_router_interface"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def remove_router_interface(router_id, subnet_id, options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
data = {
|
||||
'subnet_id' => 'a2f1f29d-571b-4533-907f-5803ab96ead1'
|
||||
}
|
||||
|
||||
self.data[:routers][data['router_id']] = data
|
||||
response.body = { 'router' => data }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
85
lib/fog/openstack/requests/network/update_router.rb
Normal file
85
lib/fog/openstack/requests/network/update_router.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
module Fog
|
||||
module Network
|
||||
class OpenStack
|
||||
|
||||
class Real
|
||||
|
||||
# Update Router
|
||||
#
|
||||
# Beyond the name and the administrative state, the only
|
||||
# parameter which can be updated with this operation is
|
||||
# the external gateway.
|
||||
#
|
||||
# router = Fog::Network[:openstack].routers.first
|
||||
# net = Fog::Network[:openstack].networks.first
|
||||
#
|
||||
# # :external_gateway_info can be either a
|
||||
# # Fog::Network::OpenStack::Network or a Hash
|
||||
# # like { 'network_id' => network.id }
|
||||
# Fog::Network[:openstack].update_router router.id,
|
||||
# :name => 'foo',
|
||||
# :external_gateway_info => net,
|
||||
# :admin_state_up => true
|
||||
#
|
||||
# @see http://docs.openstack.org/api/openstack-network/2.0/content/router_update.html
|
||||
def update_router(router_id, options = {})
|
||||
data = { 'router' => {} }
|
||||
|
||||
vanilla_options = [:name, :admin_state_up]
|
||||
|
||||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
data['router']['external_gateway_info'] = { 'network_id' => egi.id }
|
||||
elsif egi.is_a?(Hash) and egi['network_id']
|
||||
data['router']['external_gateway_info'] = egi
|
||||
else
|
||||
raise ArgumentError.new('Invalid external_gateway_info attribute')
|
||||
end
|
||||
end
|
||||
|
||||
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "routers/#{router_id}.json"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_router(router_id, options = {})
|
||||
router = self.data['routers'].find { |r| r['id'] == router_id }
|
||||
raise Fog::Network::OpenStack::NotFound unless router
|
||||
data = { 'router' => router }
|
||||
|
||||
vanilla_options = [:name, :admin_state_up]
|
||||
|
||||
egi = options[:external_gateway_info]
|
||||
if egi
|
||||
if egi.is_a?(Fog::Network::OpenStack::Network)
|
||||
data['router']['external_gateway_info'] = { 'network_id' => egi.id }
|
||||
elsif egi.is_a?(Hash) and egi['network_id']
|
||||
data['router']['external_gateway_info'] = egi
|
||||
else
|
||||
raise ArgumentError.new('Invalid external_gateway_info attribute')
|
||||
end
|
||||
end
|
||||
|
||||
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
|
||||
data['router'][key] = options[key]
|
||||
end
|
||||
response = Excon::Response.new
|
||||
response.status = 201
|
||||
response.body = data
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,13 +17,15 @@ module Fog
|
|||
# 'folder' => '/Datacenters/vm/Jeff/Templates' will be MUCH faster.
|
||||
# than simply listing everything.
|
||||
def all(filters = { })
|
||||
load service.list_virtual_machines(filters.merge(
|
||||
:datacenter => datacenter,
|
||||
:cluster => cluster,
|
||||
:network => network,
|
||||
:resource_pool => resource_pool,
|
||||
:folder => folder
|
||||
))
|
||||
f = {
|
||||
:datacenter => datacenter,
|
||||
:cluster => cluster,
|
||||
:network => network,
|
||||
:resource_pool => resource_pool,
|
||||
:folder => folder
|
||||
}.merge(filters)
|
||||
|
||||
load service.list_virtual_machines(f)
|
||||
end
|
||||
|
||||
def get(id, datacenter = nil)
|
||||
|
@ -31,9 +33,7 @@ module Fog
|
|||
rescue Fog::Compute::Vsphere::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,9 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
'Certificate' => @certificate_format,
|
||||
'RequestId' => String
|
||||
}
|
||||
@update_format = {
|
||||
'RequestId' => String
|
||||
}
|
||||
@get_server_certificate_format = {
|
||||
'Certificate' => @certificate_format,
|
||||
'RequestId' => String
|
||||
|
@ -64,6 +67,35 @@ Shindo.tests('AWS::IAM | server certificate requests', ['aws']) do
|
|||
end
|
||||
end
|
||||
|
||||
tests('#update_server_certificate') do
|
||||
public_key = AWS::IAM::SERVER_CERT_PUBLIC_KEY
|
||||
private_key = AWS::IAM::SERVER_CERT_PRIVATE_KEY
|
||||
key_name = "update-key"
|
||||
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, key_name)
|
||||
|
||||
tests('duplicate name').raises(Fog::AWS::IAM::EntityAlreadyExists) do
|
||||
other_key_name = "other-key-name"
|
||||
Fog::AWS::IAM.new.upload_server_certificate(public_key, private_key, other_key_name)
|
||||
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name})
|
||||
end
|
||||
|
||||
tests('unknown name').raises(Fog::AWS::IAM::NotFound) do
|
||||
Fog::AWS::IAM.new.update_server_certificate("unknown-key-name", {'NewServerCertificateName' => "other-keyname"})
|
||||
end
|
||||
|
||||
tests('format').formats(@update_format) do
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name).body
|
||||
end
|
||||
|
||||
tests('updates name') do
|
||||
other_key_name = "successful-update-key-name"
|
||||
Fog::AWS::IAM.new.update_server_certificate(key_name, {'NewServerCertificateName' => other_key_name})
|
||||
returns(true) { Fog::AWS::IAM.new.get_server_certificate(other_key_name).body['Certificate']['ServerCertificateName'] == other_key_name }
|
||||
end
|
||||
end
|
||||
|
||||
tests('#get_server_certificate').formats(@get_server_certificate_format) do
|
||||
tests('raises NotFound').raises(Fog::AWS::IAM::NotFound) do
|
||||
Fog::AWS::IAM.new.get_server_certificate("#{@key_name}fake")
|
||||
|
|
|
@ -10,6 +10,23 @@ Shindo.tests("Fog::Network[:openstack] | network", ['openstack']) do
|
|||
!@instance.id.nil?
|
||||
end
|
||||
|
||||
tests('#create+extensions').succeeds do
|
||||
net = Fog::Network[:openstack].networks.create(
|
||||
:name => 'net_name',
|
||||
:shared => false,
|
||||
:admin_state_up => true,
|
||||
:tenant_id => 'tenant_id',
|
||||
:router_external => true,
|
||||
# local, gre, vlan. Depends on the provider.
|
||||
# May rise an exception if the network_type isn't valid:
|
||||
# QuantumError: "Invalid input for operation: provider:physical_network"
|
||||
:provider_network_type => 'gre',
|
||||
:provider_segmentation_id => 22
|
||||
)
|
||||
net.destroy
|
||||
net.provider_network_type == 'gre'
|
||||
end
|
||||
|
||||
tests('have attributes') do
|
||||
attributes = [
|
||||
:name,
|
||||
|
|
38
tests/openstack/models/network/router_tests.rb
Normal file
38
tests/openstack/models/network/router_tests.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
Shindo.tests("Fog::Network[:openstack] | router", ['openstack']) do
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#create').succeeds do
|
||||
@instance = Fog::Network[:openstack].routers.create(
|
||||
:name => 'router_name',
|
||||
:admin_state_up => true
|
||||
)
|
||||
!@instance.id.nil?
|
||||
end
|
||||
|
||||
tests('#update') do
|
||||
test 'router name' do
|
||||
@instance.name = 'new_name'
|
||||
@instance.update.name == 'new_name'
|
||||
end
|
||||
# Needs code from issue #1598
|
||||
#test 'external_gateway_info' do
|
||||
# net = Fog::Network[:openstack].networks.create(
|
||||
# :name => 'net_name',
|
||||
# :shared => false,
|
||||
# :admin_state_up => true,
|
||||
# :tenant_id => 'tenant_id',
|
||||
# :router_external => true,
|
||||
# )
|
||||
# @instance.external_gateway_info = net
|
||||
# @instance.update
|
||||
#end
|
||||
end
|
||||
|
||||
tests('#destroy').succeeds do
|
||||
@instance.destroy == true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
21
tests/openstack/models/network/routers_tests.rb
Normal file
21
tests/openstack/models/network/routers_tests.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
Shindo.tests("Fog::Network[:openstack] | routers", ['openstack']) do
|
||||
@router = Fog::Network[:openstack].routers.create(
|
||||
:name => 'router_name',
|
||||
:admin_state_up => true
|
||||
)
|
||||
@routers = Fog::Network[:openstack].routers
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests('#all').succeeds do
|
||||
@routers.all
|
||||
end
|
||||
|
||||
tests('#get').succeeds do
|
||||
@routers.get @router.id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@router.destroy
|
||||
end
|
|
@ -1,19 +1,47 @@
|
|||
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,
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'subnets' => Array,
|
||||
'shared' => Fog::Boolean,
|
||||
'status' => String,
|
||||
'admin_state_up' => Fog::Boolean,
|
||||
'tenant_id' => String
|
||||
}
|
||||
|
||||
@network_format_extensions = {
|
||||
'router:external' => Fog::Boolean,
|
||||
'provider:network_type' => String,
|
||||
'provider:physical_network' => Fog::Nullable::String,
|
||||
'provider:segmentation_id' => Integer
|
||||
}
|
||||
|
||||
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'}
|
||||
attributes = {
|
||||
:name => 'net_name',
|
||||
:shared => false,
|
||||
:admin_state_up => true,
|
||||
:tenant_id => 'tenant_id'
|
||||
}
|
||||
Fog::Network[:openstack].create_network(attributes).body
|
||||
end
|
||||
tests('#create_network+provider extensions').formats(
|
||||
{'network' => @network_format.merge(@network_format_extensions)}
|
||||
) do
|
||||
attributes = {
|
||||
:name => 'net_name',
|
||||
:shared => false,
|
||||
:admin_state_up => true,
|
||||
:tenant_id => 'tenant_id',
|
||||
:router_external => true,
|
||||
# local, gre, vlan. Depends on the provider.
|
||||
# May rise an exception if the network_type isn't valid:
|
||||
# QuantumError: "Invalid input for operation: provider:physical_network"
|
||||
:provider_network_type => 'gre',
|
||||
:provider_segmentation_id => 22,
|
||||
}
|
||||
Fog::Network[:openstack].create_network(attributes).body
|
||||
end
|
||||
|
||||
|
@ -40,6 +68,24 @@ Shindo.tests('Fog::Network[:openstack] | network requests', ['openstack']) do
|
|||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#create_network+provider extensions').raises(
|
||||
Excon::Errors::BadRequest
|
||||
) do
|
||||
pending if Fog.mocking?
|
||||
|
||||
attributes = {
|
||||
:name => 'net_name',
|
||||
:shared => false,
|
||||
:admin_state_up => true,
|
||||
:tenant_id => 'tenant_id',
|
||||
:router_external => true,
|
||||
# QuantumError: "Invalid input for operation: provider:physical_network"
|
||||
:provider_network_type => 'foobar',
|
||||
:provider_segmentation_id => 22,
|
||||
}
|
||||
Fog::Network[:openstack].create_network(attributes)
|
||||
end
|
||||
|
||||
tests('#get_network').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].get_network(0)
|
||||
end
|
||||
|
@ -52,5 +98,10 @@ Shindo.tests('Fog::Network[:openstack] | network requests', ['openstack']) do
|
|||
Fog::Network[:openstack].delete_network(0)
|
||||
end
|
||||
end
|
||||
|
||||
# Cleaning up the mess
|
||||
Fog::Network[:openstack].networks.each do |n|
|
||||
Fog::Network[:openstack].delete_network(n.id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
75
tests/openstack/requests/network/router_tests.rb
Normal file
75
tests/openstack/requests/network/router_tests.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
Shindo.tests('Fog::Network[:openstack] | router requests', ['openstack']) do
|
||||
|
||||
@router_format = {
|
||||
'id' => String,
|
||||
'name' => String,
|
||||
'status' => String,
|
||||
'admin_state_up' => Fog::Boolean,
|
||||
'tenant_id' => String,
|
||||
'external_gateway_info' => Fog::Nullable::Hash,
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
tests('#create_router').formats({'router' => @router_format}) do
|
||||
attributes = {
|
||||
:admin_state_up => true,
|
||||
:tenant_id => 'tenant_id'
|
||||
}
|
||||
Fog::Network[:openstack].create_router('router_name', attributes).body
|
||||
end
|
||||
|
||||
tests('#list_routers').formats({'routers' => [@router_format]}) do
|
||||
Fog::Network[:openstack].list_routers.body
|
||||
end
|
||||
|
||||
tests('#get_router').formats({'router' => @router_format}) do
|
||||
router_id = Fog::Network[:openstack].routers.all.first.id
|
||||
Fog::Network[:openstack].get_router(router_id).body
|
||||
end
|
||||
|
||||
tests('#update_router').formats({'router' => @router_format}) do
|
||||
router_id = Fog::Network[:openstack].routers.all.first.id
|
||||
attributes = {}
|
||||
{
|
||||
:name => 'net_name',
|
||||
:external_gateway_info => { :network_id => 'net_id' },
|
||||
:status => 'ACTIVE',
|
||||
:admin_state_up => 'true'
|
||||
}
|
||||
Fog::Network[:openstack].update_router(router_id, attributes).body
|
||||
end
|
||||
|
||||
tests('#update_router_with_network').formats({'router' => @router_format}) do
|
||||
router_id = Fog::Network[:openstack].routers.all.first.id
|
||||
net = Fog::Network[:openstack].networks.first
|
||||
attributes = {}
|
||||
{
|
||||
:name => 'net_name',
|
||||
:external_gateway_info => net,
|
||||
:status => 'ACTIVE',
|
||||
:admin_state_up => 'true'
|
||||
}
|
||||
Fog::Network[:openstack].update_router(router_id, attributes).body
|
||||
end
|
||||
|
||||
tests('#delete_router').succeeds do
|
||||
router_id = Fog::Network[:openstack].routers.all.last.id
|
||||
Fog::Network[:openstack].delete_router(router_id)
|
||||
end
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
tests('#get_router').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].get_router(0)
|
||||
end
|
||||
|
||||
tests('#update_router').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].update_router(0, {})
|
||||
end
|
||||
|
||||
tests('#delete_router').raises(Fog::Network::OpenStack::NotFound) do
|
||||
Fog::Network[:openstack].delete_router(0)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue