2
# Copyright 2012-2013 Canonical Ltd.
2
# Copyright 2013, 2014 Canonical Ltd.
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/>.
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 (
95
98
return HttpNoContent()
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()
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
114
status = JSONStatus()
115
status.add_true_false('launchpad configured', lp, lp)
117
count = PPA.objects.all().count()
118
status.add_true_false('total ppas', count, count > 0)
120
count = PPA.objects.filter(state=PPA.AVAILABLE).count()
121
status.add_true_false('available ppas', count, count > 0)
124
output = subprocess.check_output(['/sbin/status', 'ppa-cleaner'])
125
status.add_true_false('cleaner', output, 'start/running' in output)
127
status.add_fail('cleaner', 'unable to check if daemon is running')
129
return self.create_response(request, status.results)
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())