Class: VRouter5600

Inherits:
NetconfNode show all
Defined in:
lib/netconfdev/vrouter/vrouter5600.rb

Overview

Class that represents a VRouter 5600 device.

Instance Attribute Summary

Attributes inherited from NetconfNode

#ip, #password, #port, #tcp_only, #username

Attributes inherited from Node

#name

Instance Method Summary collapse

Methods inherited from NetconfNode

#initialize, #to_hash

Methods inherited from Node

#initialize

Constructor Details

This class inherits a constructor from NetconfNode

Instance Method Details

#create_firewall_instance(firewall) ⇒ Object

Create a firewall on the VRouter5600.

Parameters

  • firewall

    Firewall : firewall object describing the firewall to be created.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ).

Raises:

  • (ArgumentError)


117
118
119
120
121
122
123
124
125
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 117

def create_firewall_instance(firewall)
  raise ArgumentError, "Firewall must be instance of 'Firewall'" unless firewall.is_a?(Firewall)
  post_uri = @controller.get_ext_mount_config_uri(self)
  response = @controller.rest_agent.post_request(post_uri, firewall.to_hash,
    headers: {'Content-Type' => 'application/yang.data+json'})
  check_response_for_success(response) do
    NetconfResponse.new(NetconfResponseStatus::OK)
  end
end

#delete_dataplane_interface_firewall(interface_name) ⇒ Object

Delete both inbound and outbound firewalls for a dataplane interface on the VRouter 5600.

Parameters

  • interface_name

    String : name of the dataplane interface to detach firewalls from.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and error details (if status is error).



292
293
294
295
296
297
298
299
300
301
302
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 292

def delete_dataplane_interface_firewall(interface_name)
  delete_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-interfaces:interfaces/vyatta-interfaces-dataplane:dataplane/"\
    "#{interface_name}/vyatta-security-firewall:firewall"
  response = @controller.rest_agent.delete_request(delete_uri)
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end

#delete_firewall_instance(firewall_or_name) ⇒ Object

Delete a firewall from the VRouter5600.

Parameters

  • firewall_or_name

    Firewall or String : A Firewall object or name of firewall for which you want to remove from vRouter5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and error info if an error.



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 134

def delete_firewall_instance(firewall_or_name)
  firewall_name = firewall_or_name.is_a?(Firewall) ? firewall_or_name.rules.name :
    firewall_or_name
  delete_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-security:security/vyatta-security-firewall:firewall/name/"\
    "#{firewall_name}"
  response = @controller.rest_agent.delete_request(delete_uri)
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end

#get_cfgObject

Return configuration of the VRouter5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and configuration of VRouter5600.



69
70
71
72
73
74
75
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 69

def get_cfg
  get_uri = @controller.get_ext_mount_config_uri(self)
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_dataplane_interface_cfg(interface_name) ⇒ Object

Return the configuration for a dataplane interface on the VRouter5600

Parameters

  • interface_name

    String : name of the dataplane interface from #get_dataplane_interfaces_list

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and configuration of the requested dataplane interface.



194
195
196
197
198
199
200
201
202
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 194

def get_dataplane_interface_cfg(interface_name)
  get_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-interfaces:interfaces/vyatta-interfaces-dataplane:dataplane/"\
    "#{interface_name}"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_dataplane_interfaces_cfgObject

Return the configuration for the dataplane interfaces on the VRouter5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and the configuration of the dataplane interfaces.



174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 174

def get_dataplane_interfaces_cfg
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash) &&
        body['interfaces'].has_key?('vyatta-interfaces-dataplane:dataplane')
      NetconfResponse.new(NetconfResponseStatus::OK,
        body['interfaces']['vyatta-interfaces-dataplane:dataplane'])
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_dataplane_interfaces_listObject

Return a list of interfaces on the VRouter5600

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and a list of datapath interfaces.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 153

def get_dataplane_interfaces_list
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash) &&
        body['interfaces'].has_key?('vyatta-interfaces-dataplane:dataplane')
      dp_interface_list = []
      body['interfaces']['vyatta-interfaces-dataplane:dataplane'].each do |interface|
        dp_interface_list << interface['tagnode']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, dp_interface_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_firewall_instance_cfg(firewall_or_name) ⇒ Object

Return configuration for a specific firewall on the VRouter5600.

Parameters

  • firewall_or_name

    Firewall or String : A Firewall object or name of firewall for which you want the configuration.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and configuration of requested firewall.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 98

def get_firewall_instance_cfg(firewall_or_name)
  firewall_name = firewall_or_name.is_a?(Firewall) ? firewall_or_name.rules.name :
    firewall_or_name 
  get_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-security:security/vyatta-security-firewall:firewall/name/"\
    "#{firewall_name}"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_firewalls_cfgObject

Return firewall configuration of the VRouter5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and Firewall configuration JSON.



82
83
84
85
86
87
88
89
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 82

def get_firewalls_cfg
  get_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-security:security/vyatta-security-firewall:firewall"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_interfaces_cfgObject

