@@ -2902,9 +2902,9 @@ def backup(self, context, instance, name, backup_type, rotation,
2902
2902
raise exception .InvalidRequest (
2903
2903
_ ('Backup is not supported for volume-backed instances.' ))
2904
2904
else :
2905
- image_meta = self . _create_image ( context , instance ,
2906
- name , 'backup' ,
2907
- extra_properties = props_copy )
2905
+ image_meta = compute_utils . create_image (
2906
+ context , instance , name , 'backup' , self . image_api ,
2907
+ extra_properties = props_copy )
2908
2908
2909
2909
# NOTE(comstud): Any changes to this method should also be made
2910
2910
# to the backup_instance() method in nova/cells/messaging.py
@@ -2935,9 +2935,9 @@ def snapshot(self, context, instance, name, extra_properties=None):
2935
2935
when creating the image.
2936
2936
:returns: A dict containing image metadata
2937
2937
"""
2938
- image_meta = self . _create_image ( context , instance , name ,
2939
- 'snapshot' ,
2940
- extra_properties = extra_properties )
2938
+ image_meta = compute_utils . create_image (
2939
+ context , instance , name , 'snapshot' , self . image_api ,
2940
+ extra_properties = extra_properties )
2941
2941
2942
2942
# NOTE(comstud): Any changes to this method should also be made
2943
2943
# to the snapshot_instance() method in nova/cells/messaging.py
@@ -2981,62 +2981,6 @@ def snapshot(self, context, instance, name, extra_properties=None):
2981
2981
2982
2982
return image_meta
2983
2983
2984
- def _create_image (self , context , instance , name , image_type ,
2985
- extra_properties = None ):
2986
- """Create new image entry in the image service. This new image
2987
- will be reserved for the compute manager to upload a snapshot
2988
- or backup.
2989
-
2990
- :param context: security context
2991
- :param instance: nova.objects.instance.Instance object
2992
- :param name: string for name of the snapshot
2993
- :param image_type: snapshot | backup
2994
- :param extra_properties: dict of extra image properties to include
2995
-
2996
- """
2997
- properties = {
2998
- 'instance_uuid' : instance .uuid ,
2999
- 'user_id' : str (context .user_id ),
3000
- 'image_type' : image_type ,
3001
- }
3002
- properties .update (extra_properties or {})
3003
-
3004
- image_meta = self ._initialize_instance_snapshot_metadata (
3005
- instance , name , properties )
3006
- # if we're making a snapshot, omit the disk and container formats,
3007
- # since the image may have been converted to another format, and the
3008
- # original values won't be accurate. The driver will populate these
3009
- # with the correct values later, on image upload.
3010
- if image_type == 'snapshot' :
3011
- image_meta .pop ('disk_format' , None )
3012
- image_meta .pop ('container_format' , None )
3013
- return self .image_api .create (context , image_meta )
3014
-
3015
- def _initialize_instance_snapshot_metadata (self , instance , name ,
3016
- extra_properties = None ):
3017
- """Initialize new metadata for a snapshot of the given instance.
3018
-
3019
- :param instance: nova.objects.instance.Instance object
3020
- :param name: string for name of the snapshot
3021
- :param extra_properties: dict of extra metadata properties to include
3022
-
3023
- :returns: the new instance snapshot metadata
3024
- """
3025
- image_meta = utils .get_image_from_system_metadata (
3026
- instance .system_metadata )
3027
- image_meta .update ({'name' : name ,
3028
- 'is_public' : False })
3029
-
3030
- # Delete properties that are non-inheritable
3031
- properties = image_meta ['properties' ]
3032
- for key in CONF .non_inheritable_image_properties :
3033
- properties .pop (key , None )
3034
-
3035
- # The properties in extra_properties have precedence
3036
- properties .update (extra_properties or {})
3037
-
3038
- return image_meta
3039
-
3040
2984
# NOTE(melwitt): We don't check instance lock for snapshot because lock is
3041
2985
# intended to prevent accidental change/delete of instances
3042
2986
@check_instance_state (vm_state = [vm_states .ACTIVE , vm_states .STOPPED ,
@@ -3051,7 +2995,7 @@ def snapshot_volume_backed(self, context, instance, name,
3051
2995
3052
2996
:returns: the new image metadata
3053
2997
"""
3054
- image_meta = self . _initialize_instance_snapshot_metadata (
2998
+ image_meta = compute_utils . initialize_instance_snapshot_metadata (
3055
2999
instance , name , extra_properties )
3056
3000
# the new image is simply a bucket of properties (particularly the
3057
3001
# block device mapping, kernel and ramdisk IDs) with no image data,
@@ -3654,8 +3598,8 @@ def shelve(self, context, instance, clean_shutdown=True):
3654
3598
3655
3599
if not compute_utils .is_volume_backed_instance (context , instance ):
3656
3600
name = '%s-shelved' % instance .display_name
3657
- image_meta = self . _create_image ( context , instance , name ,
3658
- 'snapshot' )
3601
+ image_meta = compute_utils . create_image (
3602
+ context , instance , name , 'snapshot' , self . image_api )
3659
3603
image_id = image_meta ['id' ]
3660
3604
self .compute_rpcapi .shelve_instance (context , instance = instance ,
3661
3605
image_id = image_id , clean_shutdown = clean_shutdown )
0 commit comments