Defining a Stage (Clean Step)

In this section we will be adding a stage called connect. A stage, in simple terms, is a step in the clean.

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.

In the image below (taken from the Clean Stages Browser) we can see this connect stage has a some arguments we can also change. The browser will tell you what arguments are available, if it’s an optional argument, the default values, and the type of value it takes.

../../../_images/clean_stage_browser_connect.png

We will change the connection timeout to 100 in the Clean YAML. For any optional arguments, if they are not defined, the default value is used.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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 devices within the Clean YAML.
        # Any that are not in this list are not cleaned even if they are defined below.
        devices: [PE1]

devices:
    PE1:
        connect:
            timeout: 100

Next we need to provide the order of which our stages will execute in. To do this, simply add an order key at the same level of hierarchy as stages. The order key is a list of stages we previously defined and is executed in the top-down order.

 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 devices within the Clean YAML.
        # Any that are not in this list are not cleaned even if they are defined below.
        devices: [PE1]

devices:
    PE1:
        connect:
            timeout: 100

        order:
        - connect

It is supported to add as many stages as needed. Below is an example of adding another stage called apply_configuration under PE1 in the Clean YAML.

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
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 devices within the Clean YAML.
        # Any that are not in this list are not cleaned even if they are defined below.
        devices: [PE1]

devices:
    PE1:
        connect:
            timeout: 100

        apply_configuration:
            configuration: hostname PE1

        order:
        - connect
        - apply_configuration