diff --git a/keystone_browser/domains.py b/keystone_browser/domains.py index 99df544..2d97b44 100644 --- a/keystone_browser/domains.py +++ b/keystone_browser/domains.py @@ -1,68 +1,68 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # # This file is part of the Keystone browser # # Copyright (c) 2017 Bryan Davis and contributors # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . import functools from designateclient.v2 import client as designate_client from . import keystone @functools.lru_cache(maxsize=None) -def designateclient(project): +def client(project): return designate_client.Client( session=keystone.session(project)) @functools.lru_cache(maxsize=None) def _raw_zones(project): """Return list of designate 'zone' objects owned by a project. - Node that in designate, dns domains are called - 'Zones' because the word 'Domain' was used - by Keystone for some totally other thing.""" - return(designateclient(project).zones.list()) + + Note that in designate, dns domains are called 'Zones' because the word + 'Domain' was used by Keystone for some totally other thing. + """ + return client(project).zones.list() def domains(project): - """Return a simple list of domain names""" + """Return a simple list of domain names owned by a project.""" raw_zones = _raw_zones(project) return [zone['name'] for zone in raw_zones] @functools.lru_cache(maxsize=None) def _raw_recordsets(project, domain): """Return list of designate 'recordset' objects for a given - projecet and domain name.""" + project and domain name.""" raw_zones = _raw_zones(project) for zone in raw_zones: if zone['name'] == domain: - return(designateclient(project).recordsets.list(zone['id'])) + return client(project).recordsets.list(zone['id']) return [] -def Arecords(project, domain): - """Return a list of dns A records for a given project and domain""" +def a_records(project, domain): + """Return a list of dns A records for a given project and domain.""" raw_recordsets = _raw_recordsets(project, domain) records = {} for recordset in raw_recordsets: if recordset['type'] == 'A': records[recordset['name']] = recordset['records'] - return records diff --git a/keystone_browser/proxies.py b/keystone_browser/proxies.py index 6b62739..d7cecd4 100644 --- a/keystone_browser/proxies.py +++ b/keystone_browser/proxies.py @@ -1,53 +1,49 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # # This file is part of the Keystone browser # # Copyright (c) 2017 Bryan Davis and contributors # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . import functools import re import requests from . import keystone -@functools.lru_cache(maxsize=None) -def proxy_base_url(): - keystoneclient = keystone.keystone_client() - services = keystoneclient.services.list() - for service in services: - if service.name == 'proxy': - proxyendpoint = keystoneclient.endpoints.list(service.id) - break +@functools.lru_cache(maxsize=1) +def url_template(): + """Get the url template for accessing the proxy service.""" + c = keystone.keystone_client() + proxy = c.services.list(type='proxy')[0] + endpoint = c.endpoints.list( + service=proxy.id, interface='public', enabled=True)[0] + # Secret magic! The endpoint provided by keystone is private and we can't + # access it. There's an alternative public read-only endpoint on port 5669 + # though. So, swap in 5669 for the port we got from keystone. + return re.sub(r':[0-9]+/', ':5669/', endpoint.url) - endpoint = proxyendpoint[0].url - # Secret magic! The endpoint provided by keystone is private - # and we can't access it. There's an alternative public - # read-only endpoint on port 5669 though. So, - # swap in 5669 for the port we got from keystone. - publicendpoint = re.sub(r':[0-9]+/', ':5669/', endpoint) - return publicendpoint - -def getproxiesforproject(project): - url = proxy_base_url().replace('$(tenant_id)s', project) - requrl = "%s/mapping" % url - req = requests.get(requrl, verify=False) +def project_proxies(project): + """Get a list of proxies for a project.""" + base_url = url_template().replace('$(tenant_id)s', project) + url = '%s/mapping'.format(base_url) + req = requests.get(url, verify=False) if req.status_code != 200: return [] mappings = req.json() return mappings['routes']