Add designate support for Zone choice

This commit adds support for Designate zones. This can be used to
provide the user a drop down list of zones they can choose from when
launching apps.

This should be coupled with a commit to murano to add a new
io.murano.resources.RecordSet resource type, so that new a new DNS
record can be added for new apps.

Change-Id: I71deb3e264b2777ec4126d8e46c3ac45b9fc42c6
This commit is contained in:
Andy Botting 2019-01-18 09:30:20 +11:00
parent 11181ef08b
commit 8aceeda565
5 changed files with 68 additions and 1 deletions

View File

@ -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()

View File

@ -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

View File

@ -51,7 +51,8 @@ TYPES.update({
'choice': fields.ChoiceField,
'floatingip': fields.FloatingIpBooleanField,
'securitygroup': fields.SecurityGroupChoiceField,
'volume': fields.VolumeChoiceField
'volume': fields.VolumeChoiceField,
'zone': fields.ZoneChoiceField,
})

View File

@ -0,0 +1,3 @@
---
features:
- Add Desginate support for listing available zones

View File

@ -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