+ def validate_networks(self, props):
+ caas_nets = []
+ for nets_key in [self.CLUSTER_NETS, self.TENANT_NETS]:
+ if self.caas_utils.is_optional_param_present(nets_key, self.caas_conf):
+ if not isinstance(self.caas_conf[nets_key], list):
+ raise CaasValidationError('{} is not a list'.format(nets_key))
+ if len(set(self.caas_conf[nets_key])) != len(self.caas_conf[nets_key]):
+ raise CaasValidationError('{} has duplicate entries'.format(nets_key))
+ caas_nets.extend(self.caas_conf[nets_key])
+ if len(set(caas_nets)) != len(caas_nets):
+ raise CaasValidationError('{} and {} must be distinct, but same entries are '
+ 'found from both lists'.format(self.CLUSTER_NETS,
+ self.TENANT_NETS))
+ self._validate_homogenous_net_setup(props, caas_nets)
+
+ def _validate_homogenous_net_setup(self, props, caas_nets):
+ # Validate homogenous CaaS provider network setup
+ # pylint: disable=too-many-locals,too-many-nested-blocks
+ hosts_conf = self._get_conf(props, self.HOSTS_DOMAIN)
+ netprof_conf = self._get_conf(props, self.NETPROF_DOMAIN)
+ net_iface_map = {}
+ for net in caas_nets:
+ net_iface_map[net] = None
+ for host, host_conf in hosts_conf.iteritems():
+ # Validate only nodes that can host containerized workloads
+ if ('caas_worker' in host_conf[self.SERV_PROF] or
+ ('caas_master' in host_conf[self.SERV_PROF] and
+ 'compute' not in host_conf[self.SERV_PROF])):
+ # Validating CaaS network 'net' mapping in 'host'
+ is_caas_network_present = False
+ profiles = host_conf.get('network_profiles')
+ if isinstance(profiles, list) and profiles:
+ net_prof = netprof_conf.get(profiles[0])
+ if net_prof is not None:
+ ifaces = net_prof.get('provider_network_interfaces', {})
+ for iface, data in ifaces.iteritems():
+ net_type = data.get('type')
+ networks = data.get('provider_networks', [])
+ if net in networks and net_type == 'caas':
+ is_caas_network_present = True
+ if net_iface_map[net] is None:
+ net_iface_map[net] = iface
+ elif net_iface_map[net] != iface:
+ msg = 'CaaS network {} mapped to interface {} in one host '
+ msg += 'and interface {} in another host'
+ raise CaasValidationError(msg.format(net, iface,
+ net_iface_map[net]))
+ break
+ if not is_caas_network_present:
+ raise CaasValidationError('CaaS network {} missing from host {}'
+ .format(net, host))