Skip to content

Commit

Permalink
mgmt, compute support withplan for VMSS (Azure#25323)
Browse files Browse the repository at this point in the history
* Code change to support withplan for compute virtual machine scale set

* Add test to create VMSS with plan

* Add session records

* Update CHANGELOG

* Update test to use withNewDataDisk() instead of withUnmanagedDisks()

* Remove withNewStorageAccount() in test

* update javadoc

* Update session-records due to network upgrade
  • Loading branch information
haolingdong-msft authored and XiaofeiCao committed Nov 18, 2021
1 parent 8cde504 commit 15188df
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Supported `withPlan()` for `VirtualMachineScaleSet` during create.

## 2.9.0 (2021-10-21)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import com.azure.core.management.SubResource;
import com.azure.core.management.provider.IdentifierProvider;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.authorization.utils.RoleAssignmentHelper;
import com.azure.resourcemanager.compute.ComputeManager;
import com.azure.resourcemanager.compute.fluent.models.ProximityPlacementGroupInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetExtensionInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.compute.models.AdditionalCapabilities;
import com.azure.resourcemanager.compute.models.ApiEntityReference;
import com.azure.resourcemanager.compute.models.BillingProfile;
Expand All @@ -21,8 +27,10 @@
import com.azure.resourcemanager.compute.models.KnownWindowsVirtualMachineImage;
import com.azure.resourcemanager.compute.models.LinuxConfiguration;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.Plan;
import com.azure.resourcemanager.compute.models.ProximityPlacementGroup;
import com.azure.resourcemanager.compute.models.ProximityPlacementGroupType;
import com.azure.resourcemanager.compute.models.PurchasePlan;
import com.azure.resourcemanager.compute.models.ResourceIdentityType;
import com.azure.resourcemanager.compute.models.RunCommandInput;
import com.azure.resourcemanager.compute.models.RunCommandInputParameter;
Expand Down Expand Up @@ -57,13 +65,8 @@
import com.azure.resourcemanager.compute.models.WinRMConfiguration;
import com.azure.resourcemanager.compute.models.WinRMListener;
import com.azure.resourcemanager.compute.models.WindowsConfiguration;
import com.azure.resourcemanager.compute.fluent.models.ProximityPlacementGroupInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetExtensionInner;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.authorization.utils.RoleAssignmentHelper;
import com.azure.resourcemanager.msi.models.Identity;
import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.network.models.ApplicationSecurityGroup;
import com.azure.resourcemanager.network.models.LoadBalancer;
import com.azure.resourcemanager.network.models.LoadBalancerBackend;
Expand All @@ -72,15 +75,15 @@
import com.azure.resourcemanager.network.models.Network;
import com.azure.resourcemanager.network.models.NetworkSecurityGroup;
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNetworkInterface;
import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.resources.fluentcore.arm.AvailabilityZoneId;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
import com.azure.resourcemanager.storage.models.StorageAccount;
import com.azure.resourcemanager.storage.StorageManager;
import com.azure.resourcemanager.storage.models.StorageAccount;
import reactor.core.Exceptions;
import reactor.core.publisher.Mono;

Expand All @@ -96,7 +99,6 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import com.azure.resourcemanager.resources.fluentcore.utils.PagedConverter;

/** Implementation of VirtualMachineScaleSet. */
public class VirtualMachineScaleSetImpl
Expand Down Expand Up @@ -610,6 +612,11 @@ public AdditionalCapabilities additionalCapabilities() {
return this.innerModel().additionalCapabilities();
}

@Override
public Plan plan() {
return this.innerModel().plan();
}

@Override
public VirtualMachineScaleSetNetworkInterface getNetworkInterfaceByInstanceId(String instanceId, String name) {
return this
Expand Down Expand Up @@ -2777,7 +2784,16 @@ private void createNewProximityPlacementGroup() {
}
}

/** Class to manage Data Disk collection. */
@Override
public VirtualMachineScaleSetImpl withPlan(PurchasePlan plan) {
this.innerModel().withPlan(new Plan());
this.innerModel().plan().withPublisher(plan.publisher()).withProduct(plan.product()).withName(plan.name());
return this;
}

/**
* Class to manage Data Disk collection.
*/
private class ManagedDataDiskCollection {
private final List<VirtualMachineScaleSetDataDisk> implicitDisksToAssociate = new ArrayList<>();
private final List<Integer> diskLunsToRemove = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import com.azure.core.annotation.Fluent;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.compute.ComputeManager;
import com.azure.resourcemanager.compute.fluent.models.VirtualMachineScaleSetInner;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.msi.models.Identity;
import com.azure.resourcemanager.network.models.ApplicationSecurityGroup;
import com.azure.resourcemanager.network.models.LoadBalancer;
Expand Down Expand Up @@ -382,6 +382,11 @@ PagedFlux<VirtualMachineScaleSetNetworkInterface> listNetworkInterfacesByInstanc
*/
AdditionalCapabilities additionalCapabilities();

/**
* @return the purchase plan information about marketplace image
*/
Plan plan();

/**
* The virtual machine scale set stages shared between managed and unmanaged based virtual machine scale set
* definitions.
Expand Down Expand Up @@ -1703,6 +1708,19 @@ interface WithApplicationSecurityGroup {
WithCreate withExistingApplicationSecurityGroupId(String applicationSecurityGroupId);
}

/**
* The stage of the virtual machine scale set definition allowing to configure a purchase plan.
*/
interface WithPlan {
/**
* Specifies the purchase plan for the virtual machine scale set.
*
* @param plan a purchase plan
* @return the next stage of the definition
*/
WithCreate withPlan(PurchasePlan plan);
}

/**
* The stage of a virtual machine scale set definition containing all the required inputs for the resource to be
* created, but also allowing for any other optional settings to be specified.
Expand Down Expand Up @@ -1730,6 +1748,7 @@ interface WithCreate
DefinitionStages.WithApplicationGateway,
DefinitionStages.WithApplicationSecurityGroup,
DefinitionStages.WithSecrets,
DefinitionStages.WithPlan,
Resource.DefinitionWithTags<VirtualMachineScaleSet.DefinitionStages.WithCreate> {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.authorization.models.BuiltInRole;
import com.azure.resourcemanager.authorization.models.RoleAssignment;
import com.azure.resourcemanager.compute.models.ImageReference;
import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage;
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.PowerState;
import com.azure.resourcemanager.compute.models.PurchasePlan;
import com.azure.resourcemanager.compute.models.ResourceIdentityType;
import com.azure.resourcemanager.compute.models.Sku;
import com.azure.resourcemanager.compute.models.UpgradeMode;
Expand Down Expand Up @@ -57,7 +59,6 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;


import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
Expand All @@ -84,6 +85,60 @@ protected void cleanUpResources() {
}
}

@Test
public void canCreateVMSSWithPlan() {
final String vmssName = generateRandomResourceName("vmss", 10);
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName).withRegion(region).create();
final String uname = "jvuser";

Network network =
this
.networkManager
.networks()
.define(generateRandomResourceName("vmssvnet", 15))
.withRegion(region)
.withExistingResourceGroup(resourceGroup)
.withAddressSpace("10.0.0.0/28")
.withSubnet("subnet1", "10.0.0.0/28")
.create();

PurchasePlan plan = new PurchasePlan()
.withName("access_server_byol")
.withPublisher("openvpn")
.withProduct("openvpnas");

ImageReference imageReference = new ImageReference()
.withPublisher("openvpn")
.withOffer("openvpnas")
.withSku("access_server_byol")
.withVersion("latest");

VirtualMachineScaleSet virtualMachineScaleSet =
this
.computeManager
.virtualMachineScaleSets()
.define(vmssName)
.withRegion(region)
.withExistingResourceGroup(resourceGroup)
.withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0)
.withExistingPrimaryNetworkSubnet(network, "subnet1")
.withoutPrimaryInternetFacingLoadBalancer()
.withoutPrimaryInternalLoadBalancer()
.withSpecificLinuxImageVersion(imageReference)
.withRootUsername(uname)
.withSsh(sshPublicKey())
.withNewDataDisk(1)
.withPlan(plan)
.create();

VirtualMachineScaleSet currentVirtualMachineScaleSet = this.computeManager.virtualMachineScaleSets().getByResourceGroup(rgName, vmssName);
// assertion for purchase plan
Assertions.assertEquals("access_server_byol", currentVirtualMachineScaleSet.plan().name());
Assertions.assertEquals("openvpn", currentVirtualMachineScaleSet.plan().publisher());
Assertions.assertEquals("openvpnas", currentVirtualMachineScaleSet.plan().product());

}

@Test
public void canUpdateVirtualMachineScaleSetWithExtensionProtectedSettings() throws Exception {
final String vmssName = generateRandomResourceName("vmss", 10);
Expand Down
Loading

0 comments on commit 15188df

Please sign in to comment.