Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple CLI tool for /etc/noquattor and standardise the content #148

Open
stdweird opened this issue Oct 21, 2016 · 4 comments
Open

Add simple CLI tool for /etc/noquattor and standardise the content #148

stdweird opened this issue Oct 21, 2016 · 4 comments

Comments

@stdweird
Copy link
Member

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, like fixing 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

comment =  Working on abc
action = noaction

(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

@stdweird stdweird added this to the 16.12 milestone Oct 21, 2016
@jrha
Copy link
Member

jrha commented Oct 21, 2016

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

@stdweird stdweird modified the milestones: 17.2, 16.12 Dec 6, 2016
@jrha jrha modified the milestones: 17.3, 17.2 Feb 10, 2017
@jrha jrha modified the milestones: 17.6, 17.3 Mar 22, 2017
@jrha jrha modified the milestones: 17.10, 17.8 Sep 7, 2017
@jrha jrha removed this from the 17.12 milestone Nov 24, 2017
@stdweird
Copy link
Member Author

@wdpypere what do we use for this?

@wdpypere
Copy link
Contributor

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()

@wdpypere
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants