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 # client talking to Stx standalone
\r
17 from service.client.base_client import BaseClient
\r
18 from typing import List
\r
20 from o2ims.domain import stx_object as ocloudModel
\r
21 from o2ims import config
\r
24 class StxSaOcloudClient(BaseClient):
\r
27 self.driver = StxSaClientImp()
\r
29 # def list(self) -> List[ocloudModel.StxGenericModel]:
\r
30 # return self._list()
\r
32 # def get(self, id) -> ocloudModel.StxGenericModel:
\r
33 # return self._get(id)
\r
35 def _get(self, id) -> ocloudModel.StxGenericModel:
\r
36 raise self.driver.getInstanceInfo()
\r
39 return [self.driver.getInstanceInfo()]
\r
42 class StxSaResourcePoolClient(BaseClient):
\r
45 self.driver = StxSaClientImp()
\r
47 def _get(self, id) -> ocloudModel.StxGenericModel:
\r
48 return self.driver.getInstanceInfo()
\r
51 return [self.driver.getInstanceInfo()]
\r
54 class StxSaDmsClient(BaseClient):
\r
57 self.driver = StxSaClientImp()
\r
59 def _get(self, id) -> ocloudModel.StxGenericModel:
\r
60 return self.driver.getK8sDetail(id)
\r
63 return self.driver.getK8sList()
\r
65 # internal driver which implement client call to Stx Standalone instance
\r
67 # from keystoneauth1.identity import v3
\r
68 # from keystoneauth1 import session
\r
69 # # from keystoneclient.v3 import ksclient
\r
70 # from starlingxclient.v3 import stxclient
\r
73 class StxSaClientImp(object):
\r
74 def __init__(self, access_info=None) -> None:
\r
76 self.access_info = access_info
\r
77 if self.access_info is None:
\r
78 self.access_info = config.get_stx_access_info()
\r
79 # self.auth = auth = v3.Password(
\r
80 # auth_url="http://example.com:5000/v3", username="admin",
\r
81 # password="password", project_name="admin",
\r
82 # user_domain_id="default", project_domain_id="default")
\r
83 # self.session = sess = session.Session(auth=auth)
\r
84 # # self.keystone = ksclient.Client(session=sess)
\r
85 # self.stx = stxclient.Client(session=sess)
\r
87 def getInstanceInfo(self) -> ocloudModel.StxGenericModel:
\r
88 raise NotImplementedError
\r
90 def getK8sList(self) -> List[ocloudModel.StxGenericModel]:
\r
91 raise NotImplementedError
\r
93 def getK8sDetail(self, id) -> ocloudModel.StxGenericModel:
\r
94 raise NotImplementedError
\r