Debian Codegraph @

glanceclient/v2/image_members.py

raw symbols SCIP
1 # Copyright 2013 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import warlock
17
18 from glanceclient.common import utils
19 from glanceclient.v2 import schemas
20
21
22 MEMBER_STATUS_VALUES = ('accepted', 'rejected', 'pending')
23
24
25 class Controller(object):
26 def __init__(self, http_client, schema_client):
27 self.http_client = http_client
28 self.schema_client = schema_client
29
30 @utils.memoized_property
31 def model(self):
32 schema = self.schema_client.get('member')
33 return warlock.model_factory(schema.raw(), schemas.SchemaBasedModel)
34
35 @utils.add_req_id_to_generator()
36 def list(self, image_id):
37 url = '/v2/images/%s/members' % image_id
38 resp, body = self.http_client.get(url)
39 for member in body['members']:
40 yield self.model(member), resp
41
42 @utils.add_req_id_to_object()
43 def get(self, image_id, member_id):
44 url = '/v2/images/%s/members/%s' % (image_id, member_id)
45 resp, member = self.http_client.get(url)
46 return self.model(member), resp
47
48 @utils.add_req_id_to_object()
49 def delete(self, image_id, member_id):
50 resp, body = self.http_client.delete('/v2/images/%s/members/%s' %
51 (image_id, member_id))
52 return (resp, body), resp
53
54 @utils.add_req_id_to_object()
55 def update(self, image_id, member_id, member_status):
56 url = '/v2/images/%s/members/%s' % (image_id, member_id)
57 body = {'status': member_status}
58 resp, updated_member = self.http_client.put(url, data=body)
59 return self.model(updated_member), resp
60
61 @utils.add_req_id_to_object()
62 def create(self, image_id, member_id):
63 url = '/v2/images/%s/members' % image_id
64 body = {'member': member_id}
65 resp, created_member = self.http_client.post(url, data=body)
66 return self.model(created_member), resp