3 # Notify users of slices that are about to expire
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2005 The Trustees of Princeton University
13 from optparse import OptionParser
15 # Load shell with default configuration
16 sys.path.append('/usr/share/plc_api')
17 from PLC.Shell import Shell
18 plc = Shell(globals())
20 PLC_WWW_HOST = plc.config.PLC_WWW_HOST
21 PLC_NAME = plc.config.PLC_NAME
27 slice_url = """https://%(PLC_WWW_HOST)s/db/slices/index.php?id=""" % locals()
29 parser = OptionParser()
30 parser.add_option("-s", "--slice", action = "append", dest = "slices", default = None,
31 help = "Slice(s) to check (default: all)")
32 parser.add_option("-x", "--expires", type = "int", default = 5,
33 help = "Warn if slice expires this many days from now (default: %default)")
34 parser.add_option("-n", "--dryrun", action = "store_true", default = False,
35 help = "Dry run, do not actually e-mail users (default: %default)")
36 parser.add_option("-f", "--force", action = "store_true", default = False,
37 help = "Force, send e-mail even if slice is not close to expiring (default: %default)")
38 parser.add_option("-v", "--verbose", action = "store_true", default = False,
39 help = "Be verbose (default: %default)")
40 (options, args) = parser.parse_args()
42 now = int(time.time())
43 expires = now + (options.expires * 24 * 60 * 60)
46 print "Checking for slices that expire before " + time.ctime(expires)
48 slice_filter = {'peer_id': None}
50 slice_filter['name'] = options.slices
52 for slice in GetSlices(slice_filter, ['slice_id', 'name', 'expires', 'description', 'url', 'person_ids']):
53 # See if slice expires before the specified warning date
54 if not options.force and slice['expires'] > expires:
57 # Calculate number of whole days left
58 delta = slice['expires'] - now
59 days = delta / 24 / 60 / 60
61 days = "less than a day"
67 days = "%d day%s" % (days, suffix)
70 slice_id = slice['slice_id']
73 The %(PLC_NAME)s slice %(name)s will expire in %(days)s.
76 # Explain that slices must have descriptions and URLs
77 if not slice['description'] or not slice['description'].strip() or \
78 not slice['url'] or not slice['url'].strip():
80 Before you may renew this slice, you must provide a short description
81 of the slice and a link to a project website.
84 # Provide links to renew or delete the slice
86 To update, renew, or delete this slice, visit the URL:
88 %(slice_url)s%(slice_id)d
92 if slice['person_ids']:
94 print message % locals()
96 NotifyPersons(slice['person_ids'],
97 "%(PLC_NAME)s slice %(name)s expires in %(days)s" % locals(),
100 print slice['name'], "has no users, skipping"