1
# Copyright 2012 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
6
from __future__ import (
19
from django.http import HttpResponse
22
class UnknownMetadataVersion(RuntimeError):
23
"""Not a known metadata version."""
26
def make_text_response(contents):
27
"""Create a response containing `contents` as plain text."""
28
return HttpResponse(contents, mimetype='text/plain')
31
def make_list_response(items):
32
"""Create an `HttpResponse` listing `items`, one per line."""
33
return make_text_response('\n'.join(items))
36
def check_version(version):
37
"""Check that `version` is a supported metadata version."""
38
if version != 'latest':
39
raise UnknownMetadataVersion("Unknown metadata version: %s" % version)
42
def versions_index(request):
43
"""View: top-level metadata listing."""
44
return make_list_response(['latest'])
47
def version(request, version):
48
"""View: listing for a given metadata version."""
49
check_version(version)
50
return make_list_response(['meta-data', 'user-data'])
53
def meta_data(request, version):
54
"""View: meta-data listing for a given version."""
55
check_version(version)
59
return make_list_response(items)
62
def user_data(request, version):
63
"""View: user-data blob for a given version."""
64
check_version(version)
65
data = "User data here."
66
return make_text_response(data)