@@ -97,6 +97,10 @@ class NetmikoSwitch(devices.GenericSwitchDevice):
9797
9898 SAVE_CONFIGURATION = None
9999
100+ SET_NATIVE_VLAN = None
101+
102+ ALLOW_NETWORK_ON_TRUNK = None
103+
100104 ERROR_MSG_PATTERNS = ()
101105 """Sequence of error message patterns.
102106
@@ -283,6 +287,28 @@ def del_network(self, segmentation_id, network_id):
283287 network_name = network_name )
284288 return self .send_commands_to_device (cmds )
285289
290+ @check_output ('plug port trunk' )
291+ def plug_port_to_network_trunk (self , port , segmentation_id ,
292+ trunk_details = None , vtr = False ):
293+ cmd_set = []
294+ vts = self .ngs_config .get ('vlan_translation_supported' , False )
295+ # NOTE(vsaienko) Always use vlan translation if it is supported.
296+ if vts :
297+ cmd_set .extend (self .get_trunk_port_cmds_vlan_translation (
298+ port , segmentation_id , trunk_details ))
299+ else :
300+ if vtr :
301+ msg = ("Cannot bind_port VLAN aware port as switch %s "
302+ "doesn't support VLAN translation. "
303+ "But it is required." ) % self .config ['ip' ]
304+ raise exc .GenericSwitchNotSupported (error = msg )
305+ else :
306+ cmd_set .extend (
307+ self .get_trunk_port_cmds_no_vlan_translation (
308+ port , segmentation_id , trunk_details ))
309+
310+ self .send_commands_to_device (cmd_set )
311+
286312 @check_output ('plug port' )
287313 def plug_port_to_network (self , port , segmentation_id ):
288314 cmds = []
@@ -424,3 +450,22 @@ def check_output(self, output, operation):
424450 raise exc .GenericSwitchNetmikoConfigError (
425451 config = device_utils .sanitise_config (self .config ),
426452 error = msg )
453+
454+ def get_trunk_port_cmds_no_vlan_translation (self , port_id ,
455+ segmentation_id ,
456+ trunk_details ):
457+ cmd_set = []
458+ cmd_set .extend (
459+ self ._format_commands (self .SET_NATIVE_VLAN ,
460+ port = port_id ,
461+ segmentation_id = segmentation_id ))
462+ for sub_port in trunk_details .get ('sub_ports' ):
463+ cmd_set .extend (
464+ self ._format_commands (
465+ self .ALLOW_NETWORK_ON_TRUNK , port = port_id ,
466+ segmentation_id = sub_port ['segmentation_id' ]))
467+ return cmd_set
468+
469+ def get_trunk_port_cmds_vlan_translation (self , port_id , segmentation_id ,
470+ trunk_details ):
471+ pass
0 commit comments