1111import com .google .common .base .Optional ;
1212import com .google .common .collect .ImmutableList ;
1313import com .google .common .collect .ImmutableSet ;
14+ import com .google .common .net .UrlEscapers ;
1415import org .apache .brooklyn .location .jclouds .JcloudsLocation ;
1516import org .apache .brooklyn .location .jclouds .JcloudsMachineLocation ;
17+ import org .apache .brooklyn .util .exceptions .Exceptions ;
1618import org .apache .brooklyn .util .repeat .Repeater ;
1719import org .apache .brooklyn .util .text .Identifiers ;
1820import org .apache .brooklyn .util .text .StringShortener ;
1921import org .apache .brooklyn .util .text .Strings ;
2022import org .apache .brooklyn .util .time .Duration ;
2123import org .jclouds .azurecompute .arm .AzureComputeApi ;
2224import org .jclouds .azurecompute .arm .domain .DataDisk ;
25+ import org .jclouds .azurecompute .arm .domain .Deployment ;
2326import org .jclouds .azurecompute .arm .domain .Disk ;
2427import org .jclouds .azurecompute .arm .domain .ManagedDiskParameters ;
2528import org .jclouds .azurecompute .arm .domain .ResourceGroup ;
2831import org .jclouds .azurecompute .arm .domain .VirtualMachine ;
2932import org .jclouds .azurecompute .arm .domain .VirtualMachineProperties ;
3033import org .jclouds .azurecompute .arm .features .DiskApi ;
34+ import org .jclouds .azurecompute .arm .features .DeploymentApi ;
3135import org .jclouds .azurecompute .arm .features .ResourceGroupApi ;
3236import org .jclouds .azurecompute .arm .features .StorageAccountApi ;
3337import org .jclouds .azurecompute .arm .features .VirtualMachineApi ;
3438import org .slf4j .Logger ;
3539import org .slf4j .LoggerFactory ;
3640
41+ import java .io .IOException ;
42+ import java .nio .file .Files ;
43+ import java .nio .file .Paths ;
3744import java .util .List ;
3845import java .util .concurrent .Callable ;
3946import java .util .concurrent .TimeUnit ;
@@ -154,9 +161,11 @@ private AttachedBlockDevice createAndAttachBlockDevice(JcloudsMachineLocation ma
154161 }
155162
156163 int numExistingDisks = coundDataDisks (vm );
157- int lun = numExistingDisks ; // starts from 0, so if have one disk already then next will be "1"
164+ int lun = numExistingDisks ; // starts from 0, so if have one disk already then next will be "1"
158165
159- Disk disk = addDisk (vmApi , diskApi , vm , options .getSizeInGb (), lun );
166+ DeploymentApi deploymentApi = api .getDeploymentApi (resourceGroupName .get ());
167+
168+ Disk disk = addDisk (vmApi , diskApi , vm , options .getSizeInGb (), lun , deploymentApi );
160169
161170 BlockDevice blockDevice = new AzureArmBlockDevice (location , disk , resourceGroupName .get (), storageAccountName );
162171 return blockDevice .attachedTo (machine , getVolumeDeviceName (options .getDeviceSuffix ()));
@@ -190,7 +199,7 @@ private void deleteStorageAccount(AzureComputeApi api, String resourceGroupName,
190199 }
191200 }
192201
193- private Disk addDisk (VirtualMachineApi vmApi , DiskApi diskApi , VirtualMachine vm , int diskSizeGB , int lun ) {
202+ private Disk addDisk (VirtualMachineApi vmApi , DiskApi diskApi , VirtualMachine vm , int diskSizeGB , int lun , DeploymentApi deploymentApi ) {
194203 String vmName = vm .name ();
195204 VirtualMachineProperties oldProperties = vm .properties ();
196205 StorageProfile oldStorageProfile = oldProperties .storageProfile ();
@@ -211,7 +220,19 @@ private Disk addDisk(VirtualMachineApi vmApi, DiskApi diskApi, VirtualMachine vm
211220 VirtualMachine newVm = vm .toBuilder ().properties (newProperties ).build ();
212221
213222 vmApi .createOrUpdate (vmName , newVm .location (), newVm .properties (), newVm .tags (), newVm .plan ());
214- return waitDiskToAppear (diskApi , diskName , TIMEOUT );
223+ Disk result = waitDiskToAppear (diskApi , diskName , TIMEOUT );
224+
225+ if (vm .location ().contains ("Win" )) { //TODO make better check
226+ String deploymentName = "jc" + System .currentTimeMillis ();
227+ try {
228+ String deploymentTemplate = UrlEscapers .urlFormParameterEscaper ().escape (new String (Files .readAllBytes (Paths .get ("customscriptextension.json" ))));
229+ Deployment deployment = deploymentApi .create (deploymentName , deploymentTemplate );
230+ } catch (IOException e ) {
231+ Exceptions .propagate ("Failed to read customscriptextension.json" , e );
232+ }
233+ }
234+
235+ return result ;
215236 }
216237
217238 private String getRegionName (JcloudsLocation location ) {
0 commit comments