Class: Fog::HP::Network::Mock

Inherits:
Object
  • Object
show all
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/update_port.rb,
lib/fog/hp/requests/network/delete_port.rb,
lib/fog/hp/requests/network/create_port.rb,
lib/fog/hp/requests/network/get_network.rb,
lib/fog/hp/requests/network/list_subnets.rb,
lib/fog/hp/requests/network/list_routers.rb,
lib/fog/hp/requests/network/list_networks.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/update_subnet.rb,
lib/fog/hp/requests/network/update_router.rb,
lib/fog/hp/requests/network/delete_subnet.rb,
lib/fog/hp/requests/network/delete_network.rb,
lib/fog/hp/requests/network/create_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/delete_floating_ip.rb,
lib/fog/hp/requests/network/create_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/delete_security_group.rb,
lib/fog/hp/requests/network/create_security_group.rb,
lib/fog/hp/requests/network/associate_floating_ip.rb,
lib/fog/hp/requests/network/remove_router_interface.rb,
lib/fog/hp/requests/network/get_security_group_rule.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

Constructor Details

#initialize(options = {}) ⇒ Mock



103
104
105
# File 'lib/fog/hp/network.rb', line 103

def initialize(options={})
  @hp_access_key = options[:hp_access_key]
end

Class Method Details

.dataObject



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

.resetObject



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, options = {})
  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, options = {})
  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'    => options[: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, options = {})
  response = Excon::Response.new
  response.status = 201
  data = {
    'id'                  => Fog::HP::Mock.uuid.to_s,
    'floating_network_id' => floating_network_id,
    'port_id'             => options[:port_id] || nil,
    'tenant_id'           => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s,
    'fixed_ip_address'    => options[:fixed_ip_address] || nil,
    'floating_ip_address' => options[: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(options = {})
  response = Excon::Response.new
  response.status = 201
  data = {
    'id'              => Fog::HP::Mock.uuid.to_s,
    'name'            => options[:name] || "",
    'tenant_id'       => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s,
    'status'          => 'ACTIVE',
    'subnets'         => [],
    'router:external' => false,
    'admin_state_up'  => options[:admin_state_up] || true,
    'shared'          => options[: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, options = {})
  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'           => options[:name] || "",
      'network_id'     => network_id,
      'fixed_ips'      => options[:fixed_ips] || [{'subnet_id' => "#{Fog::HP::Mock.uuid.to_s}", 'ip_address' => "#{Fog::HP::Mock.ip_address.to_s}"}],
      'mac_address'    => options[:mac_address] || Fog::HP::Mock.mac_address.to_s,
      'status'         => 'ACTIVE',
      'admin_state_up' => options[:admin_state_up] || true,
      'binding:vif_type'  => 'other',
      'device_owner'   => options[:device_owner] || "",
      'device_id'      => options[:device_id] || "",
      'security_groups'  => ["#{Fog::HP::Mock.uuid.to_s}"],
      'tenant_id'      => options[: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(options = {})
  response = Excon::Response.new
  response.status = 201
  data = {
    'id'                    => Fog::HP::Mock.uuid.to_s,
    'name'                  => options[:name] || "",
    'status'                => 'ACTIVE',
    'external_gateway_info' => options[:external_gateway_info] || nil,
    'admin_state_up'        => options[:admin_state_up] || true,
    'tenant_id'             => options[: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(options = {})
  # 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'         => options[:name] || "",
    'description'  => options[: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, options = {})
  response = Excon::Response.new
  data = {
    "id" => Fog::HP::Mock.uuid.to_s,
    "remote_group_id"   => options[:remote_group_id],
    "direction"         => direction,
    "remote_ip_prefix"  => options[:remote_ip_prefix],
    "protocol"          => options[:protocol],
    "ethertype"         => options[:ethertype] || "IPv4",
    "tenant_id"         => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s,
    "port_range_max"    => options[:port_range_max],
    "port_range_min"    => options[: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, options = {})
  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'             => options[:name] || "",
      'network_id'       => network_id,
      'cidr'             => cidr,
      'ip_version'       => ip_version,
      'gateway_ip'       => options[:gateway_ip] || Fog::HP::Mock.ip_address.to_s,
      'allocation_pools' => options[:allocation_pools] || [{"start" => "#{Fog::HP::Mock.ip_address.to_s}", "end" => "#{Fog::HP::Mock.ip_address.to_s}"}],
      'dns_nameservers'  => options[:dns_nameservers] || [],
      'host_routes'      => options[:host_routes] || [],
      'enable_dhcp'      => options[:enable_dhcp] || true,
      'tenant_id'        => options[: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

#dataObject



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, options = {})
  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(options = {})
  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(options = {})
  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(options = {})
  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(options = {})
  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(options = {})
  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(options = {})
  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(options = {})
  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, options = {})
  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_dataObject



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, options = {})
  response = Excon::Response.new
  if network = list_networks.body['networks'].find {|_| _['id'] == network_id}
    network['name']           = options[:name]
    network['shared']         = options[:shared]
    network['admin_state_up'] = options[: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, options = {})
  response = Excon::Response.new
  if port = list_ports.body['ports'].find { |_| _['id'] == port_id }
    port['name']           = options[:name]
    port['fixed_ips']      = options[:fixed_ips]
    port['device_owner']   = options[:device_owner]
    port['device_id']      = options[:device_id]
    port['admin_state_up'] = options[: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, options = {})
  response = Excon::Response.new
  if router = list_routers.body['routers'].find {|_| _['id'] == router_id}
    router['name']                  = options[:name]
    router['admin_state_up']        = options[:admin_state_up]
    router['external_gateway_info'] = options[: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, options = {})
  response = Excon::Response.new
  if subnet = list_subnets.body['subnets'].find {|_| _['id'] == subnet_id}
    subnet['name']            = options[:name]
    subnet['gateway_ip']      = options[:gateway_ip]
    subnet['dns_nameservers'] = options[:dns_nameservers]
    subnet['host_routes']     = options[:host_routes]
    subnet['enable_dhcp']     = options[:enable_dhcp]
    response.body = { 'subnet' => subnet }
    response.status = 200
    response
  else
    raise Fog::HP::Network::NotFound
  end
end