Example #1
0
 def test_delete_instance_type_info(self):
     instance_type = instance_types.get_default_instance_type()
     metadata = {}
     instance_types.save_instance_type_info(metadata, instance_type)
     instance_types.save_instance_type_info(metadata, instance_type, '_')
     instance_types.delete_instance_type_info(metadata, '', '_')
     self.assertEqual(metadata, {})
Example #2
0
def get_test_instance(context=None, instance_type=None):
    if not context:
        context = get_test_admin_context()

    if not instance_type:
        instance_type = get_test_instance_type(context)

    metadata = {}
    instance_types.save_instance_type_info(metadata, instance_type, "")

    test_instance = {
        "memory_kb": "2048000",
        "basepath": "/some/path",
        "bridge_name": "br100",
        "vcpus": 4,
        "root_gb": 40,
        "project_id": "fake",
        "bridge": "br101",
        "image_ref": "cedef40a-ed67-4d10-800e-17455edce175",
        "instance_type_id": "5",
        "system_metadata": metadata,
        "extra_specs": {},
    }

    instance_ref = nova.db.instance_create(context, test_instance)
    return instance_ref
Example #3
0
    def _test_extract_instance_type(self, prefix):
        instance_type = instance_types.get_default_instance_type()

        metadata = {}
        instance_types.save_instance_type_info(metadata, instance_type, prefix)
        instance = {'system_metadata': self._dict_to_metadata(metadata)}
        _instance_type = instance_types.extract_instance_type(instance, prefix)

        props = instance_types.system_metadata_instance_type_props.keys()
        for key in instance_type.keys():
            if key not in props:
                del instance_type[key]

        self.assertEqual(instance_type, _instance_type)
    def _test_extract_instance_type(self, prefix):
        instance_type = instance_types.get_default_instance_type()

        metadata = {}
        instance_types.save_instance_type_info(metadata, instance_type, prefix)
        instance = {"system_metadata": self._dict_to_metadata(metadata)}
        _instance_type = instance_types.extract_instance_type(instance, prefix)

        props = instance_types.system_metadata_instance_type_props.keys()
        for key in instance_type.keys():
            if key not in props:
                del instance_type[key]

        self.assertEqual(instance_type, _instance_type)
    def setUp(self):
        super(SimpleTenantUsageControllerTest, self).setUp()
        self.controller = simple_tenant_usage.SimpleTenantUsageController()

        class FakeComputeAPI:
            def get_instance_type(self, context, flavor_type):
                if flavor_type == 1:
                    return instance_types.get_default_instance_type()
                else:
                    raise exception.InstanceTypeNotFound(flavor_type)

        self.compute_api = FakeComputeAPI()
        self.context = None

        now = datetime.datetime.now()
        self.baseinst = dict(display_name='foo',
                             launched_at=now - datetime.timedelta(1),
                             terminated_at=now,
                             instance_type_id=1,
                             vm_state='deleted',
                             deleted=0)
        basetype = instance_types.get_default_instance_type()
        sys_meta = utils.dict_to_metadata(
            instance_types.save_instance_type_info({}, basetype))
        self.baseinst['system_metadata'] = sys_meta
        self.basetype = instance_types.extract_instance_type(self.baseinst)
    def setUp(self):
        super(SimpleTenantUsageControllerTest, self).setUp()
        self.controller = simple_tenant_usage.SimpleTenantUsageController()

        class FakeComputeAPI:
            def get_instance_type(self, context, flavor_type):
                if flavor_type == 1:
                    return instance_types.get_default_instance_type()
                else:
                    raise exception.InstanceTypeNotFound(flavor_type)

        self.compute_api = FakeComputeAPI()
        self.context = None

        now = datetime.datetime.now()
        self.baseinst = dict(display_name='foo',
                             launched_at=now - datetime.timedelta(1),
                             terminated_at=now,
                             instance_type_id=1,
                             vm_state='deleted',
                             deleted=0)
        basetype = instance_types.get_default_instance_type()
        sys_meta = utils.dict_to_metadata(
            instance_types.save_instance_type_info({}, basetype))
        self.baseinst['system_metadata'] = sys_meta
        self.basetype = instance_types.extract_instance_type(self.baseinst)
