Debian Codegraph @

magnum_tempest_plugin/tests/api/v1/clients/cluster_template_client.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from magnum_tempest_plugin.common import client
14 from magnum_tempest_plugin.tests.api.v1.models import cluster_template_model
15
16
17 class ClusterTemplateClient(client.MagnumClient):
18 """Encapsulates REST calls and maps JSON to/from models"""
19
20 @classmethod
21 def cluster_templates_uri(cls, filters=None):
22 """Construct clustertemplates uri with optional filters
23
24 :param filters: Optional k:v dict that's converted to url query
25 :returns: url string
26 """
27
28 url = "/clustertemplates"
29 if filters:
30 url = cls.add_filters(url, filters)
31 return url
32
33 @classmethod
34 def cluster_template_uri(cls, cluster_template_id):
35 """Construct cluster_template uri
36
37 :param cluster_template_id: cluster_template uuid or name
38 :returns: url string
39 """
40
41 return "{0}/{1}".format(cls.cluster_templates_uri(),
42 cluster_template_id)
43
44 def list_cluster_templates(self, filters=None, **kwargs):
45 """Makes GET /clustertemplates request
46
47 Abstracts REST call to return all clustertemplates
48
49 :param filters: Optional k:v dict that's converted to url query
50 :returns: response object and ClusterTemplateCollection object
51 """
52
53 resp, body = self.get(self.cluster_templates_uri(filters), **kwargs)
54 collection = cluster_template_model.ClusterTemplateCollection
55 return self.deserialize(resp, body, collection)
56
57 def get_cluster_template(self, cluster_template_id, **kwargs):
58 """Makes GET /clustertemplate request and returns ClusterTemplateEntity
59
60 Abstracts REST call to return a single clustertempalte based on uuid
61 or name
62
63 :param cluster_template_id: clustertempalte uuid or name
64 :returns: response object and ClusterTemplateCollection object
65 """
66
67 resp, body = self.get(self.cluster_template_uri(cluster_template_id))
68 return self.deserialize(resp, body,
69 cluster_template_model.ClusterTemplateEntity)
70
71 def post_cluster_template(self, model, **kwargs):
72 """Makes POST /clustertemplate request
73
74 Abstracts REST call to create new clustertemplate
75
76 :param model: ClusterTemplateEntity
77 :returns: response object and ClusterTemplateEntity object
78 """
79
80 resp, body = self.post(
81 self.cluster_templates_uri(),
82 body=model.to_json(), **kwargs)
83 entity = cluster_template_model.ClusterTemplateEntity
84 return self.deserialize(resp, body, entity)
85
86 def patch_cluster_template(self, cluster_template_id,
87 cluster_templatepatch_listmodel, **kwargs):
88 """Makes PATCH /clustertemplate and returns ClusterTemplateEntity
89
90 Abstracts REST call to update clustertemplate attributes
91
92 :param cluster_template_id: UUID of clustertemplate
93 :param cluster_templatepatch_listmodel: ClusterTemplatePatchCollection
94 :returns: response object and ClusterTemplateEntity object
95 """
96
97 resp, body = self.patch(
98 self.cluster_template_uri(cluster_template_id),
99 body=cluster_templatepatch_listmodel.to_json(), **kwargs)
100 return self.deserialize(resp, body,
101 cluster_template_model.ClusterTemplateEntity)
102
103 def delete_cluster_template(self, cluster_template_id, **kwargs):
104 """Makes DELETE /clustertemplate request and returns response object
105
106 Abstracts REST call to delete clustertemplate based on uuid or name
107
108 :param cluster_template_id: UUID or name of clustertemplate
109 :returns: response object
110 """
111
112 return self.delete(self.cluster_template_uri(cluster_template_id),
113 **kwargs)