Skip to content

Commit

Permalink
Merge pull request #559 from tcmitchell/552-maintenance
Browse files Browse the repository at this point in the history
Add geni-maintenance script for maintenance mode
  • Loading branch information
tcmitchell authored Mar 1, 2017
2 parents 4254bca + 00d8c7d commit 9131f5f
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Fix authorization for get_requests_for_context
([#536](https://github.com/GENI-NSF/geni-ch/issues/536))
* Add geni-maintenance script to set and clear maintenance mode
([#552](https://github.com/GENI-NSF/geni-ch/issues/552))
* Add support for swapping identities to support IdP changes
([#557](https://github.com/GENI-NSF/geni-ch/issues/557))

Expand Down
2 changes: 2 additions & 0 deletions bin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TEMPLATES = \
geni-install-templates \
geni-list-idp-members \
geni-list-pending-requests \
geni-maintenance \
geni-sign-tool-csr \
geni-expiring-certs

Expand All @@ -51,6 +52,7 @@ sbin_SCRIPTS = \
geni-install-templates \
geni-list-idp-members \
geni-list-pending-requests \
geni-maintenance \
geni-sign-tool-csr \
geni-expiring-certs

Expand Down
73 changes: 73 additions & 0 deletions bin/geni-maintenance.in
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())
2 changes: 2 additions & 0 deletions geni-chapi.spec
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ rm -rf $RPM_BUILD_ROOT
%{_sbindir}/geni-list-idp-members
%{_sbindir}/geni-list-member-projects
%{_sbindir}/geni-list-pending-requests
%{_sbindir}/geni-maintenance
%{_sbindir}/geni-revoke-member-certificate
%{_sbindir}/geni-revoke-member-privilege
%{_sbindir}/geni-sign-tool-csr
Expand Down Expand Up @@ -565,6 +566,7 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/geni-list-idp-members.1.gz
%{_mandir}/man1/geni-list-member-projects.1.gz
%{_mandir}/man1/geni-list-pending-requests.1.gz
%{_mandir}/man1/geni-maintenance.1.gz
%{_mandir}/man1/geni-revoke-member-certificate.1.gz
%{_mandir}/man1/geni-revoke-member-privilege.1.gz
%{_mandir}/man1/geni-sign-tool-csr.1.gz
Expand Down
24 changes: 16 additions & 8 deletions man/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
pkgsysconfdir = $(sysconfdir)/$(PACKAGE)

edit = sed \
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g'
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
-e 's|@pkgsysconfdir[@]|$(pkgsysconfdir)|g'

TEMPLATES = \
geni-check-errors.1 \
geni-maintenance.1

TEMPLATES.IN = $(TEMPLATES:%=%.in)

geni-check-errors.1: Makefile
$(TEMPLATES): Makefile
rm -f $@ $@.tmp
srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
$(edit) $${srcdir}$@.in >$@.tmp
chmod a-w $@.tmp
mv $@.tmp $@

geni-check-errors.1: $(srcdir)/geni-check-errors.1.in
%: $(srcdir)/%.in

# Distribute but do not install
EXTRA_DIST = \
geni-check-errors.1.in
EXTRA_DIST = $(TEMPLATES.IN)

CLEANFILES = \
geni-check-errors.1
CLEANFILES = $(TEMPLATES)

man_MANS = \
geni-check-errors.1
geni-check-errors.1 \
geni-maintenance.1

dist_man_MANS = \
geni-add-member-privilege.1 \
Expand Down
41 changes: 41 additions & 0 deletions man/geni-maintenance.1.in
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.

0 comments on commit 9131f5f

Please sign in to comment.