Add cloudtaf framework
[ta/cloudtaf.git] / libraries / openstackcli / cloudcli.py
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain 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,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import abc
16 import six
17 from .cliwrapperbase import CliWrapperBase
18
19
20 @six.add_metaclass(abc.ABCMeta)  # pylint: disable=abstract-method
21 class CloudCliBase(CliWrapperBase):
22
23     @property
24     def _target_kwargs(self):
25         return {'target': '{prebase}{os_cloud}.{cloudname}'.format(
26             prebase=self._prebase,
27             os_cloud=self._os_cloud,
28             cloudname=self._cloudname)}
29
30     @property
31     def _os_cloud(self):
32         return 'os-cloud'
33
34     @property
35     def _prebase(self):
36         return (''
37                 if self._expected_target == 'default' else
38                 '{}.'.format(self._expected_target))
39
40     @property
41     def _cloudname(self):
42         return 'cloudname'
43
44     @property
45     def _expected_cmd_args(self):
46         return ' --os-cloud {} '.format(self._cloudname)
47
48
49 class TargetCloud(CloudCliBase):
50
51     @property
52     def _expected_target(self):
53         return 'target'
54
55
56 class DefaultCloud(CloudCliBase):
57
58     @property
59     def _expected_target(self):
60         return 'default'
61
62
63 class TypoCloud(CloudCliBase):
64
65     @property
66     def _expected_target(self):
67         return 'target.{os_cloud}.{cloudname}'.format(
68             os_cloud=self._os_cloud,
69             cloudname=self._cloudname)
70
71     @property
72     def _prebase(self):
73         return 'target.'
74
75     @property
76     def _os_cloud(self):
77         return 'typo-cloud'
78
79     @property
80     def _expected_cmd_args(self):
81         return ' --os-cloud default '