Azure-sdk-for-java: [FEATURE REQ] Create specialised ImageVersion from disk snapshots.

Created on 13 Jul 2020  路  9Comments  路  Source: Azure/azure-sdk-for-java

Is your feature request related to a problem? Please describe.
In the Azure portal, we already have the ability to generate a specialized image version using disk snapshots but I don't see that option while trying to define a SIG Image version through the Java SDK.

Describe the solution you'd like
We should be able to create a specialized image version from disk snapshots as we are able to via the Azure portal.

Describe alternatives you've considered
There are no alternatives if we need a specialized image version. Specialized image versions are very useful if you want to avoid generalizing a VM.

Additional context
This is the page I'm referring to. We need the create from disk snapshot option in the Java SDK.
Screenshot 2020-07-13 at 12 02 40 PM

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [x] Description Added
  • [x] Expected solution specified
Compute Compute - Images Mgmt customer-reported feature-request

Most helpful comment

@Shanky2304 To make it more clearly, are you looking for some interface like:

GalleryImage galleryImage = this.computeManager.galleryImages().define(galleryImageName)
                .withExistingGallery(javaGallery)
                .withLocation(REGION)
                .withIdentifier("JavaSDKTeam", "JDK", "Jdk-9")
                // get image source from existing snapshot
                .withSnapshot(snapshotId)
                .create();

All 9 comments

let's evaluate this in Track2 scope. cc @nickzhums

@Shanky2304 To make it more clearly, are you looking for some interface like:

GalleryImage galleryImage = this.computeManager.galleryImages().define(galleryImageName)
                .withExistingGallery(javaGallery)
                .withLocation(REGION)
                .withIdentifier("JavaSDKTeam", "JDK", "Jdk-9")
                // get image source from existing snapshot
                .withSnapshot(snapshotId)
                .create();

@Shanky2304 To make it more clearly, are you looking for some interface like:

GalleryImage galleryImage = this.computeManager.galleryImages().define(galleryImageName)
                .withExistingGallery(javaGallery)
                .withLocation(REGION)
                .withIdentifier("JavaSDKTeam", "JDK", "Jdk-9")
                // get image source from existing snapshot
                .withSnapshot(snapshotId)
                .create();

Yes exactly!

For more clarity, this is the API that we need to leverage via the SDK.
https://docs.microsoft.com/en-us/rest/api/compute/galleryimageversions/createorupdate#create-or-update-a-simple-gallery-image-version-using-snapshots-as-a-source.

@Shanky2304 You can create gallery image version via snapshot by below code with existing SDK.

GalleryImageVersionInner inner = new GalleryImageVersionInner();
inner.withStorageProfile(new GalleryImageVersionStorageProfile().withOsDiskImage(new GalleryOSDiskImage()));
inner.storageProfile().osDiskImage().withSource(new GalleryArtifactVersionSource().withId("snapshot-id"));
inner.withLocation(Region.{location}.toString());
computeManager.inner().galleryImageVersions().createOrUpdate("your-resource-group", "your-gallery", "your-gallery-image", "version", inner);

We will plan to support this feature request in our next-generation SDK.

@Shanky2304 You can create gallery image version via snapshot by below code with existing SDK.

GalleryImageVersionInner inner = new GalleryImageVersionInner();
inner.withStorageProfile(new GalleryImageVersionStorageProfile().withOsDiskImage(new GalleryOSDiskImage()));
inner.storageProfile().osDiskImage().withSource(new GalleryArtifactVersionSource().withId("snapshot-id"));
inner.withLocation(Region.{location}.toString());
computeManager.inner().galleryImageVersions().createOrUpdate("your-resource-group", "your-gallery", "your-gallery-image", "version", inner);

We will plan to support this feature request in our next-generation SDK.

@xccc-msft Thanks, let me try this out and get back. Are there any caveats of this workaround that I should be aware of?

