summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorChris Yeoh <cyeoh@au1.ibm.com>2013-06-13 14:08:43 +0930
committerChris Yeoh <cyeoh@au1.ibm.com>2013-06-13 14:08:43 +0930
commit71ece4a73c86995685fcbc8de2237f4fd70d0f53 (patch)
tree4757035eb0dfa0434931d553a12d47f3dad2aa5e /nova/api
parent53f62b33caa71de1da3163e0f835e39ea7a64ee8 (diff)
downloadnova-71ece4a73c86995685fcbc8de2237f4fd70d0f53.tar.gz
nova-71ece4a73c86995685fcbc8de2237f4fd70d0f53.tar.xz
nova-71ece4a73c86995685fcbc8de2237f4fd70d0f53.zip
Port certificates API to v3 Part 1
This changeset only copies the v2 files (implementation and test) into the appropriate v3 directories unchanged. The copy as-is will not be loaded by either the v2 or v3 extension loaders. The second changeset will then make the changes required for it to work as a v3 extension. This is being done in order to make reviewing of extension porting easier as gerrit will display only what is actually changed for v3 rather than entirely new files Partially implements blueprint nova-v3-api Change-Id: Ibdb3b444432fa707786e6bb43aaba61d2a3fc89f
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/plugins/v3/certificates.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/certificates.py b/nova/api/openstack/compute/plugins/v3/certificates.py
new file mode 100644
index 000000000..64a6e26fe
--- /dev/null
+++ b/nova/api/openstack/compute/plugins/v3/certificates.py
@@ -0,0 +1,105 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012 OpenStack 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.exc
+
+from nova.api.openstack import extensions
+from nova.api.openstack import wsgi
+from nova.api.openstack import xmlutil
+import nova.cert.rpcapi
+from nova import network
+
+authorize = extensions.extension_authorizer('compute', 'certificates')
+
+
+def make_certificate(elem):
+ elem.set('data')
+ elem.set('private_key')
+
+
+class CertificateTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('certificate',
+ selector='certificate')
+ make_certificate(root)
+ return xmlutil.MasterTemplate(root, 1)
+
+
+class CertificatesTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('certificates')
+ elem = xmlutil.SubTemplateElement(root, 'certificate',
+ selector='certificates')
+ make_certificate(elem)
+ return xmlutil.MasterTemplate(root, 1)
+
+
+def _translate_certificate_view(certificate, private_key=None):
+ return {
+ 'data': certificate,
+ 'private_key': private_key,
+ }
+
+
+class CertificatesController(object):
+ """The x509 Certificates API controller for the OpenStack API."""
+
+ def __init__(self):
+ self.network_api = network.API()
+ self.cert_rpcapi = nova.cert.rpcapi.CertAPI()
+ super(CertificatesController, self).__init__()
+
+ @wsgi.serializers(xml=CertificateTemplate)
+ def show(self, req, id):
+ """Return a list of certificates."""
+ context = req.environ['nova.context']
+ authorize(context)
+ if id != 'root':
+ msg = _("Only root certificate can be retrieved.")
+ raise webob.exc.HTTPNotImplemented(explanation=msg)
+ cert = self.cert_rpcapi.fetch_ca(context,
+ project_id=context.project_id)
+ return {'certificate': _translate_certificate_view(cert)}
+
+ @wsgi.serializers(xml=CertificateTemplate)
+ def create(self, req, body=None):
+ """Return a list of certificates."""
+ context = req.environ['nova.context']
+ authorize(context)
+ pk, cert = self.cert_rpcapi.generate_x509_cert(context,
+ user_id=context.user_id, project_id=context.project_id)
+ context = req.environ['nova.context']
+ return {'certificate': _translate_certificate_view(cert, pk)}
+
+
+class Certificates(extensions.ExtensionDescriptor):
+ """Certificates support."""
+
+ name = "Certificates"
+ alias = "os-certificates"
+ namespace = ("http://docs.openstack.org/compute/ext/"
+ "certificates/api/v1.1")
+ updated = "2012-01-19T00:00:00+00:00"
+
+ def get_resources(self):
+ resources = []
+
+ res = extensions.ResourceExtension('os-certificates',
+ CertificatesController(),
+ member_actions={})
+ resources.append(res)
+
+ return resources