27 |
27 |
import os.path
|
28 |
28 |
import copy
|
29 |
29 |
import time
|
|
30 |
import logging
|
30 |
31 |
from cStringIO import StringIO
|
31 |
32 |
|
32 |
33 |
from ganeti import utils
|
... | ... | |
50 |
51 |
"FormatError", "SplitNodeOption", "SubmitOrSend",
|
51 |
52 |
"JobSubmittedException", "FormatTimestamp", "ParseTimespec",
|
52 |
53 |
"ValidateBeParams",
|
|
54 |
"ToStderr", "ToStdout",
|
53 |
55 |
]
|
54 |
56 |
|
55 |
57 |
|
... | ... | |
626 |
628 |
msg = str(err)
|
627 |
629 |
if isinstance(err, errors.ConfigurationError):
|
628 |
630 |
txt = "Corrupt configuration file: %s" % msg
|
629 |
|
logger.Error(txt)
|
|
631 |
logging.error(txt)
|
630 |
632 |
obuf.write(txt + "\n")
|
631 |
633 |
obuf.write("Aborting.")
|
632 |
634 |
retcode = 2
|
... | ... | |
718 |
720 |
utils.debug = options.debug
|
719 |
721 |
|
720 |
722 |
if old_cmdline:
|
721 |
|
logger.Info("run with arguments '%s'" % old_cmdline)
|
|
723 |
logging.info("run with arguments '%s'", old_cmdline)
|
722 |
724 |
else:
|
723 |
|
logger.Info("run with no arguments")
|
|
725 |
logging.info("run with no arguments")
|
724 |
726 |
|
725 |
727 |
try:
|
726 |
728 |
result = func(options, args)
|
727 |
729 |
except (errors.GenericError, luxi.ProtocolError), err:
|
728 |
730 |
result, err_msg = FormatError(err)
|
729 |
|
logger.ToStderr(err_msg)
|
|
731 |
logging.exception("Error durring command processing")
|
|
732 |
ToStderr(err_msg)
|
730 |
733 |
|
731 |
734 |
return result
|
732 |
735 |
|
... | ... | |
858 |
861 |
except ValueError:
|
859 |
862 |
raise errors.OpPrereqError("Invalid time specification '%s'" % value)
|
860 |
863 |
return value
|
|
864 |
|
|
865 |
|
|
866 |
def _ToStream(stream, txt, *args):
|
|
867 |
"""Write a message to a stream, bypassing the logging system
|
|
868 |
|
|
869 |
@type stream: file object
|
|
870 |
@param stream: the file to which we should write
|
|
871 |
@type txt: str
|
|
872 |
@param txt: the message
|
|
873 |
|
|
874 |
"""
|
|
875 |
if args:
|
|
876 |
args = tuple(args)
|
|
877 |
stream.write(txt % args)
|
|
878 |
else:
|
|
879 |
stream.write(txt)
|
|
880 |
stream.write('\n')
|
|
881 |
stream.flush()
|
|
882 |
|
|
883 |
|
|
884 |
def ToStdout(txt, *args):
|
|
885 |
"""Write a message to stdout only, bypassing the logging system
|
|
886 |
|
|
887 |
This is just a wrapper over _ToStream.
|
|
888 |
|
|
889 |
@type txt: str
|
|
890 |
@param txt: the message
|
|
891 |
|
|
892 |
"""
|
|
893 |
_ToStream(sys.stdout, txt, *args)
|
|
894 |
|
|
895 |
|
|
896 |
def ToStderr(txt, *args):
|
|
897 |
"""Write a message to stderr only, bypassing the logging system
|
|
898 |
|
|
899 |
This is just a wrapper over _ToStream.
|
|
900 |
|
|
901 |
@type txt: str
|
|
902 |
@param txt: the message
|
|
903 |
|
|
904 |
"""
|
|
905 |
_ToStream(sys.stderr, txt, *args)
|