From cbe8271745a92742f52d7e641495609c9bcbaa38 Mon Sep 17 00:00:00 2001 From: yanzhangi <51999930+yanzhangi@users.noreply.github.com> Date: Thu, 19 Sep 2019 08:31:44 +0800 Subject: [PATCH] update ce_static_route to fix bugs (#62498) --- .../network/cloudengine/ce_static_route.py | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/ansible/modules/network/cloudengine/ce_static_route.py b/lib/ansible/modules/network/cloudengine/ce_static_route.py index 9f82126af2..079a4069a1 100644 --- a/lib/ansible/modules/network/cloudengine/ce_static_route.py +++ b/lib/ansible/modules/network/cloudengine/ce_static_route.py @@ -471,8 +471,10 @@ class StaticRoute(object): if not self.changed: return if self.aftype == "v4": + aftype = "ip" maskstr = self.convert_len_to_mask(self.mask) else: + aftype = "ipv6" maskstr = self.mask if self.next_hop is None: next_hop = '' @@ -493,38 +495,38 @@ class StaticRoute(object): if self.state == "present": if self.vrf != "_public_": if self.destvrf != "_public_": - self.updates_cmd.append('ip route-static vpn-instance %s %s %s vpn-instance %s %s' - % (vrf, self.prefix, maskstr, destvrf, next_hop)) + self.updates_cmd.append('%s route-static vpn-instance %s %s %s vpn-instance %s %s' + % (aftype, vrf, self.prefix, maskstr, destvrf, next_hop)) else: - self.updates_cmd.append('ip route-static vpn-instance %s %s %s %s %s' - % (vrf, self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('%s route-static vpn-instance %s %s %s %s %s' + % (aftype, vrf, self.prefix, maskstr, nhp_interface, next_hop)) elif self.destvrf != "_public_": - self.updates_cmd.append('ip route-static %s %s vpn-instance %s %s' - % (self.prefix, maskstr, self.destvrf, next_hop)) + self.updates_cmd.append('%s route-static %s %s vpn-instance %s %s' + % (aftype, self.prefix, maskstr, self.destvrf, next_hop)) else: - self.updates_cmd.append('ip route-static %s %s %s %s' - % (self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('%s route-static %s %s %s %s' + % (aftype, self.prefix, maskstr, nhp_interface, next_hop)) if self.pref: - self.updates_cmd.append(' preference %s' % (self.pref)) + self.updates_cmd[0] += ' preference %s' % (self.pref) if self.tag: - self.updates_cmd.append(' tag %s' % (self.tag)) + self.updates_cmd[0] += ' tag %s' % (self.tag) if self.description: - self.updates_cmd.append(' description %s' % (self.description)) + self.updates_cmd[0] += ' description %s' % (self.description) if self.state == "absent": if self.vrf != "_public_": if self.destvrf != "_public_": - self.updates_cmd.append('undo ip route-static vpn-instance %s %s %s vpn-instance %s %s' - % (vrf, self.prefix, maskstr, destvrf, next_hop)) + self.updates_cmd.append('undo %s route-static vpn-instance %s %s %s vpn-instance %s %s' + % (aftype, vrf, self.prefix, maskstr, destvrf, next_hop)) else: - self.updates_cmd.append('undo ip route-static vpn-instance %s %s %s %s %s' - % (vrf, self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('undo %s route-static vpn-instance %s %s %s %s %s' + % (aftype, vrf, self.prefix, maskstr, nhp_interface, next_hop)) elif self.destvrf != "_public_": - self.updates_cmd.append('undo ip route-static %s %s vpn-instance %s %s' - % (self.prefix, maskstr, self.destvrf, self.next_hop)) + self.updates_cmd.append('undo %s route-static %s %s vpn-instance %s %s' + % (aftype, self.prefix, maskstr, self.destvrf, self.next_hop)) else: - self.updates_cmd.append('undo ip route-static %s %s %s %s' - % (self.prefix, maskstr, nhp_interface, next_hop)) + self.updates_cmd.append('undo %s route-static %s %s %s %s' + % (aftype, self.prefix, maskstr, nhp_interface, next_hop)) def operate_static_route(self, version, prefix, mask, nhp_interface, next_hop, vrf, destvrf, state): """operate ipv4 static route"""