Class: Fog::HP::Network::Mock
- Inherits:
-
Object
- Object
- Fog::HP::Network::Mock
- Includes:
- Utils
- Defined in:
- lib/fog/hp/network.rb,
lib/fog/hp/requests/network/get_port.rb,
lib/fog/hp/requests/network/get_router.rb,
lib/fog/hp/requests/network/get_subnet.rb,
lib/fog/hp/requests/network/list_ports.rb,
lib/fog/hp/requests/network/create_port.rb,
lib/fog/hp/requests/network/delete_port.rb,
lib/fog/hp/requests/network/get_network.rb,
lib/fog/hp/requests/network/update_port.rb,
lib/fog/hp/requests/network/list_routers.rb,
lib/fog/hp/requests/network/list_subnets.rb,
lib/fog/hp/requests/network/create_router.rb,
lib/fog/hp/requests/network/create_subnet.rb,
lib/fog/hp/requests/network/delete_router.rb,
lib/fog/hp/requests/network/delete_subnet.rb,
lib/fog/hp/requests/network/list_networks.rb,
lib/fog/hp/requests/network/update_router.rb,
lib/fog/hp/requests/network/update_subnet.rb,
lib/fog/hp/requests/network/create_network.rb,
lib/fog/hp/requests/network/delete_network.rb,
lib/fog/hp/requests/network/update_network.rb,
lib/fog/hp/requests/network/get_floating_ip.rb,
lib/fog/hp/requests/network/list_floating_ips.rb,
lib/fog/hp/requests/network/create_floating_ip.rb,
lib/fog/hp/requests/network/delete_floating_ip.rb,
lib/fog/hp/requests/network/get_security_group.rb,
lib/fog/hp/requests/network/add_router_interface.rb,
lib/fog/hp/requests/network/list_security_groups.rb,
lib/fog/hp/requests/network/associate_floating_ip.rb,
lib/fog/hp/requests/network/create_security_group.rb,
lib/fog/hp/requests/network/delete_security_group.rb,
lib/fog/hp/requests/network/get_security_group_rule.rb,
lib/fog/hp/requests/network/remove_router_interface.rb,
lib/fog/hp/requests/network/disassociate_floating_ip.rb,
lib/fog/hp/requests/network/list_security_group_rules.rb,
lib/fog/hp/requests/network/create_security_group_rule.rb,
lib/fog/hp/requests/network/delete_security_group_rule.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_router_interface(router_id, subnet_id = nil, port_id = nil, options = {}) ⇒ Object
- #associate_floating_ip(floating_ip_id, port_id, options = {}) ⇒ Object
- #create_floating_ip(floating_network_id, options = {}) ⇒ Object
- #create_network(options = {}) ⇒ Object
- #create_port(network_id, options = {}) ⇒ Object
- #create_router(options = {}) ⇒ Object
- #create_security_group(options = {}) ⇒ Object
- #create_security_group_rule(security_group_id, direction, options = {}) ⇒ Object
- #create_subnet(network_id, cidr, ip_version, options = {}) ⇒ Object
- #data ⇒ Object
- #delete_floating_ip(floating_ip_id) ⇒ Object
- #delete_network(network_id) ⇒ Object
- #delete_port(port_id) ⇒ Object
- #delete_router(router_id) ⇒ Object
- #delete_security_group(security_group_id) ⇒ Object
- #delete_security_group_rule(security_group_rule_id) ⇒ Object
- #delete_subnet(subnet_id) ⇒ Object
- #disassociate_floating_ip(floating_ip_id, options = {}) ⇒ Object
- #get_floating_ip(floating_ip_id) ⇒ Object
- #get_network(network_id) ⇒ Object
- #get_port(port_id) ⇒ Object
- #get_router(router_id) ⇒ Object
- #get_security_group(security_group_id) ⇒ Object
- #get_security_group_rule(security_group_rule_id) ⇒ Object
- #get_subnet(subnet_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_floating_ips(options = {}) ⇒ Object
- #list_networks(options = {}) ⇒ Object
- #list_ports(options = {}) ⇒ Object
- #list_routers(options = {}) ⇒ Object
- #list_security_group_rules(options = {}) ⇒ Object
- #list_security_groups(options = {}) ⇒ Object
- #list_subnets(options = {}) ⇒ Object
- #remove_router_interface(router_id, subnet_id = nil, port_id = nil, options = {}) ⇒ Object
- #reset_data ⇒ Object
- #update_network(network_id, options = {}) ⇒ Object
- #update_port(port_id, options = {}) ⇒ Object
- #update_router(router_id, options = {}) ⇒ Object
- #update_subnet(subnet_id, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
103 104 105 |
# File 'lib/fog/hp/network.rb', line 103 def initialize(={}) @hp_access_key = [:hp_access_key] end |
Class Method Details
.data ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fog/hp/network.rb', line 73 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :floating_ips => {}, :networks => { 'X0X0X0ExtNetX0X0X0' => { 'id' => 'X0X0X0ExtNetX0X0X0', 'name' => 'Mock-Ext-Net', 'tenant_id' => Fog::Mock.random_numbers(14).to_s, 'status' => 'ACTIVE', 'subnets' => [], 'router:external' => true, 'admin_state_up' => true, 'shared' => true } }, :ports => {}, :routers => {}, :security_groups => {}, :security_group_rules => {}, :subnets => {} } end end |
.reset ⇒ Object
99 100 101 |
# File 'lib/fog/hp/network.rb', line 99 def self.reset @data = nil end |
Instance Method Details
#add_router_interface(router_id, subnet_id = nil, port_id = nil, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/hp/requests/network/add_router_interface.rb', line 38 def add_router_interface(router_id, subnet_id=nil, port_id=nil, = {}) response = Excon::Response.new if list_routers.body['routers'].find {|_| _['id'] == router_id} # Either a subnet or a port can be passed, not both if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?) raise ArgumentError.new('Either a subnet or a port can be passed, not both') end if port_id.nil? # create a new port resp = create_port(self.data[:networks].keys[0], {:name => "New Port #{rand(10)}"}) port_id = resp.body['port']['id'] end data = { 'subnet_id' => subnet_id || Fog::HP::Mock.uuid.to_s, 'port_id' => port_id } # so either way if I pass a subnet or a port, # it basically adds the router uuid to the port's device_id # and sets device_owner to network:router_interface self.data[:ports][port_id]['device_id'] = router_id self.data[:ports][port_id]['device_owner'] = 'network:router_interface' response.status = 200 response.body = data response else raise Fog::HP::Network::NotFound end end |
#associate_floating_ip(floating_ip_id, port_id, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/hp/requests/network/associate_floating_ip.rb', line 45 def associate_floating_ip(floating_ip_id, port_id, = {}) response = Excon::Response.new if list_floating_ips.body['floatingips'].find {|_| _['id'] == floating_ip_id} response.status = 201 data = { 'id' => floating_ip_id, 'port_id' => port_id, 'router_id' => Fog::HP::Mock.uuid.to_s, 'tenant_id' => Fog::Mock.random_numbers(14).to_s, 'floating_network_id' => Fog::HP::Mock.uuid.to_s, 'fixed_ip_address' => [:fixed_ip_address] || Fog::HP::Mock.ip_address.to_s, 'floating_ip_address' => Fog::HP::Mock.ip_address.to_s } self.data[:floating_ips][data['id']] = data response.body = { 'floatingip' => data } response else raise Fog::HP::Network::NotFound end end |
#create_floating_ip(floating_network_id, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/hp/requests/network/create_floating_ip.rb', line 48 def create_floating_ip(floating_network_id, = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'floating_network_id' => floating_network_id, 'port_id' => [:port_id] || nil, 'tenant_id' => [:tenant_id] || Fog::Mock.random_numbers(14).to_s, 'fixed_ip_address' => [:fixed_ip_address] || nil, 'floating_ip_address' => [:floating_ip_address] || Fog::HP::Mock.ip_address.to_s, 'router_id' => Fog::HP::Mock.uuid.to_s } self.data[:floating_ips][data['id']] = data response.body = { 'floatingip' => data } response end |
#create_network(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/hp/requests/network/create_network.rb', line 45 def create_network( = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'name' => [:name] || "", 'tenant_id' => [:tenant_id] || Fog::Mock.random_numbers(14).to_s, 'status' => 'ACTIVE', 'subnets' => [], 'router:external' => false, 'admin_state_up' => [:admin_state_up] || true, 'shared' => [:shared] || false } self.data[:networks][data['id']] = data response.body = { 'network' => data } response end |
#create_port(network_id, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/fog/hp/requests/network/create_port.rb', line 62 def create_port(network_id, = {}) response = Excon::Response.new if list_networks.body['networks'].find {|_| _['id'] == network_id} response.status = 201 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'name' => [:name] || "", 'network_id' => network_id, 'fixed_ips' => [:fixed_ips] || [{'subnet_id' => "#{Fog::HP::Mock.uuid.to_s}", 'ip_address' => "#{Fog::HP::Mock.ip_address.to_s}"}], 'mac_address' => [:mac_address] || Fog::HP::Mock.mac_address.to_s, 'status' => 'ACTIVE', 'admin_state_up' => [:admin_state_up] || true, 'binding:vif_type' => 'other', 'device_owner' => [:device_owner] || "", 'device_id' => [:device_id] || "", 'security_groups' => ["#{Fog::HP::Mock.uuid.to_s}"], 'tenant_id' => [:tenant_id] || Fog::Mock.random_numbers(14).to_s } self.data[:ports][data['id']] = data response.body = { 'port' => data } response else raise Fog::HP::Network::NotFound end end |
#create_router(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/hp/requests/network/create_router.rb', line 44 def create_router( = {}) response = Excon::Response.new response.status = 201 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'name' => [:name] || "", 'status' => 'ACTIVE', 'external_gateway_info' => [:external_gateway_info] || nil, 'admin_state_up' => [:admin_state_up] || true, 'tenant_id' => [:tenant_id] || Fog::Mock.random_numbers(14).to_s } self.data[:routers][data['id']] = data response.body = { 'router' => data } response end |
#create_security_group(options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/hp/requests/network/create_security_group.rb', line 50 def create_security_group( = {}) # Spaces are NOT removed from name and description, as in case of compute sec groups tenant_id = Fog::Mock.random_numbers(14).to_s sec_group_id = Fog::HP::Mock.uuid.to_s response = Excon::Response.new response.status = 201 # by default every security group will come setup with an egress rule to "allow all out" data = { 'security_group_rules' => [ { "remote_group_id" => nil, "direction" => "egress", "remote_ip_prefix" => nil, "protocol" => nil, "ethertype" => "IPv4", "tenant_id" => tenant_id, "port_range_max" => nil, "port_range_min" => nil, "id" => Fog::HP::Mock.uuid.to_s, "security_group_id" => sec_group_id }, { "remote_group_id" => nil, "direction" => "egress", "remote_ip_prefix" => nil, "protocol" => nil, "ethertype" => "IPv6", "tenant_id" => tenant_id, "port_range_max" => nil, "port_range_min" => nil, "id" => Fog::HP::Mock.uuid.to_s, "security_group_id" => sec_group_id } ], 'id' => sec_group_id, 'tenant_id' => tenant_id, 'name' => [:name] || "", 'description' => [:description] || "" } self.data[:security_groups][data['id']] = data response.body = { 'security_group' => data } response end |
#create_security_group_rule(security_group_id, direction, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/hp/requests/network/create_security_group_rule.rb', line 56 def create_security_group_rule(security_group_id, direction, = {}) response = Excon::Response.new data = { "id" => Fog::HP::Mock.uuid.to_s, "remote_group_id" => [:remote_group_id], "direction" => direction, "remote_ip_prefix" => [:remote_ip_prefix], "protocol" => [:protocol], "ethertype" => [:ethertype] || "IPv4", "tenant_id" => [:tenant_id] || Fog::Mock.random_numbers(14).to_s, "port_range_max" => [:port_range_max], "port_range_min" => [:port_range_min], "security_group_id" => security_group_id } self.data[:security_group_rules][data['id']] = data response.status = 201 response.body = { 'security_group_rule' => data } response end |
#create_subnet(network_id, cidr, ip_version, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/hp/requests/network/create_subnet.rb', line 65 def create_subnet(network_id, cidr, ip_version, = {}) if list_networks.body['networks'].find {|_| _['id'] == network_id} response = Excon::Response.new response.status = 201 data = { 'id' => Fog::HP::Mock.uuid.to_s, 'name' => [:name] || "", 'network_id' => network_id, 'cidr' => cidr, 'ip_version' => ip_version, 'gateway_ip' => [:gateway_ip] || Fog::HP::Mock.ip_address.to_s, 'allocation_pools' => [:allocation_pools] || [{"start" => "#{Fog::HP::Mock.ip_address.to_s}", "end" => "#{Fog::HP::Mock.ip_address.to_s}"}], 'dns_nameservers' => [:dns_nameservers] || [], 'host_routes' => [:host_routes] || [], 'enable_dhcp' => [:enable_dhcp] || true, 'tenant_id' => [:tenant_id] || Fog::Mock.random_numbers(14).to_s } self.data[:subnets][data['id']] = data # add this subnet to the network self.data[:networks][network_id]['subnets'] << data['id'] response.body = { 'subnet' => data } response else raise Fog::HP::Network::NotFound end end |
#data ⇒ Object
107 108 109 |
# File 'lib/fog/hp/network.rb', line 107 def data self.class.data[@hp_access_key] end |
#delete_floating_ip(floating_ip_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_floating_ip.rb', line 19 def delete_floating_ip(floating_ip_id) response = Excon::Response.new if list_floating_ips.body['floatingips'].find {|_| _['id'] == floating_ip_id} self.data[:floating_ips].delete(floating_ip_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_network(network_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_network.rb', line 19 def delete_network(network_id) response = Excon::Response.new if list_networks.body['networks'].find {|_| _['id'] == network_id} self.data[:networks].delete(network_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_port(port_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_port.rb', line 19 def delete_port(port_id) response = Excon::Response.new if list_ports.body['ports'].find {|_| _['id'] == port_id} self.data[:ports].delete(port_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_router(router_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_router.rb', line 19 def delete_router(router_id) response = Excon::Response.new if list_routers.body['routers'].find {|_| _['id'] == router_id} self.data[:routers].delete(router_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_security_group(security_group_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_security_group.rb', line 19 def delete_security_group(security_group_id) response = Excon::Response.new if self.data[:security_groups][security_group_id] self.data[:security_groups].delete(security_group_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_security_group_rule(security_group_rule_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_security_group_rule.rb', line 19 def delete_security_group_rule(security_group_rule_id) response = Excon::Response.new if self.data[:security_group_rules][security_group_rule_id] self.data[:security_group_rules].delete(security_group_rule_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#delete_subnet(subnet_id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/hp/requests/network/delete_subnet.rb', line 19 def delete_subnet(subnet_id) response = Excon::Response.new if list_subnets.body['subnets'].find {|_| _['id'] == subnet_id} self.data[:subnets].delete(subnet_id) response.status = 204 response else raise Fog::HP::Network::NotFound end end |
#disassociate_floating_ip(floating_ip_id, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fog/hp/requests/network/disassociate_floating_ip.rb', line 45 def disassociate_floating_ip(floating_ip_id, = {}) response = Excon::Response.new if list_floating_ips.body['floatingips'].find {|_| _['id'] == floating_ip_id} response.status = 200 data = { 'id' => floating_ip_id, 'port_id' => nil, 'router_id' => Fog::HP::Mock.uuid.to_s, 'tenant_id' => Fog::Mock.random_numbers(14).to_s, 'floating_network_id' => Fog::HP::Mock.uuid.to_s, 'fixed_ip_address' => nil, 'floating_ip_address' => Fog::HP::Mock.ip_address.to_s } self.data[:floating_ips][data['id']] = data response.body = { 'floatingip' => data } response else raise Fog::HP::Network::NotFound end end |
#get_floating_ip(floating_ip_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/hp/requests/network/get_floating_ip.rb', line 31 def get_floating_ip(floating_ip_id) response = Excon::Response.new if floating_ip = list_floating_ips.body['floatingips'].find {|_| _['id'] == floating_ip_id} response.status = 200 response.body = { 'floatingip' => floating_ip } response else raise Fog::HP::Network::NotFound end end |
#get_network(network_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fog/hp/requests/network/get_network.rb', line 33 def get_network(network_id) response = Excon::Response.new if network = list_networks.body['networks'].find {|_| _['id'] == network_id} response.status = 200 response.body = { 'network' => network } response else raise Fog::HP::Network::NotFound end end |
#get_port(port_id) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/hp/requests/network/get_port.rb', line 38 def get_port(port_id) response = Excon::Response.new if port = list_ports.body['ports'].find {|_| _['id'] == port_id} response.status = 200 response.body = { 'port' => port } response else raise Fog::HP::Network::NotFound end end |
#get_router(router_id) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fog/hp/requests/network/get_router.rb', line 31 def get_router(router_id) response = Excon::Response.new if router = list_routers.body['routers'].find {|_| _['id'] == router_id} response.status = 200 response.body = { 'router' => router } response else raise Fog::HP::Network::NotFound end end |
#get_security_group(security_group_id) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fog/hp/requests/network/get_security_group.rb', line 39 def get_security_group(security_group_id) response = Excon::Response.new if sec_group = self.data[:security_groups][security_group_id] response.status = 200 response.body = { 'security_group' => sec_group } response else raise Fog::HP::Network::NotFound end end |
#get_security_group_rule(security_group_rule_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/hp/requests/network/get_security_group_rule.rb', line 34 def get_security_group_rule(security_group_rule_id) response = Excon::Response.new if sec_group_rule = self.data[:security_group_rules][security_group_rule_id] response.status = 200 response.body = { 'security_group_rule' => sec_group_rule } response else raise Fog::HP::Network::NotFound end end |
#get_subnet(subnet_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/hp/requests/network/get_subnet.rb', line 37 def get_subnet(subnet_id) response = Excon::Response.new if subnet = list_subnets.body['subnets'].find {|_| _['id'] == subnet_id} response.status = 200 response.body = { 'subnet' => subnet } response else raise Fog::HP::Network::NotFound end end |
#list_floating_ips(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/fog/hp/requests/network/list_floating_ips.rb', line 33 def list_floating_ips( = {}) response = Excon::Response.new floatingips = self.data[:floating_ips].values response.status = 200 response.body = { 'floatingips' => floatingips } response end |
#list_networks(options = {}) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/fog/hp/requests/network/list_networks.rb', line 47 def list_networks( = {}) response = Excon::Response.new networks = self.data[:networks].values response.status = 200 response.body = { 'networks' => networks } response end |
#list_ports(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/fog/hp/requests/network/list_ports.rb', line 39 def list_ports( = {}) response = Excon::Response.new ports = self.data[:ports].values response.status = 200 response.body = { 'ports' => ports } response end |
#list_routers(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/fog/hp/requests/network/list_routers.rb', line 32 def list_routers( = {}) response = Excon::Response.new routers = self.data[:routers].values response.status = 200 response.body = { 'routers' => routers } response end |
#list_security_group_rules(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/hp/requests/network/list_security_group_rules.rb', line 35 def list_security_group_rules( = {}) response = Excon::Response.new sec_group_rules = [] sec_group_rules = self.data[:security_group_rules].values unless self.data[:security_group_rules].nil? response.status = 200 response.body = { 'security_group_rules' => sec_group_rules } response end |
#list_security_groups(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/hp/requests/network/list_security_groups.rb', line 40 def list_security_groups( = {}) response = Excon::Response.new sec_groups = [] sec_groups = self.data[:security_groups].values unless self.data[:security_groups].nil? response.status = 200 response.body = { 'security_groups' => sec_groups } response end |
#list_subnets(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/fog/hp/requests/network/list_subnets.rb', line 38 def list_subnets( = {}) response = Excon::Response.new subnets = self.data[:subnets].values response.status = 200 response.body = { 'subnets' => subnets } response end |
#remove_router_interface(router_id, subnet_id = nil, port_id = nil, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/hp/requests/network/remove_router_interface.rb', line 38 def remove_router_interface(router_id, subnet_id=nil, port_id=nil, = {}) response = Excon::Response.new if list_routers.body['routers'].find {|_| _['id'] == router_id} # Either a subnet or a port can be passed, not both if (subnet_id && port_id) || (subnet_id.nil? && port_id.nil?) raise ArgumentError.new('Either a subnet or a port can be passed, not both') end # delete the port if port_id delete_port(port_id) elsif subnet_id ports = self.data[:ports].select {|p| self.data[:ports]["#{p}"]['device_id'] == router_id } #&& self.data[:ports]["#{p}"]['network_id'] == self.data[:subnets][subnet_id]['network_id']} ports.each do |key, _| delete_port(key) end end response.status = 200 response else raise Fog::HP::Network::NotFound end end |
#reset_data ⇒ Object
111 112 113 |
# File 'lib/fog/hp/network.rb', line 111 def reset_data self.class.data.delete(@hp_access_key) end |
#update_network(network_id, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/hp/requests/network/update_network.rb', line 44 def update_network(network_id, = {}) response = Excon::Response.new if network = list_networks.body['networks'].find {|_| _['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::HP::Network::NotFound end end |
#update_port(port_id, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fog/hp/requests/network/update_port.rb', line 55 def update_port(port_id, = {}) response = Excon::Response.new if port = list_ports.body['ports'].find { |_| _['id'] == port_id } port['name'] = [:name] port['fixed_ips'] = [:fixed_ips] port['device_owner'] = [:device_owner] port['device_id'] = [:device_id] port['admin_state_up'] = [:admin_state_up] response.body = { 'port' => port } response.status = 200 response else raise Fog::HP::Network::NotFound end end |
#update_router(router_id, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fog/hp/requests/network/update_router.rb', line 44 def update_router(router_id, = {}) response = Excon::Response.new if router = list_routers.body['routers'].find {|_| _['id'] == router_id} router['name'] = [:name] router['admin_state_up'] = [:admin_state_up] router['external_gateway_info'] = [:external_gateway_info] response.body = { 'router' => router } response.status = 200 response else raise Fog::HP::Network::NotFound end end |
#update_subnet(subnet_id, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/hp/requests/network/update_subnet.rb', line 52 def update_subnet(subnet_id, = {}) response = Excon::Response.new if subnet = list_subnets.body['subnets'].find {|_| _['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::HP::Network::NotFound end end |