blob: e324f6c6172616d452c261adcca521f3457750b4 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2{#
3Copyright 2017-present Open Networking Foundation
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16#}
17
18
raghunath dudyalaa927d562016-09-28 14:04:13 +053019#!/usr/bin/python
20
21"""
22Update the endpoints in a keystone db using mysql
23"""
24
25import MySQLdb
26import argparse
27import urlparse
28import sys
29
30def main(dbhost, username, password, new_endpoint, endpoint_type):
31 db = MySQLdb.connect(host=dbhost, user=username, passwd=password,
32 db="keystone")
33 cur = db.cursor()
34 cur.execute("select id, url from endpoint where interface='%s'" % endpoint_type)
35 for row in cur.fetchall():
36 url = str(row[1])
37 endpoint_id = str(row[0])
38 try:
39 u = urlparse.urlparse(url)
40 print "Changing %s to %s in URL %s" % (u.hostname,new_endpoint, url)
41 urlstring = "%s://%s:%s%s" % (u.scheme, new_endpoint, u.port,
42 u.path)
43 cur.execute("""UPDATE endpoint
44 SET url=%s
45 WHERE id=%s
46 """, (urlstring, endpoint_id))
47 except Exception as e:
48 print "Could not parse URL, giving up: %s (%s)" % (url, e)
49 cur.close()
50 db.close()
51 sys.exit(1)
52 db.commit()
53 cur.close()
54 db.close()
55
56if __name__ == "__main__":
57 parser = argparse.ArgumentParser()
58 parser.add_argument("--username", help="database username", required=True)
59 parser.add_argument("--password", help="database password", required=True)
60 parser.add_argument("--host", help="database host", required=True)
61 parser.add_argument("--endpoint", help="endpoint to move the public endpoints to", required=True)
62 parser.add_argument("--endpoint-type", help="which type of endpoint to modify", required=True, choices=['public','internal','admin'])
63 args = parser.parse_args()
64 main(args.host, args.username, args.password, args.endpoint, args.endpoint_type)