~psivaa/uci-engine/lander-jenkins-with-proxy

« back to all changes in this revision

Viewing changes to ppa-assigner/ppa_assigner/api.py

  • Committer: Tarmac
  • Author(s): Andy Doan
  • Date: 2013-12-06 23:25:38 UTC
  • mfrom: (6.1.22 ppa-assigner)
  • Revision ID: tarmac-20131206232538-auo3c8yhml7wbnee
[r=Francis Ginther] adds first pass of ppa-assigner

more changes to come following design updates.  from Andy Doan

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Ubuntu CI Services
 
2
# Copyright 2012-2013 Canonical Ltd.
 
3
 
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU Affero General Public License version 3, as
 
6
# published by the Free Software Foundation.
 
7
 
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
# PURPOSE.  See the GNU Affero General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
from tastypie.api import Api
 
17
from tastypie.http import HttpAccepted, HttpApplicationError
 
18
from tastypie.resources import ALL
 
19
 
 
20
from ppa_assigner.models import PPA, LaunchpadError
 
21
 
 
22
from ci_utils.tastypie.resource import AuthorizedResource
 
23
 
 
24
 
 
25
class PPAResource(AuthorizedResource):
 
26
    class Meta(AuthorizedResource.Meta):
 
27
        queryset = PPA.objects.filter()
 
28
        resource_name = 'ppa'
 
29
 
 
30
        filtering = {
 
31
            'reserved': ALL,
 
32
            'lockname': ALL,
 
33
        }
 
34
 
 
35
    def obj_create(self, bundle, **kwargs):
 
36
        '''We don't really create an object, so override tastypie.'''
 
37
        lockname = bundle.data.get('lockname')
 
38
        clean = bundle.data.get('clean')
 
39
        bundle.obj = PPA.reserve(lockname, clean)
 
40
        return bundle
 
41
 
 
42
    def patch_list(self, request, **kwargs):
 
43
        if request.body == '{"populate": true}':
 
44
            try:
 
45
                # populate is a bit different than normal "patch" operations
 
46
                PPA.populate_from_launchpad()
 
47
                return HttpAccepted()
 
48
            except LaunchpadError as e:
 
49
                return HttpApplicationError(e)
 
50
        return super(PPAResource, self).patch_list(request, **kwargs)
 
51
 
 
52
 
 
53
v1_api = Api(api_name='v1')
 
54
v1_api.register(PPAResource())