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
Beispiel #2
0
    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
Beispiel #3
0
    def test_get_fixed_subnet_id(self, mock_clients):
        fake_name = "fake_subnet"
        fake_id = "35ee5da0-1ac0-11e9-84cd-00224d6b7bc1"
        mock_nclient = mock.MagicMock()
        mock_nclient.list_subnets.return_value = {
            'subnets': [{
                'id': fake_id,
                'name': fake_name,
            }]
        }

        osc = mock.MagicMock()
        mock_clients.return_value = osc
        osc.neutron.return_value = mock_nclient

        subnet_id = neutron.get_fixed_subnet_id(self.context, fake_name)

        self.assertEqual(fake_id, subnet_id)