Class: Fog::Network::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::Network::OpenStack::Mock
- Defined in:
- lib/fog/openstack/network.rb,
lib/fog/openstack/requests/network/get_port.rb,
lib/fog/openstack/requests/network/get_subnet.rb,
lib/fog/openstack/requests/network/list_ports.rb,
lib/fog/openstack/requests/network/set_tenant.rb,
lib/fog/openstack/requests/network/create_port.rb,
lib/fog/openstack/requests/network/delete_port.rb,
lib/fog/openstack/requests/network/get_network.rb,
lib/fog/openstack/requests/network/update_port.rb,
lib/fog/openstack/requests/network/list_subnets.rb,
lib/fog/openstack/requests/network/create_subnet.rb,
lib/fog/openstack/requests/network/delete_subnet.rb,
lib/fog/openstack/requests/network/list_networks.rb,
lib/fog/openstack/requests/network/update_subnet.rb,
lib/fog/openstack/requests/network/create_network.rb,
lib/fog/openstack/requests/network/delete_network.rb,
lib/fog/openstack/requests/network/update_network.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_network(options = {}) ⇒ Object
- #create_port(network_id, options = {}) ⇒ Object
- #create_subnet(network_id, cidr, ip_version, options = {}) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #delete_network(network_id) ⇒ Object
- #delete_port(port_id) ⇒ Object
- #delete_subnet(subnet_id) ⇒ Object
- #get_network(network_id) ⇒ Object
- #get_port(port_id) ⇒ Object
- #get_subnet(subnet_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_networks(filters = {}) ⇒ Object
- #list_ports(filters = {}) ⇒ Object
- #list_subnets(filters = {}) ⇒ Object
- #reset_data ⇒ Object
- #set_tenant(tenant) ⇒ Object
- #update_network(network_id, options = {}) ⇒ Object
- #update_port(port_id, options = {}) ⇒ Object
- #update_subnet(subnet_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
66 67 68 69 |
# File 'lib/fog/openstack/network.rb', line 66 def initialize(={}) @openstack_username = [:openstack_username] @openstack_tenant = [:openstack_tenant] end |
Class Method Details
.data ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/fog/openstack/network.rb', line 52 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :networks => {}, :ports => {}, :subnets => {}, } end end |
.reset ⇒ Object
62 63 64 |
# File 'lib/fog/openstack/network.rb', line 62 def self.reset @data = nil end |
Instance Method Details
#create_network(options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/openstack/requests/network/create_network.rb', line 24 def create_network( = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => [:name], 'shared' => [:shared], 'subnets' => [], 'status' => 'ACTIVE', 'admin_state_up' => [:admin_state_up], 'tenant_id' => [:tenant_id], } self.data[:networks][data['id']] = data response.body = { 'network' => data } response end |
#create_port(network_id, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/openstack/requests/network/create_port.rb', line 29 def create_port(network_id, = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => [:name], 'network_id' => network_id, 'fixed_ips' => [:fixed_ips], 'mac_address' => [:mac_address], 'status' => 'ACTIVE', 'admin_state_up' => [:admin_state_up], 'device_owner' => [:device_owner], 'device_id' => [:device_id], 'tenant_id' => [:tenant_id], } self.data[:ports][data['id']] = data response.body = { 'port' => data } response end |
#create_subnet(network_id, cidr, ip_version, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fog/openstack/requests/network/create_subnet.rb', line 32 def create_subnet(network_id, cidr, ip_version, = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::Mock.random_numbers(6).to_s, 'name' => [:name], 'network_id' => network_id, 'cidr' => cidr, 'ip_version' => ip_version, 'gateway_ip' => [:gateway_ip], 'allocation_pools' => [:allocation_pools], 'dns_nameservers' => [:dns_nameservers], 'host_routes' => [:host_routes], 'enable_dhcp' => [:enable_dhcp], 'tenant_id' => [:tenant_id], } self.data[:subnets][data['id']] = data response.body = { 'subnet' => data } response end |
#credentials ⇒ Object
79 80 81 82 83 84 |
# File 'lib/fog/openstack/network.rb', line 79 def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url } end |
#data ⇒ Object
71 72 73 |
# File 'lib/fog/openstack/network.rb', line 71 def data self.class.data["#{@openstack_username}-#{@openstack_tenant}"] end |
#delete_network(network_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/network/delete_network.rb', line 16 def delete_network(network_id) response = Excon::Response.new if list_networks.body['networks'].map { |r| r['id'] }.include? network_id self.data[:networks].delete(network_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end |
#delete_port(port_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/network/delete_port.rb', line 16 def delete_port(port_id) response = Excon::Response.new if list_ports.body['ports'].map { |r| r['id'] }.include? port_id self.data[:ports].delete(port_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end |
#delete_subnet(subnet_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/openstack/requests/network/delete_subnet.rb', line 16 def delete_subnet(subnet_id) response = Excon::Response.new if list_subnets.body['subnets'].map { |r| r['id'] }.include? subnet_id self.data[:subnets].delete(subnet_id) response.status = 204 response else raise Fog::Network::OpenStack::NotFound end end |
#get_network(network_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/openstack/requests/network/get_network.rb', line 16 def get_network(network_id) response = Excon::Response.new if data = self.data[:networks][network_id] response.status = 200 response.body = { 'network' => { 'id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb', 'name' => 'network_1', 'subnets' => [ '2e4ec6a4-0150-47f5-8523-e899ac03026e' ], 'shared' => false, 'status' => 'ACTIVE', 'admin_state_up' => true, 'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9', } } response else raise Fog::Network::OpenStack::NotFound end end |
#get_port(port_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/openstack/requests/network/get_port.rb', line 16 def get_port(port_id) response = Excon::Response.new if data = self.data[:ports][port_id] response.status = 200 response.body = { 'port' => { 'id' => '5c81d975-5fea-4674-9c1f-b8aa10bf9a79', 'name' => 'port_1', 'network_id' => 'e624a36d-762b-481f-9b50-4154ceb78bbb', 'fixed_ips' => [ { 'ip_address' => '10.2.2.2', 'subnet_id' => '2e4ec6a4-0150-47f5-8523-e899ac03026e', } ], 'mac_address' => 'fa:16:3e:62:91:7f', 'status' => 'ACTIVE', 'admin_state_up' => true, 'device_id' => 'dhcp724fc160-2b2e-597e-b9ed-7f65313cd73f-e624a36d-762b-481f-9b50-4154ceb78bbb', 'device_owner' => 'network:dhcp', 'tenant_id' => 'f8b26a6032bc47718a7702233ac708b9', } } response else raise Fog::Network::OpenStack::NotFound end end |
#get_subnet(subnet_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/openstack/requests/network/get_subnet.rb', line 16 def get_subnet(subnet_id) response = Excon::Response.new if data = self.data[:subnets][subnet_id] response.status = 200 response.body = { "subnet" => { "id" => "2e4ec6a4-0150-47f5-8523-e899ac03026e", "name" => "subnet_1", "network_id" => "e624a36d-762b-481f-9b50-4154ceb78bbb", "cidr" => "10.2.2.0/24", "ip_version" => 4, "gateway_ip" => "10.2.2.1", "allocation_pools" => [ { "start" => "10.2.2.2", "end" => "10.2.2.254" } ], "dns_nameservers" => [], "host_routes" => [], "enable_dhcp" => true, "tenant_id" => "f8b26a6032bc47718a7702233ac708b9", } } response else raise Fog::Network::OpenStack::NotFound end end |
#list_networks(filters = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fog/openstack/requests/network/list_networks.rb', line 17 def list_networks(filters = {}) Excon::Response.new( :body => { 'networks' => self.data[:networks].values }, :status => 200 ) end |
#list_ports(filters = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fog/openstack/requests/network/list_ports.rb', line 17 def list_ports(filters = {}) Excon::Response.new( :body => { 'ports' => self.data[:ports].values }, :status => 200 ) end |
#list_subnets(filters = {}) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fog/openstack/requests/network/list_subnets.rb', line 17 def list_subnets(filters = {}) Excon::Response.new( :body => { 'subnets' => self.data[:subnets].values }, :status => 200 ) end |
#reset_data ⇒ Object
75 76 77 |
# File 'lib/fog/openstack/network.rb', line 75 def reset_data self.class.data.delete("#{@openstack_username}-#{@openstack_tenant}") end |
#set_tenant(tenant) ⇒ Object
14 15 16 |
# File 'lib/fog/openstack/requests/network/set_tenant.rb', line 14 def set_tenant(tenant) true end |
#update_network(network_id, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/openstack/requests/network/update_network.rb', line 24 def update_network(network_id, = {}) response = Excon::Response.new if network = list_networks.body['networks'].detect { |_| _['id'] == network_id } network['name'] = [:name] network['shared'] = [:shared] network['admin_state_up'] = [:admin_state_up] response.body = { 'network' => network } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end |
#update_port(port_id, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/openstack/requests/network/update_port.rb', line 25 def update_port(port_id, = {}) response = Excon::Response.new if port = list_ports.body['ports'].detect { |_| _['id'] == port_id } port['name'] = [:name] port['fixed_ips'] = [:fixed_ips] port['admin_state_up'] = [:admin_state_up] port['device_owner'] = [:device_owner] port['device_id'] = [:device_id] response.body = { 'port' => port } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end |
#update_subnet(subnet_id, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fog/openstack/requests/network/update_subnet.rb', line 25 def update_subnet(subnet_id, = {}) response = Excon::Response.new if subnet = list_subnets.body['subnets'].detect { |_| _['id'] == subnet_id } subnet['name'] = [:name] subnet['gateway_ip'] = [:gateway_ip] subnet['dns_nameservers'] = [:dns_nameservers] subnet['host_routes'] = [:host_routes] subnet['enable_dhcp'] = [:enable_dhcp] response.body = { 'subnet' => subnet } response.status = 200 response else raise Fog::Network::OpenStack::NotFound end end |