Exemple #1
0
    def __init__(self,
                 cmd=None,
                 rsp=None,
                 errs=None,
                 dev=None,
                 timeout=None,
                 re=None):
        """
          :cmd: is the rpc command
          :rsp: is the rpc response (after <rpc-reply>)
          :errs: is a list of dictionaries of extracted <rpc-error> elements.
          :dev: is the device rpc was executed on
          :timeout: is the timeout value of the device
          :re: is the RE or member exception occured on
        """
        self.cmd = cmd
        self.rsp = rsp
        self.dev = dev
        self.timeout = timeout
        self.re = re
        self.rpc_error = None
        self.xml = rsp
        # To handle errors coming from ncclient, Here errs is list of RPCError
        if isinstance(errs, RPCError) and hasattr(errs, 'errors'):
            self.errs = [JXML.rpc_error(error.xml) for error in errs.errors]
            for error in errs.errors:
                if error.severity == 'error':
                    self.rsp = JXML.remove_namespaces(error.xml)
                    break
            else:
                if errs.severity == 'warning':
                    for error in errs.errors:
                        if error.severity == 'warning':
                            self.rsp = JXML.remove_namespaces(error.xml)
                            break
            self.message = errs.message
        else:
            self.errs = errs
            self.message = "\n".join(["%s: %s" % (err['severity'].strip(),
                                                  err['message'].strip())
                                      for err in errs
                                      if err['message'] is not None and
                                      err['severity'] is not None]) \
                if isinstance(errs, list) else ''

        if isinstance(self.rsp, _Element):
            self.rpc_error = jxml.rpc_error(self.rsp)
            self.message = self.message or self.rpc_error['message']
            if self.errs is None or not isinstance(self.errs, list):
                self.errs = [self.rpc_error]
Exemple #2
0
    def commit_check(self):
        """
        Perform a commit check.  If the commit check passes, this function
        will return ``True``.  If the commit-check results in warnings, they
        are reported and available in the Exception errs.

        :returns: ``True`` if commit-check is successful (no errors)
        :raises CommitError: When errors detected in candidate configuration.
                             You can use the Exception errs variable
                             to identify the specific problems
        :raises RpcError: When underlying ncclient has an error
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcTimeoutError:
            raise
        except RpcError as err:        # jnpr.junos exception
            if err.rsp is not None and err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp, errs=err.errs)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #3
0
    def __init__(self,
                 cmd=None,
                 rsp=None,
                 errs=None,
                 dev=None,
                 timeout=None,
                 re=None):
        """
          :cmd: is the rpc command
          :rsp: is the rpc response (after <rpc-reply>)
          :errs: is a list of <rpc-error> elements
          :dev: is the device rpc was executed on
          :timeout: is the timeout value of the device
          :re: is the RE or member exception occured on
        """
        self.cmd = cmd
        self.rsp = rsp
        self.errs = errs
        self.dev = dev
        self.timeout = timeout
        self.re = re
        self.rpc_error = None

        if isinstance(self.rsp, _Element):
            self.rpc_error = jxml.rpc_error(self.rsp)
            if self.errs is None:
                self.errs = self.rpc_error
Exemple #4
0
    def commit_check(self):
        """
        Perform a commit check.  If the commit check passes, this function
        will return ``True``.  If the commit-check results in warnings, they
        are reported and available in the Exception errs.

        :returns: ``True`` if commit-check is successful (no errors)
        :raises CommitError: When errors detected in candidate configuration.
                             You can use the Exception errs variable
                             to identify the specific problems
        :raises RpcError: When underlying ncclient has an error
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcTimeoutError:
            raise
        except RpcError as err:        # jnpr.junos exception
            if err.rsp is not None and err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp, errs=err.errs)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #5
0
    def __init__(self, cmd=None, rsp=None, errs=None, dev=None,
                 timeout=None, re=None):
        """
          :cmd: is the rpc command
          :rsp: is the rpc response (after <rpc-reply>)
          :errs: is a list of dictionaries of extracted <rpc-error> elements.
          :dev: is the device rpc was executed on
          :timeout: is the timeout value of the device
          :re: is the RE or member exception occured on
        """
        self.cmd = cmd
        self.rsp = rsp
        self.dev = dev
        self.timeout = timeout
        self.re = re
        self.rpc_error = None
        self.xml = rsp
        # To handle errors coming from ncclient, Here errs is list of RPCError
        if isinstance(errs, RPCError) and hasattr(errs, 'errors'):
            self.errs = [JXML.rpc_error(error.xml) for error in errs.errors]
            for error in errs.errors:
                if error.severity == 'error':
                    self.rsp = JXML.remove_namespaces(error.xml)
                    break
            else:
                if errs.severity == 'warning':
                    for error in errs.errors:
                        if error.severity == 'warning':
                            self.rsp = JXML.remove_namespaces(error.xml)
                            break
            self.message = errs.message
        else:
            self.errs = errs
            self.message = "\n".join(["%s: %s" % (err['severity'].strip(),
                                                  err['message'].strip())
                                      for err in errs
                                      if err['message'] is not None and
                                      err['severity'] is not None]) \
                if isinstance(errs, list) else ''

        if isinstance(self.rsp, _Element):
            self.rpc_error = jxml.rpc_error(self.rsp)
            self.message = self.message or self.rpc_error['message']
            if self.errs is None or not isinstance(self.errs, list):
                self.errs = [self.rpc_error]
 def __repr__(self):
     """
       pprints the response XML attribute
     """
     if self.rsp is not None:
         self.rpc_error = jxml.rpc_error(self.rsp)
         if self.errs is None:
             self.errs = self.rpc_error
         return "{0}(severity: {1}, bad_element: {2}, message: {3})"\
             .format(self.__class__.__name__, self.rpc_error['severity'],
                     self.rpc_error['bad_element'], self.rpc_error['message'])
