示例#1
0
#!/usr/bin/env python3

import candice
import lxml

with candice.Task() as task:
    hostname = task.input.get("hostname", "hello")

    router = candice.Device()

    with router.executor() as executor:
        executor.namespaces.update(
            {"s": "urn:ietf:params:xml:ns:yang:ietf-system"})

        element = executor.get_xpath("/s:system/s:hostname")
        if element:
            task.output["old-hostname"] = element[0].text

        config = executor.element("config", ns="base")
        element = executor.element("system", ns="s", parent=config)
        element = executor.element("hostname", parent=element)
        element.text = hostname

        executor.manager.edit_config(target="running",
                                     config=candice.to_xml(config))

        element = executor.get_xpath("/s:system/s:hostname")
        if element:
            task.output["new-hostname"] = element[0].text
示例#2
0
#!/usr/bin/env python3

import candice

with candice.Task() as task:
    if "count" in task.store:
        task.store["count"] += 1
    else:
        task.store["count"] = 1

    task.output["count"] = task.store["count"]

    device = candice.Device()

    with device.executor() as executor:
        task.output["inputs"] = task.input

        task.output["capabilities"] = []
        for c in executor.manager.server_capabilities:
            task.output["capabilities"].append(c)

        config = candice.from_xml(executor.manager.get_config(source="running").data_xml)
        task.output["config"] = candice.to_xml(config)

        executor.namespaces.update({
            "s": "urn:ietf:params:xml:ns:yang:ietf-system",
            "k": "urn:ietf:params:xml:ns:yang:ietf-keystore",
            "i": "urn:ietf:params:xml:ns:yang:ietf-interfaces"
        })

        element = executor.get_xpath("//s:current-datetime")