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.
16 from collections import namedtuple
23 class Profiles(object):
28 def set_profiles(cls, master, worker):
45 def profiles_mask(self):
46 return set([self.master, self.worker, self.storage])
49 class MgmtTarget(namedtuple('MgmtTarget', ['host', 'user', 'password'])):
50 """Container for the cloudtaf2 management VIP target attributes.
53 host: IP address or FQDN of the host management VIP
54 user: Username, e.g. cloudadmin for login
55 password: Login password
59 Library cluster.cluster.MgmtTarget
62 ... password=good_password
69 @six.add_metaclass(abc.ABCMeta)
70 class HostBase(object):
71 """Container base for Host attributes.
74 name: name of the host
75 service_profiles: list of service profiles like ['master', 'worker']
76 shelldicts: list of dictionaries to RemoteSession.set_runner_target
78 def __init__(self, host_config):
79 self._host_config = host_config
83 """Return True if dpdk is used in provider network interfaces.
84 In more detail, is True if and only if one of the network profiles has
85 at least one interface with type *ovs-dpdk*.
87 return self._host_config.is_dpdk
91 return self._host_config.name
94 def service_profiles(self):
95 return self._host_config.service_profiles
98 def network_domain(self):
99 return self._host_config.network_domain
101 @abc.abstractproperty
102 def shelldicts(self):
103 """Return *shelldicts* for :class:`crl.remotesession.remotesession`.
107 def _host_dict(self):
108 return {'host': self._infra['ip'],
109 'user': self._host_config.mgmt_target.user,
110 'password': self._host_config.mgmt_target.password}
114 return self._host_config.networking['infra_{}'.format(self._infra_type)]
116 @abc.abstractproperty
117 def _infra_type(self):
118 """Return any infra type e.g. 'internal', 'external' etc.
122 class Master(HostBase):
124 def shelldicts(self):
125 return [self._host_dict]
128 def _infra_type(self):
132 def external_ip(self):
133 return self._infra['ip']
136 class NonMaster(HostBase):
138 def shelldicts(self):
139 return [self._host_config.mgmt_target.asdict(), self._host_dict]
142 def _infra_type(self):
146 class HostConfig(namedtuple('HostConfig', ['name',