1 # Copyright (C) 2021 Wind River Systems, Inc.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
15 # from dataclasses import dataclass
\r
20 class MismatchedModel(Exception):
\r
24 class StxGenericModel:
\r
25 def __init__(self, api_response: dict = None) -> None:
\r
27 self.id = api_response.uuid
\r
28 self.content = json.dumps(api_response.to_dict())
\r
29 self.updatetime = api_response.updated_at
\r
30 self.createtime = api_response.created_at
\r
31 self.name = api_response.name
\r
33 def is_outdated(self, newmodel) -> bool:
\r
34 return self.updatetime < newmodel.updatetime
\r
36 def update_by(self, newmodel) -> None:
\r
37 if self.id != newmodel.id:
\r
38 raise MismatchedModel("Mismatched model")
\r
39 self.name = newmodel.name
\r
41 self.content = newmodel.content
\r
42 self.createtime = newmodel.createtime
\r
43 self.updatetime = newmodel.updatetime
\r
46 class StxK8sClusterModel(StxGenericModel):
\r
47 def __init__(self, api_response: dict = None) -> None:
\r
48 super().__init__(api_response=api_response)
\r
50 def is_outdated(self, newmodel) -> bool:
\r
51 # never outdated since lack of such evidence
\r