How to use the ncclient.xml_.sub_ele 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 / examples / juniper / edit-config-std.py View on Github external
def connect(host, port, user, password):
    conn = manager.connect(host=host,
                           port=port,
                           username=user,
                           password=password,
                           timeout=60,
                           device_params={'name': 'junos'},
                           hostkey_verify=False)

    conn.lock()

    root = new_ele('config')
    configuration = sub_ele(root, 'configuration')
    system = sub_ele(configuration, 'system')
    location = sub_ele(system, 'location')
    sub_ele(location, 'building').text = "Main Campus, A"
    sub_ele(location, 'floor').text = "5"
    sub_ele(location, 'rack').text = "27"

    edit_config_result = conn.edit_config(config=root)
    logging.info(edit_config_result)

    validate_result = conn.validate()
    logging.info(validate_result)

    compare_config_result = conn.compare_configuration()
    logging.info(compare_config_result)

    conn.commit()
github ncclient / ncclient / examples / juniper / edit-config-std.py View on Github external
port=port,
                           username=user,
                           password=password,
                           timeout=60,
                           device_params={'name': 'junos'},
                           hostkey_verify=False)

    conn.lock()

    root = new_ele('config')
    configuration = sub_ele(root, 'configuration')
    system = sub_ele(configuration, 'system')
    location = sub_ele(system, 'location')
    sub_ele(location, 'building').text = "Main Campus, A"
    sub_ele(location, 'floor').text = "5"
    sub_ele(location, 'rack').text = "27"

    edit_config_result = conn.edit_config(config=root)
    logging.info(edit_config_result)

    validate_result = conn.validate()
    logging.info(validate_result)

    compare_config_result = conn.compare_configuration()
    logging.info(compare_config_result)

    conn.commit()
    conn.unlock()
    conn.close_session()
github alibaba / ansible-provider-docs / lib / ansible / plugins / netconf / junos.py View on Github external
def commit(self, confirmed=False, check=False, timeout=None, comment=None, synchronize=False, at_time=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
        """
        obj = new_ele('commit-configuration')
        if confirmed:
            sub_ele(obj, 'confirmed')
        if check:
            sub_ele(obj, 'check')
        if synchronize:
            sub_ele(obj, 'synchronize')
        if at_time:
            subele = sub_ele(obj, 'at-time')
            subele.text = str(at_time)
        if comment:
            subele = sub_ele(obj, 'log')
            subele.text = str(comment)
        if timeout:
            subele = sub_ele(obj, 'confirm-timeout')
            subele.text = str(timeout)
        return self.rpc(obj)
github ncclient / ncclient / examples / juniper / edit-config-std.py View on Github external
conn = manager.connect(host=host,
                           port=port,
                           username=user,
                           password=password,
                           timeout=60,
                           device_params={'name': 'junos'},
                           hostkey_verify=False)

    conn.lock()

    root = new_ele('config')
    configuration = sub_ele(root, 'configuration')
    system = sub_ele(configuration, 'system')
    location = sub_ele(system, 'location')
    sub_ele(location, 'building').text = "Main Campus, A"
    sub_ele(location, 'floor').text = "5"
    sub_ele(location, 'rack').text = "27"

    edit_config_result = conn.edit_config(config=root)
    logging.info(edit_config_result)

    validate_result = conn.validate()
    logging.info(validate_result)

    compare_config_result = conn.compare_configuration()
    logging.info(compare_config_result)

    conn.commit()
    conn.unlock()
    conn.close_session()
github hsnlab / escape / escape / escape / util / netconf.py View on Github external
def parseChild (parent, part):
      for key, value in part.iteritems():
        if isinstance(value, dict):
          node = sub_ele(parent, key)
          # Need to go deeper -> recursion
          parseChild(node, value)
        elif value is not None:
          node = sub_ele(parent, key)
          node.text = str(value)
github ansible / ansible / lib / ansible / plugins / netconf / junos.py View on Github external
:param check: Check correctness of syntax
        :param timeout: specifies the confirm timeout in seconds
        :param comment: Message to write to commit log
        :param synchronize: Synchronize commit on remote peers
        :param at_time: Time at which to activate configuration changes
        :return: Received rpc response from remote host
        """
        obj = new_ele('commit-configuration')
        if confirmed:
            sub_ele(obj, 'confirmed')
        if check:
            sub_ele(obj, 'check')
        if synchronize:
            sub_ele(obj, 'synchronize')
        if at_time:
            subele = sub_ele(obj, 'at-time')
            subele.text = str(at_time)
        if comment:
            subele = sub_ele(obj, 'log')
            subele.text = str(comment)
        if timeout:
            subele = sub_ele(obj, 'confirm-timeout')
            subele.text = str(timeout)
        return self.rpc(obj)
github hsnlab / escape / escape / escape / util / netconf.py View on Github external
def parseChild (parent, part):
      for key, value in part.iteritems():
        if isinstance(value, dict):
          node = sub_ele(parent, key)
          # Need to go deeper -> recursion
          parseChild(node, value)
        elif value is not None:
          node = sub_ele(parent, key)
          node.text = str(value)
github internap / netman / netman / adapters / switches / juniper / base.py View on Github external
def query(self, *args):
        filter_node = new_ele("filter")
        conf = sub_ele(filter_node, "configuration")
        for arg in args:
            conf.append(arg())
        return self.netconf.get_config(source="candidate" if self.in_transaction else "running", filter=filter_node)
github alibaba / ansible-provider-docs / lib / ansible / plugins / netconf / junos.py View on Github external
Depends on the `:confirmed-commit` capability.
        :confirmed: whether this is a confirmed commit
        :timeout: specifies the confirm timeout in seconds
        """
        obj = new_ele('commit-configuration')
        if confirmed:
            sub_ele(obj, 'confirmed')
        if check:
            sub_ele(obj, 'check')
        if synchronize:
            sub_ele(obj, 'synchronize')
        if at_time:
            subele = sub_ele(obj, 'at-time')
            subele.text = str(at_time)
        if comment:
            subele = sub_ele(obj, 'log')
            subele.text = str(comment)
        if timeout:
            subele = sub_ele(obj, 'confirm-timeout')
            subele.text = str(timeout)
        return self.rpc(obj)