How to use the ncclient.operations.rpc.RPC function in ncclient

To help you get started, we’ve selected a few ncclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ncclient / ncclient / ncclient / operations / edit.py View on Github external
** modified to only accept valid string as source argument.  Elements no longer accepted - earies - 04/22/2013

        :seealso: :ref:`srctarget_params`"""
        node = new_ele("validate")
        # rfc6241 sec 8.6.4 states valid source can be  or  elements
        tags = ("config", "candidate")
        if source not in tags:
            raise XMLError("Invalid source type: [%s], must be one of %s" % (source, tags))
        src_ele = sub_ele(node, "source")
        sub_ele(src_ele, source)
        return self._request(node)


class Commit(RPC):
    "`commit` RPC. Depends on the `:candidate` capability, and the `:confirmed-commit`."

    DEPENDS = [':candidate']

    def request(self, confirmed=False, timeout=None):
        """Commit the candidate configuration as the device's new current configuration. Depends on the `:candidate` capability.

        A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no followup commit within the *timeout* interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the *confirmed* parameter but this is not required. Depends on the `:confirmed-commit` capability.

        *confirmed* whether this is a confirmed commit

        *timeout* specifies the confirm timeout in seconds"""
        node = new_ele("commit")
        if confirmed:
            self._assert(":confirmed-commit")
            sub_ele(node, "confirmed")
github ncclient / ncclient / ncclient / operations / edit.py View on Github external
class DeleteConfig(RPC):
    "`delete-config` RPC"

    def request(self, target):
        """Delete a configuration datastore.

        *target* specifies the  name or URL of configuration datastore to delete

        :seealso: :ref:`srctarget_params`"""
        node = new_ele("delete-config")
        node.append(util.datastore_or_url("target", target, self._assert))
        return self._request(node)


class CopyConfig(RPC):
    "`copy-config` RPC"

    def request(self, source, target):
        """Create or replace an entire configuration datastore with the contents of another complete
        configuration datastore.

        *source* is the name of the configuration datastore to use as the source of the copy operation or `config` element containing the configuration subtree to copy

        *target* is the name of the configuration datastore to use as the destination of the copy operation

        :seealso: :ref:`srctarget_params`"""
        node = new_ele("copy-config")
        node.append(util.datastore_or_url("target", target, self._assert))
        node.append(util.datastore_or_url("source", source, self._assert))
        return self._request(node)
github ncclient / ncclient / ncclient / operations / third_party / h3c / rpc.py View on Github external
"The *get-bulk* RPC."

    def request(self, filter=None):
        """Retrieve running configuration and device state information.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`
        """
        node = new_ele("get-bulk")
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)


class GetBulkConfig(RPC):
    """The *get-bulk-config* RPC."""

    def request(self, source, filter=None):
        """Retrieve all or part of a specified configuration.

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`"""
        node = new_ele("get-bulk-config")
        node.append(util.datastore_or_url("source", source, self._assert))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
github ncclient / ncclient / ncclient / operations / third_party / hpcomware / rpc.py View on Github external
cmds can be a list or single command
        """
        if isinstance(cmds, list):
            cmd = '\n'.join(cmds)
        elif isinstance(cmds, str) or isinstance(cmds, unicode):
            cmd = cmds

        node = etree.Element(qualify('CLI', BASE_NS_1_0))

        etree.SubElement(node, qualify('Execution',
                                       BASE_NS_1_0)).text = cmd

        return self._request(node)


class ConfigCommand(RPC):
    def request(self, cmds):
        """
        Single Configuration element is permitted.
        cmds can be a list or single command
        commands are pushed to the switch in this method
        """

        if isinstance(cmds, list):
            cmd = '\n'.join(cmds)
        elif isinstance(cmds, str) or isinstance(cmds, unicode):
            cmd = cmds

        node = etree.Element(qualify('CLI', BASE_NS_1_0))

        etree.SubElement(node, qualify('Configuration',
                                       BASE_NS_1_0)).text = cmd
github ncclient / ncclient / ncclient / operations / retrieve.py View on Github external
"See :class:`GetReply`."

    def request(self, filter=None):
        """Retrieve running configuration and device state information.

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`
        """
        node = new_ele("get")
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)


