Skip to content

Instantly share code, notes, and snippets.

@chianingwang
Created June 14, 2018 20:19
Show Gist options
  • Save chianingwang/0f192c2cff294a8ced100ff0258b0ca8 to your computer and use it in GitHub Desktop.
Save chianingwang/0f192c2cff294a8ced100ff0258b0ca8 to your computer and use it in GitHub Desktop.
```
# /opt/ss/bin/python add_migrator_by_account_list.py -h
usage: add_migrator_by_account_list.py [-h] cluster accounts credential
positional arguments:
cluster name of the cluster
accounts file containing the account to use for migration
credential name of the credentials
optional arguments:
```
===for help
```
/opt/ss/bin/python add_migrator_by_account_list.py -h
```
===for run <cluster name> <account list file> <credential you configure on ss controller>
```
/opt/ss/bin/python add_migrator_by_account_list.py test ./account_list.csv cloud_s3
```
===
```
cat account_list.csv
AUTH_s3
```
===
REMEMBER Deployo it !
@chianingwang
Copy link
Author

chianingwang commented Jun 14, 2018

$ cat add_migrator_by_account_list.py

import argparse
import sys
import os


def get_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('cluster', help='name of the cluster')
    parser.add_argument(
        'accounts',
        help='file containing the account to use for migration')
    parser.add_argument('credential', help='name of the credentials')
    return parser.parse_args()


def import_django():
    # 5.x imports
    sys.path.append('/opt/ss/deploy/current')
    # find our psql first:
    os.environ['PATH'] = '/opt/ss/pgsql-9.5/bin:' + os.environ['PATH']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'ssman.settings.active'
    os.umask(0022)
    import django
    django.setup()
    global ssman
    import ssman.app.models.cloud_sync
    import ssman.app.models.cluster


def main():
    args = get_args()
    import_django()

    cluster = ssman.app.models.cluster.Cluster.objects.filter(
        name=args.cluster).first()
    credential =\
        ssman.app.models.cloud_sync.CloudSyncCredential.objects.filter(
            name=args.credential).first()

    with open(args.accounts) as f:
        all_accounts = [line.strip() for line in f.readlines()]

    for account in all_accounts:
        new_migration = ssman.app.models.cloud_sync.CloudSyncMigration(
            cluster=cluster,
            credential=credential,
            source_account=account,
            swift_account=account,
            source_bucket='/*',
            older_than=0,
            all_source_buckets=True,
            object_prefix='',
            destination_container='')
        new_migration.save()


main()

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