Example #7
0
    def test_save_instance_type_info(self):
        instance_type = instance_types.get_default_instance_type()

        example = {}
        example_prefix = {}

        for key in instance_types.system_metadata_instance_type_props.keys():
            example['instance_type_%s' % key] = instance_type[key]
            example_prefix['fooinstance_type_%s' % key] = instance_type[key]

        metadata = {}
        instance_types.save_instance_type_info(metadata, instance_type)
        self.assertEqual(example, metadata)

        metadata = {}
        instance_types.save_instance_type_info(metadata, instance_type, 'foo')
        self.assertEqual(example_prefix, metadata)
Example #8
0
    def _setUpBlockDeviceMapping(self):
        image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
        sys_meta = instance_types.save_instance_type_info(
            {}, instance_types.get_instance_type(1))
        inst1 = db.instance_create(self.context,
                                  {'image_ref': image_uuid,
                                   'instance_type_id': 1,
                                   'root_device_name': '/dev/sdb1',
                                   'system_metadata': sys_meta})
        inst2 = db.instance_create(self.context,
                                  {'image_ref': image_uuid,
                                   'instance_type_id': 1,
                                   'root_device_name': '/dev/sdc1',
                                   'system_metadata': sys_meta})

        instance_uuid = inst1['uuid']
        mappings0 = [
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb1',
             'snapshot_id': '1',
             'volume_id': '2'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb2',
             'volume_id': '3',
             'volume_size': 1},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb3',
             'delete_on_termination': True,
             'snapshot_id': '4',
             'volume_id': '5'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb4',
             'delete_on_termination': False,
             'snapshot_id': '6',
             'volume_id': '7'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb5',
             'snapshot_id': '8',
             'volume_id': '9',
             'volume_size': 0},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb6',
             'snapshot_id': '10',
             'volume_id': '11',
             'volume_size': 1},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb7',
             'no_device': True},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb8',
             'virtual_name': 'swap'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb9',
             'virtual_name': 'ephemeral3'}]

        volumes = self._block_device_mapping_create(instance_uuid, mappings0)
        return (inst1, inst2, volumes)
Example #9
0
    def _setUpBlockDeviceMapping(self):
        image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
        sys_meta = instance_types.save_instance_type_info(
            {}, instance_types.get_instance_type(1))
        inst1 = db.instance_create(self.context,
                                  {'image_ref': image_uuid,
                                   'instance_type_id': 1,
                                   'root_device_name': '/dev/sdb1',
                                   'system_metadata': sys_meta})
        inst2 = db.instance_create(self.context,
                                  {'image_ref': image_uuid,
                                   'instance_type_id': 1,
                                   'root_device_name': '/dev/sdc1',
                                   'system_metadata': sys_meta})

        instance_uuid = inst1['uuid']
        mappings0 = [
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb1',
             'snapshot_id': '1',
             'volume_id': '2'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb2',
             'volume_id': '3',
             'volume_size': 1},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb3',
             'delete_on_termination': True,
             'snapshot_id': '4',
             'volume_id': '5'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb4',
             'delete_on_termination': False,
             'snapshot_id': '6',
             'volume_id': '7'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb5',
             'snapshot_id': '8',
             'volume_id': '9',
             'volume_size': 0},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb6',
             'snapshot_id': '10',
             'volume_id': '11',
             'volume_size': 1},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb7',
             'no_device': True},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb8',
             'virtual_name': 'swap'},
            {'instance_uuid': instance_uuid,
             'device_name': '/dev/sdb9',
             'virtual_name': 'ephemeral3'}]

        volumes = self._block_device_mapping_create(instance_uuid, mappings0)
        return (inst1, inst2, volumes)
