1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #3349 from rackspace/neutron

Rackspace Neutron (Networking) Support
This commit is contained in:
Wesley Beary 2014-12-17 15:28:33 -06:00
commit 88f7aa507d
28 changed files with 1030 additions and 315 deletions

View file

@ -28,6 +28,8 @@ class Rackspace < Fog::Bin
Fog::Rackspace::Queues
when :networking
Fog::Rackspace::Networking
when :networking_v2
Fog::Rackspace::NetworkingV2
else
raise ArgumentError, "Unrecognized service: #{key}"
end
@ -67,6 +69,8 @@ class Rackspace < Fog::Bin
Fog::Rackspace::Queues.new
when :networking
Fog::Rackspace::Networking.new
when :networking_v2
Fog::Rackspace::NetworkingV2.new
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end

View file

@ -12,3 +12,4 @@ require 'fog/rackspace/queues'
require 'fog/rackspace/storage'
require 'fog/rackspace/networking'
require 'fog/rackspace/orchestration'
require 'fog/rackspace/networking_v2'

View file

@ -99,6 +99,7 @@ module Fog
service(:queues, 'Queues')
service(:networking, 'Networking')
service(:orchestration, 'Orchestration')
service(:networkingV2, 'NetworkingV2')
def self.authenticate(options, connection_options = {})
rackspace_auth_url = options[:rackspace_auth_url]

View file

