def get_net_params(self, context, cluster_template, cluster): extra_params = dict() # NOTE(lxkong): Convert external network name to UUID, the template # field name is confused. If external_network_id is not specified in # cluster template use 'public' as the default value, which is the same # with the heat template default value as before. external_network = cluster_template.external_network_id ext_net_id = neutron.get_external_network_id(context, external_network) extra_params['external_network'] = ext_net_id # NOTE(brtknr): Convert fixed network UUID to name if the given network # name is UUID like because OpenStack Cloud Controller Manager only # accepts a name as an argument to internal-network-name in the # cloud-config file provided to it. The default fixed network name is # the same as that defined in the heat template. fixed_network = cluster.fixed_network net_name = neutron.get_fixed_network_name(context, fixed_network) if net_name: extra_params['fixed_network_name'] = net_name else: extra_params['fixed_network_name'] = cluster.name # NOTE(brtknr): Convert fixed subnet name to UUID. If fixed_subnet # is not specified in cluster template use 'private' as the default # value, which is the same as the heat template default value. fixed_subnet = cluster.fixed_subnet subnet_id = neutron.get_fixed_subnet_id(context, fixed_subnet) if subnet_id: extra_params['fixed_subnet'] = subnet_id return extra_params
def get_net_params(self, context, cluster_template, cluster): extra_params = dict() # NOTE(lxkong): Convert external network name to UUID, the template # field name is confused. If external_network_id is not specified in # cluster template use 'public' as the default value, which is the same # with the heat template default value as before. external_network = cluster_template.external_network_id ext_net_id = neutron.get_external_network_id(context, external_network) extra_params['external_network'] = ext_net_id # NOTE(brtknr): Convert fixed network UUID to name if the given network # name is UUID like because OpenStack Cloud Controller Manager only # accepts a name as an argument to internal-network-name in the # cloud-config file provided to it. The default fixed network name is # the same as that defined in the heat template. fixed_network = cluster.fixed_network net_name = neutron.get_fixed_network_name(context, fixed_network) if net_name: extra_params['fixed_network_name'] = net_name else: extra_params['fixed_network_name'] = cluster.name if cluster.labels.get('fixed_subnet_cidr'): extra_params['fixed_subnet_cidr'] = cluster.labels.get( 'fixed_subnet_cidr') # NOTE(brtknr): Convert fixed subnet name to UUID. If fixed_subnet # is not specified in cluster template use 'private' as the default # value, which is the same as the heat template default value. fixed_subnet = cluster.fixed_subnet subnet_id = neutron.get_fixed_subnet_id(context, fixed_subnet) if subnet_id: extra_params['fixed_subnet'] = subnet_id # NOTE(flwang): If a fixed subnet is given, then the label # fixed_subnet_cidr should be updated to reflect the correct # setting. extra_params['fixed_subnet_cidr'] = neutron.get_subnet( context, subnet_id, "id", "cidr") if cluster_template.no_proxy: extra_params["no_proxy"] = ( cluster_template.no_proxy + "," + ( extra_params.get('fixed_subnet_cidr') or self.default_subnet_cidr)) return extra_params
def test_get_fixed_network_name(self, mock_clients): fake_name = "fake_network" fake_id = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1" mock_nclient = mock.MagicMock() mock_nclient.list_networks.return_value = { 'networks': [{ 'id': fake_id, 'name': fake_name, 'router:external': False }] } osc = mock.MagicMock() mock_clients.return_value = osc osc.neutron.return_value = mock_nclient network_name = neutron.get_fixed_network_name(self.context, fake_id) self.assertEqual(fake_name, network_name)
def get_params(self, context, cluster_template, cluster, **kwargs): extra_params = kwargs.pop('extra_params', {}) extra_params['discovery_url'] = self.get_discovery_url(cluster) osc = self.get_osc(context) extra_params['magnum_url'] = osc.magnum_url() if cluster_template.tls_disabled: extra_params['loadbalancing_protocol'] = 'HTTP' extra_params['kubernetes_port'] = 8080 extra_params['octavia_enabled'] = keystone.is_octavia_enabled() # NOTE(lxkong): Convert external network name to UUID, the template # field name is confused. If external_network_id is not specified in # cluster template use 'public' as the default value, which is the same # with the heat template default value as before. external_network = cluster_template.external_network_id or "public" extra_params['external_network'] = \ neutron.get_external_network_id(context, external_network) # NOTE(brtknr): Convert fixed network UUID to name if the given network # name is UUID like because OpenStack Cloud Controller Manager only # accepts a name as an argument to internal-network-name in the # cloud-config file provided to it. The default fixed network name is # the same as that defined in the heat template. fixed_network = (cluster.fixed_network or cluster_template.fixed_network or "private") extra_params['fixed_network_name'] = \ neutron.get_fixed_network_name(context, fixed_network) label_list = [ 'flannel_network_cidr', 'flannel_backend', 'flannel_network_subnetlen', 'system_pods_initial_delay', 'system_pods_timeout', 'admission_control_list', 'prometheus_monitoring', 'grafana_admin_passwd', 'kube_dashboard_enabled', 'etcd_volume_size', 'cert_manager_api', 'ingress_controller_role', 'octavia_ingress_controller_tag', 'kubelet_options', 'kubeapi_options', 'kubeproxy_options', 'kubecontroller_options', 'kubescheduler_options', 'influx_grafana_dashboard_enabled' ] for label in label_list: extra_params[label] = cluster.labels.get(label) ingress_controller = cluster.labels.get('ingress_controller', '').lower() if (ingress_controller == 'octavia' and not extra_params['octavia_enabled']): raise exception.InvalidParameterValue( 'Octavia service needs to be deployed for octavia ingress ' 'controller.') extra_params["ingress_controller"] = ingress_controller cluser_ip_range = cluster.labels.get('service_cluster_ip_range') if cluser_ip_range: extra_params['portal_network_cidr'] = cluser_ip_range if cluster_template.registry_enabled: extra_params['swift_region'] = CONF.docker_registry.swift_region extra_params['registry_container'] = ( CONF.docker_registry.swift_registry_container) kube_tag = (cluster.labels.get("kube_tag") or cluster_template.labels.get("kube_tag")) if kube_tag: extra_params['kube_version'] = kube_tag extra_params['master_kube_tag'] = kube_tag extra_params['minion_kube_tag'] = kube_tag return super(K8sTemplateDefinition, self).get_params(context, cluster_template, cluster, extra_params=extra_params, **kwargs)