コード例 #1
0
def get_test_instance(context=None, flavor=None, obj=False):
    if not context:
        context = get_test_admin_context()

    if not flavor:
        flavor = get_test_flavor(context)

    test_instance = {
        'memory_kb': '2048000',
        'basepath': '/some/path',
        'bridge_name': 'br100',
        'vcpus': 4,
        'root_gb': 40,
        'bridge': 'br101',
        'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
        'instance_type_id': flavor['id'],
        'system_metadata': {},
        'extra_specs': {},
        'user_id': context.user_id,
        'project_id': context.project_id,
    }

    if obj:
        instance = objects.Instance(context, **test_instance)
        instance.flavor = objects.Flavor.get_by_id(context, flavor['id'])
        instance.create()
    else:
        flavors.save_flavor_info(test_instance['system_metadata'], flavor, '')
        instance = db.instance_create(context, test_instance)
    return instance
コード例 #2
0
ファイル: utils.py プロジェクト: arbrandes/nova
def get_test_instance(context=None, flavor=None, obj=False):
    if not context:
        context = get_test_admin_context()

    if not flavor:
        flavor = get_test_flavor(context)

    test_instance = {'memory_kb': '2048000',
                     'basepath': '/some/path',
                     'bridge_name': 'br100',
                     'vcpus': 4,
                     'root_gb': 40,
                     'bridge': 'br101',
                     'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
                     'instance_type_id': flavor['id'],
                     'system_metadata': {},
                     'extra_specs': {},
                     'user_id': context.user_id,
                     'project_id': context.project_id,
                     }

    if obj:
        instance = objects.Instance(context, **test_instance)
        instance.flavor = objects.Flavor.get_by_id(context, flavor['id'])
        instance.create()
    else:
        flavors.save_flavor_info(test_instance['system_metadata'], flavor, '')
        instance = db.instance_create(context, test_instance)
    return instance
コード例 #3
0
ファイル: api.py プロジェクト: windskyer/k_nova
def instance_create(context, values, session=None):
    """Creates a new VM instance in the Database"""
    power_specs = values.pop('power_specs', None)
    inst_ref = db_api.instance_create(context, values)
    #If there were PowerSpecs provided, then insert them now
    if power_specs is not None:
        instance_power_specs_create(
            context, inst_ref['uuid'], power_specs, session)
        #Query the Instance again to make sure the PowerSpecs is populated
        inst_ref = db_api.instance_get_by_uuid(context, inst_ref['uuid'])
    return inst_ref
コード例 #4
0
    def test_get_network_info(self):
        quantum_mgr = QuantumManager()
        admin_context = context.get_admin_context()
        instance = db_api.instance_create(admin_context, {})

        network1 = db_api.network_create_safe(admin_context,
                                              dict(label="private1",
                                                   project_id="project1",
                                                   priority=1))
        network2 = db_api.network_create_safe(admin_context,
                                              dict(label="private2",
                                                   project_id="project1",
                                                   priority=1))

        vif1 = db_api.virtual_interface_create(admin_context,
                                         dict(address="11:22:33:44:55:66",
                                              instance_id=instance['id'],
                                              network_id=network1['id']))
        vif2 = db_api.virtual_interface_create(admin_context,
                                         dict(address="66:22:33:44:55:66",
                                              instance_id=instance['id'],
                                              network_id=network2['id']))

        self.mox.StubOutWithMock(melange_client, 'get_allocated_ips')
        block1 = 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")
        ip1 = dict(address="10.1.1.2", version=4, ip_block=block1)
        block2 = dict(netmask="255.255.255.0", cidr="77.1.1.0/24",
                      gateway="77.1.1.1", broadcast="77.1.1.255",
                      dns1="1.2.3.4", dns2=None)
        ip2 = dict(address="77.1.1.2", version=4, ip_block=block2)

        melange_client.get_allocated_ips(network1['id'], vif1['id'],
                                         project_id="project1").\
                                         AndReturn([ip1])

        melange_client.get_allocated_ips(network2['id'], vif2['id'],
                                         project_id="project1").\
                                         AndReturn([ip2])

        self.mox.ReplayAll()

        net_info = quantum_mgr.get_instance_nw_info(admin_context,
                                                    instance['id'], 1, None)
        assert_network_info_has_ip(self, net_info[0], ip1, network1)
        assert_network_info_has_ip(self, net_info[1], ip2, network2)
コード例 #5
0
    def test_deallocates_ips_from_melange(self):
        quantum_mgr = QuantumManager()
        admin_context = context.get_admin_context()
        project_id = "project1"

        instance_id = db_api.instance_create(admin_context, dict())['id']
        network1 = db_api.network_create_safe(admin_context,
                                             dict(instance_id=instance_id,
                                                  priority=1,
                                                  project_id=project_id))
        network2 = db_api.network_create_safe(admin_context,
                                             dict(instance_id=instance_id,
                                                  priority=2,
                                                  project_id=project_id))

        vif1 = db_api.virtual_interface_create(admin_context,
                                              dict(instance_id=instance_id,
                                              network_id=network1['id'],
                                              project_id=project_id))
        vif2 = db_api.virtual_interface_create(admin_context,
                                              dict(instance_id=instance_id,
                                              network_id=network2['id'],
                                              project_id=project_id))
        self._setup_quantum_mocks()

        self.mox.StubOutWithMock(melange_client, "deallocate_ips")
        melange_client.deallocate_ips(network1['id'], vif1['id'],
                                      project_id=project_id)
        melange_client.deallocate_ips(network2['id'], vif2['id'],
                                      project_id=project_id)

        self.mox.ReplayAll()

        quantum_mgr.deallocate_for_instance(admin_context,
                                            instance_id=instance_id,
                                            project_id=project_id)

        vifs_left = db_api.virtual_interface_get_by_instance(admin_context,
                                                             instance_id)
        self.assertEqual(len(vifs_left), 0)
コード例 #6
0
ファイル: test_hosts.py プロジェクト: arbrandes/nova
def _create_instance(**kwargs):
    """Create a test instance."""
    ctxt = context_maker.get_admin_context()
    return db.instance_create(ctxt, _create_instance_dict(**kwargs))
コード例 #7
0
 def setUp(self):
     super(TestAllocateForInstance, self).setUp()
     self.instance_id = db_api.instance_create(admin_context, {}).id
     self._stub_out_quantum_port_and_iface_create_calls()
     self.mox.StubOutWithMock(melange_client, 'allocate_private_net_ip')
     self.mox.StubOutWithMock(melange_client, 'allocate_global_net_ip')
コード例 #8
0
def _create_instance(**kwargs):
    """Create a test instance."""
    ctxt = context_maker.get_admin_context()
    return db.instance_create(ctxt, _create_instance_dict(**kwargs))