Exemple #7
0
 def __repr__(self):
     """
       pprints the response XML attribute
     """
     if self.rsp is not None:
         self.rpc_error = jxml.rpc_error(self.rsp)
         if self.errs is None:
             self.errs = self.rpc_error
         return "{0}(severity: {1}, bad_element: {2}, message: {3})"\
             .format(self.__class__.__name__, self.rpc_error['severity'],
                     self.rpc_error['bad_element'], self.rpc_error['message'])
    def commit_check(self, **kvargs):
        """
        Perform a commit check.  If the commit check passes, this function
        will return ``True``.  If the commit-check results in warnings, they
        are reported and available in the Exception errs.

        :param int timeout: If provided the command will wait for completion
                            using the provided value as timeout (seconds).

        :returns: ``True`` if commit-check is successful (no errors)
        :raises CommitError: When errors detected in candidate configuration.
                             You can use the Exception errs variable
                             to identify the specific problems
        :raises RpcError: When underlying ncclient has an error
        """
        rpc_args = {}

        # if a timeout is provided, then include that in the RPC

        timeout = kvargs.get("timeout")
        if timeout:
            rpc_args["dev_timeout"] = timeout

        try:
            self.rpc.commit_configuration(check=True, **rpc_args)
        except RpcTimeoutError:
            raise
        except RpcError as err:  # jnpr.junos exception
            if err.rsp is not None and err.rsp.find("ok") is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp, errs=err.errs)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            if hasattr(err, "xml") and isinstance(err.xml, etree._Element):
                return JXML.rpc_error(err.xml)
            else:
                raise

        return True
Exemple #9
0
    def commit_check(self):
        """
        perform a commit check.  if the commit check passes, this function
        will return :True:

        If there is a commit check error, then the RPC error reply XML
        structure will be returned
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcError as err:        # jnpr.junos exception
            if err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #10
0
    def commit_check(self):
        """
        perform a commit check.  if the commit check passes, this function
        will return :True:

        If there is a commit check error, then the RPC error reply XML
        structure will be returned
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcError as err:  # jnpr.junos exception
            if err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #11
0
    def commit_check(self):
        """
        Perform a commit check.  If the commit check passes, this function
        will return ``True``.  If the commit-check results in warnings, they
        are not reported (at this time).

        :returns: ``True`` if commit-check is successful (no errors)
        :raises RpcError: when commit-check fails and resulting
                          exception contains XML data.
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcError as err:        # jnpr.junos exception
            if err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #12
0
    def commit_check(self):
        """
        Perform a commit check.  If the commit check passes, this function
        will return ``True``.  If the commit-check results in warnings, they
        are not reported (at this time).

        :returns: ``True`` if commit-check is successful (no errors)
        :raises RpcError: when commit-check fails and resulting
                          exception contains XML data.
        """
        try:
            self.rpc.commit_configuration(check=True)
        except RpcError as err:  # jnpr.junos exception
            if err.rsp.find('ok') is not None:
                # this means there is a warning, but no errors
                return True
            else:
                raise CommitError(cmd=err.cmd, rsp=err.rsp)
        except Exception as err:
            # :err: is from ncclient, so extract the XML data
            # and convert into dictionary
            return JXML.rpc_error(err.xml)

        return True
Exemple #13
0
 def __init__(self, rsp):
     RpcError.__init__(self, rsp=rsp)
     self.rpc_error = jxml.rpc_error(rsp)
Exemple #14
0
 def __init__(self, cmd=None, rsp=None, errs=None):
     RpcError.__init__(self, cmd, rsp, errs)
     self.rpc_error = jxml.rpc_error(rsp)
     if self.errs is None:
         self.errs = self.rpc_error
Exemple #15
0
 def __init__(self, rsp):
     RpcError.__init__(self, rsp=rsp)
     self.rpc_error = jxml.rpc_error(rsp)
Exemple #16
0
 def __init__(self, cmd=None, rsp=None, errs=None):
     RpcError.__init__(self, cmd, rsp, errs)
     self.rpc_error = jxml.rpc_error(rsp)
     if self.errs is None:
         self.errs = self.rpc_error