class Fog::Rackspace::Networking::Real
Public Class Methods
# File lib/fog/rackspace/networking.rb, line 88 def initialize(options = {}) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] @rackspace_auth_url = options[:rackspace_auth_url] setup_custom_endpoint(options) @rackspace_must_reauthenticate = false @connection_options = options[:connection_options] || {} authenticate deprecation_warnings(options) @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new(endpoint_uri.to_s, @persistent, @connection_options) end
Public Instance Methods
Fog::Rackspace::Service#authenticate
# File lib/fog/rackspace/networking.rb, line 116 def authenticate(options={}) super({ :rackspace_api_key => @rackspace_api_key, :rackspace_username => @rackspace_username, :rackspace_auth_url => @rackspace_auth_url, :connection_options => @connection_options }) end
# File lib/fog/rackspace/requests/networking/create_network.rb, line 5 def create_network(label, cidr) data = { 'network' => { 'label' => label, 'cidr' => cidr } } request( :method => 'POST', :body => Fog::JSON.encode(data), :path => "os-networksv2", :expects => 200 ) end
Creates virtual interface for a server @param [String] server_id The server id to create the virtual interface on @param [String] network_id The network id to attach the virtual interface to @raise [Fog::Rackspace::Networking::NotFound] - HTTP 404 @raise [Fog::Rackspace::Networking::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Networking::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Networking::ServiceError] @see docs.rackspace.com/servers/api/v2/cn-devguide/content/api_create_virtual_interface.html
# File lib/fog/rackspace/requests/networking/create_virtual_interface.rb, line 13 def create_virtual_interface(server_id, network_id) data = { :virtual_interface => { :network_id => network_id } } request( :expects => [200], :method => 'POST', :path => "servers/#{server_id}/os-virtual-interfacesv2", :body => Fog::JSON.encode(data) ) end
# File lib/fog/rackspace/requests/networking/delete_network.rb, line 5 def delete_network(id) request(:method => 'DELETE', :path => "os-networksv2/#{id}", :expects => 202) end
Deletes virtual interface from server @param [String] server_id The server id that contains the virtual interface @param [String] interface_id The id of the virtual interface @raise [Fog::Rackspace::Networking::NotFound] - HTTP 404 @raise [Fog::Rackspace::Networking::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Networking::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Networking::ServiceError] @see docs.rackspace.com/servers/api/v2/cn-devguide/content/delete_virt_interface_api.html
# File lib/fog/rackspace/requests/networking/delete_virtual_interface.rb, line 13 def delete_virtual_interface(server_id, interface_id) request( :expects => [200], :method => 'DELETE', :path => "servers/#{server_id}/os-virtual-interfacesv2/#{interface_id}" ) end
Fog::Rackspace::Service#endpoint_uri
# File lib/fog/rackspace/networking.rb, line 137 def endpoint_uri(service_endpoint_url=nil) @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_compute_url) end
# File lib/fog/rackspace/requests/networking/get_network.rb, line 5 def get_network(id) request(:method => 'GET', :path => "os-networksv2/#{id}", :expects => 200) end
# File lib/fog/rackspace/requests/networking/list_networks.rb, line 5 def list_networks request(:method => 'GET', :path => 'os-networksv2', :expects => 200) end
Lists virtual interfaces for a server @param [String] server_id @raise [Fog::Rackspace::Networking::NotFound] - HTTP 404 @raise [Fog::Rackspace::Networking::BadRequest] - HTTP 400 @raise [Fog::Rackspace::Networking::InternalServerError] - HTTP 500 @raise [Fog::Rackspace::Networking::ServiceError] @see docs.rackspace.com/servers/api/v2/cn-devguide/content/list_virt_interfaces.html
# File lib/fog/rackspace/requests/networking/list_virtual_interfaces.rb, line 12 def list_virtual_interfaces(server_id) request( :expects => [200], :method => 'GET', :path => "servers/#{server_id}/os-virtual-interfacesv2" ) end
# File lib/fog/rackspace/networking.rb, line 133 def region @rackspace_region end
Fog::Rackspace::Service#request
# File lib/fog/rackspace/networking.rb, line 104 def request(params, parse_json = true) super rescue Excon::Errors::NotFound => error raise NotFound.slurp(error, self) rescue Excon::Errors::BadRequest => error raise BadRequest.slurp(error, self) rescue Excon::Errors::InternalServerError => error raise InternalServerError.slurp(error, self) rescue Excon::Errors::HTTPStatusError => error raise ServiceError.slurp(error, self) end
# File lib/fog/rackspace/networking.rb, line 129 def request_id_header "x-compute-request-id" end
# File lib/fog/rackspace/networking.rb, line 125 def service_name :cloudServersOpenStack end
Private Instance Methods
# File lib/fog/rackspace/networking.rb, line 176 def append_tenant_v1(credentials) account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1] endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || DFW_ENDPOINT @uri = URI.parse(endpoint) @uri.path = "#{@uri.path}/#{account_id}" end
# File lib/fog/rackspace/networking.rb, line 184 def authenticate_v1(options) credentials = Fog::Rackspace.authenticate(options, @connection_options) append_tenant_v1 credentials @auth_token = credentials['X-Auth-Token'] end
# File lib/fog/rackspace/networking.rb, line 167 def deprecation_warnings(options) Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_compute_url for custom endpoints") if options[:rackspace_endpoint] if [DFW_ENDPOINT, ORD_ENDPOINT, LON_ENDPOINT].include?(@rackspace_endpoint) && v2_authentication? regions = @identity_service.service_catalog.display_service_regions(service_name) Fog::Logger.deprecation("Please specify region using :rackspace_region rather than :rackspace_endpoint. Valid regions for :rackspace_region are #{regions}.") end end
# File lib/fog/rackspace/networking.rb, line 143 def setup_custom_endpoint(options) @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_compute_url] || options[:rackspace_endpoint]) if v2_authentication? case @rackspace_endpoint when DFW_ENDPOINT @rackspace_endpoint = nil @rackspace_region = :dfw when ORD_ENDPOINT @rackspace_endpoint = nil @rackspace_region = :ord when LON_ENDPOINT @rackspace_endpoint = nil @rackspace_region = :lon else # we are actually using a custom endpoint @rackspace_region = options[:rackspace_region] end else #if we are using auth1 and the endpoint is not set, default to DFW_ENDPOINT for historical reasons @rackspace_endpoint ||= DFW_ENDPOINT end end