Example #10
0
 def _create_instance(self):
     fake.stub_out_image_service(self.stubs)
     ctxt = context.get_admin_context()
     instance_type = db.instance_type_get(ctxt, 1)
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     return db.instance_create(ctxt,
                     {'user_id': 'fake',
                     'project_id': 'fake',
                     'instance_type_id': 1,
                     'memory_mb': 1024,
                     'vcpus': 2,
                     'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                     'system_metadata': sys_meta})
Example #11
0
 def _create_instance(self):
     fake.stub_out_image_service(self.stubs)
     ctxt = context.get_admin_context()
     instance_type = db.instance_type_get(ctxt, 1)
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     return db.instance_create(ctxt,
                     {'user_id': 'fake',
                     'project_id': 'fake',
                     'instance_type_id': 1,
                     'memory_mb': 1024,
                     'vcpus': 2,
                     'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                     'system_metadata': sys_meta})
Example #12
0
File: utils.py Project: ntoll/nova
def get_test_instance(context=None, instance_type=None):
    if not context:
        context = get_test_admin_context()

    if not instance_type:
        instance_type = get_test_instance_type(context)

    metadata = {}
    instance_types.save_instance_type_info(metadata, instance_type, '')

    test_instance = {'memory_kb': '2048000',
                     'basepath': '/some/path',
                     'bridge_name': 'br100',
                     'vcpus': 4,
                     'root_gb': 40,
                     'project_id': 'fake',
                     'bridge': 'br101',
                     'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
                     'instance_type_id': '5',
                     'system_metadata': metadata}

    instance_ref = nova.db.instance_create(context, test_instance)
    return instance_ref
def get_fake_db_instance(start, end, instance_id, tenant_id):
    sys_meta = utils.dict_to_metadata(
        instance_types.save_instance_type_info({}, FAKE_INST_TYPE))
    return {'id': instance_id,
            'uuid': '00000000-0000-0000-0000-00000000000000%02d' % instance_id,
            'image_ref': '1',
            'project_id': tenant_id,
            'user_id': 'fakeuser',
            'display_name': 'name',
            'state_description': 'state',
            'instance_type_id': 1,
            'launched_at': start,
            'terminated_at': end,
            'system_metadata': sys_meta}
Example #14
0
def get_test_instance(context=None, instance_type=None):
    if not context:
        context = get_test_admin_context()

    if not instance_type:
        instance_type = get_test_instance_type(context)

    metadata = {}
    instance_types.save_instance_type_info(metadata, instance_type, '')

    test_instance = {'memory_kb': '2048000',
                     'basepath': '/some/path',
                     'bridge_name': 'br100',
                     'vcpus': 4,
                     'root_gb': 40,
                     'project_id': 'fake',
                     'bridge': 'br101',
                     'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
                     'instance_type_id': '5',
                     'system_metadata': metadata,
                     'extra_specs': {}}

    instance_ref = nova.db.instance_create(context, test_instance)
    return instance_ref
def get_fake_db_instance(start, end, instance_id, tenant_id):
    sys_meta = utils.dict_to_metadata(
        instance_types.save_instance_type_info({}, FAKE_INST_TYPE))
    return {
        'id': instance_id,
        'uuid': '00000000-0000-0000-0000-00000000000000%02d' % instance_id,
        'image_ref': '1',
        'project_id': tenant_id,
        'user_id': 'fakeuser',
        'display_name': 'name',
        'state_description': 'state',
        'instance_type_id': 1,
        'launched_at': start,
        'terminated_at': end,
        'system_metadata': sys_meta
    }
Example #16
0
 def _create_instance(self):
     fake.stub_out_image_service(self.stubs)
     ctxt = context.get_admin_context()
     instance_type = db.instance_type_get(ctxt, 1)
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     return db.instance_create(
         ctxt,
         {
             "user_id": "fake",
             "project_id": "fake",
             "instance_type_id": 1,
             "memory_mb": 1024,
             "vcpus": 2,
             "image_ref": "155d900f-4e14-4e4c-a73d-069cbf4541e6",
             "system_metadata": sys_meta,
         },
     )
Example #17
0
 def _create_instance(self, params={}):
     """Create a test instance."""
     instance_type = instance_types.get_instance_type_by_name('m1.tiny')
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     inst = {}
     inst['image_ref'] = 1
     inst['reservation_id'] = 'r-fakeres'
     inst['launch_time'] = '10'
     inst['user_id'] = self.user_id
     inst['project_id'] = self.project_id
     inst['instance_type_id'] = instance_type['id']
     inst['system_metadata'] = sys_meta
     inst['ami_launch_index'] = 0
     inst['root_gb'] = 0
     inst['ephemeral_gb'] = 0
     inst.update(params)
     return db.instance_create(self.context, inst)['id']
Example #18
0
 def _create_instance(self, params={}):
     """Create a test instance."""
     instance_type = instance_types.get_instance_type_by_name('m1.tiny')
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     inst = {}
     inst['image_ref'] = 1
     inst['reservation_id'] = 'r-fakeres'
     inst['launch_time'] = '10'
     inst['user_id'] = self.user_id
     inst['project_id'] = self.project_id
     inst['instance_type_id'] = instance_type['id']
     inst['system_metadata'] = sys_meta
     inst['ami_launch_index'] = 0
     inst['root_gb'] = 0
     inst['ephemeral_gb'] = 0
     inst.update(params)
     return db.instance_create(self.context, inst)['id']
Example #19
0
 def _wrapped_create(self, params=None):
     instance_type = instance_types.get_instance_type_by_name('m1.tiny')
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     inst = {}
     inst['image_ref'] = 1
     inst['user_id'] = self.user_id
     inst['project_id'] = self.project_id
     inst['instance_type_id'] = instance_type['id']
     inst['root_gb'] = 0
     inst['ephemeral_gb'] = 0
     inst['access_ip_v4'] = '1.2.3.4'
     inst['access_ip_v6'] = 'feed:5eed'
     inst['display_name'] = 'test_instance'
     inst['hostname'] = 'test_instance_hostname'
     inst['system_metadata'] = sys_meta
     if params:
         inst.update(params)
     return db.instance_create(self.context, inst)
Example #20
0
 def _wrapped_create(self, params=None):
     instance_type = instance_types.get_instance_type_by_name('m1.tiny')
     sys_meta = instance_types.save_instance_type_info({}, instance_type)
     inst = {}
     inst['image_ref'] = 1
     inst['user_id'] = self.user_id
     inst['project_id'] = self.project_id
     inst['instance_type_id'] = instance_type['id']
     inst['root_gb'] = 0
     inst['ephemeral_gb'] = 0
     inst['access_ip_v4'] = '1.2.3.4'
     inst['access_ip_v6'] = 'feed:5eed'
     inst['display_name'] = 'test_instance'
     inst['hostname'] = 'test_instance_hostname'
     inst['system_metadata'] = sys_meta
     if params:
         inst.update(params)
     return db.instance_create(self.context, inst)
Example #21
0
 def _live_migration_instance(self):
     inst_type = instance_types.get_instance_type(1)
     # NOTE(danms): we have _got_ to stop doing this!
     inst_type['memory_mb'] = 1024
     sys_meta = utils.dict_to_metadata(
         instance_types.save_instance_type_info({}, inst_type))
     return {'id': 31337,
             'uuid': 'fake_uuid',
             'name': 'fake-instance',
             'host': 'fake_host1',
             'power_state': power_state.RUNNING,
             'memory_mb': 1024,
             'root_gb': 1024,
             'ephemeral_gb': 0,
             'vm_state': '',
             'task_state': '',
             'instance_type_id': inst_type['id'],
             'image_ref': 'fake-image-ref',
             'system_metadata': sys_meta}
Example #22
0
 def _live_migration_instance(self):
     inst_type = instance_types.get_instance_type(1)
     # NOTE(danms): we have _got_ to stop doing this!
     inst_type['memory_mb'] = 1024
     sys_meta = utils.dict_to_metadata(
         instance_types.save_instance_type_info({}, inst_type))
     return {'id': 31337,
             'uuid': 'fake_uuid',
             'name': 'fake-instance',
             'host': 'fake_host1',
             'power_state': power_state.RUNNING,
             'memory_mb': 1024,
             'root_gb': 1024,
             'ephemeral_gb': 0,
             'vm_state': '',
             'task_state': '',
             'instance_type_id': inst_type['id'],
             'image_ref': 'fake-image-ref',
             'system_metadata': sys_meta}
Example #23
0
 def test_allocate_for_instance_handles_macs_passed(self):
     # If a macs argument is supplied to the 'nova-network' API, it is just
     # ignored. This test checks that the call down to the rpcapi layer
     # doesn't pass macs down: nova-network doesn't support hypervisor
     # mac address limits (today anyhow).
     macs = set(['ab:cd:ef:01:23:34'])
     self.mox.StubOutWithMock(
         self.network_api.network_rpcapi, "allocate_for_instance")
     kwargs = dict(zip(['host', 'instance_id', 'project_id',
             'requested_networks', 'rxtx_factor', 'vpn', 'macs'],
             itertools.repeat(mox.IgnoreArg())))
     self.network_api.network_rpcapi.allocate_for_instance(
         mox.IgnoreArg(), **kwargs).AndReturn([])
     self.mox.ReplayAll()
     inst_type = instance_types.get_default_instance_type()
     inst_type['rxtx_factor'] = 0
     sys_meta = instance_types.save_instance_type_info({}, inst_type)
     instance = dict(id='id', uuid='uuid', project_id='project_id',
         host='host', system_metadata=utils.dict_to_metadata(sys_meta))
     self.network_api.allocate_for_instance(
         self.context, instance, 'vpn', 'requested_networks', macs=macs)
Example #24
0
    def setUp(self):
        super(LibvirtBlockInfoTest, self).setUp()

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.get_admin_context()
        instance_type = db.instance_type_get(self.context, 2)
        sys_meta = instance_types.save_instance_type_info({}, instance_type)
        nova.tests.image.fake.stub_out_image_service(self.stubs)
        self.test_instance = {
                'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310',
                'memory_kb': '1024000',
                'basepath': '/some/path',
                'bridge_name': 'br100',
                'vcpus': 2,
                'project_id': 'fake',
                'bridge': 'br101',
                'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
                'root_gb': 10,
                'ephemeral_gb': 20,
                'instance_type_id': 2,  # m1.tiny
                'system_metadata': sys_meta}
Example #25
0
    def setUp(self):
        super(LibvirtBlockInfoTest, self).setUp()

        self.user_id = 'fake'
        self.project_id = 'fake'
        self.context = context.get_admin_context()
        instance_type = db.instance_type_get(self.context, 2)
        sys_meta = instance_types.save_instance_type_info({}, instance_type)
        nova.tests.image.fake.stub_out_image_service(self.stubs)
        self.test_instance = {
            'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310',
            'memory_kb': '1024000',
            'basepath': '/some/path',
            'bridge_name': 'br100',
            'vcpus': 2,
            'project_id': 'fake',
            'bridge': 'br101',
            'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
            'root_gb': 10,
            'ephemeral_gb': 20,
            'instance_type_id': 2,  # m1.tiny
            'system_metadata': sys_meta
        }
Example #26
0
    def _stub_migrate_instance_calls(self, method, multi_host, info):
        fake_instance_type = instance_types.get_default_instance_type()
        fake_instance_type['rxtx_factor'] = 1.21
        sys_meta = utils.dict_to_metadata(
            instance_types.save_instance_type_info({}, fake_instance_type))
        fake_instance = {'uuid': 'fake_uuid',
                         'instance_type_id': fake_instance_type['id'],
                         'project_id': 'fake_project_id',
                         'system_metadata': sys_meta}
        fake_migration = {'source_compute': 'fake_compute_source',
                          'dest_compute': 'fake_compute_dest'}

        def fake_mig_inst_method(*args, **kwargs):
            info['kwargs'] = kwargs

        def fake_is_multi_host(*args, **kwargs):
            return multi_host

        def fake_get_floaters(*args, **kwargs):
            return ['fake_float1', 'fake_float2']

        self.stubs.Set(network_rpcapi.NetworkAPI, method,
                fake_mig_inst_method)
        self.stubs.Set(self.network_api, '_is_multi_host',
                fake_is_multi_host)
        self.stubs.Set(self.network_api, '_get_floating_ip_addresses',
                fake_get_floaters)

        expected = {'instance_uuid': 'fake_uuid',
                    'source_compute': 'fake_compute_source',
                    'dest_compute': 'fake_compute_dest',
                    'rxtx_factor': 1.21,
                    'project_id': 'fake_project_id',
                    'floating_addresses': None}
        if multi_host:
            expected['floating_addresses'] = ['fake_float1', 'fake_float2']
        return fake_instance, fake_migration, expected
Example #27
0
def stub_instance(id,
                  user_id=None,
                  project_id=None,
                  host=None,
                  node=None,
                  vm_state=None,
                  task_state=None,
                  reservation_id="",
                  uuid=FAKE_UUID,
                  image_ref="10",
                  flavor_id="1",
                  name=None,
                  key_name='',
                  access_ipv4=None,
                  access_ipv6=None,
                  progress=0,
                  auto_disk_config=False,
                  display_name=None,
                  include_fake_metadata=True,
                  config_drive=None,
                  power_state=None,
                  nw_cache=None,
                  metadata=None,
                  security_groups=None,
                  root_device_name=None,
                  limit=None,
                  marker=None):

    if user_id is None:
        user_id = 'fake_user'
    if project_id is None:
        project_id = 'fake_project'

    if metadata:
        metadata = [{'key': k, 'value': v} for k, v in metadata.items()]
    elif include_fake_metadata:
        metadata = [models.InstanceMetadata(key='seq', value=str(id))]
    else:
        metadata = []

    inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))
    sys_meta = instance_types.save_instance_type_info({}, inst_type)

    if host is not None:
        host = str(host)

    if key_name:
        key_data = 'FAKE'
    else:
        key_data = ''

    if security_groups is None:
        security_groups = [{"id": 1, "name": "test"}]

    # ReservationID isn't sent back, hack it in there.
    server_name = name or "server%s" % id
    if reservation_id != "":
        server_name = "reservation_%s" % (reservation_id, )

    info_cache = create_info_cache(nw_cache)

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "user_id": user_id,
        "project_id": project_id,
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": key_name,
        "key_data": key_data,
        "config_drive": config_drive,
        "vm_state": vm_state or vm_states.BUILDING,
        "task_state": task_state,
        "power_state": power_state,
        "memory_mb": 0,
        "vcpus": 0,
        "root_gb": 0,
        "ephemeral_gb": 0,
        "hostname": display_name or server_name,
        "host": host,
        "node": node,
        "instance_type_id": 1,
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": reservation_id,
        "mac_address": "",
        "scheduled_at": timeutils.utcnow(),
        "launched_at": timeutils.utcnow(),
        "terminated_at": timeutils.utcnow(),
        "availability_zone": "",
        "display_name": display_name or server_name,
        "display_description": "",
        "locked": False,
        "metadata": metadata,
        "access_ip_v4": access_ipv4,
        "access_ip_v6": access_ipv6,
        "uuid": uuid,
        "progress": progress,
        "auto_disk_config": auto_disk_config,
        "name": "instance-%s" % id,
        "shutdown_terminate": True,
        "disable_terminate": False,
        "security_groups": security_groups,
        "root_device_name": root_device_name,
        "system_metadata": utils.dict_to_metadata(sys_meta)
    }

    instance.update(info_cache)

    return instance
Example #28
0
def get_default_sys_meta():
    return utils.dict_to_metadata(
        instance_types.save_instance_type_info(
            {}, instance_types.get_default_instance_type()))
Example #29
0
    def apply(self, context, resource):

        if not resource.metadata:
            resource.metadata = {}
        if not resource.security_group:
            resource.security_group = 'default'

        if not resource.instance_type:
            resource.instance_type = instance_types.get_default_instance_type()
        if not resource.min_count:
            resource.min_count = 1
        if not resource.max_count:
            resource.max_count = resource.min_count

        resource.block_device_mapping = resource.block_device_mapping or []
        if resource.instance_type['disabled']:
            raise exception.InstanceTypeNotFound(
                    instance_type_id=resource.instance_type['id'])

        if resource.user_data:
            l = len(resource.user_data)
            if l > MAX_USERDATA_SIZE:
                # NOTE(mikal): user_data is stored in a text column, and
                # the database might silently truncate if its over length.
                raise exception.InstanceUserDataTooLarge(
                    length=l, maxsize=MAX_USERDATA_SIZE)

            try:
                base64.decodestring(resource.user_data)
            except base64.binascii.Error:
                raise exception.InstanceUserDataMalformed()

        # Reserve quotas
        resource.num_instances, resource.quota_reservations = \
                        self._check_num_instances_quota(context,
                                                        resource.instance_type,
                                                        resource.min_count,
                                                        resource.max_count)

        self._check_metadata_properties_quota(context, resource.metadata)
        self._check_injected_file_quota(context, resource.injected_files)
        self._check_requested_networks(context, resource.requested_networks)

        # Handle config_drive
        resource.config_drive_id = None
        if resource.config_drive and not utils.is_valid_boolstr(
                                                        resource.config_drive):
            # config_drive is volume id
            resource.config_drive_id = resource.config_drive
            resource.config_drive = None

            # Ensure config_drive image exists
            cd_image_service, config_drive_id = \
                      glance.get_remote_image_service(context,
                                                      resource.config_drive_id)
            cd_image_service.show(context, resource.config_drive_id)

        if resource.key_data is None and resource.key_name:
            resource.key_pair = self.db.key_pair_get(context, context.user_id,
                                            resource.key_name)
            resource.key_data = resource.key_pair['public_key']

        resource.root_device_name = block_device.properties_root_device_name(
                                          resource.image.get('properties', {}))

        resource.availability_zone, resource.forced_host = \
                     self._handle_availability_zone(resource.availability_zone)

        resource.system_metadata = instance_types.save_instance_type_info(
                                dict(), resource.instance_type)

        return orc_utils.DictableObject(details='request_validated',
                                        resource=resource)
Example #30
0
def stub_instance(id, user_id=None, project_id=None, host=None,
                  node=None, vm_state=None, task_state=None,
                  reservation_id="", uuid=FAKE_UUID, image_ref="10",
                  flavor_id="1", name=None, key_name='',
                  access_ipv4=None, access_ipv6=None, progress=0,
                  auto_disk_config=False, display_name=None,
                  include_fake_metadata=True, config_drive=None,
                  power_state=None, nw_cache=None, metadata=None,
                  security_groups=None, root_device_name=None,
                  limit=None, marker=None):

    if user_id is None:
        user_id = 'fake_user'
    if project_id is None:
        project_id = 'fake_project'

    if metadata:
        metadata = [{'key': k, 'value': v} for k, v in metadata.items()]
    elif include_fake_metadata:
        metadata = [models.InstanceMetadata(key='seq', value=str(id))]
    else:
        metadata = []

    inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))
    sys_meta = instance_types.save_instance_type_info({}, inst_type)

    if host is not None:
        host = str(host)

    if key_name:
        key_data = 'FAKE'
    else:
        key_data = ''

    if security_groups is None:
        security_groups = [{"id": 1, "name": "test"}]

    # ReservationID isn't sent back, hack it in there.
    server_name = name or "server%s" % id
    if reservation_id != "":
        server_name = "reservation_%s" % (reservation_id, )

    info_cache = create_info_cache(nw_cache)

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "user_id": user_id,
        "project_id": project_id,
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": key_name,
        "key_data": key_data,
        "config_drive": config_drive,
        "vm_state": vm_state or vm_states.BUILDING,
        "task_state": task_state,
        "power_state": power_state,
        "memory_mb": 0,
        "vcpus": 0,
        "root_gb": 0,
        "ephemeral_gb": 0,
        "hostname": display_name or server_name,
        "host": host,
        "node": node,
        "instance_type_id": 1,
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": reservation_id,
        "mac_address": "",
        "scheduled_at": timeutils.utcnow(),
        "launched_at": timeutils.utcnow(),
        "terminated_at": timeutils.utcnow(),
        "availability_zone": "",
        "display_name": display_name or server_name,
        "display_description": "",
        "locked": False,
        "metadata": metadata,
        "access_ip_v4": access_ipv4,
        "access_ip_v6": access_ipv6,
        "uuid": uuid,
        "progress": progress,
        "auto_disk_config": auto_disk_config,
        "name": "instance-%s" % id,
        "shutdown_terminate": True,
        "disable_terminate": False,
        "security_groups": security_groups,
        "root_device_name": root_device_name,
        "system_metadata": utils.dict_to_metadata(sys_meta)}

    instance.update(info_cache)

    return instance
Example #31
0
def get_default_sys_meta():
    return utils.dict_to_metadata(
        instance_types.save_instance_type_info(
            {}, instance_types.get_default_instance_type()))