diff --git a/muranodashboard/common/designate.py b/muranodashboard/common/designate.py new file mode 100644 index 000000000..e0d8da5fa --- /dev/null +++ b/muranodashboard/common/designate.py @@ -0,0 +1,39 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from designateclient import client + +from keystoneauth1 import loading +from keystoneauth1 import session + +from openstack_dashboard.api import base + + +def designateclient(request, api_version='2'): + loader = loading.get_plugin_loader('token') + auth = loader.load_from_options( + auth_url=base.url_for(request, 'identity'), + token=request.user.token.id, + project_id=request.user.project_id, + project_domain_id=request.user.token.project.get('domain_id')) + + sess = session.Session(auth=auth) + return client.Client(api_version, session=sess) + + +def zone_list(request): + d_client = designateclient(request) + if d_client is None: + return [] + return d_client.zones.list() diff --git a/muranodashboard/dynamic_ui/fields.py b/muranodashboard/dynamic_ui/fields.py index cc57c9d15..562339301 100644 --- a/muranodashboard/dynamic_ui/fields.py +++ b/muranodashboard/dynamic_ui/fields.py @@ -40,6 +40,7 @@ from oslo_log import versionutils from yaql import legacy from muranodashboard.api import packages as pkg_api +from muranodashboard.common import designate from muranodashboard.common import net from muranodashboard.dynamic_ui import helpers from muranodashboard.environments import api as env_api @@ -780,3 +781,25 @@ class DomainChoiceField(make_select_cls('io.murano.windows.ActiveDirectory')): def __init__(self, *args, **kwargs): super(DomainChoiceField, self).__init__(*args, **kwargs) self.choices = [('', _('Not in domain'))] + + +class ZoneChoiceField(ChoiceField): + @with_request + def update(self, request, form=None, **kwargs): + try: + zones = designate.zone_list(request) + except Exception: + zones = [] + exceptions.handle(request, _("Unable to retrieve DNS zones.")) + + # Use zone name instead of ID purely for convenience of being able to + # pass it through to construct fqdn for apps + zone_choices = [(z['name'], z['name']) for z in zones] + zone_choices.sort(key=lambda e: e[1]) + + if zones: + zone_choices.insert(0, ('', _('No DNS zone'))) + else: + zone_choices.insert(0, ('', _('No DNS zones available'))) + + self.choices = zone_choices diff --git a/muranodashboard/dynamic_ui/forms.py b/muranodashboard/dynamic_ui/forms.py index 439a3f950..745d7dee7 100644 --- a/muranodashboard/dynamic_ui/forms.py +++ b/muranodashboard/dynamic_ui/forms.py @@ -51,7 +51,8 @@ TYPES.update({ 'choice': fields.ChoiceField, 'floatingip': fields.FloatingIpBooleanField, 'securitygroup': fields.SecurityGroupChoiceField, - 'volume': fields.VolumeChoiceField + 'volume': fields.VolumeChoiceField, + 'zone': fields.ZoneChoiceField, }) diff --git a/releasenotes/notes/add-designate-support-44d8e9f9ce7b8574.yaml b/releasenotes/notes/add-designate-support-44d8e9f9ce7b8574.yaml new file mode 100644 index 000000000..b9571843a --- /dev/null +++ b/releasenotes/notes/add-designate-support-44d8e9f9ce7b8574.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add Desginate support for listing available zones diff --git a/requirements.txt b/requirements.txt index af6fe0f3c..0613667b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ beautifulsoup4>=4.6.0 # MIT django-formtools>=2.2 # BSD iso8601>=0.1.11 # MIT python-muranoclient>=0.8.2 # Apache-2.0 +python-designateclient>=2.7.0 # Apache-2.0 pytz>=2013.6 # MIT PyYAML>=3.12 # MIT yaql>=1.1.3 # Apache 2.0 License