Debian Codegraph @

blazar_tempest_plugin/services/reservation/reservation_client.py

raw
1 # Copyright 2017 NTT
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 from oslo_serialization import jsonutils as json
17 from oslo_utils import uuidutils as uuids
18 from tempest.lib.common import rest_client
19
20
21 class ResourceReservationV1Client(rest_client.RestClient):
22 """Client class for accessing the resource reservation API."""
23 BLAZARCLIENT_VERSION = '1'
24
25 lease = '/leases'
26 lease_path = '/leases/%s'
27 host = '/os-hosts'
28 host_path = '/os-hosts/%s'
29
30 def _response_helper(self, resp, body=None):
31 if body:
32 body = json.loads(body)
33 return rest_client.ResponseBody(resp, body)
34
35 def _get_headers(self):
36 headers = {
37 'Content-Type': 'application/json',
38 'Accept': 'application/json',
39 'X-Openstack-Request-Id': 'req-' + str(uuids.generate_uuid())
40 }
41 return headers
42
43 def list_lease(self):
44 resp, body = self.get(self.lease, headers=self._get_headers())
45 return self._response_helper(resp, body)
46
47 def get_lease(self, lease):
48 resp, body = self.get(self.lease_path % lease)
49 return self._response_helper(resp, body)
50
51 def create_lease(self, body):
52 body = json.dump_as_bytes(body)
53 resp, body = self.post(
54 self.lease, body=body, headers=self._get_headers())
55 return self._response_helper(resp, body)
56
57 def update_lease(self, lease, body):
58 body = json.dump_as_bytes(body)
59 resp, body = self.put(
60 self.lease_path % lease, body=body, headers=self._get_headers())
61 return self._response_helper(resp, body)
62
63 def delete_lease(self, lease):
64 resp, body = self.delete(
65 self.lease_path % lease, headers=self._get_headers())
66 return self._response_helper(resp, body)
67
68 def list_host(self):
69 resp, body = self.get(self.host, headers=self._get_headers())
70 return self._response_helper(resp, body)
71
72 def get_host(self, host):
73 resp, body = self.get(
74 self.host_path % host, headers=self._get_headers())
75 return self._response_helper(resp, body)
76
77 def create_host(self, body):
78 body = json.dump_as_bytes(body)
79 resp, body = self.post(
80 self.host, body=body, headers=self._get_headers())
81 return self._response_helper(resp, body)
82
83 def update_host(self, host, body):
84 body = json.dump_as_bytes(body)
85 resp, body = self.put(
86 self.host_path % host, body=body, headers=self._get_headers())
87 return self._response_helper(resp, body)
88
89 def delete_host(self, host):
90 resp, body = self.delete(
91 self.host_path % host, headers=self._get_headers())
92 return self._response_helper(resp, body)