示例#1
0
文件: edit.py 项目: styu2848/OPS2
    def request(self, hwcontext, 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`"""
        
        self.__setattr__('hwcontext',hwcontext)
        node = new_ele("copy-config")
        if target.find('.') != -1 :
            targetNode = util.datastore_or_url("target", 'url', self._assert)
            targetNode[0].text = target
        else:
            targetNode = util.datastore_or_url("target", target, self._assert)
        if source.find('.') !=-1 :
            sourceNode = util.datastore_or_url("source", 'url', self._assert)
            sourceNode[0].text = source
        else:
            sourceNode = util.datastore_or_url("source", source, self._assert)
        
        
        
        node.append(targetNode)
        node.append(sourceNode)
        return self._request(node)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    def request(self, rpc_command, source=None, filter=None):
        """
        *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

        *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`

        Examples of usage::

        dispatch('clear-arp-table')

        or dispatch element like ::

        xsd_fetch = new_ele('get-xnm-information')
        sub_ele(xsd_fetch, 'type').text="xml-schema"
        sub_ele(xsd_fetch, 'namespace').text="junos-configuration"
        dispatch(xsd_fetch)
        """

        if ET.iselement(rpc_command):
            node = rpc_command
        else:
            node = new_ele(rpc_command)
        if source is not None:
            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)
示例#5
0
    def request(self, rpc_command, source=None, filter=None):
        """
        *rpc_command* specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

        *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`

        Examples of usage::

            dispatch('clear-arp-table')

        or dispatch element like ::

            xsd_fetch = new_ele('get-xnm-information')
            sub_ele(xsd_fetch, 'type').text="xml-schema"
            sub_ele(xsd_fetch, 'namespace').text="junos-configuration"
            dispatch(xsd_fetch)
        """

        if etree.iselement(rpc_command):
            node = rpc_command
        else:
            node = new_ele(rpc_command)
        if source is not None:
            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)
示例#6
0
文件: edit.py 项目: styu2848/OPS2
    def request(self,hwcontext,target):
        """Delete a configuration datastore.

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

        :seealso: :ref:`srctarget_params`"""
        self.__setattr__('hwcontext',hwcontext)
        node = new_ele("delete-config")
        if target.find('.') != -1 :
            targetNode = util.datastore_or_url("target", 'url', self._assert)
            targetNode[0].text = target
        else:
            targetNode = util.datastore_or_url("target", target, self._assert)
#         node.append(util.datastore_or_url("target", target, self._assert))
        node.append(targetNode)
        return self._request(node)
示例#7
0
文件: edit.py 项目: styu2848/OPS2
    def request(self,hwcontext,target, config, default_operation=None, test_option=None, error_option=None):
        """Loads all or part of the specified *config* to the *target* configuration datastore.

        *target* is the name of the configuration datastore being edited

        *config* is the configuration, which must be rooted in the `config` element. It can be specified either as a string or an :class:`~xml.etree.ElementTree.Element`.

        *default_operation* if specified must be one of { `"merge"`, `"replace"`, or `"none"` }

        *test_option* if specified must be one of { `"test_then_set"`, `"set"` }

        *error_option* if specified must be one of { `"stop-on-error"`, `"continue-on-error"`, `"rollback-on-error"` }

        The `"rollback-on-error"` *error_option* depends on the `:rollback-on-error` capability.
        """
        
        self.__setattr__('hwcontext',hwcontext)
        node = new_ele("edit-config")
        node.append(util.datastore_or_url("target", target, self._assert))
        if error_option is not None and error_option != '':
            if error_option == "rollback-on-error":
                self._assert(":rollback-on-error")
            sub_ele(node, "error-option").text = error_option
        if test_option is not None:
            self._assert(':validate')
            sub_ele(node, "test-option").text = test_option
        if default_operation is not None:
        # TODO: check if it is a valid default-operation
            sub_ele(node, "default-operation").text = default_operation
        node.append(validated_element(config, ("config", qualify("config"))))
        return self._request(node)
示例#8
0
 def request(self, source):
     node = new_ele("validate")
     try:
         src = validated_element(source, ("config", qualify("config")))
     except Exception as e:
         logger.debug(e)
         src = util.datastore_or_url("source", source, self._assert)
     (node if src.tag == "source" else sub_ele(node, "source")).append(src)
     return self._request(node)
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    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))
        if filter is not None:
            node.append(util.build_filter(filter))
示例#12
0
    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))
        if filter is not None:
            node.append(util.build_filter(filter))
        return self._request(node)
示例#13
0
文件: edit.py 项目: styu2848/OPS2
    def request(self, source):
        """Validate the contents of the specified configuration.

        *source* is the name of the configuration datastore being validated or `config` element containing the configuration subtree to be validated

        :seealso: :ref:`srctarget_params`"""
        node = new_ele("validate")
        try:
            src = validated_element(source, ("config", qualify("config")))
        except Exception as e:
            logger.debug(e)
            src = util.datastore_or_url("source", source, self._assert)
        (node if src.tag == "source" else sub_ele(node, "source")).append(src)
        return self._request(node)
示例#14
0
 def request(self, target, config, default_operation=None, test_option=None, error_option=None):
     node = new_ele("edit-config")
     node.append(util.datastore_or_url("target", target, self._assert))
     if error_option is not None:
         if error_option == "rollback-on-error":
             self._assert(":rollback-on-error")
         sub_ele(node, "error-option").text = error_option
     if test_option is not None:
         self._assert(":validate")
         sub_ele(node, "test-option").text = test_option
     if default_operation is not None:
         # TODO: check if it is a valid default-operation
         sub_ele(node, "default-operation").text = default_operation
     node.append(validated_element(config, ("config", qualify("config"))))
     return self._request(node)
示例#15
0
 def request(self, source, filter=None):
     node = new_ele("get-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)
示例#16
0
 def request(self, source, target):
     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)
示例#17
0
 def request(self, target):
     node = new_ele("delete-config")
     node.append(util.datastore_or_url("target", target, self._assert))
     return self._request(node)