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.
17 from . profiles import (
26 def __init__(self, name, service_profiles, ippool):
28 self.service_profiles = service_profiles
29 self.internal_ip = ippool.get_internal_ip()
30 self.external_ip = ippool.get_external_ip()
34 d = self._service_profiles_dict
35 d.update({'network_domain': self.expected_network_domain})
36 d.update(self._network_profiles_dict)
40 def _service_profiles_dict(self):
41 return {'service_profiles': [str(s()) for s in self.service_profiles]}
44 def expected_network_domain(self):
45 return '{name}-domain-name'.format(name=self.name)
48 def _network_profiles_dict(self):
49 return {'network_profiles': self._network_profiles}
52 def _network_profiles(self):
53 return ['network_nondpdk']
57 return {'infra_internal': {'ip': self.internal_ip},
58 'infra_external': {'ip': self.external_ip}}
61 def network_profile_details(self):
64 'provider_network_interfaces': {
70 def expected_is_dpdk():
77 def _network_profiles(self):
78 return ['network_dpdk']
81 def network_profile_details(self):
84 'provider_network_interfaces': {
86 'type': 'ovs-dpdk'}}}}
89 def expected_is_dpdk():
93 @six.add_metaclass(abc.ABCMeta)
94 class HostGeneratorBase(object):
96 Abstract generator base for :class:`.Host` instances.
99 ippool: :class:`IPPool` instance
101 def __init__(self, ippool):
102 self._ippool = ippool
108 def gen(self, nmbr, service_profiles=None, start=1):
109 service_profiles = service_profiles or self._default_profiles
110 for i in range(start, start + nmbr):
111 yield self._host_cls(
112 name='{basename}-{i}'.format(basename=self._basename, i=i),
113 service_profiles=service_profiles,
116 @abc.abstractproperty
118 """Return basename of the host e.g. master"""
120 @abc.abstractproperty
121 def _default_profiles(self):
122 """Return iterable of service profiles"""
125 class MasterGenerator(HostGeneratorBase):
131 def _default_profiles(self):
132 return [MasterProfile,
139 class WorkerGenerator(HostGeneratorBase):
145 def _default_profiles(self):
146 return [WorkerProfile, BaseProfile]
149 class StorageGenerator(HostGeneratorBase):
155 def _default_profiles(self):
156 return [StorageProfile]
159 class DpdkWorkerGenerator(WorkerGenerator):