Skip to content

Commit c7c71b9

Browse files
authored
Merge pull request #134 from QualiSystems/dev
Release 6.1.4
2 parents 07680cf + b614c88 commit c7c71b9

File tree

13 files changed

+7950
-7869
lines changed

13 files changed

+7950
-7869
lines changed

.coveragerc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[report]
2-
omit =
3-
*/mibs/*
4-
*__init__*
1+
[report]
2+
omit =
3+
*/mibs/*
4+
*__init__*

cloudshell/networking/cisco/command_actions/add_remove_vlan_actions.py

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from cloudshell.cli.command_template.command_template_executor import (
77
CommandTemplateExecutor,
88
)
9+
from cloudshell.cli.session.session_exceptions import SessionException
10+
from cloudshell.shell.flows.connectivity.helpers.vlan_handler import VLANHandler
911

1012
from cloudshell.networking.cisco.command_templates import add_remove_vlan, iface
1113

@@ -18,7 +20,7 @@ class AddRemoveVlanActions(object):
1820
r"^command\s*rejected.*encapsulation\s*is\s*\S*Auto", re.IGNORECASE
1921
)
2022
CREATE_VLAN_ERROR_PATTERN = re.compile(r"%.*\\.", re.IGNORECASE)
21-
CHECK_VLAN_ASSIGNED = re.compile(
23+
CHECK_ANY_VLAN_CFGED = re.compile(
2224
r"switchport.*vlan\s+\d+$|switchport\s+mode\s+trunk",
2325
re.MULTILINE | re.IGNORECASE | re.DOTALL,
2426
)
@@ -42,7 +44,7 @@ def verify_interface_configured(current_config):
4244
:param current_config:
4345
:return: True or False
4446
"""
45-
return bool(AddRemoveVlanActions.CHECK_VLAN_ASSIGNED.search(current_config))
47+
return bool(AddRemoveVlanActions.CHECK_ANY_VLAN_CFGED.search(current_config))
4648

4749
@staticmethod
4850
def verify_interface_has_vlan_assigned(vlan_range, current_config):
@@ -52,11 +54,33 @@ def verify_interface_has_vlan_assigned(vlan_range, current_config):
5254
:param current_config:
5355
:return: True or False
5456
"""
55-
return re.search(
56-
r"switchport.*vlan\s+{0}$".format(str(vlan_range)),
57-
current_config,
58-
re.MULTILINE | re.IGNORECASE | re.DOTALL,
59-
)
57+
success = True
58+
vlans_list = VLANHandler(
59+
is_vlan_range_supported=True, is_multi_vlan_supported=False
60+
).get_vlan_list(vlan_range)
61+
vlan_range_list = [v for v in vlans_list if "-" in v]
62+
for vlan_range in vlan_range_list:
63+
str_vlan_range_ls = vlan_range.split("-")
64+
65+
vlan_range_ls = list(map(int, str_vlan_range_ls))
66+
vlan_min = min(vlan_range_ls)
67+
vlan_max = max(vlan_range_ls)
68+
69+
for vlan in vlans_list:
70+
vlans_range = range(vlan_min, vlan_max)
71+
if vlan not in vlan_range_list and int(vlan) in vlans_range:
72+
vlans_list.remove(vlan)
73+
if len(range(vlan_min, vlan_max)) == 1:
74+
vlans_list.remove(vlan_range)
75+
vlans_list.extend(str_vlan_range_ls)
76+
for vlan in vlans_list:
77+
if not re.search(
78+
r"switchport.*vlan.*\b{vlan}\b".format(vlan=vlan),
79+
current_config,
80+
re.IGNORECASE,
81+
):
82+
success = False
83+
return success
6084

6185
def create_vlan(self, vlan_range, action_map=None, error_map=None):
6286
"""Create vlan entity on the device.
@@ -233,12 +257,23 @@ def set_vlan_to_sub_interface(
233257
error_map=error_map,
234258
).execute_command(vlan_id=vlan_range, qnq="")
235259
else:
236-
CommandTemplateExecutor(
237-
self._cli_service,
238-
add_remove_vlan.VLAN_SUB_IFACE,
239-
action_map=action_map,
240-
error_map=error_map,
241-
).execute_command(vlan_id=vlan_range, untagged=untagged)
260+
try:
261+
CommandTemplateExecutor(
262+
self._cli_service,
263+
add_remove_vlan.VLAN_SUB_IFACE,
264+
action_map=action_map,
265+
error_map=error_map,
266+
).execute_command(vlan_id=vlan_range, untagged=untagged)
267+
except SessionException:
268+
self._logger.warning(
269+
"Unable to configure sub interface with untagged encapsulation."
270+
)
271+
CommandTemplateExecutor(
272+
self._cli_service,
273+
add_remove_vlan.VLAN_SUB_IFACE,
274+
action_map=action_map,
275+
error_map=error_map,
276+
).execute_command(vlan_id=vlan_range)
242277

243278
def clean_vlan_sub_interface(self, port_name):
244279
CommandTemplateExecutor(

cloudshell/networking/cisco/command_actions/system_actions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ def delete_file(self, path, action_map=None, error_map=None):
147147
).execute_command(target=path)
148148

149149
def override_running(
150-
self, path, action_map=None, error_map=None, timeout=300, reconnect_timeout=1600
150+
self,
151+
path,
152+
vrf=None,
153+
action_map=None,
154+
error_map=None,
155+
timeout=300,
156+
reconnect_timeout=1600,
151157
):
152158
"""Override running-config.
153159
@@ -167,7 +173,7 @@ def override_running(
167173
error_map=error_map,
168174
timeout=timeout,
169175
check_action_loop_detector=False,
170-
).execute_command(path=path)
176+
).execute_command(path=path, vrf=vrf)
171177
match_error = re.search(r"[Ee]rror.*", output, flags=re.DOTALL)
172178
if match_error:
173179
error_str = match_error.group()

cloudshell/networking/cisco/command_templates/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
)
3737

3838
CONFIGURE_REPLACE = CommandTemplate(
39-
"configure replace {path}",
39+
"configure replace {path} [{vrf}]",
4040
action_map=OrderedDict(
4141
{
4242
r"[\[\(][Yy]es/[Nn]o[\)\]]": lambda session, logger: session.send_line(
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
3-
4-
from cloudshell.cli.command_template.command_template import CommandTemplate
5-
6-
BOOT_SYSTEM_FILE = CommandTemplate("boot system {firmware_file_name}")
7-
8-
CONFIG_REG = CommandTemplate("config-reg 0x2102")
9-
10-
SHOW_RUNNING = CommandTemplate("show running-config | include boot")
11-
12-
SHOW_VERSION = CommandTemplate("show version")
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
from cloudshell.cli.command_template.command_template import CommandTemplate
5+
6+
BOOT_SYSTEM_FILE = CommandTemplate("boot system {firmware_file_name}")
7+
8+
CONFIG_REG = CommandTemplate("config-reg 0x2102")
9+
10+
SHOW_RUNNING = CommandTemplate("show running-config | include boot")
11+
12+
SHOW_VERSION = CommandTemplate("show version")

cloudshell/networking/cisco/flows/cisco_autoload_flow.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33
import os
4+
import re
5+
from collections import OrderedDict
46

57
from cloudshell.shell.flows.autoload.basic_flow import AbstractAutoloadFlow
8+
from cloudshell.snmp.autoload.constants import entity_constants
69

710
from cloudshell.networking.cisco.autoload.cisco_generic_snmp_autoload import (
811
CiscoGenericSNMPAutoload,
@@ -15,8 +18,19 @@
1518
CiscoIfPortChannel,
1619
)
1720

21+
entity_constants.ENTITY_VENDOR_TYPE_TO_CLASS_MAP = OrderedDict(
22+
[
23+
(re.compile(r"^\S+cevcontainer", re.IGNORECASE), "container"),
24+
(re.compile(r"^\S+cevchassis", re.IGNORECASE), "chassis"),
25+
(re.compile(r"^\S+cevmodule", re.IGNORECASE), "module"),
26+
(re.compile(r"^\S+cevport", re.IGNORECASE), "port"),
27+
(re.compile(r"^\S+cevpowersupply", re.IGNORECASE), "powerSupply"),
28+
]
29+
)
30+
1831

1932
class CiscoSnmpAutoloadFlow(AbstractAutoloadFlow):
33+
2034
CISCO_MIBS_FOLDER = os.path.join(os.path.dirname(__file__), os.pardir, "mibs")
2135
DEVICE_NAMES_MAP_FILE = os.path.join(CISCO_MIBS_FOLDER, "device_names_map.csv")
2236

@@ -35,12 +49,12 @@ def _autoload_flow(self, supported_os, resource_model):
3549
r"stack|engine|management|"
3650
r"mgmt|voice|foreign|cpu|"
3751
r"control\s*ethernet\s*port|"
38-
r"console\s*port"
52+
r"usb\s*port"
3953
)
4054
cisco_snmp_autoload.entity_table_service.set_module_exclude_pattern(
4155
r"powershelf|cevsfp|cevxfr|"
4256
r"cevxfp|cevContainer10GigBasePort|"
43-
r"cevModulePseAsicPlim"
57+
r"cevModulePseAsicPlim|cevModuleCommonCardsPSEASIC"
4458
)
4559
(
4660
cisco_snmp_autoload.if_table_service.port_attributes_service

cloudshell/networking/cisco/flows/cisco_connectivity_flow.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ def __init__(
1818
logger,
1919
support_vlan_range_str=False,
2020
support_multi_vlan_str=False,
21+
is_switch=False,
2122
):
2223
super(CiscoConnectivityFlow, self).__init__(logger)
2324
self._cli_handler = cli_handler
2425
self.IS_VLAN_RANGE_SUPPORTED = support_vlan_range_str
2526
self.IS_MULTI_VLAN_SUPPORTED = support_multi_vlan_str
27+
self.is_switch = is_switch
2628

2729
def _get_vlan_actions(self, config_session):
2830
return AddRemoveVlanActions(config_session, self._logger)
@@ -41,7 +43,7 @@ def _add_vlan_flow(self, vlan_range, port_mode, full_name, qnq, c_tag, vm_uid=No
4143
:param c_tag:
4244
:return:
4345
"""
44-
success = True
46+
success = False
4547
self._logger.info("Add VLAN(s) {} configuration started".format(vlan_range))
4648

4749
with self._cli_handler.get_cli_service(
@@ -62,23 +64,24 @@ def _add_vlan_flow(self, vlan_range, port_mode, full_name, qnq, c_tag, vm_uid=No
6264
qnq,
6365
c_tag,
6466
)
65-
if not vlan_actions.verify_interface_has_vlan_assigned(
67+
if vlan_actions.verify_interface_has_vlan_assigned(
6668
vlan_range, current_config
6769
):
68-
success = False
70+
success = True
6971
except CommandExecutionException:
70-
current_config = self._add_sub_interface_vlan(
71-
vlan_actions,
72-
iface_action,
73-
vlan_range,
74-
port_name,
75-
port_mode,
76-
qnq,
77-
c_tag,
78-
)
72+
if not self.is_switch:
73+
current_config = self._add_sub_interface_vlan(
74+
vlan_actions,
75+
iface_action,
76+
vlan_range,
77+
port_name,
78+
port_mode,
79+
qnq,
80+
c_tag,
81+
)
7982

80-
if not "{}.{}".format(port_name, vlan_range) in current_config:
81-
success = False
83+
if "{}.{}".format(port_name, vlan_range) in current_config:
84+
success = True
8285
if not success:
8386
raise Exception(
8487
self.__class__.__name__,
@@ -174,16 +177,19 @@ def _remove_vlan_flow(self, vlan_range, full_name, port_mode, vm_uid=None):
174177

175178
current_config = iface_action.get_current_interface_config(port_name)
176179
if "switchport" not in current_config:
177-
sub_interface_name = "{}.{}".format(port_name, vlan_range)
178-
self._remove_sub_interface(sub_interface_name, iface_action)
179-
sub_interfaces_list = iface_action.get_current_interface_config(
180-
sub_interface_name
181-
)
182-
if sub_interface_name in sub_interfaces_list:
183-
is_failed = True
184-
self._logger.error(
185-
"Failed to remove sub interface: {}".format(sub_interface_name)
180+
if not self.is_switch:
181+
sub_interface_name = "{}.{}".format(port_name, vlan_range)
182+
self._remove_sub_interface(sub_interface_name, iface_action)
183+
sub_interfaces_list = iface_action.get_current_interface_config(
184+
sub_interface_name
186185
)
186+
if sub_interface_name in sub_interfaces_list:
187+
is_failed = True
188+
self._logger.error(
189+
"Failed to remove sub interface: {}".format(
190+
sub_interface_name
191+
)
192+
)
187193
else:
188194
iface_action.enter_iface_config_mode(port_name)
189195
iface_action.clean_interface_switchport_config(current_config)

0 commit comments

Comments
 (0)