コード例 #1
0
    def acquire_service_pub_ip_info(self, spec_type, spec_lb_ip, project_id):

        if spec_type != 'LoadBalancer':
            return None

        if spec_lb_ip:
            user_specified_ip = spec_lb_ip.format()
            res_id = self._drv_pub_ip.is_ip_available(user_specified_ip)
            if res_id:
                service_pub_ip_info = (obj_lbaas.LBaaSPubIp(
                                       ip_id=res_id,
                                       ip_addr=str(user_specified_ip),
                                       alloc_method='user'))

                return service_pub_ip_info
            else:
                # user specified IP is not valid
                LOG.error("IP=%s is not available", user_specified_ip)
                return None
        else:
            LOG.debug("Trying to allocate public ip from pool")

        # get public subnet id from kuryr.conf
        external_svc_subnet = config.CONF.neutron_defaults.external_svc_subnet
        if not external_svc_subnet:
            raise cfg.RequiredOptError('external_svc_subnet',
                                       cfg.OptGroup('neutron_defaults'))

        neutron = clients.get_neutron_client()
        n_subnet = neutron.show_subnet(external_svc_subnet).get('subnet')
        if not n_subnet:
            LOG.error(
                "No subnet found for external_svc_subnet=%s",
                external_svc_subnet)
            raise kl_exc.NoResourceException

        public_network_id = n_subnet['network_id']

        res_id, alloc_ip_addr = (self._drv_pub_ip.allocate_ip
                                 (public_network_id,
                                  external_svc_subnet,
                                  project_id,
                                  'kuryr_lb'))
        service_pub_ip_info = obj_lbaas.LBaaSPubIp(ip_id=res_id,
                                                   ip_addr=alloc_ip_addr,
                                                   alloc_method='pool')

        return service_pub_ip_info
コード例 #2
0
    def test_acquire_service_pub_ip_info_usr_specified_ip(self):
        cls = d_lb_public_ip.FloatingIpServicePubIPDriver
        m_driver = mock.Mock(spec=cls)
        m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
        neutron = self.useFixture(k_fix.MockNeutronClient()).client

        floating_ip = {
            'floating_ip_address': '1.2.3.4',
            'port_id': None,
            'id': 'a2a62ea7-e3bf-40df-8c09-aa0c29876a6b'
        }
        neutron.list_floatingips.return_value = {'floatingips': [floating_ip]}
        project_id = mock.sentinel.project_id
        spec_type = 'LoadBalancer'
        spec_lb_ip = '1.2.3.4'

        expected_resp = \
            obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'],
                                 ip_addr=floating_ip['floating_ip_address'],
                                 alloc_method='user')

        self.assertEqual(
            expected_resp,
            cls.acquire_service_pub_ip_info(m_driver, spec_type, spec_lb_ip,
                                            project_id))
コード例 #3
0
    def test_acquire_service_pub_ip_info_alloc_from_pool(self, m_cfg):
        cls = d_lb_public_ip.FloatingIpServicePubIPDriver
        m_driver = mock.Mock(spec=cls)
        m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        m_cfg.neutron_defaults.external_svc_subnet =\
            mock.sentinel.external_svc_subnet

        neutron.show_subnet.return_value =\
            {'subnet': {'network_id': 'ec29d641-fec4-4f67-928a-124a76b3a8e6'}}
        floating_ip = {
            'floating_ip_address': '1.2.3.5',
            'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'
        }
        neutron.create_floatingip.return_value = {'floatingip': floating_ip}

        project_id = mock.sentinel.project_id
        spec_type = 'LoadBalancer'
        spec_lb_ip = None

        expected_resp = \
            obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'],
                                 ip_addr=floating_ip['floating_ip_address'],
                                 alloc_method='pool')

        self.assertEqual(
            expected_resp,
            cls.acquire_service_pub_ip_info(m_driver, spec_type, spec_lb_ip,
                                            project_id))
コード例 #4
0
    def test_release_pub_ip_alloc_method_user(self):
        cls = d_lb_public_ip.FloatingIpServicePubIPDriver
        m_driver = mock.Mock(spec=cls)

        floating_ip = {
            'floating_ip_address': '1.2.3.5',
            'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'
        }

        service_pub_ip_info = \
            obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'],
                                 ip_addr=floating_ip['floating_ip_address'],
                                 alloc_method='user')

        self.assertIsNone(cls.release_pub_ip(m_driver, service_pub_ip_info))
コード例 #5
0
    def test_disassociate_pub_ip_neutron_exception(self):
        cls = d_lb_public_ip.FloatingIpServicePubIPDriver
        m_driver = mock.Mock(spec=cls)
        m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        neutron.update_floatingip.side_effect = n_exc.NeutronClientException
        floating_ip = {
            'floating_ip_address': '1.2.3.5',
            'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'
        }
        service_pub_ip_info = \
            obj_lbaas.LBaaSPubIp(ip_id=floating_ip['id'],
                                 ip_addr=floating_ip['floating_ip_address'],
                                 alloc_method='pool')

        self.assertRaises(n_exc.NeutronClientException,
                          cls.disassociate_pub_ip, m_driver,
                          service_pub_ip_info)
コード例 #6
0
    def test_disassociate_pub_ip_fip_id_not_exist(self):
        cls = d_lb_public_ip.FloatingIpServicePubIPDriver
        m_driver = mock.Mock(spec=cls)
        m_driver._drv_pub_ip = public_ip.FipPubIpDriver()
        neutron = self.useFixture(k_fix.MockNeutronClient()).client
        neutron.update_floatingip.return_value = None
        floating_ip = {
            'floating_ip_address': '1.2.3.5',
            'id': 'ec29d641-fec4-4f67-928a-124a76b3a888'
        }

        service_pub_ip_info = \
            obj_lbaas.LBaaSPubIp(ip_id=0,
                                 ip_addr=floating_ip['floating_ip_address'],
                                 alloc_method='pool')

        self.assertIsNone(
            cls.disassociate_pub_ip(m_driver, service_pub_ip_info))