Пример #1
0
    def test_allocates_v4_ips_for_public_network(self):
        public_network = db_api.network_create_safe(admin_context,
                                    dict(label="public", project_id=None,
                                         priority=1))
        private_noise_network = db_api.network_create_safe(admin_context,
                        dict(label="private", project_id="another_project",
                             priority=1))

        public_v4block = dict(netmask="255.255.255.0", cidr="10.1.1.0/24",
                               gateway="10.1.1.1", broadcast="10.1.1.255",
                               dns1="1.2.3.4", dns2="2.3.4.5")
        public_v4ip = dict(address="10.1.1.2", version=4,
                            ip_block=public_v4block)
        melange_client.allocate_global_net_ip(public_network.id, IgnoreArg(),
                                              project_id="project1",
                                              mac_address=IgnoreArg())\
                                   .InAnyOrder().AndReturn([public_v4ip])

        self.mox.ReplayAll()

        net_info = QuantumManager().allocate_for_instance(admin_context,
                                               instance_id=self.instance_id,
                                               host="localhost",
                                               project_id="project1",
                                               instance_type_id=1,
                                               vpn="vpn_address")

        self.assertEqual(len(net_info), 1)
        assert_network_info_has_ip(self, net_info[0], public_v4ip,
                                         public_network)
Пример #2
0
    def test_allocates_public_and_private_network_ips_from_melange(self):
        network_params = dict(label="private", project_id="some_other_project",
                              priority=1)
        private_noise_network = db_api.network_create_safe(admin_context,
                                                           network_params)

        private_nw, private_ip = self._setup_network("10.1.1.2", "10.1.1.0/24",
                                                     net_label="private",
                                                     project_id="project1")
        melange_client.allocate_private_net_ip(private_nw.id, IgnoreArg(),
                                               project_id="project1",
                                               mac_address=IgnoreArg()).\
                                               AndReturn([private_ip])
        public_nw, public_ip = self._setup_network("77.1.1.2", "77.1.1.0/24",
                                                   net_label="public",
                                                   project_id=None)
        melange_client.allocate_global_net_ip(public_nw.id, IgnoreArg(),
                                               project_id="project1",
                                               mac_address=IgnoreArg()).\
                                               AndReturn([public_ip])
        self.mox.ReplayAll()

        net_info = QuantumManager().allocate_for_instance(admin_context,
                                               instance_id=self.instance_id,
                                               host=None,
                                               project_id="project1",
                                               instance_type_id=1,
                                               vpn=None)
        [private_net, public_net] = net_info

        assert_network_info_has_ip(self, private_net, private_ip, private_nw)
        assert_network_info_has_ip(self, public_net, public_ip, public_nw)
Пример #3
0
 def allocate_ip(vif):
 
     if is_private_network(vif):
         return melange.allocate_private_net_ip(
             vif['network_id'],
             vif['id'], project_id=project_id,
             mac_address=vif['address'])
     
     return melange.allocate_global_net_ip(
         vif['network_id'],
         vif['id'], project_id=project_id,
         mac_address=vif['address'])
Пример #4
0
    def test_allocate_global_net_ip_posts_to_non_tenantscope_allocations(self):
        network_id = "network333"
        vif_id = "vif1"
        project_id = "project"
        mac_address = "11:22:33:44:55:66"
        mock_client = setup_mock_client(self.mox)
        request_body = json.dumps(dict(network=dict(mac_address=mac_address,
                                                    tenant_id=project_id)))
        stub_response = ResponseStub({'ip_addresses': [{'id': "123"}]})
        mock_client.post("/v0.1/ipam/networks/network333/"
                         "interfaces/vif1/ip_allocations", body=request_body,
                         headers=json_content_type()).AndReturn(stub_response)

        self.mox.ReplayAll()

        ip_addresses = melange_client.allocate_global_net_ip(
            network_id, vif_id,
            project_id=project_id,
            mac_address=mac_address)

        self.assertEqual(ip_addresses, [{'id': "123"}])