Class: Fog::Rackspace::Networking::Real

Inherits:
Service
  • Object
show all
Defined in:
lib/fog/rackspace/networking.rb,
lib/fog/rackspace/requests/networking/get_network.rb,
lib/fog/rackspace/requests/networking/list_networks.rb,
lib/fog/rackspace/requests/networking/create_network.rb,
lib/fog/rackspace/requests/networking/delete_network.rb,
lib/fog/rackspace/requests/networking/list_virtual_interfaces.rb,
lib/fog/rackspace/requests/networking/create_virtual_interface.rb,
lib/fog/rackspace/requests/networking/delete_virtual_interface.rb

Instance Method Summary collapse

Methods inherited from Service

#request_without_retry, #service_net?

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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

Instance Method Details

#authenticate(options = {}) ⇒ Object



116
117
118
119
120
121
122
123
# 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

#create_network(label, cidr) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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

#create_virtual_interface(server_id, network_id) ⇒ Object

Creates virtual interface for a server

Parameters:

  • server_id (String)

    The server id to create the virtual interface on

  • network_id (String)

    The network id to attach the virtual interface to

Raises:

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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

#delete_network(id) ⇒ Object



5
6
7
# 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

#delete_virtual_interface(server_id, interface_id) ⇒ Object

Deletes virtual interface from server

Parameters:

  • server_id (String)

    The server id that contains the virtual interface

  • interface_id (String)

    The id of the virtual interface

Raises:

See Also:



13
14
15
16
17
18
19
# 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

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



137
138
139
# 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

#get_network(id) ⇒ Object



5
6
7
# 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

#list_networksObject



5
6
7
# File 'lib/fog/rackspace/requests/networking/list_networks.rb', line 5

def list_networks
  request(:method => 'GET', :path => 'os-networksv2', :expects => 200)
end

#list_virtual_interfaces(server_id) ⇒ Object

Lists virtual interfaces for a server



12
13
14
15
16
17
18
# 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

#regionObject



133
134
135
# File 'lib/fog/rackspace/networking.rb', line 133

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
# 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

#request_id_headerObject



129
130
131
# File 'lib/fog/rackspace/networking.rb', line 129

def request_id_header
  "x-compute-request-id"
end

#service_nameObject



125
126
127
# File 'lib/fog/rackspace/networking.rb', line 125

def service_name
  :cloudServersOpenStack
end