~ursinha/ubuntu-ci-services-itself/401-copying-di-check

« back to all changes in this revision

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

  • Committer: Evan Dandrea
  • Date: 2014-03-10 22:25:00 UTC
  • mfrom: (352 ubuntu-ci-services-itself)
  • mto: This revision was merged to the branch mainline in revision 353.
  • Revision ID: evan.dandrea@canonical.com-20140310222500-vu87pulv0k74b8sh
Merge with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Ubuntu CI Engine
2
 
# Copyright 2012-2013 Canonical Ltd.
 
2
# Copyright 2013, 2014 Canonical Ltd.
3
3
 
4
4
# This program is free software: you can redistribute it and/or modify it
5
5
# under the terms of the GNU Affero General Public License version 3, as
13
13
# You should have received a copy of the GNU Affero General Public License
14
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
 
 
16
import subprocess
16
17
import urllib2
17
18
 
 
19
from django.conf import settings
18
20
from tastypie.api import Api
19
21
from tastypie.exceptions import ImmediateHttpResponse
20
22
from tastypie.http import (
29
31
from ppa_assigner import ppa_sync
30
32
from ppa_assigner.models import PPA
31
33
 
 
34
from ci_utils.json_status import JSONStatus
32
35
from ci_utils.tastypie.resource import AuthorizedResource
33
36
 
34
37
 
95
98
        return HttpNoContent()
96
99
 
97
100
 
 
101
class PPAStatus(AuthorizedResource):
 
102
    class Meta(AuthorizedResource.Meta):
 
103
        resource_name = 'status'
 
104
        allowed_methods = ['get']
 
105
        # just return nothing to work with tastypie
 
106
        queryset = PPA.objects.none()
 
107
 
 
108
    def get_list(self, request, **kwargs):
 
109
        lp = settings.LAUNCHPAD_PPA_USER is not None
 
110
        lp = lp and settings.OAUTH_TOKEN is not None
 
111
        lp = lp and settings.OAUTH_TOKEN_SECRET is not None
 
112
        lp = lp and settings.OAUTH_CONSUMER_KEY is not None
 
113
 
 
114
        status = JSONStatus()
 
115
        status.add_true_false('launchpad configured', lp, lp)
 
116
 
 
117
        count = PPA.objects.all().count()
 
118
        status.add_true_false('total ppas', count, count > 0)
 
119
 
 
120
        count = PPA.objects.filter(state=PPA.AVAILABLE).count()
 
121
        status.add_true_false('available ppas', count, count > 0)
 
122
 
 
123
        try:
 
124
            output = subprocess.check_output(['/sbin/status', 'ppa-cleaner'])
 
125
            status.add_true_false('cleaner', output, 'start/running' in output)
 
126
        except:
 
127
            status.add_fail('cleaner', 'unable to check if daemon is running')
 
128
 
 
129
        return self.create_response(request, status.results)
 
130
 
98
131
v1_api = Api(api_name='v1')
99
132
v1_api.register(PPAResource())
100
133
v1_api.register(PPACopyResource())
 
134
v1_api.register(PPAStatus())