#NEWLINE# def clean( self ) : #NEWLINE# #INDENT# cleaned_data = super ( SetInstanceDetailsAction , self ) . clean ( ) #NEWLINE# count = cleaned_data . get ( 'count' , 1 ) #NEWLINE# usages = quotas . tenant_quota_usages ( self . request ) #NEWLINE# available_count = usages [ 'instances' ] [ 'available' ] #NEWLINE# if ( available_count < count ) : #NEWLINE# #INDENT# error_message = ungettext_lazy ( 'The requested instance cannot be launched as you only have %(avail)i of your quota available. ' , 'The requested %(req)i instances cannot be launched as you only have %(avail)i of your quota available.' , count ) #NEWLINE# params = { #NEWLINE# #INDENT# 'req' : count , #NEWLINE# 'avail' : available_count , #NEWLINE# #UNINDENT# } #NEWLINE# raise forms . ValidationError ( ( error_message % params ) ) #NEWLINE# #UNINDENT# source_type = self . data . get ( 'source_type' , None ) #NEWLINE# if ( source_type == 'image_id' ) : #NEWLINE# #INDENT# if ( not cleaned_data . get ( 'image_id' ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must select an image.' ) #NEWLINE# self . _errors [ 'image_id' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( source_type == 'instance_snapshot_id' ) : #NEWLINE# #INDENT# if ( not cleaned_data [ 'instance_snapshot_id' ] ) : #NEWLINE# #INDENT# msg = _ ( 'You must select a snapshot.' ) #NEWLINE# self . _errors [ 'instance_snapshot_id' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( source_type == 'volume_id' ) : #NEWLINE# #INDENT# if ( not cleaned_data . get ( 'volume_id' ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must select a volume.' ) #NEWLINE# self . _errors [ 'volume_id' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# if ( count > 1 ) : #NEWLINE# #INDENT# msg = _ ( 'Launching multiple instances is only supported for images and instance snapshots.' ) #NEWLINE# raise forms . ValidationError ( msg ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( source_type == 'volume_image_id' ) : #NEWLINE# #INDENT# if ( not cleaned_data [ 'image_id' ] ) : #NEWLINE# #INDENT# msg = _ ( 'You must select an image.' ) #NEWLINE# self . _errors [ 'image_id' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# if ( not self . data . get ( 'volume_size' , None ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must set volume size' ) #NEWLINE# self . _errors [ 'volume_size' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# if ( not cleaned_data . get ( 'device_name' ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must set device name' ) #NEWLINE# self . _errors [ 'device_name' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( source_type == 'volume_snapshot_id' ) : #NEWLINE# #INDENT# if ( not cleaned_data . get ( 'volume_snapshot_id' ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must select a snapshot.' ) #NEWLINE# self . _errors [ 'volume_snapshot_id' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# if ( not cleaned_data . get ( 'device_name' ) ) : #NEWLINE# #INDENT# msg = _ ( 'You must set device name' ) #NEWLINE# self . _errors [ 'device_name' ] = self . error_class ( [ msg ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return cleaned_data