Cleaning Like Devices¶
This topic contains the information required to group devices together in order to perform a clean operation on
multiple similar devices in your testbed. The groups
block is an optional block.
Devices can be grouped by:
Device - Manually provide a list of devices that belong to a group.
Platform - Provide the platform and all devices with that platform will be grouped together under this group.
OS - Provide the os and all devices with that os will be grouped together under this group.
Note
Only one method is supported per group. You cannot combine group-by-device, group-by-platform and group-by-os in the same group. You can have multiple groups with each group using a different method (a sample is provided below showing this option).
Device groups simplify the Clean YAML
, by removing duplicate stages and arguments for devices that use a similar clean.
For example, if you have two devices in the devices
block that use the same stages, arguments, and order, then you
could combine these devices under one group.
The topics covered in this section are:
How to Specify Device Groups?¶
Note
These examples only show the required Device/Platform/OS Group information part of the Clean YAML file, and not the entire file requirements.
Option 1: Device - Manually provide a list of devices that belong to a group.
The following Clean YAML
demonstrates how to create a group that contains PE1
and PE2
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_device]
9
10groups:
11 # The group name can be anything
12 my_group_by_device:
13 # The 'devices' key takes a list of devices you want under this group
14 devices:
15 - PE1
16 - PE2
Option 2: Platform - Provide the platform and all devices with that platform will be grouped together under this group.
The following Clean YAML
demonstrates how to create a group that contains all devices of the n9k
platform.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_platform]
9
10groups:
11 # The group name can be anything
12 my_group_by_platform:
13 # The 'platforms' key takes a list of all platforms you want under this group
14 platforms:
15 - n9k
Option 3: OS - Provide the os and all devices with that os will be grouped together under this group.
The following Clean YAML
demonstrates how to create a group that contains all devices of the iosxe
os.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_os]
9
10groups:
11 # The group name can be anything
12 my_group_by_os:
13 # The 'os' key takes a list of all os you want under this group
14 os:
15 - iosxe
Adding multiple groups to the same Clean YAML.
The following Clean YAML
demonstrates how to combine two groups, where one group uses group-by-device
and the other
uses group-by-platform
.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_device, my_group_by_platform]
9
10groups:
11 # The group name can be anything
12 my_group_by_device:
13 # The 'devices' key takes a list of devices you want under this group
14 devices:
15 - PE1
16 - PE2
17
18 # The group name can be anything
19 my_group_by_platform:
20 # The 'platforms' key takes a list of all platforms you want under this group
21 platforms:
22 - n9k
How to add Stages to Device Groups?¶
Note
In the event you do not know what a stage is, what it does, and what arguments they accept, you can find that information in the Clean Stages document.
Adding a stage to a group is the same as adding a stage to a device under the devices
block.
There are three steps in order to add a stage to the clean.
Find a suitable stage from the Clean Stage Browser.
Choose which device to add the stage under.
Choose the order the stage(s) will execute in.
Below is an example of adding the connect
stage under my_group_by_device
and my_group_by_platform
in the Clean YAML
. This stage has a few arguments that are
all optional. If in the case you are satisfied with the default values, you can leave the value side of the key-value
pair empty as shown in the example.
The order
key must also be defined, even if there is only one stage.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_device, my_group_by_platform]
9
10groups:
11 # The group name can be anything
12 my_group_by_device:
13 # The 'devices' key takes a list of devices you want under this group
14 devices:
15 - PE1
16 - PE2
17
18 connect:
19
20 order:
21 - connect
22
23 # The group name can be anything
24 my_group_by_platform:
25 # The 'platforms' key takes a list of all platforms you want under this group
26 platforms:
27 - n9k
28
29 connect:
30
31 order:
32 - connect
It is supported to add as many stages as needed. Below is an example of adding another stage called
apply_configuration
under my_group_by_device
and my_group_by_platform
in the Clean YAML
. To pass any arguments for the stage,
simply add it under the stage as shown in the example.
It will run after the connect
stage as defined under the order
key.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_device, my_group_by_platform]
9
10groups:
11 # The group name can be anything
12 my_group_by_device:
13 # The 'devices' key takes a list of devices you want under this group
14 devices:
15 - PE1
16 - PE2
17
18 connect:
19
20 apply_configuration:
21 configuration: |
22 interface GigabitEthernet1
23 shutdown
24
25 order:
26 - connect
27 - apply_configuration
28
29 # The group name can be anything
30 my_group_by_platform:
31 # The 'platforms' key takes a list of all platforms you want under this group
32 platforms:
33 - n9k
34
35 connect:
36
37 apply_configuration:
38 configuration: |
39 interface GigabitEthernet1
40 shutdown
41
42 order:
43 - connect
44 - apply_configuration
Note
Every Clean Stage under the group applies to all devices in the specified group but can be overwritten by
specifying a stage under a specific device in the devices
block.
For example, in this Clean YAML
the highlighted lines overwrite the apply_configuration
stage on line 20
to
no shutdown
instead of shutdown
interface GigabitEthernet1 on the PE1
device.
1cleaners:
2 # This means to use the cleaner class `PyatsDeviceClean`
3 PyatsDeviceClean:
4 # The module is where the cleaner class above can be found
5 module: genie.libs.clean
6 # You can define many groups within the Clean YAML.
7 # Any groups not in this list are not cleaned even if they are defined below.
8 groups: [my_group_by_device, my_group_by_platform]
9
10groups:
11 # The group name can be anything
12 my_group_by_device:
13 # The 'devices' key takes a list of devices you want under this group
14 devices:
15 - PE1
16 - PE2
17
18 connect:
19
20 apply_configuration:
21 configuration: |
22 interface GigabitEthernet1
23 shutdown
24
25 order:
26 - connect
27 - apply_configuration
28
29 # The group name can be anything
30 my_group_by_platform:
31 # The 'platforms' key takes a list of all platforms you want under this group
32 platforms:
33 - n9k
34
35 connect:
36
37 apply_configuration:
38 configuration: |
39 interface GigabitEthernet1
40 shutdown
41
42 order:
43 - connect
44 - apply_configuration
45
46devices:
47 PE1:
48 apply_configuration:
49 configuration: |
50 interface GigabitEthernet1
51 no shutdown