def _delete(self, req, id): context = req.environ['nova.context'] authorize(context) try: flavor = flavors.get_instance_type_by_flavor_id( id, read_deleted="no") except exception.NotFound, e: raise webob.exc.HTTPNotFound(explanation=e.format_message())
def _delete(self, req, id): context = req.environ['nova.context'] authorize(context) try: flavor = flavors.get_instance_type_by_flavor_id(id, read_deleted="no") except exception.NotFound, e: raise webob.exc.HTTPNotFound(explanation=e.format_message())
def show(self, req, id): """Return data about the given flavor id.""" try: flavor = flavors.get_instance_type_by_flavor_id(id) req.cache_db_flavor(flavor) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, flavor)
def test_read_deleted_false_converting_flavorid(self): """ Ensure deleted instance types are not returned when not needed (for example when creating a server and attempting to translate from flavorid to instance_type_id. """ flavors.create("instance_type1", 256, 1, 120, 100, "test1") flavors.destroy("instance_type1") flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1") instance_type = flavors.get_instance_type_by_flavor_id("test1", read_deleted="no") self.assertEqual("instance_type1_redo", instance_type["name"])
def _delete(self, req, id): context = req.environ['nova.context'] authorize(context) try: flavor = flavors.get_instance_type_by_flavor_id( id, read_deleted="no") except exception.NotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) flavors.destroy(flavor['name']) return webob.Response(status_int=202)
def test_read_deleted_false_converting_flavorid(self): """ Ensure deleted instance types are not returned when not needed (for example when creating a server and attempting to translate from flavorid to instance_type_id. """ flavors.create("instance_type1", 256, 1, 120, 100, "test1") flavors.destroy("instance_type1") flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1") instance_type = flavors.get_instance_type_by_flavor_id( "test1", read_deleted="no") self.assertEqual("instance_type1_redo", instance_type["name"])
def test_can_read_deleted_types_using_flavor_id(self): # Ensure deleted instance types can be read when querying flavor_id. inst_type_name = "test" inst_type_flavor_id = "test1" inst_type = flavors.create(inst_type_name, 256, 1, 120, 100, inst_type_flavor_id) self.assertEqual(inst_type_name, inst_type["name"]) # NOTE(jk0): The deleted flavor will show up here because the context # in get_instance_type_by_flavor_id() is set to use read_deleted by # default. flavors.destroy(inst_type["name"]) deleted_inst_type = flavors.get_instance_type_by_flavor_id(inst_type_flavor_id) self.assertEqual(inst_type_name, deleted_inst_type["name"])
def test_can_read_deleted_types_using_flavor_id(self): # Ensure deleted instance types can be read when querying flavor_id. inst_type_name = "test" inst_type_flavor_id = "test1" inst_type = flavors.create(inst_type_name, 256, 1, 120, 100, inst_type_flavor_id) self.assertEqual(inst_type_name, inst_type["name"]) # NOTE(jk0): The deleted flavor will show up here because the context # in get_instance_type_by_flavor_id() is set to use read_deleted by # default. flavors.destroy(inst_type["name"]) deleted_inst_type = flavors.get_instance_type_by_flavor_id( inst_type_flavor_id) self.assertEqual(inst_type_name, deleted_inst_type["name"])
def resize(self, context, instance, flavor_id=None, *args, **kwargs): """Resize (ie, migrate) a running instance. If flavor_id is None, the process is considered a migration, keeping the original flavor_id. If flavor_id is not None, the instance should be migrated to a new host and resized to the new flavor_id. """ super(ComputeCellsAPI, self).resize(context, instance, flavor_id=flavor_id, *args, **kwargs) # NOTE(johannes): If we get to this point, then we know the # specified flavor_id is valid and exists. We'll need to load # it again, but that should be safe. old_instance_type = flavors.extract_instance_type(instance) if not flavor_id: new_instance_type = old_instance_type else: new_instance_type = flavors.get_instance_type_by_flavor_id( flavor_id, read_deleted="no") # NOTE(johannes): Later, when the resize is confirmed or reverted, # the superclass implementations of those methods will need access # to a local migration record for quota reasons. We don't need # source and/or destination information, just the old and new # flavors. Status is set to 'finished' since nothing else # will update the status along the way. self.db.migration_create( context.elevated(), { 'instance_uuid': instance['uuid'], 'old_instance_type_id': old_instance_type['id'], 'new_instance_type_id': new_instance_type['id'], 'status': 'finished' }) # FIXME(comstud): pass new instance_type object down to a method # that'll unfold it self._cast_to_cells(context, instance, 'resize', flavor_id=flavor_id, *args, **kwargs)
def index(self, req, flavor_id): context = req.environ['nova.context'] authorize(context) try: flavor = flavors.get_instance_type_by_flavor_id(flavor_id) except exception.FlavorNotFound: explanation = _("Flavor not found.") raise webob.exc.HTTPNotFound(explanation=explanation) # public flavor to all projects if flavor['is_public']: explanation = _("Access list not available for public flavors.") raise webob.exc.HTTPNotFound(explanation=explanation) # private flavor to listed projects only return _marshall_flavor_access(flavor_id)
def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs): global _block_device_mapping_seen _block_device_mapping_seen = kwargs.get('block_device_mapping') inst_type = flavors.get_instance_type_by_flavor_id(2) resv_id = None return ([{'id': 1, 'display_name': 'test_server', 'uuid': FAKE_UUID, 'instance_type': dict(inst_type), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fead::1234', 'image_ref': IMAGE_UUID, 'user_id': 'fake', 'project_id': 'fake', 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'updated_at': datetime.datetime(2010, 11, 11, 11, 0, 0), 'progress': 0, 'fixed_ips': [] }], resv_id)
def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs): global _block_device_mapping_seen _block_device_mapping_seen = kwargs.get('block_device_mapping') inst_type = flavors.get_instance_type_by_flavor_id(2) resv_id = None return ([{ 'id': 1, 'display_name': 'test_server', 'uuid': FAKE_UUID, 'instance_type': dict(inst_type), 'access_ip_v4': '1.2.3.4', 'access_ip_v6': 'fead::1234', 'image_ref': IMAGE_UUID, 'user_id': 'fake', 'project_id': 'fake', 'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0), 'updated_at': datetime.datetime(2010, 11, 11, 11, 0, 0), 'progress': 0, 'fixed_ips': [] }], resv_id)
def resize(self, context, instance, flavor_id=None, *args, **kwargs): """Resize (ie, migrate) a running instance. If flavor_id is None, the process is considered a migration, keeping the original flavor_id. If flavor_id is not None, the instance should be migrated to a new host and resized to the new flavor_id. """ super(ComputeCellsAPI, self).resize(context, instance, flavor_id=flavor_id, *args, **kwargs) # NOTE(johannes): If we get to this point, then we know the # specified flavor_id is valid and exists. We'll need to load # it again, but that should be safe. old_instance_type = flavors.extract_instance_type(instance) if not flavor_id: new_instance_type = old_instance_type else: new_instance_type = flavors.get_instance_type_by_flavor_id( flavor_id, read_deleted="no") # NOTE(johannes): Later, when the resize is confirmed or reverted, # the superclass implementations of those methods will need access # to a local migration record for quota reasons. We don't need # source and/or destination information, just the old and new # flavors. Status is set to 'finished' since nothing else # will update the status along the way. self.db.migration_create(context.elevated(), {'instance_uuid': instance['uuid'], 'old_instance_type_id': old_instance_type['id'], 'new_instance_type_id': new_instance_type['id'], 'status': 'finished'}) # FIXME(comstud): pass new instance_type object down to a method # that'll unfold it self._cast_to_cells(context, instance, 'resize', flavor_id=flavor_id, *args, **kwargs)
def test_will_get_instance_by_flavor_id(self): default_instance_type = flavors.get_default_instance_type() flavorid = default_instance_type['flavorid'] fetched = flavors.get_instance_type_by_flavor_id(flavorid) self.assertEqual(default_instance_type, fetched)
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 = flavors.get_instance_type_by_flavor_id(int(flavor_id)) sys_meta = flavors.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), "vm_mode": "", "default_swap_device": "", "default_ephemeral_device": "", "launched_on": "", "cell_name": "", "architecture": "", "os_type": ""} instance.update(info_cache) return instance
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 = flavors.get_instance_type_by_flavor_id(int(flavor_id)) sys_meta = flavors.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), "vm_mode": "", "default_swap_device": "", "default_ephemeral_device": "", "launched_on": "", "cell_name": "", "architecture": "", "os_type": "" } instance.update(info_cache) return instance
def test_will_get_instance_by_flavor_id(self): default_instance_type = flavors.get_default_instance_type() flavorid = default_instance_type["flavorid"] fetched = flavors.get_instance_type_by_flavor_id(flavorid) self.assertEqual(default_instance_type, fetched)