class GetConfig(RPC):

    """The *get-config* RPC."""

    REPLY_CLS = GetReply
    """See :class:`GetReply`."""

    def request(self, source, filter=None):
        """Retrieve all or part of a specified configuration.

        *source* name of the configuration datastore being queried

        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

        :seealso: :ref:`filter_params`"""
        node = new_ele("get-config")
        node.append(util.datastore_or_url("source", source, self._assert))
github ncclient / ncclient / ncclient / operations / lock.py View on Github external
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"Locking-related NETCONF operations"

from ncclient.xml_ import *

from ncclient.operations.rpc import RaiseMode, RPC

# TODO: parse session-id from a lock-denied error, and raise a tailored exception?

class Lock(RPC):

    "`lock` RPC"


    def request(self, target="candidate"):
        """Allows the client to lock the configuration system of a device.

        *target* is the name of the configuration datastore to lock
        """
        node = new_ele("lock")
        sub_ele(sub_ele(node, "target"), target)
        return self._request(node)


class Unlock(RPC):
github ncclient / ncclient / ncclient / operations / third_party / h3c / rpc.py View on Github external
return self._request(node)


class CLI(RPC):
    def request(self, command=None):
        """command text
        view: Execution user view exec
              Configuration system view exec
        """
        node = new_ele("CLI")
        node.append(validated_element(command))
        # sub_ele(node, view).text = command
        return self._request(node)


class Action(RPC):
    def request(self, action=None):
        node = new_ele("action")
        node.append(validated_element(action))
        return self._request(node)

class Save(RPC):
    def request(self, file=None):
        node = new_ele('save')
        sub_ele(node, 'file').text = file
        return self._request(node)


class Load(RPC):
    def request(self, file=None):
        node = new_ele('load')
        sub_ele(node, 'file').text = file
github ncclient / ncclient / ncclient / operations / edit.py View on Github external
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no followup commit within the *timeout* interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the *confirmed* parameter but this is not required. Depends on the `:confirmed-commit` capability.

        *confirmed* whether this is a confirmed commit

        *timeout* specifies the confirm timeout in seconds"""
        node = new_ele("commit")
        if confirmed:
            self._assert(":confirmed-commit")
            sub_ele(node, "confirmed")
            if timeout is not None:
                sub_ele(node, "confirm-timeout").text = timeout
        return self._request(node)


class DiscardChanges(RPC):
    "`discard-changes` RPC. Depends on the `:candidate` capability."

    DEPENDS = [":candidate"]

    def request(self):
        """Revert the candidate configuration to the currently running configuration. Any uncommitted changes are discarded."""

        return self._request(new_ele("discard-changes"))
github ncclient / ncclient / ncclient / operations / third_party / juniper / rpc.py View on Github external
from ncclient.xml_ import *

from ncclient.operations.rpc import RPC
from ncclient import NCClientError

class GetConfiguration(RPC):
    def request(self, format='xml', filter=None):
        node = new_ele('get-configuration', {'format':format})
        if filter is not None:
            node.append(filter)
        return self._request(node)

class LoadConfiguration(RPC):
    def request(self, format='xml', action='merge',
            target='candidate', config=None):
        if config is not None:
            if type(config) == list:
                config = '\n'.join(config)
            if action == 'set':
                format = 'text'
            node = new_ele('load-configuration', {'action':action, 'format':format})
            if format == 'xml':
                config_node = sub_ele(node, 'configuration')
                config_node.append(config)
            if format == 'text' and not action == 'set':
                config_node = sub_ele(node, 'configuration-text').text = config
            if action == 'set' and format == 'text':
                config_node = sub_ele(node, 'configuration-set').text = config
            return self._request(node)
github ncclient / ncclient / ncclient / operations / flowmon.py View on Github external
from ncclient.xml_ import *

from ncclient.operations.rpc import RPC

PC_URN = "urn:liberouter:params:xml:ns:netconf:power-control:1.0"

class PoweroffMachine(RPC):

    "*poweroff-machine* RPC (flowmon)"

    DEPENDS = ["urn:liberouter:param:netconf:capability:power-control:1.0"]
    
    def request(self):
        return self._request(new_ele(qualify("poweroff-machine", PC_URN)))

class RebootMachine(RPC):

    "*reboot-machine* RPC (flowmon)"

    DEPENDS = ["urn:liberouter:params:netconf:capability:power-control:1.0"]

    def request(self):
        return self._request(new_ele(qualify("reboot-machine", PC_URN)))