How to use the ncclient.xml_.new_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)
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 ansible / ansible / lib / ansible / plugins / netconf / junos.py View on Github external
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.
        :param confirmed: whether this is a confirmed commit
        :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
has this input list, called 'options'. Switches is used for connectVNF
    rpc in order to set the switches where the vnf should be connected.

    :param rpc_name: rpc name
    :type rpc_name: str
    :param options: additional RPC input in the specific  tag
    :type options: dict
    :param switches: set the switches where the vnf should be connected
    :type switches: list
    :param params: input params for the RPC using param's name as XML tag name
    :type params: dict
    :return: raw RPC message in XML format (lxml library)
    :rtype: :class:`lxml.etree.ElementTree`
    """
    # create the desired xml element
    xsd_fetch = new_ele(rpc_name)
    # set the namespace of your rpc
    xsd_fetch.set('xmlns', self.RPC_NAMESPACE)
    # set input params
    self.__parse_rpc_params(xsd_fetch, params)
    # we need to remove the confusing netconf namespaces with our own function
    rpc_request = self.__remove_namespace(xsd_fetch, self.NETCONF_NAMESPACE)
    # show how the created rpc message looks like
    if self.debug:
      print "Generated raw RPC message:\n", etree.tostring(rpc_request,
                                                           pretty_print=True)
    return rpc_request
github internap / netman / netman / adapters / switches / juniper / base.py View on Github external
def __init__(self):
        self.root = new_ele("configuration")
        self.vlans_root = None
        self.interfaces_root = None
        self.protocols_root = None
        self.sub_protocol_roots = {}
github alibaba / ansible-provider-docs / lib / ansible / plugins / netconf / junos.py View on Github external
def get_device_info(self):
        device_info = dict()
        device_info['network_os'] = 'junos'
        ele = new_ele('get-software-information')
        data = self.execute_rpc(to_xml(ele))
        reply = to_ele(data)
        sw_info = reply.find('.//software-information')

        device_info['network_os_version'] = self.get_text(sw_info, 'junos-version')
        device_info['network_os_hostname'] = self.get_text(sw_info, 'host-name')
        device_info['network_os_model'] = self.get_text(sw_info, 'product-model')

        return device_info