@ -1,315 +0,0 @@
#Networking (neutron)
This document explains how to get started using Networking with Fog. It assumes you have read the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
## Starting irb console
Start by executing the following command:
irb
Once `irb` has launched you need to require the Fog library.
If using Ruby 1.8.x execute:
require 'rubygems'
require 'fog'
If using Ruby 1.9.x execute:
require 'fog'
## Create Service
Next, create a connection to Rackspace's Networking API:
Using a US-based account:
service = Fog::Rackspace::Networking.new({
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_region => :ord, # Defaults to :dfw
})
Using a UK-based account:
service = Fog::Compute.new({
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,
:rackspace_region => :lon,
})
To learn more about obtaining cloud credentials refer to the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
By default `Fog::Rackspace::Networking` will authenticate against the US authentication endpoint and connect to the DFW region. You can specify alternative authentication endpoints using the key `:rackspace_auth_url`. Please refer to [Alternate Authentication Endpoints](http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html) for a list of alternative Rackspace authentication endpoints.
Alternative regions are specified using the key `:rackspace_region `. A list of regions available for Cloud Servers can be found by executing the following:
identity_service = Fog::Identity({
:provider => 'Rackspace', # Rackspace Fog provider
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT # Not specified for US Cloud
})
identity_service.service_catalog.display_service_regions :cloudServersOpenStack
### Optional Connection Parameters
Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
<table>
<tr>
<th>Key</th>
<th>Description</th>
</tr>
<tr>
<td>:connect_timeout</td>
<td>Connection timeout (default: 60 seconds)</td>
</tr>
<tr>
<td>:read_timeout</td>
<td>Read timeout for connection (default: 60 seconds)</td> </tr>
<tr>
<td>:write_timeout</td>
<td>Write timeout for connection (default: 60 seconds)</td>
</tr>
<tr>
<td>:proxy</td>
<td>Proxy for HTTP and HTTPS connections</td>
</tr>
<tr>
<td>:ssl_ca_path</td>
<td>Path to SSL certificate authorities</td>
</tr>
<tr>
<td>:ssl_ca_file</td>
<td>SSL certificate authority file</td>
</tr>
<tr>
<td>:ssl_verify_peer</td>
<td>SSL verify peer (default: true)</td>
</tr>
</table>
## Fog Abstractions
Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
### Request Layer
The request abstraction maps directly to the [Networking API](http://docs.rackspace.com/networks/api/v2/cn-gettingstarted/content/ch_overview.html). It provides the most efficient interface to the Rackspace Networking
To see a list of requests supported by the service:
service.requests
This returns:
[:list_networks, :get_network, :create_network, :delete_network, :list_virtual_interfaces, :create_virtual_interface, :delete_virtual_interface]
#### Example Request
To request a list of flavors:
response = service.list_networks
This returns in the following `Excon::Response`:
<Excon::Response:0x0000010231acd8 @data={:body=>{"networks"=>[{"cidr"=>"192.168.0.0/24", "id"=>"08df79ae-b714-425c-ba25-91b0a8a78b9e", "label"=>"something"}, {"cidr"=>"192.168.0.0/24", "id"=>"eb3ed4b8-21d4-478e-9ae4-a35c0cc0437c", "label"=>"something"}, {"id"=>"00000000-0000-0000-0000-000000000000", "label"=>"public"}, {"id"=>"11111111-1111-1111-1111-111111111111", "label"=>"private"}]}, :headers=>{"Content-Type"=>"application/json", "Via"=>"1.1 Repose (Repose/2.12)", "Content-Length"=>"341", "Date"=>"Thu, 23 Oct 2014 20:53:41 GMT", "x-compute-request-id"=>"req-d34ab53c-45ed-433f-8a9d-b3341896b7e5", "Server"=>"Jetty(8.0.y.z-SNAPSHOT)"}, :status=>200, :remote_ip=>"162.209.116.128", :local_port=>60153, :local_address=>"192.168.1.65"}, @body="{\"networks\": [{\"cidr\": \"192.168.0.0/24\", \"id\": \"08df79ae-b714-425c-ba25-91b0a8a78b9e\", \"label\": \"something\"}, {\"cidr\": \"192.168.0.0/24\", \"id\": \"eb3ed4b8-21d4-478e-9ae4-a35c0cc0437c\", \"label\": \"something\"}, {\"id\": \"00000000-0000-0000-0000-000000000000\", \"label\": \"public\"}, {\"id\": \"11111111-1111-1111-1111-111111111111\", \"label\": \"private\"}]}", @headers={"Content-Type"=>"application/json", "Via"=>"1.1 Repose (Repose/2.12)", "Content-Length"=>"341", "Date"=>"Thu, 23 Oct 2014 20:53:41 GMT", "x-compute-request-id"=>"req-d34ab53c-45ed-433f-8a9d-b3341896b7e5", "Server"=>"Jetty(8.0.y.z-SNAPSHOT)"}, @status=200, @remote_ip="162.209.116.128", @local_port=60153, @local_address="192.168.1.65">
To view the status of the response:
response.status
**Note**: Fog is aware of valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception.
To view response body:
response.body
This will return:
{"networks"=>[{"cidr"=>"192.168.0.0/24", "id"=>"08df79ae-b714-425c-ba25-91b0a8a78b9e", "label"=>"something"}, {"cidr"=>"192.168.0.0/24", "id"=>"eb3ed4b8-21d4-478e-9ae4-a35c0cc0437c", "label"=>"something"}, {"id"=>"00000000-0000-0000-0000-000000000000", "label"=>"public"}, {"id"=>"11111111-1111-1111-1111-111111111111", "label"=>"private"}]}
To learn more about Networking request methods refer to [rdoc](http://www.rubydoc.info/gems/fog/Fog/Rackspace/Networking/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
### Model Layer
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
Here is a summary of common model methods:
<table>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
<tr>
<td>create</td>
<td>
Accepts hash of attributes and creates object.<br>
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
</td>
</tr>
<tr>
<td>save</td>
<td>Saves object.<br>
Note: not all objects support updating object.</td>
</tr>
<tr>
<td>persisted?</td>
<td>Returns true if the object has been persisted.</td>
</tr>
<tr>
<td>destroy</td>
<td>
Destroys object.<br>
Note: this is a non-blocking call and object deletion might not be instantaneous.
</td>
<tr>
<td>reload</td>
<td>Updates object with latest state from service.</td>
<tr>
<td>ready?</td>
<td>Returns true if object is in a ready state and able to perform actions. This method will raise an exception if object is in an error state.</td>
</tr>
<tr>
<td>attributes</td>
<td>Returns a hash containing the list of model attributes and values.</td>
</tr>
<td>identity</td>
<td>
Returns the identity of the object.<br>
Note: This might not always be equal to object.id.
</td>
</tr>
<tr>
<td>wait_for</td>
<td>This method periodically reloads model and then yields to specified block until block returns true or a timeout occurs.</td>
</tr>
</table>
The remainder of this document details the model abstraction.
## List Networks
To retrieve a list of available networks:
service.networks
This returns a collection of `Fog::Rackspace::Networking::Network` models:
<Fog::Rackspace::Networking::Networks
[
<Fog::Rackspace::Networking::Network
id="08df79ae-b714-425c-ba25-91b0a8a78b9e",
label="something",
cidr="192.168.0.0/24"
>,
<Fog::Rackspace::Networking::Network
id="eb3ed4b8-21d4-478e-9ae4-a35c0cc0437c",
label="something",
cidr="192.168.0.0/24"
>,
<Fog::Rackspace::Networking::Network
id="00000000-0000-0000-0000-000000000000",
label="public",
cidr=nil
>,
<Fog::Rackspace::Networking::Network
id="11111111-1111-1111-1111-111111111111",
label="private",
cidr=nil
>
]
>
## Create Network
Create a network:
service.networks.create(label: "new_network", cidr: "192.168.0.0/24")
## Get Network
To retrieve individual network:
service.networks.get "8a3a9f96-b997-46fd-b7a8-a9e740796ffd"
This returns an `Fog::Rackspace::Networking::Network` instance:
<Fog::Rackspace::Networking::Network
id="08df79ae-b714-425c-ba25-91b0a8a78b9e",
label="new_network",
cidr="192.168.0.0/24"
>
## Delete Network
To delete a network:
network.destroy
**Note**: The network is not immediately destroyed, but it does occur shortly there after.
## List Virtual Interfaces
To retrieve a list of available virtual interfaces:
service.virtual_interfaces.all(server: <server obj, or server id>)
This returns a collection of `Fog::Rackspace::Networking::VirtualInterface` models:
<Fog::Rackspace::Networking::VirtualInterfaces
[
<Fog::Rackspace::Networking::VirtualInterface
id="f063815f-e576-450e-92bd-ff3aeeeb11e0",
mac_address="BC:76:4E:20:A9:16",
ip_addresses=[{"network_id"=>"11111111-1111-1111-1111-111111111111", "network_label"=>"private", "address"=>"10.176.12.249"}]
>,
<Fog::Rackspace::Networking::VirtualInterface
id="f8196e20-788b-4447-80a5-32ca8fc9622f",
mac_address="BC:76:4E:20:A8:56",
ip_addresses=[{"network_id"=>"08df79ae-b714-425c-ba25-91b0a8a78b9e", "network_label"=>"new_network", "address"=>"192.168.0.1"}]
>
]
>
## Create Virtual Interface
Create a virtual interface:
service.virtual_interfaces.create(network: <network_id>, server: <server_id>)
## Delete Virtual Interface
To delete a virtual interface:
vis = service.virtual_interfaces.all(server: <server obj, or server id>)
vis.first.destroy
**Note**: The virtual interface is not immediately destroyed, but it does occur shortly there after.
## Examples
Example code using Networking can be found [here](https://github.com/fog/fog/tree/master/lib/fog/rackspace/examples).
## Additional Resources
* [fog.io](http://fog.io/)
* [Fog rdoc](http://rubydoc.info/gems/fog/)
* [Fog Github repo](https://github.com/fog/fog)
* [Fog Github Issues](https://github.com/fog/fog/issues)
* [Excon Github repo](https://github.com/geemus/excon)
* [Rackspace Networking API](http://docs.rackspace.com/networking/api/v2/cs-devguide/content/ch_preface.html)
## Support and Feedback
Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues).
For general feedback and support requests, send an email to: <sdk-support@rackspace.com>.

View file

@ -0,0 +1,422 @@
#NetworkingV2 (neutron)
This document explains how to get started using NetworkingV2 with Fog. It assumes you have read the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
## Starting irb console
Start by executing the following command:
irb
Once `irb` has launched you need to require the Fog library.
If using Ruby 1.8.x execute:
require 'rubygems'
require 'fog'
If using Ruby 1.9.x execute:
require 'fog'
## Create Service
Next, create a connection to Rackspace's NetworkingV2 API:
Using a US-based account:
service = Fog::Rackspace::NetworkingV2.new({
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_region => :ord, # Defaults to :dfw
})
Using a UK-based account:
service = Fog::Compute.new({
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,
:rackspace_region => :lon,
})
To learn more about obtaining cloud credentials refer to the [Getting Started with Fog and the Rackspace Open Cloud](getting_started.md) document.
By default `Fog::Rackspace::NetworkingV2` will authenticate against the US authentication endpoint and connect to the DFW region. You can specify alternative authentication endpoints using the key `:rackspace_auth_url`. Please refer to [Alternate Authentication Endpoints](http://docs.rackspace.com/auth/api/v2.0/auth-client-devguide/content/Endpoints-d1e180.html) for a list of alternative Rackspace authentication endpoints.
Alternative regions are specified using the key `:rackspace_region `. A list of regions available for Cloud Servers can be found by executing the following:
identity_service = Fog::Identity({
:provider => 'Rackspace', # Rackspace Fog provider
:rackspace_username => RACKSPACE_USER_NAME, # Your Rackspace Username
:rackspace_api_key => RACKSPACE_API, # Your Rackspace API key
:rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT # Not specified for US Cloud
})
identity_service.service_catalog.display_service_regions :cloudServersOpenStack
### Optional Connection Parameters
Fog supports passing additional connection parameters to its underlying HTTP library (Excon) using the `:connection_options` parameter.
<table>
<tr>
<th>Key</th>
<th>Description</th>
</tr>
<tr>
<td>:connect_timeout</td>
<td>Connection timeout (default: 60 seconds)</td>
</tr>
<tr>
<td>:read_timeout</td>
<td>Read timeout for connection (default: 60 seconds)</td> </tr>
<tr>
<td>:write_timeout</td>
<td>Write timeout for connection (default: 60 seconds)</td>
</tr>
<tr>
<td>:proxy</td>
<td>Proxy for HTTP and HTTPS connections</td>
</tr>
<tr>
<td>:ssl_ca_path</td>
<td>Path to SSL certificate authorities</td>
</tr>
<tr>
<td>:ssl_ca_file</td>
<td>SSL certificate authority file</td>
</tr>
<tr>
<td>:ssl_verify_peer</td>
<td>SSL verify peer (default: true)</td>
</tr>
</table>
## Fog Abstractions
Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
### Request Layer
The request abstraction maps directly to the [NetworkingV2 API](http://docs.rackspace.com/networks/api/v2/cn-devguide/content/ch_overview.html). It provides the most efficient interface to the Rackspace NetworkingV2
To see a list of requests supported by the service:
service.requests
This returns:
[:list_networks, :create_network, :show_network, :update_network, :delete_network, :list_subnets, :create_subnet, :show_subnet, :update_subnet, :delete_subnet, :list_ports, :create_port, :show_port, :update_port, :delete_port]
#### Example Request
To request a list of flavors:
response = service.list_networks
This returns in the following `Excon::Response`:
#<Excon::Response:0x007fbce39798a0 @data={:body=>{"networks"=>[{"status"=>"ACTIVE", "subnets"=>["79a2a078-84bd-4ffd-8e68-67f7854bb772"], "name"=>"Testing", "admin_state_up"=>true, "tenant_id"=>"000000", "shared"=>false, "id"=>"eff4da21-e006-4468-b9ce-798eb2fed3e8"}]}, :headers=>{"Content-Type"=>"application/json; charset=UTF-8", "Via"=>"1.1 Repose (Repose/2.12)", "Content-Length"=>"218", "Date"=>"Wed, 17 Dec 2014 19:37:49 GMT", "Server"=>"Jetty(8.0.y.z-SNAPSHOT)"}, :status=>200, :reason_phrase=>"OK", :remote_ip=>"69.20.65.143", :local_port=>63382, :local_address=>"192.168.1.80"}, @body="{\"networks\": [{\"status\": \"ACTIVE\", \"subnets\": [\"79a2a078-84bd-4ffd-8e68-67f7854bb772\"], \"name\": \"Testing\", \"admin_state_up\": true, \"tenant_id\": \"000000\", \"shared\": false, \"id\": \"eff4da21-e006-4468-b9ce-798eb2fed3e8\"}]}", @headers={"Content-Type"=>"application/json; charset=UTF-8", "Via"=>"1.1 Repose (Repose/2.12)", "Content-Length"=>"218", "Date"=>"Wed, 17 Dec 2014 19:37:49 GMT", "Server"=>"Jetty(8.0.y.z-SNAPSHOT)"}, @status=200, @remote_ip="69.20.0.0", @local_port=63382, @local_address="192.168.1.80">
To view the status of the response:
response.status
**Note**: Fog is aware of valid HTTP response statuses for each request type. If an unexpected HTTP response status occurs, Fog will raise an exception.
To view response body:
response.body
This will return:
{"networks"=>[{"status"=>"ACTIVE", "subnets"=>["79a2a078-84bd-4ffd-8e68-67f7854bb772"], "name"=>"Testing", "admin_state_up"=>true, "tenant_id"=>"000000", "shared"=>false, "id"=>"eff4da21-e006-4468-b9ce-798eb2fed3e8"}]}
To learn more about NetworkingV2 request methods refer to [rdoc](http://www.rubydoc.info/gems/fog/Fog/Rackspace/NetworkingV2/Real). To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
### Model Layer
Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
Here is a summary of common model methods:
<table>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
<tr>
<td>create</td>
<td>
Accepts hash of attributes and creates object.<br>
Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
</td>
</tr>
<tr>
<td>save</td>
<td>Saves object.<br>
Note: not all objects support updating object.</td>
</tr>
<tr>
<td>persisted?</td>
<td>Returns true if the object has been persisted.</td>
</tr>
<tr>
<td>destroy</td>
<td>
Destroys object.<br>
Note: this is a non-blocking call and object deletion might not be instantaneous.
</td>
<tr>
<td>reload</td>
<td>Updates object with latest state from service.</td>
<tr>
<td>ready?</td>
<td>Returns true if object is in a ready state and able to perform actions. This method will raise an exception if object is in an error state.</td>
</tr>
<tr>
<td>attributes</td>
<td>Returns a hash containing the list of model attributes and values.</td>
</tr>
<td>identity</td>
<td>
Returns the identity of the object.<br>
Note: This might not always be equal to object.id.
</td>
</tr>
<tr>
<td>wait_for</td>
<td>This method periodically reloads model and then yields to specified block until block returns true or a timeout occurs.</td>
</tr>
</table>
The remainder of this document details the model abstraction.
## List Networks
To retrieve a list of available networks:
service.networks
This returns a collection of `Fog::Rackspace::NetworkingV2::Network` models:
<Fog::Rackspace::NetworkingV2::Networks
[
<Fog::Rackspace::NetworkingV2::Network
id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
admin_state_up=true,
label=nil,
name="Testing",
shared=false,
status="ACTIVE",
subnets=["79a2a078-84bd-4ffd-8e68-67f7854bb772"],
tenant_id="000000"
>
]
>
## Create Network
Create a network:
service.networks.create(label: "new_network", cidr: "192.168.0.0/24")
## Get Network
To retrieve individual network:
service.networks.get "eff4da21-e006-4468-b9ce-798eb2fed3e8"
This returns an `Fog::Rackspace::NetworkingV2::Network` instance:
<Fog::Rackspace::NetworkingV2::Network
id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
admin_state_up=true,
label=nil,
name="Testing",
shared=false,
status="ACTIVE",
subnets=["79a2a078-84bd-4ffd-8e68-67f7854bb772"],
tenant_id="000000"
>
## Delete Network
To delete a network:
network.destroy
**Note**: The network is not immediately destroyed, but it does occur shortly there after.
## List Subnets
To retrieve a list of available subnets:
service.subnets
This returns a collection of `Fog::Rackspace::NetworkingV2::Subnet` models:
<Fog::Rackspace::NetworkingV2::Subnets
[
<Fog::Rackspace::NetworkingV2::Subnet
id="79a2a078-84bd-4ffd-8e68-67f7854bb772",
name="",
enable_dhcp=nil,
network_id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
tenant_id="000000",
dns_nameservers=[],
allocation_pools=[{"start"=>"192.168.3.1", "end"=>"192.168.3.254"}],
host_routes=[],
ip_version=4,
gateway_ip=nil,
cidr="192.168.3.0/24"
>
]
>
## Create Subnet
Create a subnet:
subnet = service.subnets.new({
:name => "ANewsubnet",
:cidr => "192.168.101.1/24",
:network_id => "79a2a078-84bd-4ffd-8e68-67f7854bb772",
:ip_version => "4"
}).save
## Get Subnet
To retrieve individual subnet:
service.subnets.get "79a2a078-84bd-4ffd-8e68-67f7854bb772"
This returns an `Fog::Rackspace::NetworkingV2::Subnet` instance:
<Fog::Rackspace::NetworkingV2::Subnet
id="79a2a078-84bd-4ffd-8e68-67f7854bb772",
name="",
enable_dhcp=nil,
network_id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
tenant_id="000000",
dns_nameservers=[],
allocation_pools=[{"start"=>"192.168.3.1", "end"=>"192.168.3.254"}],
host_routes=[],
ip_version=4,
gateway_ip=nil,
cidr="192.168.3.0/24"
>
## Delete Subnet
To delete a subnet:
subnet.destroy
**Note**: The subnet is not immediately destroyed, but it does occur shortly there after.
## List Ports
To retrieve a list of available ports:
service.ports
This returns a collection of `Fog::Rackspace::NetworkingV2::Port` models:
<Fog::Rackspace::NetworkingV2::Ports
[
<Fog::Rackspace::NetworkingV2::Port
id="79a2a078-84bd-4ffd-8e68-67f7854bb772",
name="",
enable_dhcp=nil,
network_id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
tenant_id="000000",
dns_nameservers=[],
allocation_pools=[{"start"=>"192.168.3.1", "end"=>"192.168.3.254"}],
host_routes=[],
ip_version=4,
gateway_ip=nil,
cidr="192.168.3.0/24"
>
]
>
## Create Port
Create a port:
s.ports.new({name: "something", network_id: network.id}).save
<Fog::Rackspace::NetworkingV2::Ports
[
<Fog::Rackspace::NetworkingV2::Port
id="f90c5970-1bce-4403-82ee-7713854de7c7",
admin_state_up=true,
device_id="",
device_owner=nil,
fixed_ips=[{"subnet_id"=>"79a2a078-84bd-4ffd-8e68-67f7854bb772", "ip_address"=>"192.168.3.1"}],
mac_address="BC:76:4E:20:CB:0D",
name="something",
network_id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
security_groups=[],
status="ACTIVE",
tenant_id="000000"
>
]
>
## Get Port
To retrieve individual port:
service.ports.get "f90c5970-1bce-4403-82ee-7713854de7c7"
This returns an `Fog::Rackspace::NetworkingV2::Port` instance:
<Fog::Rackspace::NetworkingV2::Port
id="f90c5970-1bce-4403-82ee-7713854de7c7",
admin_state_up=true,
device_id="",
device_owner=nil,
fixed_ips=[{"subnet_id"=>"79a2a078-84bd-4ffd-8e68-67f7854bb772", "ip_address"=>"192.168.3.1"}],
mac_address="BC:76:4E:20:CB:0D",
name="something",
network_id="eff4da21-e006-4468-b9ce-798eb2fed3e8",
security_groups=[],
status="ACTIVE",
tenant_id="000000"
>
## Delete Port
To delete a port:
port.destroy
**Note**: The port is not immediately destroyed, but it does occur shortly there after.
## Examples
Example code using Networking can be found [here](https://github.com/fog/fog/tree/master/lib/fog/rackspace/examples).
## Additional Resources
* [fog.io](http://fog.io/)
* [Fog rdoc](http://rubydoc.info/gems/fog/)
* [Fog Github repo](https://github.com/fog/fog)
* [Fog Github Issues](https://github.com/fog/fog/issues)
* [Excon Github repo](https://github.com/geemus/excon)
* [Rackspace Networking API](http://docs.rackspace.com/networking/api/v2/cs-devguide/content/ch_preface.html)
## Support and Feedback
Your feedback is appreciated! If you have specific issues with the **fog** SDK, you should file an [issue via Github](https://github.com/fog/fog/issues).
For general feedback and support requests, send an email to: <sdk-support@rackspace.com>.

View file

@ -0,0 +1,36 @@
module Fog
module Rackspace
class NetworkingV2
class Network < Fog::Model
identity :id
attribute :admin_state_up
attribute :label
attribute :name
attribute :shared
attribute :status
attribute :subnets
attribute :tenant_id
def save
data = unless self.id.nil?
service.update_network(self)
else
service.create_network(self)
end
merge_attributes(data.body['network'])
true
end
def destroy
requires :identity
service.delete_network(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/rackspace/models/networking_v2/network'
module Fog
module Rackspace
class NetworkingV2
class Networks < Fog::Collection
model Fog::Rackspace::NetworkingV2::Network
def all
data = service.list_networks.body['networks']
load(data)
end
def get(id)
data = service.show_network(id).body['network']
new(data)
rescue Fog::Rackspace::NetworkingV2::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Rackspace
class NetworkingV2
class Port < Fog::Model
identity :id
attribute :admin_state_up
attribute :device_id
attribute :device_owner
attribute :fixed_ips
attribute :mac_address
attribute :name
attribute :network_id
attribute :security_groups
attribute :status
attribute :tenant_id
def save
data = unless self.id.nil?
service.update_port(self)
else
service.create_port(self)
end
merge_attributes(data.body['port'])
true
end
def destroy
requires :identity
service.delete_port(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/rackspace/models/networking_v2/port'
module Fog
module Rackspace
class NetworkingV2
class Ports < Fog::Collection
model Fog::Rackspace::NetworkingV2::Port
def all
data = service.list_ports.body['ports']
load(data)
end
def get(id)
data = service.show_port(id).body['port']
new(data)
rescue Fog::Rackspace::NetworkingV2::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,38 @@
module Fog
module Rackspace
class NetworkingV2
class Subnet < Fog::Model
identity :id
attribute :name
attribute :enable_dhcp
attribute :network_id
attribute :tenant_id
attribute :dns_nameservers
attribute :allocation_pools
attribute :host_routes
attribute :ip_version
attribute :gateway_ip
attribute :cidr
def save
data = unless self.id.nil?
service.update_subnet(self)
else
service.create_subnet(self)
end
merge_attributes(data.body['subnet'])
true
end
def destroy
requires :identity
service.delete_subnet(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/rackspace/models/networking_v2/subnet'
module Fog
module Rackspace
class NetworkingV2
class Subnets < Fog::Collection
model Fog::Rackspace::NetworkingV2::Subnet
def all
data = service.list_subnets.body['subnets']
load(data)
end
def get(id)
data = service.show_subnet(id).body['subnet']
new(data)
rescue Fog::Rackspace::NetworkingV2::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,205 @@
require 'fog/rackspace/core'
module Fog
module Rackspace
class NetworkingV2 < Fog::Service
include Fog::Rackspace::Errors
class ServiceError < Fog::Rackspace::Errors::ServiceError; end
class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end
class BadRequest < Fog::Rackspace::Errors::BadRequest; end
NETWORKS_DFW_URL = "https://dfw.networks.api.rackspacecloud.com/v2.0"
NETWORKS_LON_URL = "https://lon.networks.api.rackspacecloud.com/v2.0"
NETWORKS_IAD_URL = "https://iad.networks.api.rackspacecloud.com/v2.0"
NETWORKS_ORD_URL = "https://ord.networks.api.rackspacecloud.com/v2.0"
class InvalidStateException < ::RuntimeError
attr_reader :desired_state
attr_reader :current_state
def initialize(desired_state, current_state)
@desired_state = desired_state
@current_state = current_state
end
end
class InvalidServerStateException < InvalidStateException
def to_s
"Server should have transitioned to '#{desired_state}' not '#{current_state}'"
end
end
class InvalidImageStateException < InvalidStateException
def to_s
"Image should have transitioned to '#{desired_state}' not '#{current_state}'"
end
end
requires :rackspace_username, :rackspace_api_key
recognizes :rackspace_endpoint
recognizes :rackspace_auth_url
recognizes :rackspace_auth_token
recognizes :rackspace_region
recognizes :rackspace_networking_v2_url
model_path 'fog/rackspace/models/networking_v2'
model :network
collection :networks
model :subnet
collection :subnets
model :port
collection :ports
request_path 'fog/rackspace/requests/networking_v2'
request :list_networks
request :create_network
request :show_network
request :update_network
request :delete_network
request :list_subnets
request :create_subnet
request :show_subnet
request :update_subnet
request :delete_subnet
request :list_ports
request :create_port
request :show_port
request :update_port
request :delete_port
class Mock < Fog::Rackspace::Service
include Fog::Rackspace::MockData
def initialize(options)
@rackspace_api_key = options[:rackspace_api_key]
end
def request(params)
Fog::Mock.not_implemented
end
def response(params={})
body = params[:body] || {}
status = params[:status] || 200
headers = params[:headers] || {}
response = Excon::Response.new(:body => body, :headers => headers, :status => status)
if params.key?(:expects) && ![*params[:expects]].include?(response.status)
raise(Excon::Errors.status_error(params, response))
else response
end
end
end
class Real < Fog::Rackspace::Service
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
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
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
def service_name
:cloudNetworks
end
def request_id_header
"x-networks-request-id"
end
def region
@rackspace_region
end
def endpoint_uri(service_endpoint_url=nil)
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_networking_v2_url)
end
private
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
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
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
def authenticate_v1(options)
credentials = Fog::Rackspace.authenticate(options, @connection_options)
append_tenant_v1 credentials
@auth_token = credentials['X-Auth-Token']
end
end
end
end
end

View file

@ -118,6 +118,9 @@ module Fog
service_catalog_entry("cloudOrchestration", "orchestration", compute_tenant,
:rackspace_api_name => 'orchestration', :rackspace_api_version => '1'),
service_catalog_entry("cloudNetworks", "network", compute_tenant,
:rackspace_api_name => 'networks', :rackspace_api_version => '2.0'),
service_catalog_entry("cloudQueues", "rax:queues", compute_tenant,
:internal_url_snet => true,
:rackspace_api_name => 'queues', :rackspace_api_version => '1'),

View file

@ -0,0 +1,18 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def create_network(network)
data = {:network => network.attributes}
request(
:method => 'POST',
:body => Fog::JSON.encode(data),
:path => "networks",
:expects => 201
)
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def create_port(port)
data = {:port => port.attributes}
request(
:method => 'POST',
:body => Fog::JSON.encode(data),
:path => "ports",
:expects => 201
)
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def create_subnet(subnet)
data = {:subnet => subnet.attributes}
request(
:method => 'POST',
:body => Fog::JSON.encode(data),
:path => "subnets",
:expects => 201
)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def delete_network(id)
request(:method => 'DELETE', :path => "networks/#{id}", :expects => 204)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def delete_port(id)
request(:method => 'DELETE', :path => "ports/#{id}", :expects => 204)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def delete_subnet(id)
request(:method => 'DELETE', :path => "subnets/#{id}", :expects => 204)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def list_networks
request(:method => 'GET', :path => 'networks', :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def list_ports
request(:method => 'GET', :path => 'ports', :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def list_subnets
request(:method => 'GET', :path => 'subnets', :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def show_network(id)
request(:method => 'GET', :path => "networks/#{id}", :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def show_port(id)
request(:method => 'GET', :path => "ports/#{id}", :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,11 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def show_subnet(id)
request(:method => 'GET', :path => "subnets/#{id}", :expects => 200)
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def update_network(network)
data = {:network => {:name => network.name}}
request(
:method => 'PUT',
:body => Fog::JSON.encode(data),
:path => "networks/#{network.id}",
:expects => 200
)
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Rackspace
class NetworkingV2
class Real
def update_port(port)
data = {:port => {:name => port.name}}
request(
:method => 'PUT',
:body => Fog::JSON.encode(data),
:path => "ports/#{port.id}",
:expects => 200
)
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Rackspace
class NetworkingV2
class Real
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
end
end
end
end