public boolean createVolumes() throws TargetException {

		String zoneName = OpenstackIaasHandler.findZoneName( this.novaApi, this.targetProperties );
		for( String storageId : OpenstackIaasHandler.findStorageIds( this.targetProperties )) {

			// Prepare the parameters
			String name = OpenstackIaasHandler.findStorageProperty( this.targetProperties, storageId, VOLUME_NAME_PREFIX );
			name = OpenstackIaasHandler.expandVolumeName( name, this.applicationName, this.scopedInstance.getName());
			VolumeApi volumeApi = this.novaApi.getVolumeExtensionForZone( zoneName ).get();

			// If the volume should not volatile (i.e. not deleted on termination), we try to reuse it, if it exists.
			String deleteOnT = OpenstackIaasHandler.findStorageProperty( this.targetProperties, storageId, VOLUME_DELETE_OT_PREFIX );
			boolean deleteOnTermination = Boolean.parseBoolean( deleteOnT );
			String volumeId = null;
			if( ! deleteOnTermination ) {
				for( Volume vol : volumeApi.list()) {

					if( name.equals( vol.getName())) {
						this.logger.info( "Volume " + name + " (" + vol.getId() + ") already exists and is not volatile. It will be reused." );
						volumeId = vol.getId();
						break;
					}
				}
			}

			// Otherwise, create it.
			if( volumeId == null ) {

				String volumeType = OpenstackIaasHandler.findStorageProperty( this.targetProperties, storageId, VOLUME_TYPE_PREFIX );
				String volumeSize = OpenstackIaasHandler.findStorageProperty( this.targetProperties, storageId, VOLUME_SIZE_GB_PREFIX );
				int vsize = Integer.parseInt( volumeSize );

				CreateVolumeOptions options = CreateVolumeOptions.Builder.name( name );
				if( ! Utils.isEmptyOrWhitespaces( volumeType ))
					options = options.volumeType( volumeType );

				if( deleteOnTermination ) {
					Map<String,String> metadata = new HashMap<>( 1 );
					metadata.put( DELETE_ON_TERMINATION, "true" );
					options = options.metadata( metadata );
				}

				Volume volume = volumeApi.create( vsize, options );
				volumeId = volume.getId();
			}

			if( Utils.isEmptyOrWhitespaces( volumeId ))
				throw new TargetException( "Volume " + name + " was not found and could not be created." );

			this.logger.info( "Volume " + volumeId + " was successfully created." );
			this.storageIdToVolumeId.put( storageId, volumeId );
		}

		return true;
	}
public boolean createVolumes ( ) throws TargetException { String zoneName = OpenstackIaasHandler . findZoneName ( this . novaApi , this . targetProperties ) ; for ( String storageId : OpenstackIaasHandler . findStorageIds ( this . targetProperties ) ) { String name = OpenstackIaasHandler . findStorageProperty ( this . targetProperties , storageId , VOLUME_NAME_PREFIX ) ; name = OpenstackIaasHandler . expandVolumeName ( name , this . applicationName , this . scopedInstance . getName ( ) ) ; VolumeApi volumeApi = this . novaApi . getVolumeExtensionForZone ( zoneName ) . get ( ) ; String deleteOnT = OpenstackIaasHandler . findStorageProperty ( this . targetProperties , storageId , VOLUME_DELETE_OT_PREFIX ) ; boolean deleteOnTermination = Boolean . parseBoolean ( deleteOnT ) ; String volumeId = null ; if ( ! deleteOnTermination ) { for ( Volume vol : volumeApi . list ( ) ) { if ( name . equals ( vol . getName ( ) ) ) { this . logger . info ( "Volume " + name + " (" + vol . getId ( ) + ") already exists and is not volatile. It will be reused." ) ; volumeId = vol . getId ( ) ; break ; } } } if ( volumeId == null ) { String volumeType = OpenstackIaasHandler . findStorageProperty ( this . targetProperties , storageId , VOLUME_TYPE_PREFIX ) ; String volumeSize = OpenstackIaasHandler . findStorageProperty ( this . targetProperties , storageId , VOLUME_SIZE_GB_PREFIX ) ; int vsize = Integer . parseInt ( volumeSize ) ; CreateVolumeOptions options = CreateVolumeOptions . Builder . name ( name ) ; if ( ! Utils . isEmptyOrWhitespaces ( volumeType ) ) options = options . volumeType ( volumeType ) ; if ( deleteOnTermination ) { Map < String , String > metadata = new HashMap < > ( 1 ) ; metadata . put ( DELETE_ON_TERMINATION , "true" ) ; options = options . metadata ( metadata ) ; } Volume volume = volumeApi . create ( vsize , options ) ; volumeId = volume . getId ( ) ; } if ( Utils . isEmptyOrWhitespaces ( volumeId ) ) throw new TargetException ( "Volume " + name + " was not found and could not be created." ) ; this . logger . info ( "Volume " + volumeId + " was successfully created." ) ; this . storageIdToVolumeId . put ( storageId , volumeId ) ; } return true ; }
Creates block storage volumes in Openstack infrastructure.
<p>
Volume creation goes in a single row. For a given VM, we should enter this method
only once.
</p>

@throws TargetException