2
# Copyright (c) 2010 OpenStack, LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
17
from os.path import basename
18
from sys import argv, exit
20
from swift.common.db import get_db_connection
23
if __name__ == '__main__':
24
app = basename(argv[0])
27
Syntax : %s <auth.db> <new_prefix>
28
Example: %s /etc/swift/auth.db AUTH'''.strip() % (app, app))
30
new_prefix = argv[2].rstrip('_')
31
print 'Updating %s' % db
32
conn = get_db_connection(db)
33
rows = conn.execute('SELECT url, cfaccount FROM account').fetchall()
38
old_prefix, uuid = row[1].split('_', 1)
39
new_cfaccount = '%s_%s' % (new_prefix, uuid)
40
new_url = row[0].replace(row[1], new_cfaccount)
41
print '%s ->\n%s' % (row[0], new_url)
42
print '%s ->\n%s' % (row[1], new_cfaccount)
44
conn.execute('''UPDATE account SET url = ?, cfaccount = ?
45
WHERE url = ? AND cfaccount = ?''',
46
(new_url, new_cfaccount, row[0], row[1]))
48
print 'Updated %s rows.' % len(rows)