blob: 21f1fd501a746c6b9617284dd77c1bb41dd6dec1 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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 implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
rdudyalab086cf32016-08-11 00:07:45 -040017#!/usr/bin/python
18
19__author__ = 'Matt Fischer <matt.fischer@twcable.com>'
20__copyright__ = 'Copyright 2013, Matt Fischer'
21
22"""
23Update the endpoints in a keystone db using mysql
24"""
25
26import MySQLdb
27import argparse
28import urlparse
29import sys
30
31# a12ab673016d40da
32
33def main(dbhost, username, password, new_endpoint, endpoint_type):
34 db = MySQLdb.connect(host=dbhost, user=username, passwd=password,
35 db="keystone")
36 cur = db.cursor()
37 cur.execute("select id, url from endpoint where interface='%s'" % endpoint_type)
38 for row in cur.fetchall():
39 url = str(row[1])
40 endpoint_id = str(row[0])
41 try:
42 u = urlparse.urlparse(url)
43 print "Changing %s to %s in URL %s" % (u.hostname,new_endpoint, url)
44 urlstring = "%s://%s:%s%s" % (u.scheme, new_endpoint, u.port,
45 u.path)
46 cur.execute("""UPDATE endpoint
47 SET url=%s
48 WHERE id=%s
49 """, (urlstring, endpoint_id))
50 except Exception as e:
51 print "Could not parse URL, giving up: %s (%s)" % (url, e)
52 cur.close()
53 db.close()
54 sys.exit(1)
55 db.commit()
56 cur.close()
57 db.close()
58
59if __name__ == "__main__":
60 parser = argparse.ArgumentParser()
61 parser.add_argument("--username", help="database username", required=True)
62 parser.add_argument("--password", help="database password", required=True)
63 parser.add_argument("--host", help="database host", required=True)
64 parser.add_argument("--endpoint", help="endpoint to move the public endpoints to", required=True)
65 parser.add_argument("--endpoint-type", help="which type of endpoint to modify", required=True, choices=['public','internal','admin'])
66 args = parser.parse_args()
67 main(args.host, args.username, args.password, args.endpoint, args.endpoint_type)