class Fog::Rackspace::NetworkingV2::Real

Public Class Methods

new(options = {}) click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 118
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 146
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_security_group(security_group) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/create_security_group.rb, line 2
def create_security_group(security_group)
  data = {:security_group => security_group.attributes}

  request(
    :method  => 'POST',
    :body    => Fog::JSON.encode(data),
    :path    => "security-groups",
    :expects => 201
  )
end
create_security_group_rule(security_group_rule) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/create_security_group_rule.rb, line 2
def create_security_group_rule(security_group_rule)
  data = {:security_group_rule => security_group_rule.attributes}

  request(
    :method  => 'POST',
    :body    => Fog::JSON.encode(data),
    :path    => "security-group-rules",
    :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_security_group(id) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/delete_security_group.rb, line 2
def delete_security_group(id)
  request(:method => 'DELETE', :path => "security-groups/#{id}", :expects => 204)
end
delete_security_group_rule(id) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/delete_security_group_rule.rb, line 2
def delete_security_group_rule(id)
  request(:method => 'DELETE', :path => "security-group-rules/#{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 167
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_security_group_rules() click to toggle source
# File lib/fog/rackspace/requests/networking_v2/list_security_group_rules.rb, line 2
def list_security_group_rules
  request(:method => 'GET', :path => 'security-group-rules', :expects => 200)
end
list_security_groups() click to toggle source
# File lib/fog/rackspace/requests/networking_v2/list_security_groups.rb, line 2
def list_security_groups
  request(:method => 'GET', :path => 'security-groups', :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 163
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 134
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 159
def request_id_header
  "x-networks-request-id"
end
service_name() click to toggle source
# File lib/fog/rackspace/networking_v2.rb, line 155
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_security_group(id) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/show_security_group.rb, line 2
def show_security_group(id)
  request(:method => 'GET', :path => "security-groups/#{id}", :expects => 200)
end
show_security_group_rule(id) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/show_security_group_rule.rb, line 2
def show_security_group_rule(id)
  request(:method => 'GET', :path => "security-group-rules/#{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_security_group(security_group) click to toggle source
# File lib/fog/rackspace/requests/networking_v2/update_security_group.rb, line 2
def update_security_group(security_group)
  data = {:security_group => {:name => security_group.name}}

  request(
    :method  => 'PUT',
    :body    => Fog::JSON.encode(data),
    :path    => "security-groups/#{security_group.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 206
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 214
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 197
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 173
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