/usr/share/openstack-dashboard/openstack_dashboard/dashboards/project/dns_domains/views.py is in python-designate-dashboard 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | # 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 django.core.urlresolvers import reverse, reverse_lazy # noqa
from django.utils.translation import ugettext_lazy as _ # noqa
from horizon import exceptions
from horizon import forms
from horizon import tables
from horizon.views import HorizonTemplateView # noqa
from openstack_dashboard.api.network import tenant_floating_ip_list
from openstack_dashboard.api.nova import server_list
from designatedashboard import api
from .forms import DomainCreate # noqa
from .forms import DomainUpdate # noqa
from .forms import RecordCreate # noqa
from .forms import RecordUpdate # noqa
from .tables import DomainsTable # noqa
from .tables import RecordsTable # noqa
from .utils import limit_records_to_fips # noqa
class IndexView(tables.DataTableView):
table_class = DomainsTable
template_name = 'project/dns_domains/index.html'
def get_data(self):
try:
return api.designate.domain_list(self.request)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve domain list.'))
return []
class CreateDomainView(forms.ModalFormView):
form_class = DomainCreate
template_name = 'project/dns_domains/create_domain.html'
success_url = reverse_lazy('horizon:project:dns_domains:index')
def get_object_display(self, obj):
return obj.ip
class DomainDetailView(HorizonTemplateView):
template_name = 'project/dns_domains/domain_detail.html'
def get_context_data(self, **kwargs):
context = super(DomainDetailView, self).get_context_data(**kwargs)
domain_id = self.kwargs['domain_id']
try:
context["domain"] = api.designate.domain_get(self.request,
domain_id)
table = DomainsTable(self.request)
context["actions"] = table.render_row_actions(context["domain"])
except Exception:
redirect = reverse('horizon:project:dns_domains:index')
exceptions.handle(self.request,
_('Unable to retrieve domain record.'),
redirect=redirect)
return context
class UpdateDomainView(forms.ModalFormView):
form_class = DomainUpdate
template_name = 'project/dns_domains/update_domain.html'
success_url = reverse_lazy('horizon:project:dns_domains:index')
def get_object(self):
domain_id = self.kwargs['domain_id']
try:
return api.designate.domain_get(self.request, domain_id)
except Exception:
redirect = reverse('horizon:project:dns_domains:index')
exceptions.handle(self.request,
_('Unable to retrieve domain record.'),
redirect=redirect)
def get_initial(self):
self.domain = self.get_object()
return self.domain
def get_context_data(self, **kwargs):
context = super(UpdateDomainView, self).get_context_data(**kwargs)
context["domain"] = self.domain
return context
class RecordsView(tables.DataTableView):
table_class = RecordsTable
template_name = 'project/dns_domains/records.html'
def get_data(self):
domain_id = self.kwargs['domain_id']
try:
self.domain = api.designate.domain_get(self.request, domain_id)
self.servers = api.designate.server_list(self.request, domain_id)
records = api.designate.record_list(self.request, domain_id)
except Exception:
redirect = reverse('horizon:project:dns_domains:index')
exceptions.handle(self.request,
_('Unable to retrieve record list.'),
redirect=redirect)
# TODO(Matt): This may not be defined here.
return records
def get_context_data(self, **kwargs):
context = super(RecordsView, self).get_context_data(**kwargs)
context['domain'] = self.domain
context['servers'] = self.servers
return context
class BaseRecordFormView(forms.ModalFormView):
cancel_label = _("Cancel")
def get_success_url(self):
return reverse('horizon:project:dns_domains:records',
args=(self.kwargs['domain_id'],))
def get_domain(self):
domain_id = self.kwargs['domain_id']
try:
return api.designate.domain_get(self.request, domain_id)
except Exception:
redirect = reverse('horizon:project:dns_domains:records',
args=(self.kwargs['domain_id'],))
exceptions.handle(self.request,
('Unable to retrieve domain record.'),
redirect=redirect)
# NotAuthorized errors won't be redirected automatically. Need
# to force the issue
raise exceptions.Http302(redirect)
def get_initial(self):
self.domain = self.get_domain()
results = {'domain_id': self.domain.id,
'domain_name': self.domain.name, }
if limit_records_to_fips():
results.update({'fips': tenant_floating_ip_list(self.request),
'instances': server_list(self.request)[0]})
return results
def get_context_data(self, **kwargs):
"""Set the cancel url
the cancel_url needs a variable in it
so we cannot do this with a simple class attr
this is critical to perform before the super.get_context_data
"""
self.cancel_url = reverse('horizon:project:dns_domains:records',
args=(self.kwargs['domain_id'],))
context = super(BaseRecordFormView, self).get_context_data(**kwargs)
context['domain'] = self.domain
return context
class CreateRecordView(BaseRecordFormView):
form_class = RecordCreate
submit_label = _("Create Record")
template_name = 'project/dns_domains/create_record.html'
class ViewRecordDetailsView(HorizonTemplateView):
template_name = 'project/dns_domains/record_detail.html'
def get_record(self):
domain_id = self.kwargs['domain_id']
record_id = self.kwargs['record_id']
try:
return api.designate.record_get(self.request, domain_id, record_id)
except Exception:
redirect = reverse('horizon:project:dns_domains:records',
args=(self.kwargs['domain_id'],))
exceptions.handle(self.request,
_('Unable to retrieve domain record.'),
redirect=redirect)
def get_context_data(self, **kwargs):
context = super(ViewRecordDetailsView, self).get_context_data(**kwargs)
self.record = self.get_record()
context["record"] = self.record
context["domain_id"] = self.kwargs['domain_id']
return context
class UpdateRecordView(BaseRecordFormView):
form_class = RecordUpdate
submit_label = _("Update Record")
template_name = 'project/dns_domains/update_record.html'
def get_record(self):
domain_id = self.kwargs['domain_id']
record_id = self.kwargs['record_id']
try:
return api.designate.record_get(self.request, domain_id, record_id)
except Exception:
redirect = reverse('horizon:project:dns_domains:records',
args=(self.kwargs['domain_id'],))
exceptions.handle(self.request,
_('Unable to retrieve domain record.'),
redirect=redirect)
def get_initial(self):
initial = super(UpdateRecordView, self).get_initial()
self.record = self.get_record()
initial.update({
'id': self.record.id,
'name': self.record.name.replace("." + initial['domain_name'], ''),
'data': self.record.data,
'txt': self.record.data,
'priority': self.record.priority,
'ttl': self.record.ttl,
'type': self.record.type.lower(),
'description': self.record.description,
})
if limit_records_to_fips():
initial.update({'ip_addr': self.record.data})
return initial
def get_context_data(self, **kwargs):
context = super(UpdateRecordView, self).get_context_data(**kwargs)
context["record"] = self.record
return context
|