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