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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from openstackcli import (
18 from .hostcli import HostCli
21 class HostCliUser(object): # pylint: disable=too-few-public-methods
22 """Base class for users of the
25 - `crl.remotesession.remotesession.RemoteSession`
31 _hostcli: :class:`HostCli` instance
33 _openstack: :class:`.OpenStack` instance
35 _runner: :class:`.Runner` instance
37 _remotesession: :class:`crl.remotesession.remotesession.RemoteSession`
42 self._hostcli = HostCli()
43 self._openstack = OpenStack()
44 self._runner = Runner()
45 self._remotesession = None
48 def initialize(self, remotesession, envname=None):
49 self._remotesession = remotesession
50 self._envname = envname
51 envkwargs = {} if envname is None else {'envname': envname}
52 for runner in [self._hostcli, self._openstack, self._runner]:
53 runner.initialize(remotesession, **envkwargs)
55 def _get_env_target(self, target='default'):
56 """Get ennvironment target for the *target*.
58 return '{target}{env_postfix}'.format(
60 env_postfix=self._env_postfix)
63 def _env_postfix(self):
64 return '.{}'.format(self._envname) if self._envname else ''