blob: c6d4dbe3b7233c1d5726877c3b864956be344694 [file] [log] [blame]
Artem Panchenko0594cd72017-06-12 13:25:26 +03001# Copyright 2017 Mirantis, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13
14
15from tcp_tests.managers.k8s.base import K8sBaseResource
16from tcp_tests.managers.k8s.base import K8sBaseManager
17
18
19class K8sNode(K8sBaseResource):
20 """docstring for ClassName"""
21
22 def __repr__(self):
23 return "<K8sNode: %s>" % self.name
24
25 @property
26 def name(self):
27 return self.metadata.name
28
29 @property
30 def labels(self):
31 return self.metadata.labels
32
33 @labels.setter
34 def labels(self, labels):
35 current_labels = {
36 label: None for label in self.labels
37 }
38 current_labels.update(labels)
39 self.add_labels(labels=current_labels)
40
41 def add_labels(self, labels):
42 if not isinstance(labels, dict):
43 raise TypeError("labels must be a dict!")
44 body = {
45 "metadata":
46 {
47 "labels": labels
48 }
49 }
50 self._add_details(self._manager.update(body=body, name=self.name))
51
52 def remove_labels(self, list_labels):
53 labels = {label: None for label in list_labels}
54 self.add_labels(labels=labels)
55
56
57class K8sNodeManager(K8sBaseManager):
58 """docstring for ClassName"""
59
60 resource_class = K8sNode
61
62 def _get(self, name, **kwargs):
63 return self.api.read_namespaced_node(name=name, **kwargs)
64
65 def _list(self, **kwargs):
66 return self.api.list_namespaced_node(**kwargs)
67
68 def _create(self, body, **kwargs):
69 return self.api.create_namespaced_node(body=body, **kwargs)
70
71 def _replace(self, body, name, **kwargs):
72 return self.api.replace_namespaced_node(body=body, name=name, **kwargs)
73
74 def _delete(self, body, name, **kwargs):
75 return self.api.delete_namespaced_node(body=body, name=name, **kwargs)
76
77 def _deletecollection(self, **kwargs):
78 return self.api.deletecollection_namespaced_node(**kwargs)
79
80 def update(self, body, name, **kwargs):
81 return self.api.patch_namespaced_node(body=body, name=name, **kwargs)