@xccc-msft Hey thanks. I think the image version got created successfully. However, when I try to create a VM from this image version with the below code:

azure.virtualMachines().define("replicatedVM-sdk")
                .withRegion(region)
                .withExistingResourceGroup(rg)
                .withExistingPrimaryNetwork(network).withSubnet(subnetName)
                .withPrimaryPrivateIPAddressDynamic()
                .withoutPrimaryPublicIPAddress()
                .withWindowsGalleryImageVersion(galleryImageVersion.id())
                .withAdminUsername("azureadmin")
                .withAdminPassword("somepwd")
                .withSize(VirtualMachineSizeTypes.STANDARD_D2_V3)
                .create();

I see the below exception:

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:293)
    at java.lang.Thread.run (Thread.java:834)
Caused by: com.microsoft.azure.CloudException: Parameter 'osProfile' is not allowed.
    at com.microsoft.azure.AzureClient.createExceptionFromResponse (AzureClient.java:771)
    at com.microsoft.azure.AzureClient.access$100 (AzureClient.java:33)
    at com.microsoft.azure.AzureClient$3.call (AzureClient.java:160)
    at com.microsoft.azure.AzureClient$3.call (AzureClient.java:157)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext (OnSubscribeMap.java:69)
    at retrofit2.adapter.rxjava.CallArbiter.deliverResponse (CallArbiter.java:120)
    at retrofit2.adapter.rxjava.CallArbiter.emitResponse (CallArbiter.java:102)
    at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call (CallExecuteOnSubscribe.java:46)
    at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call (CallExecuteOnSubscribe.java:24)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:48)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:33)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeSingle.call (OnSubscribeSingle.java:81)
    at rx.internal.operators.OnSubscribeSingle.call (OnSubscribeSingle.java:27)
    at rx.internal.operators.SingleToObservable.call (SingleToObservable.java:39)
    at rx.internal.operators.SingleToObservable.call (SingleToObservable.java:27)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:48)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:33)
    at rx.internal.operators.OnSubscribeLift.call (OnSubscribeLift.java:48)
    at rx.internal.operators.OnSubscribeLift.call (OnSubscribeLift.java:30)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.DeferredScalarSubscriber.subscribeTo (DeferredScalarSubscriber.java:153)
    at rx.internal.operators.OnSubscribeTakeLastOne.call (OnSubscribeTakeLastOne.java:32)
    at rx.internal.operators.OnSubscribeTakeLastOne.call (OnSubscribeTakeLastOne.java:22)
    at rx.internal.operators.OnSubscribeLift.call (OnSubscribeLift.java:48)
    at rx.internal.operators.OnSubscribeLift.call (OnSubscribeLift.java:30)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:48)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:33)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:48)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:33)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:48)
    at rx.internal.operators.OnSubscribeMap.call (OnSubscribeMap.java:33)
    at rx.Observable.unsafeSubscribe (Observable.java:10327)
    at rx.internal.operators.OperatorSubscribeOn$SubscribeOnSubscriber.call (OperatorSubscribeOn.java:100)
    at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call (CachedThreadScheduler.java:230)
    at rx.internal.schedulers.ScheduledAction.run (ScheduledAction.java:55)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:304)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:834)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: retrofit2.Response.class
    at rx.exceptions.OnErrorThrowable.addValueAsLastCause (OnErrorThrowable.java:118)
    at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext (OnSubscribeMap.java:73)

Any clues?

@Shanky2304 It looks you are creating a vm by specialized image. Can you try withSpecializedWindowsGalleryImageVersion() instead of withWindowsGalleryImageVersion()?

@Shanky2304 It looks you are creating a vm by specialized image. Can you try withSpecializedWindowsGalleryImageVersion() instead of withWindowsGalleryImageVersion()?

Yes, it was exactly that.

Thanks again, I'll close this issue. The workaround looks good for now.

Was this page helpful?
0 / 5 - 0 ratings