Class: Fog::Rackspace::NetworkingV2::Real

Inherits:
Service
  • Object
show all
Defined in:
lib/fog/rackspace/networking_v2.rb,
lib/fog/rackspace/requests/networking_v2/show_port.rb,
lib/fog/rackspace/requests/networking_v2/list_ports.rb,
lib/fog/rackspace/requests/networking_v2/create_port.rb,
lib/fog/rackspace/requests/networking_v2/delete_port.rb,
lib/fog/rackspace/requests/networking_v2/show_subnet.rb,
lib/fog/rackspace/requests/networking_v2/update_port.rb,
lib/fog/rackspace/requests/networking_v2/list_subnets.rb,
lib/fog/rackspace/requests/networking_v2/show_network.rb,
lib/fog/rackspace/requests/networking_v2/create_subnet.rb,
lib/fog/rackspace/requests/networking_v2/delete_subnet.rb,
lib/fog/rackspace/requests/networking_v2/list_networks.rb,
lib/fog/rackspace/requests/networking_v2/update_subnet.rb,
lib/fog/rackspace/requests/networking_v2/create_network.rb,
lib/fog/rackspace/requests/networking_v2/delete_network.rb,
lib/fog/rackspace/requests/networking_v2/update_network.rb,
lib/fog/rackspace/requests/networking_v2/show_security_group.rb,
lib/fog/rackspace/requests/networking_v2/list_security_groups.rb,
lib/fog/rackspace/requests/networking_v2/create_security_group.rb,
lib/fog/rackspace/requests/networking_v2/delete_security_group.rb,
lib/fog/rackspace/requests/networking_v2/update_security_group.rb,
lib/fog/rackspace/requests/networking_v2/show_security_group_rule.rb,
lib/fog/rackspace/requests/networking_v2/list_security_group_rules.rb,
lib/fog/rackspace/requests/networking_v2/create_security_group_rule.rb,
lib/fog/rackspace/requests/networking_v2/delete_security_group_rule.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.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# 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

Instance Method Details

#authenticate(options = {}) ⇒ Object



146
147
148
149
150
151
152
153
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



5
6
7
# 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) ⇒ Object



5
6
7
# 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) ⇒ Object



2
3
4
# 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) ⇒ Object



2
3
4
# 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) ⇒ Object



5
6
7
# 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) ⇒ Object



167
168
169
# 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_networksObject



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

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

#list_portsObject



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



2
3
4
# 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_groupsObject



2
3
4
# 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_subnetsObject



5
6
7
# File 'lib/fog/rackspace/requests/networking_v2/list_subnets.rb', line 5

def list_subnets
  request(:method => 'GET', :path => 'subnets', :expects => 200)
end

#regionObject



163
164
165
# File 'lib/fog/rackspace/networking_v2.rb', line 163

def region
  @rackspace_region
end

#request(params, parse_json = true) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# 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_headerObject



159
160
161
# File 'lib/fog/rackspace/networking_v2.rb', line 159

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

#service_nameObject



155
156
157
# File 'lib/fog/rackspace/networking_v2.rb', line 155

def service_name
  :cloudNetworks
end

#show_network(id) ⇒ Object



5
6
7
# 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) ⇒ Object



5
6
7
# 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) ⇒ Object



2
3
4
# 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) ⇒ Object



2
3
4
# 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) ⇒ Object



5
6
7
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# 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) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# 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) ⇒ Object



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