class Fog::Rackspace::NetworkingV2::Real
Public Class Methods
new(options = {})
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 101 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
authenticate(options={})
click to toggle source
Calls superclass method
Fog::Rackspace::Service#authenticate
# File lib/fog/rackspace/networking_v2.rb, line 129 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
create_network(network)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/create_network.rb, line 5 def create_network(network) data = {:network => network.attributes} request( :method => 'POST', :body => Fog::JSON.encode(data), :path => "networks", :expects => 201 ) end
create_port(port)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/create_port.rb, line 5 def create_port(port) data = {:port => port.attributes} request( :method => 'POST', :body => Fog::JSON.encode(data), :path => "ports", :expects => 201 ) end
create_subnet(subnet)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/create_subnet.rb, line 5 def create_subnet(subnet) data = {:subnet => subnet.attributes} request( :method => 'POST', :body => Fog::JSON.encode(data), :path => "subnets", :expects => 201 ) end
delete_network(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/delete_network.rb, line 5 def delete_network(id) request(:method => 'DELETE', :path => "networks/#{id}", :expects => 204) end
delete_port(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/delete_port.rb, line 5 def delete_port(id) request(:method => 'DELETE', :path => "ports/#{id}", :expects => 204) end
delete_subnet(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/delete_subnet.rb, line 5 def delete_subnet(id) request(:method => 'DELETE', :path => "subnets/#{id}", :expects => 204) end
endpoint_uri(service_endpoint_url=nil)
click to toggle source
Calls superclass method
Fog::Rackspace::Service#endpoint_uri
# File lib/fog/rackspace/networking_v2.rb, line 150 def endpoint_uri(service_endpoint_url=nil) @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_networking_v2_url) end
list_networks()
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/list_networks.rb, line 5 def list_networks request(:method => 'GET', :path => 'networks', :expects => 200) end
list_ports()
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/list_ports.rb, line 5 def list_ports request(:method => 'GET', :path => 'ports', :expects => 200) end
list_subnets()
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/list_subnets.rb, line 5 def list_subnets request(:method => 'GET', :path => 'subnets', :expects => 200) end
region()
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 146 def region @rackspace_region end
request(params, parse_json = true)
click to toggle source
Calls superclass method
Fog::Rackspace::Service#request
# File lib/fog/rackspace/networking_v2.rb, line 117 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
request_id_header()
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 142 def request_id_header "x-networks-request-id" end
service_name()
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 138 def service_name :cloudNetworks end
show_network(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/show_network.rb, line 5 def show_network(id) request(:method => 'GET', :path => "networks/#{id}", :expects => 200) end
show_port(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/show_port.rb, line 5 def show_port(id) request(:method => 'GET', :path => "ports/#{id}", :expects => 200) end
show_subnet(id)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/show_subnet.rb, line 5 def show_subnet(id) request(:method => 'GET', :path => "subnets/#{id}", :expects => 200) end
update_network(network)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/update_network.rb, line 5 def update_network(network) data = {:network => {:name => network.name}} request( :method => 'PUT', :body => Fog::JSON.encode(data), :path => "networks/#{network.id}", :expects => 200 ) end
update_port(port)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/update_port.rb, line 5 def update_port(port) data = {:port => {:name => port.name}} request( :method => 'PUT', :body => Fog::JSON.encode(data), :path => "ports/#{port.id}", :expects => 200 ) end
update_subnet(subnet)
click to toggle source
# File lib/fog/rackspace/requests/networking_v2/update_subnet.rb, line 5 def update_subnet(subnet) data = { :subnet => { :name => subnet.name, :gateway_ip => subnet.gateway_ip } } request( :method => 'PUT', :body => Fog::JSON.encode(data), :path => "subnets/#{subnet.id}", :expects => 200 ) end
Private Instance Methods
append_tenant_v1(credentials)
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 189 def append_tenant_v1(credentials) account_id = credentials['X-Server-Management-Url'].match(/.*\/([\d]+)$/)[1] endpoint = @rackspace_endpoint || credentials['X-Server-Management-Url'] || NETWORKS_DFW_URL @uri = URI.parse(endpoint) @uri.path = "#{@uri.path}/#{account_id}" end
authenticate_v1(options)
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 197 def authenticate_v1(options) credentials = Fog::Rackspace.authenticate(options, @connection_options) append_tenant_v1 credentials @auth_token = credentials['X-Auth-Token'] end
deprecation_warnings(options)
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 180 def deprecation_warnings(options) Fog::Logger.deprecation("The :rackspace_endpoint option is deprecated. Please use :rackspace_networking_v2_url for custom endpoints") if options[:rackspace_endpoint] if [NETWORKS_DFW_URL, NETWORKS_ORD_URL, NETWORKS_LON_URL].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
setup_custom_endpoint(options)
click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 156 def setup_custom_endpoint(options) @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_networking_v2_url] || options[:rackspace_endpoint]) if v2_authentication? case @rackspace_endpoint when NETWORKS_DFW_URL @rackspace_endpoint = nil @rackspace_region = :dfw when NETWORKS_ORD_URL @rackspace_endpoint = nil @rackspace_region = :ord when NETWORKS_LON_URL @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 NETWORKS_DFW_URL for historical reasons @rackspace_endpoint ||= NETWORKS_DFW_URL end end