@@ -507,28 +507,40 @@ def take_action(self, parsed_args):
507507 "exception" : e }
508508 )
509509
510- block_device_mapping = {}
510+ block_device_mapping_v2 = []
511511 if volume :
512- # When booting from volume, for now assume no other mappings
513- # This device value is likely KVM-specific
514- block_device_mapping = {'vda' : volume }
515- else :
516- for dev_map in parsed_args .block_device_mapping :
517- dev_key , dev_vol = dev_map .split ('=' , 1 )
518- block_volume = None
519- if dev_vol :
520- vol = dev_vol .split (':' , 1 )[0 ]
521- if vol :
522- vol_id = utils .find_resource (
512+ block_device_mapping_v2 = [{'uuid' : volume ,
513+ 'boot_index' : '0' ,
514+ 'source_type' : 'volume' ,
515+ 'destination_type' : 'volume'
516+ }]
517+ for dev_map in parsed_args .block_device_mapping :
518+ dev_name , dev_map = dev_map .split ('=' , 1 )
519+ if dev_map :
520+ dev_map = dev_map .split (':' )
521+ if len (dev_map ) > 0 :
522+ mapping = {
523+ 'device_name' : dev_name ,
524+ 'uuid' : utils .find_resource (
523525 volume_client .volumes ,
524- vol ,
525- ).id
526- block_volume = dev_vol .replace (vol , vol_id )
526+ dev_map [0 ],
527+ ).id }
528+ # Block device mapping v1 compatibility
529+ if len (dev_map ) > 1 and \
530+ dev_map [1 ] in ('volume' , 'snapshot' ):
531+ mapping ['source_type' ] = dev_map [1 ]
527532 else :
528- msg = _ ("Volume name or ID must be specified if "
529- "--block-device-mapping is specified" )
530- raise exceptions .CommandError (msg )
531- block_device_mapping .update ({dev_key : block_volume })
533+ mapping ['source_type' ] = 'volume'
534+ mapping ['destination_type' ] = 'volume'
535+ if len (dev_map ) > 2 :
536+ mapping ['volume_size' ] = dev_map [2 ]
537+ if len (dev_map ) > 3 :
538+ mapping ['delete_on_termination' ] = dev_map [3 ]
539+ else :
540+ msg = _ ("Volume name or ID must be specified if "
541+ "--block-device-mapping is specified" )
542+ raise exceptions .CommandError (msg )
543+ block_device_mapping_v2 .append (mapping )
532544
533545 nics = []
534546 if parsed_args .nic in ('auto' , 'none' ):
@@ -598,7 +610,7 @@ def take_action(self, parsed_args):
598610 userdata = userdata ,
599611 key_name = parsed_args .key_name ,
600612 availability_zone = parsed_args .availability_zone ,
601- block_device_mapping = block_device_mapping ,
613+ block_device_mapping_v2 = block_device_mapping_v2 ,
602614 nics = nics ,
603615 scheduler_hints = hints ,
604616 config_drive = config_drive )
0 commit comments