|
14 | 14 |
|
15 | 15 | # BEGIN CONFIGURATION
|
16 | 16 |
|
| 17 | +# some settings can also be set on command line. start with --help to see options |
| 18 | + |
17 | 19 | BASE_DATA_PATH='/data/db/sharding/' #warning: gets wiped every time you run this
|
18 | 20 | MONGO_PATH=os.getenv( "MONGO_HOME" , os.path.expanduser('~/10gen/mongo/') )
|
19 | 21 | print( "MONGO_PATH: " + MONGO_PATH )
|
|
32 | 34 | MONGOD_COLOR=36 #cyan
|
33 | 35 | BOLD=True
|
34 | 36 |
|
35 |
| -TEST_FOO_SHARD_KEY = "_id"; |
| 37 | +# defaults -- can change on command line |
| 38 | +COLLECTION_KEYS = {'foo' : '_id', 'bar': 'key'} |
36 | 39 |
|
37 | 40 | for x in sys.argv[1:]:
|
38 |
| - opt = x.split("=") |
39 |
| - if len(opt) != 2: |
| 41 | + opt = x.split("=", 1) |
| 42 | + if opt[0] != '--help' and len(opt) != 2: |
40 | 43 | raise Exception("bad arg: " + x )
|
41 | 44 |
|
42 |
| - if opt[0] == "chunkSize": |
43 |
| - CHUNK_SIZE = int(opt[1]) |
44 |
| - elif opt[0] == "foo": |
45 |
| - TEST_FOO_SHARD_KEY = opt[1] |
| 45 | + if opt[0].startswith('--'): |
| 46 | + opt[0] = opt[0][2:].lower() |
| 47 | + if opt[0] == 'help': |
| 48 | + print sys.argv[0], '[--help] [--chunksize=200] [--port=27017] [collection=key]' |
| 49 | + sys.exit() |
| 50 | + elif opt[0] == 'chunksize': |
| 51 | + CHUNK_SIZE = int(opt[1]) |
| 52 | + elif opt[0] == 'port': |
| 53 | + MONGOS_PORT = int(opt[1]) |
| 54 | + else: |
| 55 | + raise( Exception("unknown option: " + opt[0] ) ) |
46 | 56 | else:
|
47 |
| - raise( Exception("unknown arg: " + opt[0] ) ) |
| 57 | + COLLECTION_KEYS[opt[0]] = opt[1] |
48 | 58 |
|
49 | 59 | def AFTER_SETUP():
|
50 | 60 | # feel free to change any of this
|
51 | 61 | # admin and conn are both defined globaly
|
52 | 62 | admin.command('enablesharding', 'test')
|
53 | 63 |
|
54 |
| - admin.command('shardcollection', 'test.foo', key={ TEST_FOO_SHARD_KEY : 1 }) |
| 64 | + for (collection, key) in COLLECTION_KEYS.iteritems(): |
| 65 | + admin.command('shardcollection', 'test.'+collection, key={ key : 1 }) |
55 | 66 |
|
56 | 67 | admin.command('shardcollection', 'test.fs.files', key={'_id':1})
|
57 | 68 | admin.command('shardcollection', 'test.fs.chunks', key={'files_id':1})
|
|
0 commit comments