blob: fa8bf2b0b4dcda0739809ddd5d3fee13514a8ca2 [file] [log] [blame]
rdudyalab086cf32016-08-11 00:07:45 -04001#!/usr/bin/python
2
3__author__ = 'Matt Fischer <matt.fischer@twcable.com>'
4__copyright__ = 'Copyright 2013, Matt Fischer'
5
6"""
7Update the endpoints in a keystone db using mysql
8"""
9
10import MySQLdb
11import argparse
12import urlparse
13import sys
14
15# a12ab673016d40da
16
17def main(dbhost, username, password, new_endpoint, endpoint_type):
18 db = MySQLdb.connect(host=dbhost, user=username, passwd=password,
19 db="keystone")
20 cur = db.cursor()
21 cur.execute("select id, url from endpoint where interface='%s'" % endpoint_type)
22 for row in cur.fetchall():
23 url = str(row[1])
24 endpoint_id = str(row[0])
25 try:
26 u = urlparse.urlparse(url)
27 print "Changing %s to %s in URL %s" % (u.hostname,new_endpoint, url)
28 urlstring = "%s://%s:%s%s" % (u.scheme, new_endpoint, u.port,
29 u.path)
30 cur.execute("""UPDATE endpoint
31 SET url=%s
32 WHERE id=%s
33 """, (urlstring, endpoint_id))
34 except Exception as e:
35 print "Could not parse URL, giving up: %s (%s)" % (url, e)
36 cur.close()
37 db.close()
38 sys.exit(1)
39 db.commit()
40 cur.close()
41 db.close()
42
43if __name__ == "__main__":
44 parser = argparse.ArgumentParser()
45 parser.add_argument("--username", help="database username", required=True)
46 parser.add_argument("--password", help="database password", required=True)
47 parser.add_argument("--host", help="database host", required=True)
48 parser.add_argument("--endpoint", help="endpoint to move the public endpoints to", required=True)
49 parser.add_argument("--endpoint-type", help="which type of endpoint to modify", required=True, choices=['public','internal','admin'])
50 args = parser.parse_args()
51 main(args.host, args.username, args.password, args.endpoint, args.endpoint_type)