Class: Fog::Rackspace::Networking::Mock

Inherits:
Service
  • Object
show all
Includes:
MockData
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/delete_network.rb,
lib/fog/rackspace/requests/networking/create_network.rb

Constant Summary

Constants included from MockData

MockData::NOT_FOUND_ID

Instance Method Summary collapse

Methods included from MockData

#data, ipv4_address, ipv6_address, keep, slice, stringify, uuid, zulu_time

Methods inherited from Service

#authenticate, #endpoint_uri, #region, #request_without_retry, #service_name, #service_net?

Constructor Details

#initialize(options) ⇒ Mock

Returns a new instance of Mock



66
67
68
# File 'lib/fog/rackspace/networking.rb', line 66

def initialize(options)
  @rackspace_api_key = options[:rackspace_api_key]
end

Instance Method Details

#create_network(label, cidr) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/rackspace/requests/networking/create_network.rb', line 23

def create_network(label, cidr)
  network_id = Fog::Rackspace::MockData.uuid

  self.data[:networks][network_id] = {
    'id' => network_id,
    'label' => label,
    'cidr' => cidr
  }
  response(:body => { 'network' => self.data[:networks][network_id] })
end

#delete_network(id) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/fog/rackspace/requests/networking/delete_network.rb', line 11

def delete_network(id)
  unless self.data[:networks].key?(id)
    raise Fog::Rackspace::Networking::NotFound
  end

  response(:body => '', :status => 202)
end

#get_network(id) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/fog/rackspace/requests/networking/get_network.rb', line 11

def get_network(id)
  unless self.data[:networks].key?(id)
    raise Fog::Rackspace::Networking::NotFound
  end

  response(:body => { 'network' => self.data[:networks][id] })
end

#list_networksObject



11
12
13
14
# File 'lib/fog/rackspace/requests/networking/list_networks.rb', line 11

def list_networks
  networks = self.data[:networks].values
  response(:body => { 'networks' => networks })
end

#request(params) ⇒ Object



70
71
72
# File 'lib/fog/rackspace/networking.rb', line 70

def request(params)
  Fog::Mock.not_implemented
end

#response(params = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/rackspace/networking.rb', line 74

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