pystorcli.exc
StorCLI exceptions
1# -*- coding: utf-8 -*- 2 3# Copyright (c) 2018, Martin Dojcak <martin@dojcak.sk> 4# Copyright (c) 2022, Rafael Leira & Naudit HPCN S.L. <rafael.leira@naudit.es> 5# See LICENSE for details. 6 7'''StorCLI exceptions 8''' 9 10import subprocess 11 12 13class StorCliError(Exception): 14 """StorCLI general exception 15 """ 16 pass 17 18 19class StorCliCmdError(StorCliError): 20 """StorCLI command output error 21 """ 22 23 def __init__(self, cmd, msg): 24 msg = msg.lstrip().rstrip() 25 super().__init__("Command '{0}' error: {1}".format(' '.join(cmd), msg)) 26 27 28class StorCliMissingError(StorCliError): 29 """StorCLI missing object error 30 """ 31 32 def __init__(self, obj_type, obj_name): 33 super().__init__( 34 "Object '{0}' doesnt exist: {1}".format(obj_type, obj_name)) 35 36 37class StorCliRunError(StorCliError): 38 """StorCLI general subprocess exception 39 """ 40 41 def __init__(self, ctx, *args, **kwargs): 42 super().__init__(ctx, *args, **kwargs) 43 self.cmd = ctx.cmd if isinstance( 44 ctx, subprocess.SubprocessError) else ctx.args 45 self.stderr = ctx.stderr 46 self.stdout = ctx.stdout 47 48 49class StorCliRunTimeError(StorCliRunError): 50 """StorCLI subprocess ret code exception 51 """ 52 53 def __init__(self, ctx, *args, **kwargs): 54 super().__init__(ctx, *args, **kwargs) 55 self.retcode = ctx.returncode if isinstance( 56 ctx, subprocess.CalledProcessError) else None 57 58 def __str__(self): 59 return ("Command '{0}' returned with non-zero exit status " 60 "{1}: {2}".format(' '.join(self.cmd), self.retcode, self.stderr)) 61 62 63class StorCliRunTimeout(StorCliError): 64 """StorCLI subprocess timeout exception 65 """ 66 67 def __init__(self, ctx, *args, **kwargs): 68 super().__init__(ctx, *args, **kwargs) 69 self.timeout = ctx.timeout 70 71 def __str__(self): 72 return ("Command '{0}' timeout after " 73 "{1}: {2}, {3}".format(' '.join(self.cmd), self.timeout, self.stdout, self.stderr))
class
StorCliError(builtins.Exception):
StorCLI general exception
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- args
20class StorCliCmdError(StorCliError): 21 """StorCLI command output error 22 """ 23 24 def __init__(self, cmd, msg): 25 msg = msg.lstrip().rstrip() 26 super().__init__("Command '{0}' error: {1}".format(' '.join(cmd), msg))
StorCLI command output error
Inherited Members
- builtins.BaseException
- with_traceback
- args
29class StorCliMissingError(StorCliError): 30 """StorCLI missing object error 31 """ 32 33 def __init__(self, obj_type, obj_name): 34 super().__init__( 35 "Object '{0}' doesnt exist: {1}".format(obj_type, obj_name))
StorCLI missing object error
Inherited Members
- builtins.BaseException
- with_traceback
- args
38class StorCliRunError(StorCliError): 39 """StorCLI general subprocess exception 40 """ 41 42 def __init__(self, ctx, *args, **kwargs): 43 super().__init__(ctx, *args, **kwargs) 44 self.cmd = ctx.cmd if isinstance( 45 ctx, subprocess.SubprocessError) else ctx.args 46 self.stderr = ctx.stderr 47 self.stdout = ctx.stdout
StorCLI general subprocess exception
Inherited Members
- builtins.BaseException
- with_traceback
- args
50class StorCliRunTimeError(StorCliRunError): 51 """StorCLI subprocess ret code exception 52 """ 53 54 def __init__(self, ctx, *args, **kwargs): 55 super().__init__(ctx, *args, **kwargs) 56 self.retcode = ctx.returncode if isinstance( 57 ctx, subprocess.CalledProcessError) else None 58 59 def __str__(self): 60 return ("Command '{0}' returned with non-zero exit status " 61 "{1}: {2}".format(' '.join(self.cmd), self.retcode, self.stderr))
StorCLI subprocess ret code exception
Inherited Members
- builtins.BaseException
- with_traceback
- args
64class StorCliRunTimeout(StorCliError): 65 """StorCLI subprocess timeout exception 66 """ 67 68 def __init__(self, ctx, *args, **kwargs): 69 super().__init__(ctx, *args, **kwargs) 70 self.timeout = ctx.timeout 71 72 def __str__(self): 73 return ("Command '{0}' timeout after " 74 "{1}: {2}, {3}".format(' '.join(self.cmd), self.timeout, self.stdout, self.stderr))
StorCLI subprocess timeout exception
Inherited Members
- builtins.BaseException
- with_traceback
- args