Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 2 | {# |
| 3 | Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | #} |
| 17 | |
| 18 | |
raghunath dudyala | a927d56 | 2016-09-28 14:04:13 +0530 | [diff] [blame] | 19 | #!/usr/bin/python |
| 20 | |
| 21 | """ |
| 22 | Update the endpoints in a keystone db using mysql |
| 23 | """ |
| 24 | |
| 25 | import MySQLdb |
| 26 | import argparse |
| 27 | import urlparse |
| 28 | import sys |
| 29 | |
| 30 | def 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 | |
| 56 | if __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) |