Skip to content

Commit

Permalink
ce_netstream_global: update to fix a bug. (ansible#59689)
Browse files Browse the repository at this point in the history
* update to fix a bug.

* Update ce_netstream_global.py
  • Loading branch information
yuandongx authored and ansibot committed Jul 30, 2019
1 parent dbe618c commit 3c7e8f7
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions lib/ansible/modules/network/cloudengine/ce_netstream_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@
'''

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_config, load_config
from ansible.module_utils.network.cloudengine.ce import load_config
from ansible.module_utils.network.cloudengine.ce import get_connection, rm_config_prefix
from ansible.module_utils.network.cloudengine.ce import ce_argument_spec


Expand Down Expand Up @@ -247,6 +248,38 @@ def get_interface_type(interface):
return iftype.lower()


def get_config(module, flags):

"""Retrieves the current config from the device or cache
"""
flags = [] if flags is None else flags
if isinstance(flags, str):
flags = [flags]
elif not isinstance(flags, list):
flags = []

cmd = 'display current-configuration '
cmd += ' '.join(flags)
cmd = cmd.strip()
conn = get_connection(module)
rc, out, err = conn.exec_command(cmd)
if rc != 0:
module.fail_json(msg=err)
cfg = str(out).strip()
# remove default configuration prefix '~'
for flag in flags:
if "include-default" in flag:
cfg = rm_config_prefix(cfg)
break
if cfg.startswith('display'):
lines = cfg.split('\n')
if len(lines) > 1:
return '\n'.join(lines[1:])
else:
return ''
return cfg


class NetStreamGlobal(object):
"""
Manages netstream global parameters.
Expand Down Expand Up @@ -342,8 +375,8 @@ def get_exist_sampler_interval(self):
self.existing["sampler"].append(sampler_tmp)
if self.interface != "all":
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream sampler random-packets" % self.interface
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream sampler random-packets" % self.interface
flags.append(exp)
config = get_config(self.module, flags)
if not config:
Expand Down Expand Up @@ -376,8 +409,8 @@ def get_exist_statistic_record(self):
statistic_tmp1["statistics_record"] = list()
statistic_tmp1["interface"] = self.interface
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream record"\
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream record"\
% (self.interface)
flags.append(exp)
config = get_config(self.module, flags)
Expand Down Expand Up @@ -414,8 +447,8 @@ def get_exist_interface_statistic(self):
statistic_tmp1 = dict()
statistic_tmp1["statistics_direction"] = list()
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream inbound|outbound"\
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream inbound|outbound"\
% self.interface
flags.append(exp)
config = get_config(self.module, flags)
Expand Down Expand Up @@ -501,8 +534,8 @@ def get_end_sampler_interval(self):
self.end_state["sampler"].append(sampler_tmp)
if self.interface != "all":
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream sampler random-packets" % self.interface
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream sampler random-packets" % self.interface
flags.append(exp)
config = get_config(self.module, flags)
if not config:
Expand Down Expand Up @@ -535,8 +568,8 @@ def get_end_statistic_record(self):
statistic_tmp1["statistics_record"] = list()
statistic_tmp1["interface"] = self.interface
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream record"\
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream record"\
% (self.interface)
flags.append(exp)
config = get_config(self.module, flags)
Expand Down Expand Up @@ -573,8 +606,8 @@ def get_end_interface_statistic(self):
statistic_tmp1 = dict()
statistic_tmp1["statistics_direction"] = list()
flags = list()
exp = " | ignore-case section include ^interface %s$" \
" | include netstream inbound|outbound"\
exp = r" | ignore-case section include ^#\s+interface %s" \
r" | include netstream inbound|outbound"\
% self.interface
flags.append(exp)
config = get_config(self.module, flags)
Expand Down

0 comments on commit 3c7e8f7

Please sign in to comment.