-1

When I am scaling up a scaleset I want to specify the image version to use. Right now it always uses the latest image from the compute gallery. I think that is what this az CLI command does: az vmss update -- resource-group myResourceGroup --name myScaleSet --set virtualMachineProfile.storageProfile.imageReference.version=0.235.102011129

Now I want to do the same in Java with the Azure Resource Manager SDK. ChatGPT gave this suggestion

// Resource group and scale set names
final String resourceGroupName = "myResourceGroup";
final String scaleSetName = "myScaleSet";

// Retrieve the scale set
VirtualMachineScaleSet scaleSet = azureResourceManager.virtualMachineScaleSets()
      .getByResourceGroup(resourceGroupName, scaleSetName);

// Update the image reference version
VirtualMachineScaleSetUpdate updateParams = scaleSet.update()
      .withVirtualMachineProfileStorageProfile(new VirtualMachineScaleSetUpdateStorageProfile()
              .withImageReference(new ImageReference()
              .withVersion("0.235.102011129")))
      .apply();

But the problem is that withVirtualMachineProfileStorageProfile does not exist for scaleSet.update().

Does anyone know how to do this?

1 Answer 1

0

Refer this MS Document which calls Azure Resource manager API with JAVA and updates Image with specific version by accessing StorageProfile of the VMSS:-

Code Reference from MS Document:-

VirtualMachineScaleSetUpdateStorageProfile()
                            .withImageReference(new ImageReference()
                                .withId("hhhhhhhhh").withPublisher("MicrosoftWindowsServer")
                                .withOffer("WindowsServer").withSku("2016-Datacenter").withVersion("latest")
                                .withSharedGalleryImageId("aaaaaa"))
                            .withOsDisk(new VirtualMachineScaleSetUpdateOSDisk().withCaching(CachingTypes.READ_WRITE)
                                .withWriteAcceleratorEnabled(true).withDiskSizeGB(6)
                                .withImage(new VirtualHardDisk().withUri(
                                    "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"))

sample.java:-

import com.azure.resourcemanager.compute.models.*;

public final class Main {
    public static void main(String[] args) {
        VirtualMachineScaleSetUpdateStorageProfile storageProfile = new VirtualMachineScaleSetUpdateStorageProfile()
            .withImageReference(new ImageReference()
                .withId("aaaaaaaaaaaaaaaaaaa")
                .withPublisher("MicrosoftWindowsServer")
                .withOffer("WindowsServer")
                .withSku("2016-Datacenter")
                .withVersion("latest")
                .withSharedGalleryImageId("hshshs"))
            .withOsDisk(new VirtualMachineScaleSetUpdateOSDisk()
                .withCaching(CachingTypes.READ_WRITE)
                .withWriteAcceleratorEnabled(true)
                .withDiskSizeGB(6)
                .withImage(new VirtualHardDisk()
                    .withUri("http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd")));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.