Return the configuration for the interfaces on the VRouter 5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and configuration for interfaces.



331
332
333
334
335
336
337
338
339
340
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 331

def get_interfaces_cfg
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash)
      NetconfResponse.new(NetconfResponseStatus::OK, body)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_interfaces_listObject

Get the list of interfaces on the VRouter 5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and list of all interfaces.



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 309

def get_interfaces_list
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash)
      if_list = []
      body['interfaces'].each do |if_name, interfaces|
        interfaces.each do |interface|
          if_list << interface['tagnode']
        end
      end
      NetconfResponse.new(NetconfResponseStatus::OK, if_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_loopback_interface_cfg(interface_name) ⇒ Object

Return the configuration for a single loopback interface on the VRouter 5600.

Parameters

  • interface_name

    String : name of the loopback interface from the #get_loopback_interfaces_list

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and configuration for the requested loopback interface.



248
249
250
251
252
253
254
255
256
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 248

def get_loopback_interface_cfg(interface_name)
  get_uri = "#{@controller.get_ext_mount_config_uri(self)}/"\
    "vyatta-interfaces:interfaces/vyatta-interfaces-loopback:loopback/"\
    "#{interface_name}"
  response = @controller.rest_agent.get_request(get_uri)
  check_response_for_success(response) do |body|
    NetconfResponse.new(NetconfResponseStatus::OK, body)
  end
end

#get_loopback_interfaces_cfgObject

Return the configuration for the loopback interfaces on the VRouter 5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and list of configurations of loopback interfaces.



230
231
232
233
234
235
236
237
238
239
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 230

def get_loopback_interfaces_cfg
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash) &&
        body['interfaces'].has_key?('vyatta-interfaces-loopback:loopback')
      NetconfResponse.new(NetconfResponseStatus::OK,
        body['interfaces']['vyatta-interfaces-loopback:loopback'])
    end
  end
end

#get_loopback_interfaces_listObject

Return a list of loopback interfaces on the VRouter5600

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and list of loopback interfaces.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 209

def get_loopback_interfaces_list
  response = get_interfaces_config
  check_response_for_success(response) do |body|
    if body.has_key?('interfaces') && body['interfaces'].is_a?(Hash) &&
        body['interfaces'].has_key?('vyatta-interfaces-loopback:loopback')
      lb_interface_list = []
      body['interfaces']['vyatta-interfaces-loopback:loopback'].each do |interface|
        lb_interface_list << interface['tagnode']
      end
      NetconfResponse.new(NetconfResponseStatus::OK, lb_interface_list)
    else
      NetconfResponse.new(NetconfResponseStatus::DATA_NOT_FOUND)
    end
  end
end

#get_schema(id: nil, version: nil) ⇒ Object

Return a YANG schema for the indicated schema on the VRouter5600.

Parameters

  • id

    String : Identifier for schema

  • version

    String : Version/date for schema

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and YANG schema.

Raises:

  • (ArgumentError)


57
58
59
60
61
62
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 57

def get_schema(id: nil, version: nil)
  raise ArgumentError, "Identifier (id) required" unless id
  raise ArgumentError, "Version (version) required" unless version
  
  @controller.get_schema(@name, id: id, version: version)
end

#get_schemasObject

Return a list of YANG schemas for this VRouter5600.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and list of YANG schemas for the node.



45
46
47
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 45

def get_schemas
  @controller.get_schemas(@name)
end

#set_dataplane_interface_firewall(interface_name, inbound_firewall_name: nil, outbound_firewall_name: nil) ⇒ Object

Set a firewall for inbound, outbound or both for a dataplane interface on the VRouter 5600.

Parameters

  • interface_name

    String : The dataplane interface to attach firewalls.

  • inbound_firewall_name

    String : [optional] name of firewall on VRouter5600 to use for traffic inbound towards router.

  • outbound_firewall_name

    String : [optional] name of firewall on VRouter5600 to use for traffic outbound from router.

Return Value

  • NetconfResponse : Status ( NetconfResponseStatus ) and YANG schema.

Raises:

  • (ArgumentError)


267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/netconfdev/vrouter/vrouter5600.rb', line 267

def set_dataplane_interface_firewall(interface_name,
    inbound_firewall_name: nil, outbound_firewall_name: nil)
  raise ArgumentError, "At least one firewall (inbound_firewall_name, "\
    "outbound_firewall_name) required" unless inbound_firewall_name || outbound_firewall_name
  dpif = DataplaneFirewall.new(interface_name: interface_name,
    in_firewall_name: inbound_firewall_name,
    out_firewall_name: outbound_firewall_name)
  
  put_uri = "#{@controller.get_ext_mount_config_uri(self)}/#{dpif.get_uri}"
  response = @controller.rest_agent.put_request(put_uri, dpif.to_hash,
    headers: {'Content-Type' => 'application/yang.data+json'})
  if response.code.to_i == 200
    NetconfResponse.new(NetconfResponseStatus::OK)
  else
    handle_error_response(response)
  end
end