Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #725 from calvinmclean/script_fixes
Browse files Browse the repository at this point in the history
Add/fix more scripts
  • Loading branch information
Calvin McLean authored Sep 27, 2019
2 parents 951a4ca + bdb289d commit d08379b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
([#723](https://github.com/cyverse/atmosphere/pull/723))
- More Jetstream specific scripts
([#724](https://github.com/cyverse/atmosphere/pull/724))
- Add purge_old_chromo_images script and install postgresql client
([#725](https://github.com/cyverse/atmosphere/pull/725))

### Fixed
- Filter out system-y metadata keys introduced in Rocky which we aren't currently using and make Glance client confused
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RUN apt-get update && \
make \
netcat \
openssl \
postgresql-client \
python \
python-dev \
python-m2crypto \
Expand Down
38 changes: 26 additions & 12 deletions scripts/jetstream/enforce_special_allocation_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,31 @@ def main():
Reset quotas for users on a particular allocation source
"""
parser = argparse.ArgumentParser()
parser.add_argument('--dry-run', action='store_true', help='Print output rather than perform operation')
parser.add_argument('--allocation-source', required=True,
help='Allocation source name to reset quotas for, e.g. TG-ASC160018')
parser.add_argument('--quota-id', required=True, type=int,
help='Quota ID to set')
parser.add_argument('--whitelist-quota-ids', type=lambda s: [int(item.strip()) for item in s.split(',')],
help='Quota IDs that are acceptable and won\'t be overwritten (comma separated)')
parser.add_argument(
'--dry-run',
action='store_true',
help='Print output rather than perform operation'
)
parser.add_argument(
'--allocation-source',
required=True,
help='Allocation source name to reset quotas for, e.g. TG-ASC160018'
)
parser.add_argument(
'--quota-id', required=True, type=int, help='Quota ID to set'
)
parser.add_argument(
'--whitelist-quota-ids',
type=lambda s: [int(item.strip()) for item in s.split(',')],
help=
'Quota IDs that are acceptable and won\'t be overwritten (comma separated)'
)
parser.set_defaults(dry_run=False)
args = parser.parse_args()
return run_command(args.dry_run,
args.allocation_source,
args.quota_id,
args.whitelist_quota_ids)
return run_command(
args.dry_run, args.allocation_source, args.quota_id,
args.whitelist_quota_ids
)


def run_command(dry_run, allocation_source, quota_id, whitelist_quota_ids):
Expand Down Expand Up @@ -70,7 +82,9 @@ def run_command(dry_run, allocation_source, quota_id, whitelist_quota_ids):
print('DRY-RUN: Not changing quota to {}'.format(quota_id))
else:
print('Changing provider quota to {}...'.format(quota_id))
updated_provider_quota = set_provider_quota(identity.uuid, quota=quota_to_set)
updated_provider_quota = set_provider_quota(
identity.uuid, quota=quota_to_set
)
print('Updated provider quota: {}'.format(updated_provider_quota))
print('Changing DB quota to {}...'.format(quota_id))
identity.quota = quota_to_set
Expand Down
22 changes: 22 additions & 0 deletions scripts/purge_old_chromo_images
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

IMAGE_LOCATION='/Storage/'
DAYS_TO_KEEP_IMAGES=7
LOG=/var/log/atmo_chromo_purge_old_images.log

# first grab any files that are older than DAYS_TO_KEEP_IMAGES
old_files=`/usr/bin/find ${IMAGE_LOCATION} -maxdepth 1 -type f -mtime +${DAYS_TO_KEEP_IMAGES}`

for f in $old_files; do

# as a precaution, make sure no process is currently accessing old image
`/bin/fuser $f >/dev/null 2>&1`
if [ $? -ne 0 ]; then
echo `date`" Deleting old chromogenic image $f"
echo `date`" Deleting old chromogenic image $f" >> $LOG
/bin/rm -f $f
else
echo `date`" Skipping delete of chromogenic image $f, it's being used"
echo `date`" Skipping delete of chromogenic image $f, it's being used" >>$LOG
fi
done

0 comments on commit d08379b

Please sign in to comment.