Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # vim: tabstop=4 shiftwidth=4 softtabstop=4
- # Copyright 2012 Andrew Bogott for the Wikimedia Foundation
- #
- # 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
- import webob
- from nova.api.openstack import wsgi
- from nova.api.openstack import xmlutil
- from nova.api.openstack.v2 import extensions
- from nova import compute
- from nova import exception
- from nova import log as logging
- from nova import network
- from nova import rpc
- LOG = logging.getLogger('nova.api.openstack.v2.contrib.floating_ip_dns')
- def _translate_dns_entry_view(dns_entry):
- result = {'id': dns_entry['id'],
- 'ip': dns_entry['address'],
- 'dns_name': dns_entry['dns_name']}
- try:
- result['fixed_ip'] = floating_ip['fixed_ip']['address']
- except (TypeError, KeyError):
- result['fixed_ip'] = None
- try:
- result['instance_id'] = floating_ip['fixed_ip']['instance_id']
- except (TypeError, KeyError):
- result['instance_id'] = None
- return {'floating_ip': result}
- def _translate_floating_ips_view(floating_ips):
- return {'floating_ips': [_translate_floating_ip_view(ip)['floating_ip']
- for ip in floating_ips]}
- def _translate_dns_zones(zones):
- return {'zones': [{'zone': zone} for zone in zones]}
- class FloatingIPDNSController(object):
- """FIXME"""
- def __init__(self):
- self.network_api = network.API()
- super(FloatingIPDNSController, self).__init__()
- def index(self, req):
- """Return a list of available DNS zones."""
- context = req.environ['nova.context']
- zones = self.network_api.get_dns_zones(context)
- return _translate_dns_zones(zones)
- def make_dns_entry(elem):
- elem.set('id')
- elem.set('ip')
- elem.set('dns_name')
- class FloatingIPDNSTemplate(xmlutil.TemplateBuilder):
- def construct(self):
- root = xmlutil.TemplateElement('dns_entry',
- selector='dns_entry')
- make_dns_entry(root)
- return xmlutil.MasterTemplate(root, 1)
- class FloatingIPDNSsTemplate(xmlutil.TemplateBuilder):
- def construct(self):
- root = xmlutil.TemplateElement('dns_entries')
- elem = xmlutil.SubTemplateElement(root, 'dns_entry',
- selector='dns_entries')
- make_dns_entry(elem)
- return xmlutil.MasterTemplate(root, 1)
- class FloatingIPDNSSerializer(xmlutil.XMLTemplateSerializer):
- def index(self):
- return FloatingIPDNSsTemplate()
- def default(self):
- return FloatingIPDNSTemplate()
- class Floating_ip_dns(extensions.ExtensionDescriptor):
- """Floating IPs support"""
- name = "Floating_ip_dns"
- alias = "os-floating-ip-dns"
- # namespace = "http://docs.openstack.org/ext/floating_ip_dns/api/v1.1"
- updated = "2011-12-12:00:00+00:00"
- def __init__(self, ext_mgr):
- self.compute_api = compute.API()
- self.network_api = network.API()
- super(Floating_ips, self).__init__(ext_mgr)
- def get_resources(self):
- resources = []
- body_serializers = {
- 'application/xml': FloatingIPDNSSerializer(),
- }
- serializer = wsgi.ResponseSerializer(body_serializers)
- res = extensions.ResourceExtension('os-floating-ip-dns',
- FloatingIPDNSController(),
- serializer=serializer)
- resources.append(res)
- return resources
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement