@ -212,6 +212,7 @@ changed:
sample : true
'''
import re
from ansible . module_utils . basic import AnsibleModule
from ansible . module_utils . network . cloudengine . ce import load_config
from ansible . module_utils . network . cloudengine . ce import get_connection , rm_config_prefix
@ -252,6 +253,7 @@ def get_config(module, flags):
""" Retrieves the current config from the device or cache
"""
time_stamp_regex = re . compile ( r ' \ s* \ d {4} - \ d { 1,2}- \ d { 1,2} \ s+ \ d {2} \ : \ d {2} \ : \ d {2} \ . \ d+ \ s* ' )
flags = [ ] if flags is None else flags
if isinstance ( flags , str ) :
flags = [ flags ]
@ -271,13 +273,14 @@ def get_config(module, flags):
if " include-default " in flag :
cfg = rm_config_prefix ( cfg )
break
if cfg . startswith ( ' display ' ) :
lines = cfg . split ( ' \n ' )
lines = [ l for l in lines if time_stamp_regex . match ( l ) is None ]
if cfg . startswith ( ' display ' ) :
if len ( lines ) > 1 :
return ' \n ' . join ( lines [ 1 : ] )
lines . pop ( 0 )
else :
return ' '
return cfg
return ' \n ' . join ( lines )
class NetStreamGlobal ( object ) :
@ -366,6 +369,7 @@ class NetStreamGlobal(object):
if not config :
sampler_tmp [ " sampler_interval " ] = " null "
sampler_tmp [ " sampler_direction " ] = " null "
sampler_tmp [ " interface " ] = " null "
else :
config_list = config . split ( ' ' )
config_num = len ( config_list )
@ -389,6 +393,7 @@ class NetStreamGlobal(object):
sampler_tmp1 = dict ( )
config_mem_list = config_mem . split ( ' ' )
config_num = len ( config_mem_list )
if config_num > 1 :
sampler_tmp1 [ " sampler_direction " ] = config_mem_list [
config_num - 1 ]
sampler_tmp1 [ " sampler_interval " ] = config_mem_list [
@ -426,7 +431,7 @@ class NetStreamGlobal(object):
config_mem = config_mem . lstrip ( )
statistic_tmp [ " statistics_record " ] = list ( )
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 3 ] ) == " ip " :
if len( config_mem_list ) > 3 and str( config_mem_list [ 3 ] ) == " ip " :
statistic_tmp [ " statistics_record " ] . append (
str ( config_mem_list [ 2 ] ) )
statistic_tmp [ " type " ] = " ip "
@ -435,7 +440,7 @@ class NetStreamGlobal(object):
statistic_tmp1 [ " statistics_record " ] = list ( )
config_mem = config_mem . lstrip ( )
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 3 ] ) == " vxlan " :
if len( config_mem_list ) > 3 and str( config_mem_list [ 3 ] ) == " vxlan " :
statistic_tmp1 [ " statistics_record " ] . append (
str ( config_mem_list [ 2 ] ) )
statistic_tmp1 [ " type " ] = " vxlan "
@ -461,6 +466,7 @@ class NetStreamGlobal(object):
for config_mem in config_list :
config_mem = config_mem . lstrip ( )
config_mem_list = config_mem . split ( ' ' )
if len ( config_mem_list ) > 1 :
statistic_tmp1 [ " statistics_direction " ] . append (
str ( config_mem_list [ 1 ] ) )
statistic_tmp1 [ " interface " ] = self . interface
@ -487,10 +493,10 @@ class NetStreamGlobal(object):
config_list = config . split ( ' \n ' )
for config_mem in config_list :
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 2 ] ) == " ip " :
if len( config_mem_list ) > 2 and str( config_mem_list [ 2 ] ) == " ip " :
index_switch_tmp [ " index-switch " ] = " 32 "
index_switch_tmp [ " type " ] = " ip "
if str( config_mem_list [ 2 ] ) == " vxlan " :
if len( config_mem_list ) > 2 and str( config_mem_list [ 2 ] ) == " vxlan " :
index_switch_tmp1 [ " index-switch " ] = " 32 "
index_switch_tmp1 [ " type " ] = " vxlan "
self . existing [ " index-switch " ] . append ( index_switch_tmp )
@ -508,9 +514,9 @@ class NetStreamGlobal(object):
config_list = config . split ( ' \n ' )
for config_mem in config_list :
config_mem_list = config_mem . split ( ' ' )
if config_mem_list [ 3 ] == " ip " :
if len ( config_mem_list ) > 3 and config_mem_list [ 3 ] == " ip " :
self . existing [ " ip_record " ] . append ( config_mem_list [ 2 ] )
if config_mem_list [ 3 ] == " vxlan " :
if len ( config_mem_list ) > 3 and config_mem_list [ 3 ] == " vxlan " :
self . existing [ " vxlan_record " ] . append ( config_mem_list [ 2 ] )
def get_end_sampler_interval ( self ) :
@ -528,6 +534,7 @@ class NetStreamGlobal(object):
else :
config_list = config . split ( ' ' )
config_num = len ( config_list )
if config_num > 1 :
sampler_tmp [ " sampler_direction " ] = config_list [ config_num - 1 ]
sampler_tmp [ " sampler_interval " ] = config_list [ config_num - 2 ]
sampler_tmp [ " interface " ] = " all "
@ -548,6 +555,7 @@ class NetStreamGlobal(object):
sampler_tmp1 = dict ( )
config_mem_list = config_mem . split ( ' ' )
config_num = len ( config_mem_list )
if config_num > 1 :
sampler_tmp1 [ " sampler_direction " ] = config_mem_list [
config_num - 1 ]
sampler_tmp1 [ " sampler_interval " ] = config_mem_list [
@ -585,7 +593,7 @@ class NetStreamGlobal(object):
config_mem = config_mem . lstrip ( )
statistic_tmp [ " statistics_record " ] = list ( )
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 3 ] ) == " ip " :
if len( config_mem_list ) > 3 and str( config_mem_list [ 3 ] ) == " ip " :
statistic_tmp [ " statistics_record " ] . append (
str ( config_mem_list [ 2 ] ) )
statistic_tmp [ " type " ] = " ip "
@ -594,7 +602,7 @@ class NetStreamGlobal(object):
statistic_tmp1 [ " statistics_record " ] = list ( )
config_mem = config_mem . lstrip ( )
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 3 ] ) == " vxlan " :
if len( config_mem_list ) > 3 and str( config_mem_list [ 3 ] ) == " vxlan " :
statistic_tmp1 [ " statistics_record " ] . append (
str ( config_mem_list [ 2 ] ) )
statistic_tmp1 [ " type " ] = " vxlan "
@ -620,6 +628,7 @@ class NetStreamGlobal(object):
for config_mem in config_list :
config_mem = config_mem . lstrip ( )
config_mem_list = config_mem . split ( ' ' )
if len ( config_mem_list ) > 1 :
statistic_tmp1 [ " statistics_direction " ] . append (
str ( config_mem_list [ 1 ] ) )
statistic_tmp1 [ " interface " ] = self . interface
@ -646,10 +655,10 @@ class NetStreamGlobal(object):
config_list = config . split ( ' \n ' )
for config_mem in config_list :
config_mem_list = config_mem . split ( ' ' )
if str( config_mem_list [ 2 ] ) == " ip " :
if len( config_mem_list ) > 2 and str( config_mem_list [ 2 ] ) == " ip " :
index_switch_tmp [ " index-switch " ] = " 32 "
index_switch_tmp [ " type " ] = " ip "
if str( config_mem_list [ 2 ] ) == " vxlan " :
if len( config_mem_list ) > 2 and str( config_mem_list [ 2 ] ) == " vxlan " :
index_switch_tmp1 [ " index-switch " ] = " 32 "
index_switch_tmp1 [ " type " ] = " vxlan "
self . end_state [ " index-switch " ] . append ( index_switch_tmp )
@ -843,13 +852,13 @@ class NetStreamGlobal(object):
tmp_list = statistic_tmp [ " statistics_record " ]
if self . type == statistic_tmp [ " type " ] :
if self . type == " ip " :
if len ( tmp_list ) :
if len ( tmp_list ) > 0 :
cmd = " netstream record %s ip " % tmp_list [ 0 ]
self . cli_add_command ( cmd , undo = True )
cmd = " netstream record %s ip " % self . statistics_record
self . cli_add_command ( cmd )
if self . type == " vxlan " :
if len ( tmp_list ) :
if len ( tmp_list ) > 0 :
cmd = " netstream record %s vxlan inner-ip " % tmp_list [
0 ]
self . cli_add_command ( cmd , undo = True )