ce_stp: update to fix a bug. (#59347)
* update to fix a bug. * update for shippable. * Update ce_stp.py
This commit is contained in:
parent
b4494fa547
commit
c3d1f9b085
1 changed files with 27 additions and 10 deletions
|
@ -167,7 +167,22 @@ updates:
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.network.cloudengine.ce import get_config, load_config, ce_argument_spec
|
from ansible.module_utils.network.cloudengine.ce import load_config, ce_argument_spec
|
||||||
|
from ansible.module_utils.network.cloudengine.ce import get_config as get_cli_config
|
||||||
|
|
||||||
|
|
||||||
|
def get_config(module, flags):
|
||||||
|
|
||||||
|
cfg = get_cli_config(module, flags)
|
||||||
|
config = cfg.strip() if cfg else ""
|
||||||
|
if config.startswith("display"):
|
||||||
|
configs = config.split("\n")
|
||||||
|
if len(configs) > 1:
|
||||||
|
return "\n".join(configs[1:])
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
else:
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
class Stp(object):
|
class Stp(object):
|
||||||
|
@ -219,17 +234,14 @@ class Stp(object):
|
||||||
def cli_get_stp_config(self):
|
def cli_get_stp_config(self):
|
||||||
""" Cli get stp configuration """
|
""" Cli get stp configuration """
|
||||||
|
|
||||||
regular = "| include stp"
|
flags = [r"| section include #\s*\n\s*stp", r"| section exclude #\s*\n+\s*stp process \d+"]
|
||||||
|
|
||||||
flags = list()
|
|
||||||
flags.append(regular)
|
|
||||||
self.stp_cfg = get_config(self.module, flags)
|
self.stp_cfg = get_config(self.module, flags)
|
||||||
|
|
||||||
def cli_get_interface_stp_config(self):
|
def cli_get_interface_stp_config(self):
|
||||||
""" Cli get interface's stp configuration """
|
""" Cli get interface's stp configuration """
|
||||||
|
|
||||||
if self.interface:
|
if self.interface:
|
||||||
regular = "| ignore-case section include ^interface %s$" % self.interface
|
regular = r"| ignore-case section include ^#\s+interface %s\s+" % self.interface.replace(" ", "")
|
||||||
flags = list()
|
flags = list()
|
||||||
flags.append(regular)
|
flags.append(regular)
|
||||||
tmp_cfg = get_config(self.module, flags)
|
tmp_cfg = get_config(self.module, flags)
|
||||||
|
@ -399,7 +411,8 @@ class Stp(object):
|
||||||
self.existing["bpdu_protection"] = "disable"
|
self.existing["bpdu_protection"] = "disable"
|
||||||
|
|
||||||
if self.tc_protection:
|
if self.tc_protection:
|
||||||
if "stp tc-protection" in self.stp_cfg:
|
pre_cfg = self.stp_cfg.split("\n")
|
||||||
|
if "stp tc-protection" in pre_cfg:
|
||||||
self.cur_cfg["tc_protection"] = "enable"
|
self.cur_cfg["tc_protection"] = "enable"
|
||||||
self.existing["tc_protection"] = "enable"
|
self.existing["tc_protection"] = "enable"
|
||||||
else:
|
else:
|
||||||
|
@ -513,7 +526,8 @@ class Stp(object):
|
||||||
self.end_state["bpdu_protection"] = "disable"
|
self.end_state["bpdu_protection"] = "disable"
|
||||||
|
|
||||||
if self.tc_protection:
|
if self.tc_protection:
|
||||||
if "stp tc-protection" in self.stp_cfg:
|
pre_cfg = self.stp_cfg.split("\n")
|
||||||
|
if "stp tc-protection" in pre_cfg:
|
||||||
self.end_state["tc_protection"] = "enable"
|
self.end_state["tc_protection"] = "enable"
|
||||||
else:
|
else:
|
||||||
self.end_state["tc_protection"] = "disable"
|
self.end_state["tc_protection"] = "disable"
|
||||||
|
@ -545,18 +559,21 @@ class Stp(object):
|
||||||
else:
|
else:
|
||||||
self.end_state["cost"] = tmp_value[0][1]
|
self.end_state["cost"] = tmp_value[0][1]
|
||||||
|
|
||||||
if self.root_protection:
|
if self.root_protection or self.loop_protection:
|
||||||
if "stp root-protection" in self.interface_stp_cfg:
|
if "stp root-protection" in self.interface_stp_cfg:
|
||||||
self.end_state["root_protection"] = "enable"
|
self.end_state["root_protection"] = "enable"
|
||||||
else:
|
else:
|
||||||
self.end_state["root_protection"] = "disable"
|
self.end_state["root_protection"] = "disable"
|
||||||
|
|
||||||
if self.loop_protection:
|
|
||||||
if "stp loop-protection" in self.interface_stp_cfg:
|
if "stp loop-protection" in self.interface_stp_cfg:
|
||||||
self.end_state["loop_protection"] = "enable"
|
self.end_state["loop_protection"] = "enable"
|
||||||
else:
|
else:
|
||||||
self.end_state["loop_protection"] = "disable"
|
self.end_state["loop_protection"] = "disable"
|
||||||
|
|
||||||
|
if self.existing == self.end_state:
|
||||||
|
self.changed = False
|
||||||
|
self.updates_cmd = list()
|
||||||
|
|
||||||
def present_stp(self):
|
def present_stp(self):
|
||||||
""" Present stp configuration """
|
""" Present stp configuration """
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue