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.
Note
Only one method is supported per group. You cannot combine group-by-device and group-by-platform 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 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_device] groups: # The group name can be anything my_group_by_device: # The 'devices' key takes a list of devices you want under this group devices: - PE1 - 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_platform] groups: # The group name can be anything my_group_by_platform: # The 'platforms' key takes a list of all platforms you want under this group platforms: - n9k |
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
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_device, my_group_by_platform] groups: # The group name can be anything my_group_by_device: # The 'devices' key takes a list of devices you want under this group devices: - PE1 - PE2 # The group name can be anything my_group_by_platform: # The 'platforms' key takes a list of all platforms you want under this group platforms: - 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_device, my_group_by_platform] groups: # The group name can be anything my_group_by_device: # The 'devices' key takes a list of devices you want under this group devices: - PE1 - PE2 connect: order: - connect # The group name can be anything my_group_by_platform: # The 'platforms' key takes a list of all platforms you want under this group platforms: - n9k connect: order: - 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_device, my_group_by_platform] groups: # The group name can be anything my_group_by_device: # The 'devices' key takes a list of devices you want under this group devices: - PE1 - PE2 connect: apply_configuration: configuration: | interface GigabitEthernet1 shutdown order: - connect - apply_configuration # The group name can be anything my_group_by_platform: # The 'platforms' key takes a list of all platforms you want under this group platforms: - n9k connect: apply_configuration: configuration: | interface GigabitEthernet1 shutdown order: - connect - 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | cleaners: # This means to use the cleaner class `PyatsDeviceClean` PyatsDeviceClean: # The module is where the cleaner class above can be found module: genie.libs.clean # You can define many groups within the Clean YAML. # Any groups not in this list are not cleaned even if they are defined below. groups: [my_group_by_device, my_group_by_platform] groups: # The group name can be anything my_group_by_device: # The 'devices' key takes a list of devices you want under this group devices: - PE1 - PE2 connect: apply_configuration: configuration: | interface GigabitEthernet1 shutdown order: - connect - apply_configuration # The group name can be anything my_group_by_platform: # The 'platforms' key takes a list of all platforms you want under this group platforms: - n9k connect: apply_configuration: configuration: | interface GigabitEthernet1 shutdown order: - connect - apply_configuration devices: PE1: apply_configuration: configuration: | interface GigabitEthernet1 no shutdown |