Open stdweird opened 8 years ago
Good idea, we have a nagios alarm for /etc/noquattor
without contents.
ccm-fetch
already prints the contents as a warning.
e.g.
# quattor-fetch
[WARN] CCM updates disabled globally (/etc/noquattor present)
[WARN] foo blah
@wdpypere what do we use for this?
We have a simple python script that does this.
#!/usr/bin/env python
#
# Copyright 2023-2023 Ghent University
#
# This file is part of vsc-host-tools,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.ugent.be/hpcugent/vsc-host-tools
#
# All rights reserved.
#
"""
Create an admin friendly noquattor.
"""
import argparse
import sys
from pathlib import Path
from os import getlogin
from datetime import datetime
import logging
def set_noquattor(filename, comment, force):
if filename.is_file():
if force:
filename.unlink()
else:
logging.error("Noquattor already set. Use '--force' to overwrite. Content:")
logging.error(filename.read_text())
sys.exit(1)
try:
filename.write_text("%s: %s - %s" % (getlogin(), datetime.now(), " ".join(comment)))
filename.chmod(0o600)
except PermissionError as err:
logging.error("Permissions error. (did you forget sudo?): %s", err)
def main():
parser = argparse.ArgumentParser(description='Handle noquattor file',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('comment', type=str, help="Comment to use in the noquattor file", nargs="*")
parser.add_argument("--location", "-l", default="/etc/noquattor", help="location of the file", type=Path)
parser.add_argument("--force", "-f", action="store_true", help="write file even if it exists")
parser.add_argument("--remove", "-r", action="store_true", help="remove existing noquattor file")
parser.add_argument("--show", "-s", action="store_true", help="show current noquattor file content")
args = parser.parse_args()
if args.remove:
if args.location.is_file():
args.location.unlink()
else:
logging.error("%s does not exist.", args.location)
sys.exit(1)
elif args.show:
if args.location.is_file():
print(args.location.read_text())
else:
logging.error("%s does not exist.", args.location)
sys.exit(2)
else:
set_noquattor(args.location, args.comment, args.force)
if __name__ == '__main__':
main()
does something like:
[root@node3903 ~]# noquattor installed new nvidia drivers
[root@node3903 ~]# noquattor -s
wdpypere: 2023-08-25 13:23:42.028443 - installed new nvidia drivers
The nice part is the original user is kept.
Standardised content could be meaningful, eg that /etc/noquattor is set, but implies
noaction
instead of do nothing. But by default i'd like it to use it store the reason why it was set, likefixing ticket 123
. When eg ccm-fetch or ncm-ncd run, it could print this message.I would add a cli tool to edit the message, esp if the message is structured, like
(
config::tiny
with textrender) by default, contents would be message only.Proposals for a good name and any config options are always welcome, otherwsie i'll use
quattor-disable