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/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

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



105
106
107
# File 'lib/fog/hp/network.rb', line 105

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

Class Method Details

.dataObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fog/hp/network.rb', line 75

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



101
102
103
# File 'lib/fog/hp/network.rb', line 101

def self.reset
  @data = nil
end

Instance Method Details

#add_router_interface(router_id, subnet_id = nil, port_id = nil, options = {}) ⇒ Object



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
70
# File 'lib/fog/hp/requests/network/add_router_interface.rb', line 39

def add_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
  response = Excon::Response.new
  if list_routers.body['routers'].detect {|_| _['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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/hp/requests/network/associate_floating_ip.rb', line 46

def associate_floating_ip(floating_ip_id, port_id, options = {})
  response = Excon::Response.new
  if list_floating_ips.body['floatingips'].detect {|_| _['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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fog/hp/requests/network/create_floating_ip.rb', line 49

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/hp/requests/network/create_network.rb', line 47

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



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
# File 'lib/fog/hp/requests/network/create_port.rb', line 63

def create_port(network_id, options = {})
  response = Excon::Response.new
  if list_networks.body['networks'].detect {|_| _['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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/hp/requests/network/create_router.rb', line 45

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



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
92
93
94
# File 'lib/fog/hp/requests/network/create_security_group.rb', line 53

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/hp/requests/network/create_security_group_rule.rb', line 59

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



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
92
# File 'lib/fog/hp/requests/network/create_subnet.rb', line 66

def create_subnet(network_id, cidr, ip_version, options = {})
  if list_networks.body['networks'].detect {|_| _['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



109
110
111
# File 'lib/fog/hp/network.rb', line 109

def data
  self.class.data[@hp_access_key]
end

#delete_floating_ip(floating_ip_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/network/delete_floating_ip.rb', line 20

def delete_floating_ip(floating_ip_id)
  response = Excon::Response.new
  if list_floating_ips.body['floatingips'].detect {|_| _['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



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/network/delete_network.rb', line 20

def delete_network(network_id)
  response = Excon::Response.new
  if list_networks.body['networks'].detect {|_| _['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



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/network/delete_port.rb', line 20

def delete_port(port_id)
  response = Excon::Response.new
  if list_ports.body['ports'].detect {|_| _['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



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/network/delete_router.rb', line 20

def delete_router(router_id)
  response = Excon::Response.new
  if list_routers.body['routers'].detect {|_| _['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



22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/hp/requests/network/delete_security_group.rb', line 22

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/hp/requests/network/delete_security_group_rule.rb', line 22

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



20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/hp/requests/network/delete_subnet.rb', line 20

def delete_subnet(subnet_id)
  response = Excon::Response.new
  if list_subnets.body['subnets'].detect {|_| _['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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/hp/requests/network/disassociate_floating_ip.rb', line 46

def disassociate_floating_ip(floating_ip_id, options = {})
  response = Excon::Response.new
  if list_floating_ips.body['floatingips'].detect {|_| _['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



32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/hp/requests/network/get_floating_ip.rb', line 32

def get_floating_ip(floating_ip_id)
  response = Excon::Response.new
  if floating_ip = list_floating_ips.body['floatingips'].detect {|_| _['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



35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/hp/requests/network/get_network.rb', line 35

def get_network(network_id)
  response = Excon::Response.new
  if network = list_networks.body['networks'].detect {|_| _['id'] == network_id}
    response.status = 200
    response.body = { 'network' => network }
    response
  else
    raise Fog::HP::Network::NotFound
  end
end

#get_port(port_id) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/fog/hp/requests/network/get_port.rb', line 39

def get_port(port_id)
  response = Excon::Response.new
  if port = list_ports.body['ports'].detect {|_| _['id'] == port_id}
    response.status = 200
    response.body = { 'port' => port }
    response
  else
    raise Fog::HP::Network::NotFound
  end
end

#get_router(router_id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/hp/requests/network/get_router.rb', line 32

def get_router(router_id)
  response = Excon::Response.new
  if router = list_routers.body['routers'].detect {|_| _['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



42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/hp/requests/network/get_security_group.rb', line 42

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



37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/hp/requests/network/get_security_group_rule.rb', line 37

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



38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/hp/requests/network/get_subnet.rb', line 38

def get_subnet(subnet_id)
  response = Excon::Response.new
  if subnet = list_subnets.body['subnets'].detect {|_| _['id'] == subnet_id}
    response.status = 200
    response.body = { 'subnet' => subnet }
    response
  else
    raise Fog::HP::Network::NotFound
  end
end

#list_floating_ips(options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/fog/hp/requests/network/list_floating_ips.rb', line 34

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



36
37
38
39
40
41
42
43
# File 'lib/fog/hp/requests/network/list_networks.rb', line 36

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



40
41
42
43
44
45
46
47
# File 'lib/fog/hp/requests/network/list_ports.rb', line 40

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



33
34
35
36
37
38
39
40
# File 'lib/fog/hp/requests/network/list_routers.rb', line 33

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



38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/hp/requests/network/list_security_group_rules.rb', line 38

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



43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/hp/requests/network/list_security_groups.rb', line 43

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



39
40
41
42
43
44
45
46
# File 'lib/fog/hp/requests/network/list_subnets.rb', line 39

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/hp/requests/network/remove_router_interface.rb', line 39

def remove_router_interface(router_id, subnet_id=nil, port_id=nil, options = {})
  response = Excon::Response.new
  if list_routers.body['routers'].detect {|_| _['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



113
114
115
# File 'lib/fog/hp/network.rb', line 113

def reset_data
  self.class.data.delete(@hp_access_key)
end

#update_network(network_id, options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/hp/requests/network/update_network.rb', line 45

def update_network(network_id, options = {})
  response = Excon::Response.new
  if network = list_networks.body['networks'].detect {|_| _['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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/hp/requests/network/update_port.rb', line 56

def update_port(port_id, options = {})
  response = Excon::Response.new
  if port = list_ports.body['ports'].detect { |_| _['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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/hp/requests/network/update_router.rb', line 45

def update_router(router_id, options = {})
  response = Excon::Response.new
  if router = list_routers.body['routers'].detect {|_| _['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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fog/hp/requests/network/update_subnet.rb', line 53

def update_subnet(subnet_id, options = {})
  response = Excon::Response.new
  if subnet = list_subnets.body['subnets'].detect {|_| _['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