-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #559 from tcmitchell/552-maintenance
Add geni-maintenance script for maintenance mode
- Loading branch information
Showing
6 changed files
with
136 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
# ---------------------------------------------------------------------- | ||
# Copyright (c) 2017 Raytheon BBN Technologies | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining | ||
# a copy of this software and/or hardware specification (the "Work") to | ||
# deal in the Work without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Work, and to permit persons to whom the Work | ||
# is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be | ||
# included in all copies or substantial portions of the Work. | ||
# | ||
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS | ||
# IN THE WORK. | ||
# ---------------------------------------------------------------------- | ||
|
||
import argparse | ||
import os | ||
import sys | ||
import ConfigParser | ||
|
||
|
||
def parse_args(argv): | ||
parser = argparse.ArgumentParser(description='Set/Clear maintenance mode') | ||
|
||
default_conf = '@pkgsysconfdir@/chapi.ini' | ||
parser.add_argument("-c", "--conf", default=default_conf, | ||
help='chapi config file (default:%s)' % (default_conf)) | ||
parser.add_argument('--clear', action="store_true", default=False, | ||
help='clear maintenance mode') | ||
parser.add_argument('message', nargs='?', default=None, | ||
help='the maintenance message') | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def load_ini(ini_file): | ||
config = ConfigParser.SafeConfigParser() | ||
config.read(ini_file) | ||
return config | ||
|
||
|
||
def main(argv=None): | ||
if argv is None: | ||
argv = sys.argv | ||
args = parse_args(argv) | ||
if not args.clear and not args.message: | ||
print 'You must specify a message or use the --clear option' | ||
return 2 | ||
config = load_ini(args.conf) | ||
maint_file = config.get('geni', 'maintenance_outage_location') | ||
print 'Found maintenance file %s' % (maint_file) | ||
if args.clear: | ||
# Delete the file | ||
os.remove(maint_file) | ||
print 'Cleared maintenance mode' | ||
else: | ||
# Write/create the file with message as the contents | ||
with open(maint_file, 'wb') as dest: | ||
dest.write(args.message) | ||
print 'Set maintenance mode to %r' % (args.message) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
.TH GENI-MAINTENANCE 1 "March 1, 2017" | ||
.SH NAME | ||
geni-maintenance \- set or clear maintenance mode | ||
.SH SYNOPSIS | ||
.B geni-maintenance | ||
.I <message> | ||
.br | ||
.B geni-maintenance | ||
.I \-\-clear | ||
.SH DESCRIPTION | ||
.B geni-maintenance | ||
allows a GENI operator to set or clear a maintenance outage. | ||
|
||
The first form enables maintenance mode and sets the maintenance message | ||
to the message argument. Use a quoted string for multiple words. See EXAMPLES | ||
for an example. | ||
|
||
The second form clears maintenance mode. | ||
.SH OPTIONS | ||
These programs follow the usual GNU command line syntax, with long | ||
options starting with two dashes (`-'). | ||
.TP | ||
.B \-\-clear | ||
Clear the maintenance message. The message is ignored if the \-\-clear | ||
option is present. | ||
.TP | ||
.B \-c <conf file>, \-\-conf <conf file> | ||
The clearinghouse config file. This defaults to @pkgsysconfdir@/chapi.ini | ||
.TP | ||
.B \-h, \-\-help | ||
Show summary of options. | ||
.SH EXAMPLES | ||
Set maintenance outage: | ||
|
||
geni-maintenance 'The GENI Clearinghouse is in maintenance' | ||
|
||
Clear maintenance outage: | ||
|
||
geni-maintenance --clear | ||
.SH AUTHOR | ||
geni-maintenance was written by Raytheon BBN Technologies. |