diff --git a/azure-mgmt-compute/pom.xml b/azure-mgmt-compute/pom.xml index fa4ae4c6e5e41..634fa7bf996ab 100644 --- a/azure-mgmt-compute/pom.xml +++ b/azure-mgmt-compute/pom.xml @@ -82,6 +82,12 @@ api-annotations 0.0.1-SNAPSHOT + + com.jcraft + jsch + 0.1.53 + test + diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java new file mode 100644 index 0000000000000..28558f7375ffd --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -0,0 +1,1042 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetInner; +import com.microsoft.azure.management.network.Backend; +import com.microsoft.azure.management.network.InboundNatPool; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.resources.fluentcore.arm.models.GroupableResource; +import com.microsoft.azure.management.resources.fluentcore.arm.models.Resource; +import com.microsoft.azure.management.resources.fluentcore.model.Appliable; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.model.Refreshable; +import com.microsoft.azure.management.resources.fluentcore.model.Updatable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; +import com.microsoft.azure.management.storage.StorageAccount; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * An immutable client-side representation of an Azure virtual machine scale set. + */ +@LangDefinition() +public interface VirtualMachineScaleSet extends + GroupableResource, + Refreshable, + Wrapper, + Updatable { + // Actions + // + /** + * @return available skus for the virtual machine scale set including the minimum and maximum vm instances + * allowed for a particular sku + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + */ + PagedList availableSkus() throws CloudException, IOException; + + /** + * Shuts down the Virtual Machine in the scale set and releases the compute resources. + *

+ * You are not billed for the compute resources that the Virtual Machines uses. + * + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void deallocate() throws CloudException, IOException, InterruptedException; + + /** + * Power off (stop) the virtual machines in the scale set. + *

+ * You will be billed for the compute resources that the Virtual Machines uses + * + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void powerOff() throws CloudException, IOException, InterruptedException; + + /** + * Restart the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void restart() throws CloudException, IOException, InterruptedException; + + /** + * Start the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void start() throws CloudException, IOException, InterruptedException; + + /** + * Re-image (update the version of the installed operating system) the virtual machines in the scale set. + * + * @throws CloudException thrown for an invalid response from the service + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void reimage() throws CloudException, IOException, InterruptedException; + + // Getters + // + + /** + * @return the name prefix of the virtual machines in the scale set + */ + String computerNamePrefix(); + + /** + * @return the operating system of the virtual machines in the scale set + */ + OperatingSystemTypes osType(); + + /** + * @return the operating system disk caching type, valid values are 'None', 'ReadOnly', 'ReadWrite' + */ + CachingTypes osDiskCachingType(); + + /** + * @return gets the name of the OS disk of virtual machines in the scale set + */ + String osDiskName(); + + /** + * @return the upgradeModel + */ + UpgradeMode upgradeModel(); + + /** + * @return true if over provision is enabled for the virtual machines, false otherwise + */ + boolean overProvisionEnabled(); + + /** + * @return the sku of the virtual machines in the scale set + */ + VirtualMachineScaleSetSkuTypes sku(); + + /** + * @return the number of virtual machine instances in the scale set + */ + int capacity(); + + /** + * @return the virtual network associated with the primary network interfaces of the virtual machines + * in the scale set. + *

+ * A primary internal load balancer associated with the primary network interfaces of the scale set + * virtual machine will be also belongs to this network + *

+ * @throws IOException the IO exception + */ + Network primaryNetwork() throws IOException; + + /** + * @return the internet facing load balancer associated with the primary network interface of + * the virtual machines in the scale set. + * + * @throws IOException the IO exception + */ + LoadBalancer primaryInternetFacingLoadBalancer() throws IOException; + + /** + * @return the internet facing load balancer's backends associated with the primary network interface + * of the virtual machines in the scale set + * + * @throws IOException the IO exception + */ + Map primaryInternetFacingLoadBalancerBackEnds() throws IOException; + + /** + * @return the internet facing load balancer's inbound NAT pool associated with the primary network interface + * of the virtual machines in the scale set + * + * @throws IOException the IO exception + */ + Map primaryInternetFacingLoadBalancerInboundNatPools() throws IOException; + + /** + * @return the internal load balancer associated with the primary network interface of + * the virtual machines in the scale set + * + * @throws IOException the IO exception + */ + LoadBalancer primaryInternalLoadBalancer() throws IOException; + + /** + * @return the internal load balancer's backends associated with the primary network interface + * of the virtual machines in the scale set + * + * @throws IOException the IO exception + */ + Map primaryInternalLoadBalancerBackEnds() throws IOException; + + /** + * @return the internal load balancer's inbound NAT pool associated with the primary network interface + * of the virtual machines in the scale set + * + * @throws IOException the IO exception + */ + Map primaryInternalLoadBalancerInboundNatPools() throws IOException; + + /** + * @return the list of ids of public Ip addresses associated with the primary internet facing load balancer + * of the scale set + * @throws IOException the IO exception + */ + List primaryPublicIpAddressIds() throws IOException; + + /** + * @return the url to storage containers that stores vhds of virtual machines in the scale set + */ + List vhdContainers(); + + /** + * @return the storage profile + */ + VirtualMachineScaleSetStorageProfile storageProfile(); + + /** + * @return the network profile + */ + VirtualMachineScaleSetNetworkProfile networkProfile(); + + /** + * @return the extensions attached to the Virtual Machines in the scale set + */ + Map extensions(); + + /** + * The entirety of the load balancer definition. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Definition", ContainerFileName = "IDefinition") + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithSku, + DefinitionStages.WithNetworkSubnet, + DefinitionStages.WithPrimaryInternetFacingLoadBalancer, + DefinitionStages.WithPrimaryInternalLoadBalancer, + DefinitionStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, + DefinitionStages.WithInternalLoadBalancerBackendOrNatPool, + DefinitionStages.WithPrimaryInternetFacingLoadBalancerNatPool, + DefinitionStages.WithInternalInternalLoadBalancerNatPool, + DefinitionStages.WithOS, + DefinitionStages.WithAdminUserName, + DefinitionStages.WithRootUserName, + DefinitionStages.WithLinuxCreate, + DefinitionStages.WithWindowsCreate, + DefinitionStages.WithCreate { + } + + /** + * Grouping of virtual machine scale set definition stages. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Definition", ContainerFileName = "IDefinition", IsContainerOnly = true) + interface DefinitionStages { + /** + * The first stage of a virtual machine scale set definition. + */ + interface Blank + extends GroupableResource.DefinitionWithRegion { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify the resource group. + */ + interface WithGroup + extends GroupableResource.DefinitionStages.WithGroup { + } + + /** + * The stage of the virtual machine scale set definition allowing to specify Sku for the virtual machines. + */ + interface WithSku { + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param skuType the sku type + * @return the stage representing creatable VM scale set definition + */ + WithNetworkSubnet withSku(VirtualMachineScaleSetSkuTypes skuType); + + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param sku a sku from the list of available sizes for the virtual machines in this scale set + * @return the stage representing creatable VM scale set definition + */ + WithNetworkSubnet withSku(VirtualMachineScaleSetSku sku); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify virtual network subnet for the + * primary network configuration. + */ + interface WithNetworkSubnet { + /** + * Associate an existing virtual network subnet with the primary network interface of the virtual machines + * in the scale set. + * + * @param network an existing virtual network + * @param subnetName the subnet name + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancer withExistingPrimaryNetworkSubnet(Network network, String subnetName); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify a public load balancer for + * the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancer { + /** + * Specify the public load balancer where it's backends and/or NAT pools can be assigned to the primary network + * interface of the scale set virtual machines. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternetFacingLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer an existing public load balancer + * @return the next stage of the definition + */ + WithPrimaryInternetFacingLoadBalancerBackendOrNatPool withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer); + + /** + * Specifies that no public load balancer needs to be associated with virtual machine scale set. + * + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternalLoadBalancer withoutPrimaryInternetFacingLoadBalancer(); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify an internal load balancer for + * the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancer { + /** + * Specify the internal load balancer where it's backends and/or NAT pools can be assigned to the primary network + * interface of the scale set virtual machines. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithInternalLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer an existing internal load balancer + * @return the next stage of the definition + */ + WithInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); + + /** + * Specifies that no internal load balancer needs to be associated with primary network interface of the + * virtual machines in the scale set. + * + * @return the next stage of the virtual machine scale set definition + */ + WithOS withoutPrimaryInternalLoadBalancer(); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool + * of the internet facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} + * with the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { + /** + * Associate internet facing load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate inbound NAT pool of the internet + * facing load balancer selected in the previous state {@link WithPrimaryInternetFacingLoadBalancer} with the + * primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { + /** + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate backend pool and/or inbound NAT pool + * of the internal load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the + * primary network interface of the scale set virtual machines. + */ + interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { + /** + * Associate internal load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set definition + */ + WithInternalInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to associate inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the primary network + * interface of the scale set virtual machines. + */ + interface WithInternalInternalLoadBalancerNatPool extends WithOS { + /** + * Associate internal load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machine. + * + * + * @param natPoolNames inbound NAT pool names + * @return the next stage of the virtual machine scale set definition + */ + WithOS withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify the Operation System image. + */ + interface WithOS { + /** + * Specifies the known marketplace Windows image used as OS for virtual machines in the scale set. + * + * @param knownImage enum value indicating known market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage); + + /** + * Specifies that the latest version of a marketplace Windows image needs to be used. + * + * @param publisher specifies the publisher of the image + * @param offer specifies the offer of the image + * @param sku specifies the SKU of the image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withLatestWindowsImage(String publisher, String offer, String sku); + + /** + * Specifies the version of a marketplace Windows image needs to be used. + * + * @param imageReference describes publisher, offer, sku and version of the market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withSpecificWindowsImageVersion(ImageReference imageReference); + + /** + * Specifies the user (custom) Windows image used for as the OS for virtual machines in the + * scale set. + *

+ * Custom images are currently limited to single storage account and the number of virtual machines + * in the scale set that can be created using custom image is limited to 40 when over provision + * is disabled {@link WithOverProvision} and up to 20 when enabled. + *

+ * @param imageUrl the url the the VHD + * @return the next stage of the virtual machine scale set definition + */ + WithAdminUserName withStoredWindowsImage(String imageUrl); + + /** + * Specifies the known marketplace Linux image used for the virtual machine's OS. + * + * @param knownImage enum value indicating known market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage); + + /** + * Specifies that the latest version of a marketplace Linux image needs to be used. + * + * @param publisher specifies the publisher of the image + * @param offer specifies the offer of the image + * @param sku specifies the SKU of the image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withLatestLinuxImage(String publisher, String offer, String sku); + + /** + * Specifies the version of a market-place Linux image needs to be used. + * + * @param imageReference describes publisher, offer, sku and version of the market-place image + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withSpecificLinuxImageVersion(ImageReference imageReference); + + /** + * Specifies the user (custom) Linux image used for the virtual machine's OS. + *

+ * Custom images are currently limited to single storage account and the number of virtual machines + * in the scale set that can be created using custom image is limited to 40 when over provision + * is disabled {@link WithOverProvision} and up to 20 when enabled. + *

+ * @param imageUrl the url the the VHD + * @return the next stage of the virtual machine scale set definition + */ + WithRootUserName withStoredLinuxImage(String imageUrl); + } + + /** + * The stage of the Linux virtual machine scale set definition allowing to specify root user name. + */ + interface WithRootUserName { + /** + * Specifies the root user name for the Linux virtual machines in the scale set. + * + * @param rootUserName the Linux root user name. This must follow the required naming convention for Linux user name + * @return the next stage of the Linux virtual machine scale set definition + */ + WithLinuxCreate withRootUserName(String rootUserName); + } + + /** + * The stage of the Windows virtual machine scale set definition allowing to specify administrator user name. + */ + interface WithAdminUserName { + /** + * Specifies the administrator user name for the Windows virtual machines in the scale set. + * + * @param adminUserName the Windows administrator user name. This must follow the required naming convention for Windows user name + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withAdminUserName(String adminUserName); + } + + /** + * The stage of the Linux virtual machine scale set definition which contains all the minimum required inputs + * for the resource to be created (via {@link WithCreate#create()}), but also allows for any other optional + * settings to be specified. + * + */ + interface WithLinuxCreate extends WithCreate { + /** + * Specifies the SSH public key. + *

+ * Each call to this method adds the given public key to the list of VM's public keys. + * + * @param publicKey the SSH public key in PEM format. + * @return the stage representing creatable Linux VM scale set definition + */ + WithLinuxCreate withSsh(String publicKey); + } + + /** + * The stage of the Windows virtual machine scale set definition which contains all the minimum required + * inputs for the resource to be created (via {@link WithCreate#create()}, but also allows for any other + * optional settings to be specified. + * + */ + interface WithWindowsCreate extends WithCreate { + /** + * Specifies that VM Agent should be provisioned. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withVmAgent(); + + /** + * Specifies that VM Agent should not be provisioned. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withoutVmAgent(); + + /** + * Specifies that automatic updates should be enabled. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withAutoUpdate(); + + /** + * Specifies that automatic updates should be disabled. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withoutAutoUpdate(); + + /** + * Specifies the time-zone. + * + * @param timeZone the timezone + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withTimeZone(String timeZone); + + /** + * Specifies the WINRM listener. + *

+ * Each call to this method adds the given listener to the list of VM's WinRM listeners. + * + * @param listener the WinRmListener + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate withWinRm(WinRMListener listener); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify password. + */ + interface WithPassword { + /** + * Specifies the password for the virtual machines in the scale set. + * + * @param password the password, this must follow the criteria for Azure VM password + * @return the stage representing creatable VM scale set definition + */ + WithCreate withPassword(String password); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify the computer name prefix. + */ + interface WithComputerNamePrefix { + /** + * Specifies the bane prefix for the virtual machines in the scale set. + * + * @param namePrefix the prefix for the name of virtual machines in the scale set + * @return the stage representing creatable VM scale set definition + */ + WithCreate withComputerNamePrefix(String namePrefix); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify number of + * virtual machines in the scale set. + */ + interface WithCapacity { + /** + * Specifies the number of virtual machines in the scale set. + * + * @param capacity the virtual machine capacity + * @return the stage representing creatable VM scale set definition + */ + WithCreate withCapacity(int capacity); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify upgrade policy. + */ + interface WithUpgradePolicy { + /** + * Specifies virtual machine scale set upgrade policy mode. + * + * @param upgradeMode upgrade policy mode + * @return the stage representing creatable VM scale set definition + */ + WithCreate withUpgradeMode(UpgradeMode upgradeMode); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify whether + * or not over provision virtual machines in the scale set. + */ + interface WithOverProvision { + /** + * Enable or disable over provisioning of virtual machines in the scale set. + * + * @param enabled true to enable over provisioning of virtual machines in the + * scale set + * @return Enable over provision of virtual machines + */ + WithCreate withOverProvision(boolean enabled); + + /** + * Enable over provision of virtual machines. + * + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOverProvisionEnabled(); + + /** + * Disable over provision of virtual machines. + * + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOverProvisionDisabled(); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify OS disk configurations. + */ + interface WithOsDiskSettings { + /** + * Specifies the caching type for the Operating System disk. + * + * @param cachingType the caching type + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOsDiskCaching(CachingTypes cachingType); + + /** + * Specifies the name for the OS Disk. + * + * @param name the OS Disk name + * @return the stage representing creatable VM scale set definition + */ + WithCreate withOsDiskName(String name); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify storage account. + */ + interface WithStorageAccount { + /** + * Specifies the name of a new storage account to put the OS and data disk VHD of the virtual machines + * in the scale set. + * + * @param name the name of the storage account + * @return the stage representing creatable VM scale set definition + */ + WithCreate withNewStorageAccount(String name); + + /** + * Specifies definition of a not-yet-created storage account definition + * to put OS and data disk VHDs of virtual machines in the scale set. + * + * @param creatable the storage account in creatable stage + * @return the stage representing creatable VM scale set definition + */ + WithCreate withNewStorageAccount(Creatable creatable); + + /** + * Specifies an existing {@link StorageAccount} storage account to put the OS and data disk VHD of + * virtual machines in the scale set. + * + * @param storageAccount an existing storage account + * @return the stage representing creatable VM scale set definition + */ + WithCreate withExistingStorageAccount(StorageAccount storageAccount); + } + + /** + * The stage of the virtual machine definition allowing to specify extensions. + */ + interface WithExtension { + /** + * Specifies definition of an extension to be attached to the virtual machines in the scale set. + * + * @param name the reference name for the extension + * @return the stage representing configuration for the extension + */ + VirtualMachineScaleSetExtension.DefinitionStages.Blank defineNewExtension(String name); + } + + /** + * The stage of a virtual machine scale set definition containing all the required inputs for the resource + * to be created (via {@link WithCreate#create()}), but also allowing for any other optional settings + * to be specified. + */ + interface WithCreate extends + Creatable, + DefinitionStages.WithPassword, + DefinitionStages.WithOsDiskSettings, + DefinitionStages.WithComputerNamePrefix, + DefinitionStages.WithCapacity, + DefinitionStages.WithUpgradePolicy, + DefinitionStages.WithOverProvision, + DefinitionStages.WithStorageAccount, + DefinitionStages.WithExtension, + Resource.DefinitionWithTags { + } + } + + /** + * Grouping of virtual machine scale set update stages. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Update", ContainerFileName = "IUpdate", IsContainerOnly = true) + interface UpdateStages { + /** + * The stage of the virtual machine scale set update allowing to specify load balancers for the primary + * network interface of the scale set virtual machines. + */ + interface WithPrimaryLoadBalancer extends WithPrimaryInternalLoadBalancer { + /** + * Specifies load balancer to tbe used as the internet facing load balancer for the virtual machines in the + * scale set. + *

+ * This will replace the current internet facing load balancer associated with the virtual machines in the + * scale set (if any). + * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternetFacingLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer the primary internet facing load balancer + * @return the next stage of the virtual machine scale set update allowing to choose backends or inbound + * nat pool from the load balancer. + */ + WithPrimaryInternetFacingLoadBalancerBackendOrNatPool withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer); + } + + /** + * The stage of the virtual machine scale set update allowing to associate backend pool and/or inbound NAT pool + * of the internet facing load balancer selected in the previous state {@link WithPrimaryLoadBalancer} + * with the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { + /** + * Associate internet facing load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from + * the load balancer + */ + WithPrimaryInternetFacingLoadBalancerNatPool withPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set update allowing to associate inbound NAT pool of the internet + * facing load balancer selected in the previous state {@link WithPrimaryLoadBalancer} with the + * primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { + /** + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set update + */ + WithPrimaryInternalLoadBalancer withPrimaryInternetFacingLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set update allowing to specify an internal load balancer for + * the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancer extends WithApply { + /** + * Specifies load balancer to tbe used as the internal load balancer for the virtual machines in the + * scale set. + *

+ * This will replace the current internal load balancer associated with the virtual machines in the + * scale set (if any). + * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface of the scale set virtual machines unless subset of them is selected in the next stages + * {@link WithPrimaryInternalLoadBalancerBackendOrNatPool}. + *

+ * @param loadBalancer the primary internet facing load balancer + * @return the next stage of the virtual machine scale set update allowing to choose backends or inbound + * nat pool from the load balancer + */ + WithPrimaryInternalLoadBalancerBackendOrNatPool withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer); + } + + /** + * The stage of the virtual machine scale set update allowing to associate backend pool and/or inbound NAT pool + * of the internal load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} + * with the primary network interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancerBackendOrNatPool extends WithPrimaryInternalLoadBalancerNatPool { + /** + * Associate internal load balancer backends with the primary network interface of the scale set virtual machines. + * + * @param backendNames the backend names + * @return the next stage of the virtual machine scale set update allowing to choose inbound nat pool from + * the load balancer + */ + WithPrimaryInternalLoadBalancerNatPool withPrimaryInternalLoadBalancerBackends(String ...backendNames); + } + + /** + * The stage of the virtual machine scale set update allowing to associate inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the primary network + * interface of the scale set virtual machines. + */ + interface WithPrimaryInternalLoadBalancerNatPool extends WithApply { + /** + * Associate internet facing load balancer inbound NAT pools with the the primary network interface of the + * scale set virtual machines. + * + * @param natPoolNames the inbound NAT pool names + * @return the next stage of the virtual machine scale set update + */ + WithApply withPrimaryInternalLoadBalancerInboundNatPools(String ...natPoolNames); + } + + /** + * The stage of the virtual machine scale set update allowing to change Sku for the virtual machines in the scale set. + */ + interface WithSku { + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param skuType the sku type + * @return the next stage of the virtual machine scale set update + */ + WithApply withSku(VirtualMachineScaleSetSkuTypes skuType); + + /** + * Specifies sku for the virtual machines in the scale set. + * + * @param sku a sku from the list of available sizes for the virtual machines in this scale set + * @return the next stage of the virtual machine scale set update + */ + WithApply withSku(VirtualMachineScaleSetSku sku); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify number of + * virtual machines in the scale set. + */ + interface WithCapacity { + /** + * Specifies the new number of virtual machines in the scale set. + * + * @param capacity the virtual machine capacity + * @return the next stage of the virtual machine scale set update + */ + WithApply withCapacity(int capacity); + } + + /** + * The stage of the virtual machine definition allowing to specify extensions. + */ + interface WithExtension { + /** + * Specifies definition of an extension to be attached to the virtual machines in the scale set. + * + * @param name the reference name for the extension + * @return the stage representing configuration for the extension + */ + VirtualMachineScaleSetExtension + .UpdateDefinitionStages + .Blank defineNewExtension(String name); + + /** + * Begins the description of an update of an existing extension assigned to the virtual machines in the scale set. + * + * @param name the reference name for the extension + * @return the stage representing updatable extension definition + */ + VirtualMachineScaleSetExtension.Update updateExtension(String name); + + /** + * Detaches an extension with the given name from the virtual machines in the scale set. + * + * @param name the reference name for the extension to be removed/uninstalled + * @return the stage representing updatable VM scale set definition + */ + WithApply withoutExtension(String name); + } + + /** + * Stage of the virtual machine scale set update allowing to remove public and internal load balancer + * from the primary network interface configuration. + */ + interface WithoutPrimaryLoadBalancer { + /** + * Remove the internet facing load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

+ * + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternetFacingLoadBalancer(); + + /** + * Remove the internal load balancer associated to the primary network interface configuration. + *

+ * This removes the association between primary network interface configuration and all backend and + * inbound NAT pools in the load balancer. + *

+ * + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternalLoadBalancer(); + } + + /** + * Stage of the virtual machine scale set update allowing to remove association between the primary network interface + * configuration and backend of the load balancer. + */ + interface WithoutPrimaryLoadBalancerBackend { + /** + * Removes association between the primary network interface configuration and backend of the internet facing + * load balancer. + * + * @param backendNames the existing backend names to remove + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames); + + /** + * Removes association between the primary network interface configuration and backend of the internal load balancer. + * + * @param backendNames the existing backend names to remove + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternalLoadBalancerBackends(String ...backendNames); + } + + /** + * Stage of the virtual machine scale set update allowing to remove association between the primary network interface + * configuration and inbound NAT pool of the load balancer. + */ + interface WithoutPrimaryLoadBalancerNatPool { + /** + * Removes association between the primary network interface configuration and inbound NAT pool of the + * internet facing load balancer. + * + * @param natPoolNames the name of an existing inbound NAT pools to remove + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames); + + /** + * Removes association between the primary network interface configuration and inbound NAT pool of the + * internal load balancer. + * + * @param natPoolNames the name of an existing inbound NAT pools to remove + * @return the next stage of the virtual machine scale set update + */ + WithApply withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames); + } + + /** + * The stage of a virtual machine scale set update containing inputs for the resource to be updated + * (via {@link WithApply#apply()}). + */ + interface WithApply extends + Appliable, + Resource.UpdateWithTags, + UpdateStages.WithSku, + UpdateStages.WithCapacity, + UpdateStages.WithExtension, + UpdateStages.WithoutPrimaryLoadBalancer, + UpdateStages.WithoutPrimaryLoadBalancerBackend, + UpdateStages.WithoutPrimaryLoadBalancerNatPool { + } + } + + /** + * The entirety of the load balancer update. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSet.Update", ContainerFileName = "IUpdate") + interface Update extends + UpdateStages.WithPrimaryLoadBalancer, + UpdateStages.WithPrimaryInternetFacingLoadBalancerBackendOrNatPool, + UpdateStages.WithPrimaryInternalLoadBalancerBackendOrNatPool { + } +} \ No newline at end of file diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java new file mode 100644 index 0000000000000..ceb12a32f5053 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java @@ -0,0 +1,471 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetExtensionInner; +import com.microsoft.azure.management.resources.fluentcore.arm.models.ChildResource; +import com.microsoft.azure.management.resources.fluentcore.model.Attachable; +import com.microsoft.azure.management.resources.fluentcore.model.Settable; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +import java.util.HashMap; +import java.util.Map; + +/** + * An immutable client-side representation of an extension associated with virtual machines in a scale set. + * An extension associated with a virtual machine scale set will be created from a {@link VirtualMachineExtensionImage }. + */ +@LangDefinition() +public interface VirtualMachineScaleSetExtension extends + Wrapper, + ChildResource { + /** + * @return the publisher name of the virtual machine scale set extension image this extension is created from + */ + String publisherName(); + + /** + * @return the type name of the virtual machine scale set extension image this extension is created from + */ + String typeName(); + + /** + * @return the version name of the virtual machine scale set extension image this extension is created from + */ + String versionName(); + + /** + * @return true if this extension is configured to upgrade automatically when a new minor version of + * virtual machine scale set extension image that this extension based on is published + */ + boolean autoUpgradeMinorVersionEnabled(); + + /** + * @return the public settings of the virtual machine scale set extension as key value pairs + */ + Map publicSettings(); + + /** + * @return the public settings of the virtual machine extension as a json string + */ + String publicSettingsAsJsonString(); + + /** + * @return the provisioning state of this virtual machine scale set extension + */ + String provisioningState(); + + /** + * The entirety of a virtual machine scale set extension definition as a part of parent definition. + * + * @param the return type of the final {@link Attachable#attach()} + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Definition", ContainerFileName = "IDefinition") + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithImageOrPublisher, + DefinitionStages.WithPublisher, + DefinitionStages.WithType, + DefinitionStages.WithVersion, + DefinitionStages.WithAttach { + } + + /** + * Grouping of virtual machine scale set extension definition stages as a part of parent virtual machine scale set definition. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Definition", ContainerFileName = "IDefinition", IsContainerOnly = true) + interface DefinitionStages { + /** + * The first stage of a virtual machine scale set extension definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank + extends WithImageOrPublisher { + } + + /** + * The stage of the virtual machinescale set extension definition allowing to specify extension image or specify name of + * the virtual machine scale set extension publisher. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithImageOrPublisher + extends WithPublisher { + /** + * Specifies the virtual machine scale set extension image to use. + * + * @param image the image + * @return the next stage of the definition + */ + WithAttach withImage(VirtualMachineExtensionImage image); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the publisher of the + * virtual machine scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPublisher { + /** + * Specifies the name of the virtual machine scale set extension image publisher. + * + * @param extensionImagePublisherName the publisher name + * @return the next stage of the definition + */ + WithType withPublisher(String extensionImagePublisherName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithType { + /** + * Specifies the type of the virtual machine scale set extension image. + * + * @param extensionImageTypeName the image type name + * @return the next stage of the definition + */ + WithVersion withType(String extensionImageTypeName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension version this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithVersion { + /** + * Specifies the version of the virtual machine scale set image extension. + * + * @param extensionImageVersionName the version name + * @return the next stage of the definition + */ + WithAttach withVersion(String extensionImageVersionName); + } + + /** The final stage of the virtual machine scale set extension definition. + *

+ * At this stage, any remaining optional settings can be specified, or the virtual machine scale set extension definition + * can be attached to the parent virtual machine scale set definition using {@link VirtualMachineExtension.DefinitionStages.WithAttach#attach()}. + * @param the return type of {@link VirtualMachineExtension.DefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InDefinition, + WithAutoUpgradeMinorVersion, + WithSettings { + } + + /** + * The stage of the virtual machine scale set extension definition allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAutoUpgradeMinorVersion { + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionEnabled(); + + /** + * disables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the public and private settings. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the definition + */ + WithAttach withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the definition + */ + WithAttach withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the definition + */ + WithAttach withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the definition + */ + WithAttach withProtectedSettings(HashMap settings); + } + } + + /** + * Grouping of virtual machine scale set extension definition stages as part of parent virtual machine scale set update. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdateDefinition", IsContainerOnly = true) + interface UpdateDefinitionStages { + /** + * The first stage of a virtual machine scale set extension definition. + * + * @param the return type of the final {@link WithAttach#attach()} + */ + interface Blank + extends WithImageOrPublisher { + } + + /** + * The stage of the virtual machine scale set extension allowing to specify extension image or specify name of the + * virtual machine extension publisher. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithImageOrPublisher + extends WithPublisher { + /** + * Specifies the virtual machine scale set extension image to use. + * + * @param image the image + * @return the next stage of the definition + */ + WithAttach withImage(VirtualMachineExtensionImage image); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the publisher of the + * virtual machine scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithPublisher { + /** + * Specifies the name of the virtual machine scale set extension image publisher. + * + * @param extensionImagePublisherName the publisher name + * @return the next stage of the definition + */ + WithType withPublisher(String extensionImagePublisherName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension image this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithType { + /** + * Specifies the type of the virtual machine scale set extension image. + * + * @param extensionImageTypeName the image type name + * @return the next stage of the definition + */ + WithVersion withType(String extensionImageTypeName); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the type of the virtual machine + * scale set extension version this extension is based on. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithVersion { + /** + * Specifies the version of the virtual machine scale set image extension. + * + * @param extensionImageVersionName the version name + * @return the next stage of the definition + */ + WithAttach withVersion(String extensionImageVersionName); + } + + /** The final stage of the virtual machine scale set extension definition. + *

+ * At this stage, any remaining optional settings can be specified, or the virtual machine scale set extension definition + * can be attached to the parent virtual machine scale set definition using {@link VirtualMachineExtension.UpdateDefinitionStages.WithAttach#attach()}. + * @param the return type of {@link VirtualMachineExtension.UpdateDefinitionStages.WithAttach#attach()} + */ + interface WithAttach extends + Attachable.InUpdate, + WithAutoUpgradeMinorVersion, + WithSettings { + } + + /** + * The stage of the virtual machine scale set extension definition allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithAutoUpgradeMinorVersion { + /** + * Enables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionEnabled(); + + /** + * Disables auto upgrade of the extension. + * + * @return the next stage of the definition + */ + WithAttach withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension definition allowing to specify the public and private settings. + * + * @param the return type of {@link WithAttach#attach()} + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the definition + */ + WithAttach withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the definition + */ + WithAttach withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the definition + */ + WithAttach withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the definition + */ + WithAttach withProtectedSettings(HashMap settings); + } + } + + /** + * The entirety of a virtual machine scale set extension definition as a part of parent update. + * @param the return type of the final {@link Attachable#attach()} + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdateDefinition") + interface UpdateDefinition extends + UpdateDefinitionStages.Blank, + UpdateDefinitionStages.WithImageOrPublisher, + UpdateDefinitionStages.WithPublisher, + UpdateDefinitionStages.WithType, + UpdateDefinitionStages.WithVersion, + UpdateDefinitionStages.WithAttach { + } + + /** + * Grouping of virtual machine extension update stages. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdate", IsContainerOnly = true) + interface UpdateStages { + /** + * The stage of the virtual machine scale set extension update allowing to enable or disable auto upgrade of the + * extension when when a new minor version of virtual machine scale set extension image gets published. + */ + interface WithAutoUpgradeMinorVersion { + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the update + */ + Update withAutoUpgradeMinorVersionEnabled(); + + /** + * enables auto upgrade of the extension. + * + * @return the next stage of the update + */ + Update withAutoUpgradeMinorVersionDisabled(); + } + + /** + * The stage of the virtual machine scale set extension update allowing to add or update public and private settings. + */ + interface WithSettings { + /** + * Specifies a public settings entry. + * + * @param key the key of a public settings entry + * @param value the value of the public settings entry + * @return the next stage of the update + */ + Update withPublicSetting(String key, Object value); + + /** + * Specifies a private settings entry. + * + * @param key the key of a private settings entry + * @param value the value of the private settings entry + * @return the next stage of the update + */ + Update withProtectedSetting(String key, Object value); + + /** + * Specifies public settings. + * + * @param settings the public settings + * @return the next stage of the update + */ + Update withPublicSettings(HashMap settings); + + /** + * Specifies private settings. + * + * @param settings the private settings + * @return the next stage of the update + */ + Update withProtectedSettings(HashMap settings); + } + } + + /** + * The entirety of virtual machine scale set extension update as a part of parent virtual machine scale set update. + */ + @LangDefinition(ContainerName = "~/VirtualMachineScaleSetExtension.Update", ContainerFileName = "IUpdate") + interface Update extends + Settable, + UpdateStages.WithAutoUpgradeMinorVersion, + UpdateStages.WithSettings { + + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java new file mode 100644 index 0000000000000..1f66e3ee92b56 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java @@ -0,0 +1,24 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.apigeneration.LangDefinition; + +/** + * A type representing sku available for virtual machines in a scale set. + */ +@LangDefinition(ContainerName = "~/") +public interface VirtualMachineScaleSetSku { + /** + * @return the type of resource the sku applies to. + */ + String resourceType(); + + /** + * @return the Sku type. + */ + VirtualMachineScaleSetSkuTypes skuType(); + + /** + * @return available scaling information. + */ + VirtualMachineScaleSetSkuCapacity capacity(); +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java new file mode 100644 index 0000000000000..548c9b59d9973 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java @@ -0,0 +1,247 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.apigeneration.LangDefinition; + +/** + * Scale set virtual machine sku types. + */ +@LangDefinition +public class VirtualMachineScaleSetSkuTypes { + /** Static value Standard_A0 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A0 = new VirtualMachineScaleSetSkuTypes("Standard_A0", "Standard"); + + /** Static value Standard_A1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A1 = new VirtualMachineScaleSetSkuTypes("Standard_A1", "Standard"); + + /** Static value Standard_A2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A2 = new VirtualMachineScaleSetSkuTypes("Standard_A2", "Standard"); + + /** Static value Standard_A3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A3 = new VirtualMachineScaleSetSkuTypes("Standard_A3", "Standard"); + + /** Static value Standard_A4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A4 = new VirtualMachineScaleSetSkuTypes("Standard_A4", "Standard"); + + /** Static value Standard_A5 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A5 = new VirtualMachineScaleSetSkuTypes("Standard_A5", "Standard"); + + /** Static value Standard_A6 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A6 = new VirtualMachineScaleSetSkuTypes("Standard_A6", "Standard"); + + /** Static value Standard_A7 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A7 = new VirtualMachineScaleSetSkuTypes("Standard_A7", "Standard"); + + /** Static value Standard_A8 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A8 = new VirtualMachineScaleSetSkuTypes("Standard_A8", "Standard"); + + /** Static value Standard_A9 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A9 = new VirtualMachineScaleSetSkuTypes("Standard_A9", "Standard"); + + /** Static value Standard_A10 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A10 = new VirtualMachineScaleSetSkuTypes("Standard_A10", "Standard"); + + /** Static value Standard_A11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_A11 = new VirtualMachineScaleSetSkuTypes("Standard_A11", "Standard"); + + /** Static value Standard_D1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D1 = new VirtualMachineScaleSetSkuTypes("Standard_D1", "Standard"); + + /** Static value Standard_D2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D2 = new VirtualMachineScaleSetSkuTypes("Standard_D2", "Standard"); + + /** Static value Standard_D3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D3 = new VirtualMachineScaleSetSkuTypes("Standard_D3", "Standard"); + + /** Static value Standard_D4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D4 = new VirtualMachineScaleSetSkuTypes("Standard_D4", "Standard"); + + /** Static value Standard_D11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D11 = new VirtualMachineScaleSetSkuTypes("Standard_D11", "Standard"); + + /** Static value Standard_D12 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D12 = new VirtualMachineScaleSetSkuTypes("Standard_D12", "Standard"); + + /** Static value Standard_D13 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D13 = new VirtualMachineScaleSetSkuTypes("Standard_D13", "Standard"); + + /** Static value Standard_D14 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D14 = new VirtualMachineScaleSetSkuTypes("Standard_D14", "Standard"); + + /** Static value Standard_D1_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D1_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D1_v2", "Standard"); + + /** Static value Standard_D2_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D2_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D2_v2", "Standard"); + + /** Static value Standard_D3_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D3_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D3_v2", "Standard"); + + /** Static value Standard_D4_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D4_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D4_v2", "Standard"); + + /** Static value Standard_D5_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D5_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D5_v2", "Standard"); + + /** Static value Standard_D11_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D11_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D11_v2", "Standard"); + + /** Static value Standard_D12_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D12_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D12_v2", "Standard"); + + /** Static value Standard_D13_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D13_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D13_v2", "Standard"); + + /** Static value Standard_D14_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D14_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D14_v2", "Standard"); + + /** Static value Standard_D15_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_D15_V2 = new VirtualMachineScaleSetSkuTypes("Standard_D15_v2", "Standard"); + + /** Static value Standard_DS1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS1 = new VirtualMachineScaleSetSkuTypes("Standard_DS1", "Standard"); + + /** Static value Standard_DS2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS2 = new VirtualMachineScaleSetSkuTypes("Standard_DS2", "Standard"); + + /** Static value Standard_DS3 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS3 = new VirtualMachineScaleSetSkuTypes("Standard_DS3", "Standard"); + + /** Static value Standard_DS4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS4 = new VirtualMachineScaleSetSkuTypes("Standard_DS4", "Standard"); + + /** Static value Standard_DS11 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS11 = new VirtualMachineScaleSetSkuTypes("Standard_DS11", "Standard"); + + /** Static value Standard_DS12 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS12 = new VirtualMachineScaleSetSkuTypes("Standard_DS12", "Standard"); + + /** Static value Standard_DS13 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS13 = new VirtualMachineScaleSetSkuTypes("Standard_DS13", "Standard"); + + /** Static value Standard_DS14 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS14 = new VirtualMachineScaleSetSkuTypes("Standard_DS14", "Standard"); + + /** Static value Standard_DS1_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS1_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS1_v2", "Standard"); + + /** Static value Standard_DS2_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS2_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS2_v2", "Standard"); + + /** Static value Standard_DS3_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS3_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS3_v2", "Standard"); + + /** Static value Standard_DS4_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS4_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS4_v2", "Standard"); + + /** Static value Standard_DS5_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS5_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS5_v2", "Standard"); + + /** Static value Standard_DS11_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS11_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS11_v2", "Standard"); + + /** Static value Standard_DS12_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS12_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS12_v2", "Standard"); + + /** Static value Standard_DS13_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS13_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS13_v2", "Standard"); + + /** Static value Standard_DS14_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS14_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS14_v2", "Standard"); + + /** Static value Standard_DS15_v2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_DS15_V2 = new VirtualMachineScaleSetSkuTypes("Standard_DS15_v2", "Standard"); + + /** Static value STANDARD_F1S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F1S = new VirtualMachineScaleSetSkuTypes("STANDARD_F1S", "Standard"); + + /** Static value STANDARD_F2S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F2S = new VirtualMachineScaleSetSkuTypes("STANDARD_F2S", "Standard"); + + /** Static value STANDARD_F4S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F4S = new VirtualMachineScaleSetSkuTypes("STANDARD_F4S", "Standard"); + + /** Static value STANDARD_F8S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F8S = new VirtualMachineScaleSetSkuTypes("STANDARD_F8S", "Standard"); + + /** Static value STANDARD_F16S for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F16S = new VirtualMachineScaleSetSkuTypes("STANDARD_F16S", "Standard"); + + /** Static value STANDARD_F1 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F1 = new VirtualMachineScaleSetSkuTypes("STANDARD_F1", "Standard"); + + /** Static value STANDARD_F2 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F2 = new VirtualMachineScaleSetSkuTypes("STANDARD_F2", "Standard"); + + /** Static value STANDARD_F4 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F4 = new VirtualMachineScaleSetSkuTypes("STANDARD_F4", "Standard"); + + /** Static value STANDARD_F8 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F8 = new VirtualMachineScaleSetSkuTypes("STANDARD_F8", "Standard"); + + /** Static value STANDARD_F16 for VirtualMachineScaleSetSkuTypes. */ + public static final VirtualMachineScaleSetSkuTypes STANDARD_F16 = new VirtualMachineScaleSetSkuTypes("STANDARD_F16", "Standard"); + + /** + * the sku corresponding to this size. + */ + private Sku sku; + + /** + * The string value of the sku. + */ + private String value; + /** + * Creates a custom value for VirtualMachineSizeTypes. + * @param skuName the sku name + * @param skuTier thr sku tier + */ + public VirtualMachineScaleSetSkuTypes(String skuName, String skuTier) { + this(new Sku().withName(skuName).withTier(skuTier)); + } + + /** + * Creates a custom value for VirtualMachineSizeTypes. + * @param sku the sku + */ + public VirtualMachineScaleSetSkuTypes(Sku sku) { + this.sku = sku; + this.value = this.sku.name(); + if (this.sku.tier() != null) { + this.value = this.value + "_" + this.sku.tier(); + } + } + + /** + * @return the sku + */ + public Sku sku() { + return this.sku; + } + + @Override + public String toString() { + return this.value; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + String value = this.toString(); + if (!(obj instanceof VirtualMachineScaleSetSkuTypes)) { + return false; + } + if (obj == this) { + return true; + } + VirtualMachineScaleSetSkuTypes rhs = (VirtualMachineScaleSetSkuTypes) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java new file mode 100644 index 0000000000000..db7b57e0f6464 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java @@ -0,0 +1,87 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingById; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsBatchCreation; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; + +import java.io.IOException; + +/** + * Entry point to virtual machine scale set management API. + */ +@LangDefinition(ContainerName = "~/") +public interface VirtualMachineScaleSets extends + SupportsListing, + SupportsListingByGroup, + SupportsGettingByGroup, + SupportsGettingById, + SupportsCreating, + SupportsDeleting, + SupportsDeletingByGroup, + SupportsBatchCreation { + /** + * Shuts down the Virtual Machine in the scale set and releases the compute resources. + *

+ * You are not billed for the compute resources that the Virtual Machines uses + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void deallocate(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Power off (stop) the virtual machines in the scale set. + *

+ * You will be billed for the compute resources that the Virtual Machines uses. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void powerOff(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Restart the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void restart(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Start the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void start(String groupName, String name) throws CloudException, IOException, InterruptedException; + + /** + * Re-image (update the version of the installed operating system) the virtual machines in the scale set. + * + * @param groupName the name of the resource group the virtual machine scale set is in + * @param name the name of the virtual machine scale set + * @throws CloudException thrown for an invalid response from the service. + * @throws IOException exception thrown from serialization/deserialization + * @throws InterruptedException exception thrown when the operation is interrupted + */ + void reimage(String groupName, String name) throws CloudException, IOException, InterruptedException; +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java index 50744531ae9a6..e48c6854dc8b5 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java @@ -4,6 +4,7 @@ import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachineExtensionImages; import com.microsoft.azure.management.compute.VirtualMachineImages; +import com.microsoft.azure.management.compute.VirtualMachineScaleSets; import com.microsoft.azure.management.compute.VirtualMachines; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; @@ -25,6 +26,7 @@ public final class ComputeManager extends Manager implements VirtualMachineExtensionImage { private final VirtualMachineExtensionImageVersion version; diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java new file mode 100644 index 0000000000000..01e4d63dd2e4a --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -0,0 +1,176 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.VirtualMachineExtensionImage; +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtension; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.ChildResourceImpl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Implementation of {@link VirtualMachineScaleSetExtension}. + */ +@LangDefinition() +public class VirtualMachineScaleSetExtensionImpl + extends ChildResourceImpl + implements + VirtualMachineScaleSetExtension, + VirtualMachineScaleSetExtension.Definition, + VirtualMachineScaleSetExtension.UpdateDefinition, + VirtualMachineScaleSetExtension.Update { + + private HashMap publicSettings; + private HashMap protectedSettings; + + protected VirtualMachineScaleSetExtensionImpl(VirtualMachineScaleSetExtensionInner inner, + VirtualMachineScaleSetImpl parent) { + super(inner, parent); + initializeSettings(); + } + + // Getters + // + @Override + public String name() { + return this.inner().name(); + } + + @Override + public String publisherName() { + return this.inner().publisher(); + } + + @Override + public String typeName() { + return this.inner().type(); + } + + @Override + public String versionName() { + return this.inner().typeHandlerVersion(); + } + + @Override + public boolean autoUpgradeMinorVersionEnabled() { + return this.inner().autoUpgradeMinorVersion(); + } + + @Override + public Map publicSettings() { + return Collections.unmodifiableMap(this.publicSettings); + } + + @Override + public String publicSettingsAsJsonString() { + return null; + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + // Withers + // + + @Override + public VirtualMachineScaleSetExtensionImpl withAutoUpgradeMinorVersionEnabled() { + this.inner().withAutoUpgradeMinorVersion(true); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withAutoUpgradeMinorVersionDisabled() { + this.inner().withAutoUpgradeMinorVersion(false); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withImage(VirtualMachineExtensionImage image) { + this.inner().withPublisher(image.publisherName()) + .withType(image.typeName()) + .withTypeHandlerVersion(image.versionName()); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublisher(String extensionImagePublisherName) { + this.inner().withPublisher(extensionImagePublisherName); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublicSetting(String key, Object value) { + this.publicSettings.put(key, value); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withProtectedSetting(String key, Object value) { + this.protectedSettings.put(key, value); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withPublicSettings(HashMap settings) { + this.publicSettings.clear(); + this.publicSettings.putAll(settings); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withProtectedSettings(HashMap settings) { + this.protectedSettings.clear(); + this.protectedSettings.putAll(settings); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withType(String extensionImageTypeName) { + this.inner().withType(extensionImageTypeName); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl withVersion(String extensionImageVersionName) { + this.inner().withTypeHandlerVersion(extensionImageVersionName); + return this; + } + + // Helper methods + // + private void nullifySettingsIfEmpty() { + if (this.publicSettings.size() == 0) { + this.inner().withSettings(null); + } + if (this.protectedSettings.size() == 0) { + this.inner().withProtectedSettings(null); + } + } + + private void initializeSettings() { + if (this.inner().settings() == null) { + this.publicSettings = new LinkedHashMap<>(); + this.inner().withSettings(this.publicSettings); + } else { + this.publicSettings = (LinkedHashMap) this.inner().settings(); + } + + if (this.inner().protectedSettings() == null) { + this.protectedSettings = new LinkedHashMap<>(); + this.inner().withProtectedSettings(this.protectedSettings); + } else { + this.protectedSettings = (LinkedHashMap) this.inner().protectedSettings(); + } + } + + @Override + public VirtualMachineScaleSetImpl attach() { + nullifySettingsIfEmpty(); + return this.parent().withExtension(this); + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java new file mode 100644 index 0000000000000..fd1672da35d13 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -0,0 +1,1407 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.SubResource; +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.ApiEntityReference; +import com.microsoft.azure.management.compute.CachingTypes; +import com.microsoft.azure.management.compute.DiskCreateOptionTypes; +import com.microsoft.azure.management.compute.ImageReference; +import com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage; +import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage; +import com.microsoft.azure.management.compute.LinuxConfiguration; +import com.microsoft.azure.management.compute.OperatingSystemTypes; +import com.microsoft.azure.management.compute.SshConfiguration; +import com.microsoft.azure.management.compute.SshPublicKey; +import com.microsoft.azure.management.compute.UpgradeMode; +import com.microsoft.azure.management.compute.UpgradePolicy; +import com.microsoft.azure.management.compute.VirtualHardDisk; +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtension; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetExtensionProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSku; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetStorageProfile; +import com.microsoft.azure.management.compute.WinRMConfiguration; +import com.microsoft.azure.management.compute.WinRMListener; +import com.microsoft.azure.management.compute.WindowsConfiguration; +import com.microsoft.azure.management.network.Backend; +import com.microsoft.azure.management.network.Frontend; +import com.microsoft.azure.management.network.InboundNatPool; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupableParentResourceImpl; +import com.microsoft.azure.management.resources.fluentcore.model.Creatable; +import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import com.microsoft.azure.management.storage.StorageAccount; +import com.microsoft.azure.management.storage.implementation.StorageManager; +import rx.Observable; +import rx.functions.Func1; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Implementation of {@link VirtualMachineScaleSet}. + */ +@LangDefinition +public class VirtualMachineScaleSetImpl + extends GroupableParentResourceImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetImpl, + ComputeManager> + implements + VirtualMachineScaleSet, + VirtualMachineScaleSet.Definition, + VirtualMachineScaleSet.Update { + // Clients + private final VirtualMachineScaleSetsInner client; + private final StorageManager storageManager; + private final NetworkManager networkManager; + // used to generate unique name for any dependency resources + private final ResourceNamer namer; + private boolean isMarketplaceLinuxImage = false; + // name of an existing subnet in the primary network to use + private String existingPrimaryNetworkSubnetNameToAssociate; + // unique key of a creatable storage accounts to be used for virtual machines child resources that + // requires storage [OS disk] + private List creatableStorageAccountKeys = new ArrayList<>(); + // reference to an existing storage account to be used for virtual machines child resources that + // requires storage [OS disk] + private List existingStorageAccountsToAssociate = new ArrayList<>(); + // Name of the container in the storage account to use to store the disks + private String vhdContainerName; + // the child resource extensions + private Map extensions; + // reference to the primary and internal internet facing load balancer + private LoadBalancer primaryInternetFacingLoadBalancer; + private LoadBalancer primaryInternalLoadBalancer; + // Load balancer specific variables used during update + private boolean removePrimaryInternetFacingLoadBalancerOnUpdate; + private boolean removePrimaryInternalLoadBalancerOnUpdate; + private LoadBalancer primaryInternetFacingLoadBalancerToAttachOnUpdate; + private LoadBalancer primaryInternalLoadBalancerToAttachOnUpdate; + private List primaryInternetFacingLBBackendsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternalLBBackendsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternalLBInboundNatPoolsToRemoveOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBBackendsToAddOnUpdate = new ArrayList<>(); + private List primaryInternetFacingLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + private List primaryInternalLBBackendsToAddOnUpdate = new ArrayList<>(); + private List primaryInternalLBInboundNatPoolsToAddOnUpdate = new ArrayList<>(); + // cached primary virtual network + private Network primaryVirtualNetwork; + // The paged converter for virtual machine scale set sku + private PagedListConverter skuConverter; + + VirtualMachineScaleSetImpl(String name, + VirtualMachineScaleSetInner innerModel, + VirtualMachineScaleSetsInner client, + final ComputeManager computeManager, + final StorageManager storageManager, + final NetworkManager networkManager) { + super(name, innerModel, computeManager); + this.client = client; + this.storageManager = storageManager; + this.networkManager = networkManager; + this.namer = new ResourceNamer(this.name()); + this.skuConverter = new PagedListConverter() { + @Override + public VirtualMachineScaleSetSku typeConvert(VirtualMachineScaleSetSkuInner inner) { + return new VirtualMachineScaleSetSkuImpl(inner); + } + }; + } + + @Override + protected void initializeChildrenFromInner() { + this.extensions = new HashMap<>(); + if (this.inner().virtualMachineProfile().extensionProfile() != null) { + if (this.inner().virtualMachineProfile().extensionProfile().extensions() != null) { + for (VirtualMachineScaleSetExtensionInner inner : this.inner().virtualMachineProfile().extensionProfile().extensions()) { + this.extensions.put(inner.name(), new VirtualMachineScaleSetExtensionImpl(inner, this)); + } + } + } + } + + @Override + public PagedList availableSkus() throws CloudException, IOException { + return this.skuConverter.convert(this.client.listSkus(this.resourceGroupName(), this.name())); + } + + @Override + public void deallocate() throws CloudException, IOException, InterruptedException { + this.client.deallocate(this.resourceGroupName(), this.name()); + } + + @Override + public void powerOff() throws CloudException, IOException, InterruptedException { + this.client.powerOff(this.resourceGroupName(), this.name()); + } + + @Override + public void restart() throws CloudException, IOException, InterruptedException { + this.client.restart(this.resourceGroupName(), this.name()); + } + + @Override + public void start() throws CloudException, IOException, InterruptedException { + this.client.start(this.resourceGroupName(), this.name()); + } + + @Override + public void reimage() throws CloudException, IOException, InterruptedException { + this.client.reimage(this.resourceGroupName(), this.name()); + } + + @Override + public String computerNamePrefix() { + return this.inner().virtualMachineProfile().osProfile().computerNamePrefix(); + } + + @Override + public OperatingSystemTypes osType() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().osType(); + } + + @Override + public CachingTypes osDiskCachingType() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().caching(); + } + + @Override + public String osDiskName() { + return this.inner().virtualMachineProfile().storageProfile().osDisk().name(); + } + + @Override + public UpgradeMode upgradeModel() { + // upgradePolicy is a required property so no null check + return this.inner().upgradePolicy().mode(); + } + + @Override + public boolean overProvisionEnabled() { + return this.inner().overProvision(); + } + + @Override + public VirtualMachineScaleSetSkuTypes sku() { + return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); + } + + @Override + public int capacity() { + return this.inner().sku().capacity().intValue(); + } + + @Override + public Network primaryNetwork() throws IOException { + if (this.primaryVirtualNetwork == null) { + String subnetId = primaryNicDefaultIPConfiguration().subnet().id(); + String virtualNetworkId = ResourceUtils.parentResourcePathFromResourceId(subnetId); + this.primaryVirtualNetwork = this.networkManager + .networks() + .getById(virtualNetworkId); + } + return this.primaryVirtualNetwork; + } + + @Override + public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { + if (this.primaryInternetFacingLoadBalancer == null) { + loadCurrentPrimaryLoadBalancersIfAvailable(); + } + return this.primaryInternetFacingLoadBalancer; + } + + @Override + public Map primaryInternetFacingLoadBalancerBackEnds() throws IOException { + if (this.primaryInternetFacingLoadBalancer() != null) { + return getBackendsAssociatedWithIpConfiguration(this.primaryInternetFacingLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); + } + + @Override + public Map primaryInternetFacingLoadBalancerInboundNatPools() throws IOException { + if (this.primaryInternetFacingLoadBalancer() != null) { + return getInboundNatPoolsAssociatedWithIpConfiguration(this.primaryInternetFacingLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); + } + + @Override + public LoadBalancer primaryInternalLoadBalancer() throws IOException { + if (this.primaryInternalLoadBalancer == null) { + loadCurrentPrimaryLoadBalancersIfAvailable(); + } + return this.primaryInternalLoadBalancer; + } + + @Override + public Map primaryInternalLoadBalancerBackEnds() throws IOException { + if (this.primaryInternalLoadBalancer() != null) { + return getBackendsAssociatedWithIpConfiguration(this.primaryInternalLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); + } + + @Override + public Map primaryInternalLoadBalancerInboundNatPools() throws IOException { + if (this.primaryInternalLoadBalancer() != null) { + return getInboundNatPoolsAssociatedWithIpConfiguration(this.primaryInternalLoadBalancer, + primaryNicDefaultIPConfiguration()); + } + return new HashMap<>(); + } + + @Override + public List primaryPublicIpAddressIds() throws IOException { + LoadBalancer loadBalancer = this.primaryInternetFacingLoadBalancer(); + if (loadBalancer != null) { + return loadBalancer.publicIpAddressIds(); + } + return new ArrayList<>(); + } + + @Override + public List vhdContainers() { + if (this.storageProfile() != null + && this.storageProfile().osDisk() != null + && this.storageProfile().osDisk().vhdContainers() != null) { + return this.storageProfile().osDisk().vhdContainers(); + } + return new ArrayList<>(); + } + + @Override + public VirtualMachineScaleSetStorageProfile storageProfile() { + return this.inner().virtualMachineProfile().storageProfile(); + } + + @Override + public VirtualMachineScaleSetNetworkProfile networkProfile() { + return this.inner().virtualMachineProfile().networkProfile(); + } + + @Override + public Map extensions() { + return Collections.unmodifiableMap(this.extensions); + } + + // Fluent setters + + @Override + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSkuTypes skuType) { + this.inner() + .withSku(skuType.sku()); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSku(VirtualMachineScaleSetSku sku) { + return this.withSku(sku.skuType()); + } + + @Override + public VirtualMachineScaleSetImpl withExistingPrimaryNetworkSubnet(Network network, String subnetName) { + this.existingPrimaryNetworkSubnetNameToAssociate = mergePath(network.id(), "subnets", subnetName); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancer(LoadBalancer loadBalancer) { + if (loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internet facing load balancer"); + } + + if (isInCreateMode()) { + this.primaryInternetFacingLoadBalancer = loadBalancer; + associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + } else { + this.primaryInternetFacingLoadBalancerToAttachOnUpdate = loadBalancer; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerBackends(String... backendNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + removeAllBackendAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, defaultPrimaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } else { + addToList(this.primaryInternetFacingLBBackendsToAddOnUpdate, backendNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternetFacingLoadBalancerInboundNatPools(String... natPoolNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, + defaultPrimaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } else { + addToList(this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate, natPoolNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancer(LoadBalancer loadBalancer) { + if (!loadBalancer.publicIpAddressIds().isEmpty()) { + throw new IllegalArgumentException("Parameter loadBalancer must be an internal load balancer"); + } + String lbNetworkId = null; + for (Frontend frontEnd : loadBalancer.frontends().values()) { + if (frontEnd.inner().subnet().id() != null) { + lbNetworkId = ResourceUtils.parentResourcePathFromResourceId(frontEnd.inner().subnet().id()); + } + } + + if (isInCreateMode()) { + String vmNICNetworkId = ResourceUtils.parentResourcePathFromResourceId(this.existingPrimaryNetworkSubnetNameToAssociate); + // Azure has a really wired BUG that - it throws exception when vnet of VMSS and LB are not same + // (code: NetworkInterfaceAndInternalLoadBalancerMustUseSameVnet) but at the same time Azure update + // the VMSS's network section to refer this invalid internal LB. This makes VMSS un-usable and portal + // will show a error above VMSS profile page. + // + if (!vmNICNetworkId.equalsIgnoreCase(lbNetworkId)) { + throw new IllegalArgumentException("Virtual network associated with scale set virtual machines" + + " and internal load balancer must be same. " + + "'" + vmNICNetworkId + "'" + + "'" + lbNetworkId); + } + + this.primaryInternalLoadBalancer = loadBalancer; + associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + } else { + String vmNicVnetId = ResourceUtils.parentResourcePathFromResourceId(primaryNicDefaultIPConfiguration() + .subnet() + .id()); + if (!vmNicVnetId.equalsIgnoreCase(lbNetworkId)) { + throw new IllegalArgumentException("Virtual network associated with scale set virtual machines" + + " and internal load balancer must be same. " + + "'" + vmNicVnetId + "'" + + "'" + lbNetworkId); + } + this.primaryInternalLoadBalancerToAttachOnUpdate = loadBalancer; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerBackends(String... backendNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = primaryNicDefaultIPConfiguration(); + this.removeAllBackendAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, + defaultPrimaryIpConfig); + this.associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + backendNames); + } else { + addToList(this.primaryInternalLBBackendsToAddOnUpdate, backendNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPrimaryInternalLoadBalancerInboundNatPools(String... natPoolNames) { + if (this.isInCreateMode()) { + VirtualMachineScaleSetIPConfigurationInner defaultPrimaryIpConfig = this.primaryNicDefaultIPConfiguration(); + this.removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, + defaultPrimaryIpConfig); + this.associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancer.id(), + defaultPrimaryIpConfig, + natPoolNames); + } else { + addToList(this.primaryInternalLBInboundNatPoolsToAddOnUpdate, natPoolNames); + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancer() { + if (this.isInUpdateMode()) { + this.removePrimaryInternalLoadBalancerOnUpdate = true; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancer() { + if (this.isInUpdateMode()) { + this.removePrimaryInternetFacingLoadBalancerOnUpdate = true; + } + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancerBackends(String ...backendNames) { + addToList(this.primaryInternetFacingLBBackendsToRemoveOnUpdate, backendNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancerBackends(String ...backendNames) { + addToList(this.primaryInternalLBBackendsToRemoveOnUpdate, backendNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternetFacingLoadBalancerNatPools(String ...natPoolNames) { + addToList(this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate, natPoolNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutPrimaryInternalLoadBalancerNatPools(String ...natPoolNames) { + addToList(this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate, natPoolNames); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage) { + return withSpecificWindowsImageVersion(knownImage.imageReference()); + } + + @Override + public VirtualMachineScaleSetImpl withLatestWindowsImage(String publisher, String offer, String sku) { + ImageReference imageReference = new ImageReference() + .withPublisher(publisher) + .withOffer(offer) + .withSku(sku) + .withVersion("latest"); + return withSpecificWindowsImageVersion(imageReference); + } + + @Override + public VirtualMachineScaleSetImpl withSpecificWindowsImageVersion(ImageReference imageReference) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().withImageReference(imageReference); + this.inner() + .virtualMachineProfile() + .osProfile().withWindowsConfiguration(new WindowsConfiguration()); + // sets defaults for "Stored(Custom)Image" or "VM(Platform)Image" + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withStoredWindowsImage(String imageUrl) { + VirtualHardDisk userImageVhd = new VirtualHardDisk(); + userImageVhd.withUri(imageUrl); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withImage(userImageVhd); + // For platform image osType will be null, azure will pick it from the image metadata. + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withOsType(OperatingSystemTypes.WINDOWS); + this.inner() + .virtualMachineProfile() + .osProfile().withWindowsConfiguration(new WindowsConfiguration()); + // sets defaults for "Stored(Custom)Image" or "VM(Platform)Image" + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage) { + return withSpecificLinuxImageVersion(knownImage.imageReference()); + } + + @Override + public VirtualMachineScaleSetImpl withLatestLinuxImage(String publisher, String offer, String sku) { + ImageReference imageReference = new ImageReference() + .withPublisher(publisher) + .withOffer(offer) + .withSku(sku) + .withVersion("latest"); + return withSpecificLinuxImageVersion(imageReference); + } + + @Override + public VirtualMachineScaleSetImpl withSpecificLinuxImageVersion(ImageReference imageReference) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().withImageReference(imageReference); + this.inner() + .virtualMachineProfile() + .osProfile().withLinuxConfiguration(new LinuxConfiguration()); + this.isMarketplaceLinuxImage = true; + return this; + } + + @Override + public VirtualMachineScaleSetImpl withStoredLinuxImage(String imageUrl) { + VirtualHardDisk userImageVhd = new VirtualHardDisk(); + userImageVhd.withUri(imageUrl); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCreateOption(DiskCreateOptionTypes.FROM_IMAGE); + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withImage(userImageVhd); + // For platform image osType will be null, azure will pick it from the image metadata. + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withOsType(OperatingSystemTypes.LINUX); + this.inner() + .virtualMachineProfile() + .osProfile().withLinuxConfiguration(new LinuxConfiguration()); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withAdminUserName(String adminUserName) { + this.inner() + .virtualMachineProfile() + .osProfile() + .withAdminUsername(adminUserName); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withRootUserName(String rootUserName) { + return this.withAdminUserName(rootUserName); + } + + @Override + public VirtualMachineScaleSetImpl withPassword(String password) { + this.inner() + .virtualMachineProfile() + .osProfile() + .withAdminPassword(password); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSsh(String publicKeyData) { + VirtualMachineScaleSetOSProfile osProfile = this.inner() + .virtualMachineProfile() + .osProfile(); + if (osProfile.linuxConfiguration().ssh() == null) { + SshConfiguration sshConfiguration = new SshConfiguration(); + sshConfiguration.withPublicKeys(new ArrayList()); + osProfile.linuxConfiguration().withSsh(sshConfiguration); + } + SshPublicKey sshPublicKey = new SshPublicKey(); + sshPublicKey.withKeyData(publicKeyData); + sshPublicKey.withPath("/home/" + osProfile.adminUsername() + "/.ssh/authorized_keys"); + osProfile.linuxConfiguration().ssh().publicKeys().add(sshPublicKey); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withVmAgent() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutVmAgent() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(false); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withAutoUpdate() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(true); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withoutAutoUpdate() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withEnableAutomaticUpdates(false); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withTimeZone(String timeZone) { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withTimeZone(timeZone); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withWinRm(WinRMListener listener) { + if (this.inner().virtualMachineProfile().osProfile().windowsConfiguration().winRM() == null) { + WinRMConfiguration winRMConfiguration = new WinRMConfiguration(); + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withWinRM(winRMConfiguration); + } + this.inner() + .virtualMachineProfile() + .osProfile() + .windowsConfiguration() + .winRM() + .listeners() + .add(listener); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOsDiskCaching(CachingTypes cachingType) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withCaching(cachingType); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOsDiskName(String name) { + this.inner() + .virtualMachineProfile() + .storageProfile().osDisk().withName(name); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withComputerNamePrefix(String namePrefix) { + this.inner() + .virtualMachineProfile() + .osProfile() + .withComputerNamePrefix(namePrefix); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withUpgradeMode(UpgradeMode upgradeMode) { + this.inner() + .upgradePolicy() + .withMode(upgradeMode); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOverProvision(boolean enabled) { + this.inner() + .withOverProvision(enabled); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withOverProvisionEnabled() { + return this.withOverProvision(true); + } + + @Override + public VirtualMachineScaleSetImpl withOverProvisionDisabled() { + return this.withOverProvision(false); + } + + @Override + public VirtualMachineScaleSetImpl withCapacity(int capacity) { + this.inner() + .sku().withCapacity(new Long(capacity)); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withNewStorageAccount(String name) { + StorageAccount.DefinitionStages.WithGroup definitionWithGroup = this.storageManager + .storageAccounts() + .define(name) + .withRegion(this.regionName()); + Creatable definitionAfterGroup; + if (this.creatableGroup != null) { + definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); + } else { + definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); + } + return withNewStorageAccount(definitionAfterGroup); + } + + @Override + public VirtualMachineScaleSetImpl withNewStorageAccount(Creatable creatable) { + this.creatableStorageAccountKeys.add(creatable.key()); + this.addCreatableDependency(creatable); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withExistingStorageAccount(StorageAccount storageAccount) { + this.existingStorageAccountsToAssociate.add(storageAccount); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl defineNewExtension(String name) { + return new VirtualMachineScaleSetExtensionImpl(new VirtualMachineScaleSetExtensionInner().withName(name), this); + } + + protected VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { + this.extensions.put(extension.name(), extension); + return this; + } + + @Override + public VirtualMachineScaleSetExtensionImpl updateExtension(String name) { + return (VirtualMachineScaleSetExtensionImpl) this.extensions.get(name); + } + + @Override + public VirtualMachineScaleSetImpl withoutExtension(String name) { + if (this.extensions.containsKey(name)) { + this.extensions.remove(name); + } + return this; + } + + // Create Update specific methods + // + @Override + protected void beforeCreating() { + if (this.extensions.size() > 0) { + this.inner() + .virtualMachineProfile() + .withExtensionProfile(new VirtualMachineScaleSetExtensionProfile()) + .extensionProfile() + .withExtensions(innersFromWrappers(this.extensions.values())); + } + } + + @Override + protected Observable createInner() { + this.setOSDiskAndOSProfileDefaults(); + this.setPrimaryIpConfigurationSubnet(); + this.setPrimaryIpConfigurationBackendsAndInboundNatPools(); + return this.handleOSDiskContainersAsync() + .flatMap(new Func1>() { + @Override + public Observable call(Void aVoid) { + return client.createOrUpdateAsync(resourceGroupName(), name(), inner()); + } + }); + } + + @Override + protected void afterCreating() { + this.clearCachedProperties(); + this.initializeChildrenFromInner(); + } + + @Override + public Observable applyAsync() { + return this.createAsync(); + } + + @Override + public Observable applyUpdateAsync() { + return this.createResourceAsync(); + } + + @Override + public VirtualMachineScaleSetImpl refresh() { + VirtualMachineScaleSetInner inner = this.client.get(this.resourceGroupName(), this.name()); + this.setInner(inner); + this.clearCachedProperties(); + this.initializeChildrenFromInner(); + return this; + } + + // Helpers + // + + private boolean isInUpdateMode() { + return !this.isInCreateMode(); + } + + private void setOSDiskAndOSProfileDefaults() { + if (isInUpdateMode()) { + return; + } + + if (this.inner().sku().capacity() == null) { + this.withCapacity(2); + } + + if (this.inner().upgradePolicy() == null + || this.inner().upgradePolicy().mode() == null) { + this.inner() + .withUpgradePolicy(new UpgradePolicy() + .withMode(UpgradeMode.AUTOMATIC)); + } + + VirtualMachineScaleSetOSProfile osProfile = this.inner() + .virtualMachineProfile() + .osProfile(); + // linux image: Custom or marketplace linux image + if (this.osType() == OperatingSystemTypes.LINUX || this.isMarketplaceLinuxImage) { + if (osProfile.linuxConfiguration() == null) { + osProfile.withLinuxConfiguration(new LinuxConfiguration()); + } + osProfile + .linuxConfiguration() + .withDisablePasswordAuthentication(osProfile.adminPassword() == null); + } + + if (this.osDiskCachingType() == null) { + withOsDiskCaching(CachingTypes.READ_WRITE); + } + + if (this.osDiskName() == null) { + withOsDiskName(this.name() + "-os-disk"); + } + + if (this.computerNamePrefix() == null) { + // VM name cannot contain only numeric values and cannot exceed 15 chars + if (this.name().matches("[0-9]+")) { + withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } else if (this.name().length() <= 12) { + withComputerNamePrefix(this.name() + "-vm"); + } else { + withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } + } + } + + private boolean isCustomImage(VirtualMachineScaleSetStorageProfile storageProfile) { + return storageProfile.osDisk().image() != null + && storageProfile.osDisk().image().uri() != null; + } + + private Observable handleOSDiskContainersAsync() { + final VirtualMachineScaleSetStorageProfile storageProfile = inner() + .virtualMachineProfile() + .storageProfile(); + if (isCustomImage(storageProfile)) { + // There is a restriction currently that virtual machine's disk cannot be stored in multiple storage accounts + // if scale set is based on custom image. Remove this check once azure start supporting it. + storageProfile.osDisk() + .vhdContainers() + .clear(); + return Observable.just(null); + } + + if (this.isInCreateMode() + && this.creatableStorageAccountKeys.isEmpty() + && this.existingStorageAccountsToAssociate.isEmpty()) { + return this.storageManager.storageAccounts() + .define(this.namer.randomName("stg", 24)) + .withRegion(this.regionName()) + .withExistingResourceGroup(this.resourceGroupName()) + .createAsync() + .map(new Func1() { + @Override + public Void call(StorageAccount storageAccount) { + String containerName = vhdContainerName; + if (containerName == null) { + containerName = "vhds"; + } + storageProfile.osDisk() + .vhdContainers() + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); + vhdContainerName = null; + creatableStorageAccountKeys.clear(); + existingStorageAccountsToAssociate.clear(); + return null; + } + }); + } else { + String containerName = this.vhdContainerName; + if (containerName == null) { + for (String containerUrl : storageProfile.osDisk().vhdContainers()) { + containerName = containerUrl.substring(containerUrl.lastIndexOf("/") + 1); + break; + } + } + + if (containerName == null) { + containerName = "vhds"; + } + + for (String storageAccountKey : this.creatableStorageAccountKeys) { + StorageAccount storageAccount = (StorageAccount) createdResource(storageAccountKey); + storageProfile.osDisk() + .vhdContainers() + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); + } + + for (StorageAccount storageAccount : this.existingStorageAccountsToAssociate) { + storageProfile.osDisk() + .vhdContainers() + .add(mergePath(storageAccount.endPoints().primary().blob(), containerName)); + } + + this.vhdContainerName = null; + this.creatableStorageAccountKeys.clear(); + this.existingStorageAccountsToAssociate.clear(); + return Observable.just(null); + } + } + + private void setPrimaryIpConfigurationSubnet() { + if (isInUpdateMode()) { + return; + } + + VirtualMachineScaleSetIPConfigurationInner ipConfig = this.primaryNicDefaultIPConfiguration(); + ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkSubnetNameToAssociate)); + this.existingPrimaryNetworkSubnetNameToAssociate = null; + } + + private void setPrimaryIpConfigurationBackendsAndInboundNatPools() { + if (isInCreateMode()) { + return; + } + + try { + this.loadCurrentPrimaryLoadBalancersIfAvailable(); + } catch (IOException ioException) { + throw new RuntimeException(ioException); + } + + VirtualMachineScaleSetIPConfigurationInner primaryIpConfig = primaryNicDefaultIPConfiguration(); + if (this.primaryInternetFacingLoadBalancer != null) { + removeBackendsFromIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToRemoveOnUpdate.toArray(new String[0])); + + associateBackEndsToIpConfiguration(primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToAddOnUpdate.toArray(new String[0])); + + removeInboundNatPoolsFromIpConfiguration(this.primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate.toArray(new String[0])); + + associateInboundNATPoolsToIpConfiguration(primaryInternetFacingLoadBalancer.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + + if (this.primaryInternalLoadBalancer != null) { + removeBackendsFromIpConfiguration(this.primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToRemoveOnUpdate.toArray(new String[0])); + + associateBackEndsToIpConfiguration(primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToAddOnUpdate.toArray(new String[0])); + + removeInboundNatPoolsFromIpConfiguration(this.primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate.toArray(new String[0])); + + associateInboundNATPoolsToIpConfiguration(primaryInternalLoadBalancer.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + + if (this.removePrimaryInternetFacingLoadBalancerOnUpdate) { + if (this.primaryInternetFacingLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, primaryIpConfig); + } + } + + if (this.removePrimaryInternalLoadBalancerOnUpdate) { + if (this.primaryInternalLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, primaryIpConfig); + } + } + + if (this.primaryInternetFacingLoadBalancerToAttachOnUpdate != null) { + if (this.primaryInternetFacingLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancer, primaryIpConfig); + } + associateLoadBalancerToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + if (!this.primaryInternetFacingLBBackendsToAddOnUpdate.isEmpty()) { + removeAllBackendAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternetFacingLBBackendsToAddOnUpdate.toArray(new String[0])); + } + if (!this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.isEmpty()) { + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternetFacingLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + } + + if (this.primaryInternalLoadBalancerToAttachOnUpdate != null) { + if (this.primaryInternalLoadBalancer != null) { + removeLoadBalancerAssociationFromIpConfiguration(this.primaryInternalLoadBalancer, primaryIpConfig); + } + associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + if (!this.primaryInternalLBBackendsToAddOnUpdate.isEmpty()) { + removeAllBackendAssociationFromIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateBackEndsToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternalLBBackendsToAddOnUpdate.toArray(new String[0])); + } + + if (!this.primaryInternalLBInboundNatPoolsToAddOnUpdate.isEmpty()) { + removeAllInboundNatPoolAssociationFromIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate, primaryIpConfig); + associateInboundNATPoolsToIpConfiguration(this.primaryInternalLoadBalancerToAttachOnUpdate.id(), + primaryIpConfig, + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.toArray(new String[0])); + } + } + + this.removePrimaryInternetFacingLoadBalancerOnUpdate = false; + this.removePrimaryInternalLoadBalancerOnUpdate = false; + this.primaryInternetFacingLoadBalancerToAttachOnUpdate = null; + this.primaryInternalLoadBalancerToAttachOnUpdate = null; + this.primaryInternetFacingLBBackendsToRemoveOnUpdate.clear(); + this.primaryInternetFacingLBInboundNatPoolsToRemoveOnUpdate.clear(); + this.primaryInternalLBBackendsToRemoveOnUpdate.clear(); + this.primaryInternalLBInboundNatPoolsToRemoveOnUpdate.clear(); + this.primaryInternetFacingLBBackendsToAddOnUpdate.clear(); + this.primaryInternetFacingLBInboundNatPoolsToAddOnUpdate.clear(); + this.primaryInternalLBBackendsToAddOnUpdate.clear(); + this.primaryInternalLBInboundNatPoolsToAddOnUpdate.clear(); + } + + private void clearCachedProperties() { + this.primaryInternetFacingLoadBalancer = null; + this.primaryInternalLoadBalancer = null; + this.primaryVirtualNetwork = null; + } + + private void loadCurrentPrimaryLoadBalancersIfAvailable() throws IOException { + if (this.primaryInternetFacingLoadBalancer != null && this.primaryInternalLoadBalancer != null) { + return; + } + + String firstLoadBalancerId = null; + VirtualMachineScaleSetIPConfigurationInner ipConfig = primaryNicDefaultIPConfiguration(); + if (!ipConfig.loadBalancerBackendAddressPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerBackendAddressPools().get(0).id()); + } + + if (firstLoadBalancerId == null && !ipConfig.loadBalancerInboundNatPools().isEmpty()) { + firstLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(ipConfig.loadBalancerInboundNatPools().get(0).id()); + } + + if (firstLoadBalancerId == null) { + return; + } + + LoadBalancer loadBalancer1 = this.networkManager + .loadBalancers() + .getById(firstLoadBalancerId); + if (loadBalancer1.publicIpAddressIds() != null && loadBalancer1.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer1; + } else { + this.primaryInternalLoadBalancer = loadBalancer1; + } + + String secondLoadBalancerId = null; + for (SubResource subResource: ipConfig.loadBalancerBackendAddressPools()) { + if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + } + + if (secondLoadBalancerId == null) { + for (SubResource subResource: ipConfig.loadBalancerInboundNatPools()) { + if (!subResource.id().toLowerCase().startsWith(firstLoadBalancerId.toLowerCase())) { + secondLoadBalancerId = ResourceUtils + .parentResourcePathFromResourceId(subResource.id()); + break; + } + } + } + + if (secondLoadBalancerId == null) { + return; + } + + LoadBalancer loadBalancer2 = this.networkManager + .loadBalancers() + .getById(secondLoadBalancerId); + if (loadBalancer2.publicIpAddressIds() != null && loadBalancer2.publicIpAddressIds().size() > 0) { + this.primaryInternetFacingLoadBalancer = loadBalancer2; + } else { + this.primaryInternalLoadBalancer = loadBalancer2; + } + } + + private VirtualMachineScaleSetIPConfigurationInner primaryNicDefaultIPConfiguration() { + List nicConfigurations = this.inner() + .virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations(); + + for (VirtualMachineScaleSetNetworkConfigurationInner nicConfiguration : nicConfigurations) { + if (nicConfiguration.primary()) { + if (nicConfiguration.ipConfigurations().size() > 0) { + VirtualMachineScaleSetIPConfigurationInner ipConfig = nicConfiguration.ipConfigurations().get(0); + if (ipConfig.loadBalancerBackendAddressPools() == null) { + ipConfig.withLoadBalancerBackendAddressPools(new ArrayList()); + } + if (ipConfig.loadBalancerInboundNatPools() == null) { + ipConfig.withLoadBalancerInboundNatPools(new ArrayList()); + } + return ipConfig; + } + } + } + throw new RuntimeException("Could not find the primary nic configuration or an IP configuration in it"); + } + + private static void associateBackEndsToIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... backendNames) { + List backendSubResourcesToAssociate = new ArrayList<>(); + for (String backendName : backendNames) { + String backendPoolId = mergePath(loadBalancerId, "backendAddressPools", backendName); + boolean found = false; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().equalsIgnoreCase(backendPoolId)) { + found = true; + break; + } + } + if (!found) { + backendSubResourcesToAssociate.add(new SubResource().withId(backendPoolId)); + } + } + + for (SubResource backendSubResource : backendSubResourcesToAssociate) { + ipConfig.loadBalancerBackendAddressPools().add(backendSubResource); + } + } + + private static void associateInboundNATPoolsToIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... inboundNatPools) { + List inboundNatPoolSubResourcesToAssociate = new ArrayList<>(); + for (String inboundNatPool : inboundNatPools) { + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", inboundNatPool); + boolean found = false; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + found = true; + break; + } + } + if (!found) { + inboundNatPoolSubResourcesToAssociate.add(new SubResource().withId(inboundNatPoolId)); + } + } + + for (SubResource backendSubResource : inboundNatPoolSubResourcesToAssociate) { + ipConfig.loadBalancerInboundNatPools().add(backendSubResource); + } + } + + private static Map getBackendsAssociatedWithIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + String loadBalancerId = loadBalancer.id(); + Map attachedBackends = new HashMap<>(); + Map lbBackends = loadBalancer.backends(); + for (Backend lbBackend : lbBackends.values()) { + String backendId = mergePath(loadBalancerId, "backendAddressPools", lbBackend.name()); + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().equalsIgnoreCase(backendId)) { + attachedBackends.put(lbBackend.name(), lbBackend); + } + } + } + return attachedBackends; + } + + private static Map getInboundNatPoolsAssociatedWithIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + String loadBalancerId = loadBalancer.id(); + Map attachedInboundNatPools = new HashMap<>(); + Map lbInboundNatPools = loadBalancer.inboundNatPools(); + for (InboundNatPool lbInboundNatPool : lbInboundNatPools.values()) { + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", lbInboundNatPool.name()); + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + attachedInboundNatPools.put(lbInboundNatPool.name(), lbInboundNatPool); + } + } + } + return attachedInboundNatPools; + } + + private static void associateLoadBalancerToIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + Collection backends = loadBalancer.backends().values(); + String[] backendNames = new String[backends.size()]; + int i = 0; + for (Backend backend : backends) { + backendNames[i] = backend.name(); + i++; + } + + associateBackEndsToIpConfiguration(loadBalancer.id(), + ipConfig, + backendNames); + + Collection inboundNatPools = loadBalancer.inboundNatPools().values(); + String[] natPoolNames = new String[inboundNatPools.size()]; + i = 0; + for (InboundNatPool inboundNatPool : inboundNatPools) { + natPoolNames[i] = inboundNatPool.name(); + i++; + } + + associateInboundNATPoolsToIpConfiguration(loadBalancer.id(), + ipConfig, + natPoolNames); + } + + private static void removeLoadBalancerAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + removeAllBackendAssociationFromIpConfiguration(loadBalancer, ipConfig); + removeAllInboundNatPoolAssociationFromIpConfiguration(loadBalancer, ipConfig); + } + + private static void removeAllBackendAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + List toRemove = new ArrayList<>(); + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemove.add(subResource); + } + } + + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerBackendAddressPools().remove(subResource); + } + } + + private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + List toRemove = new ArrayList<>(); + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemove.add(subResource); + } + } + + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerInboundNatPools().remove(subResource); + } + } + + private static void removeBackendsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... backendNames) { + List toRemove = new ArrayList<>(); + for (String backendName : backendNames) { + String backendPoolId = mergePath(loadBalancerId, "backendAddressPools", backendName); + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().equalsIgnoreCase(backendPoolId)) { + toRemove.add(subResource); + break; + } + } + } + + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerBackendAddressPools().remove(subResource); + } + } + + private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... inboundNatPoolNames) { + List toRemove = new ArrayList<>(); + for (String natPoolName : inboundNatPoolNames) { + String inboundNatPoolId = mergePath(loadBalancerId, "inboundNatPools", natPoolName); + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + toRemove.add(subResource); + break; + } + } + } + + for (SubResource subResource : toRemove) { + ipConfig.loadBalancerInboundNatPools().remove(subResource); + } + } + + private static void addToList(List list, T...items) { + for (T item : items) { + list.add(item); + } + } + + private static String mergePath(String... segments) { + StringBuilder builder = new StringBuilder(); + for (String segment : segments) { + while (segment.length() > 1 && segment.endsWith("/")) { + segment = segment.substring(0, segment.length() - 1); + } + + if (segment.length() > 0) { + builder.append(segment); + builder.append("/"); + } + } + + String merged = builder.toString(); + if (merged.endsWith("/")) { + merged = merged.substring(0, merged.length() - 1); + } + return merged; + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java new file mode 100644 index 0000000000000..4e798a101234f --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java @@ -0,0 +1,35 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSku; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuCapacity; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetSkuTypes; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; + +/** + * implementation of {@link VirtualMachineScaleSetSku}. + */ +@LangDefinition +class VirtualMachineScaleSetSkuImpl + extends WrapperImpl + implements VirtualMachineScaleSetSku { + VirtualMachineScaleSetSkuImpl(VirtualMachineScaleSetSkuInner inner) { + super(inner); + } + + @Override + public String resourceType() { + return this.inner().resourceType(); + } + + @Override + public VirtualMachineScaleSetSkuTypes skuType() { + return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); + } + + @Override + public VirtualMachineScaleSetSkuCapacity capacity() { + return this.inner().capacity(); + } +} + diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java new file mode 100644 index 0000000000000..5bed8a37ce2d9 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -0,0 +1,147 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.apigeneration.LangDefinition; +import com.microsoft.azure.management.compute.VirtualMachineScaleSet; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetNetworkProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSDisk; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetOSProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetStorageProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSetVMProfile; +import com.microsoft.azure.management.compute.VirtualMachineScaleSets; +import com.microsoft.azure.management.network.implementation.NetworkManager; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.GroupableResourcesImpl; +import com.microsoft.azure.management.storage.implementation.StorageManager; +import java.util.ArrayList; + +/** + * The implementation for {@link VirtualMachineScaleSets}. + */ +@LangDefinition +public class VirtualMachineScaleSetsImpl + extends GroupableResourcesImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetImpl, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetsInner, + ComputeManager> + implements VirtualMachineScaleSets { + private final StorageManager storageManager; + private final NetworkManager networkManager; + + VirtualMachineScaleSetsImpl(VirtualMachineScaleSetsInner client, + ComputeManager computeManager, + StorageManager storageManager, + NetworkManager networkManager) { + super(client, computeManager); + this.storageManager = storageManager; + this.networkManager = networkManager; + } + + @Override + public VirtualMachineScaleSet getByGroup(String groupName, String name) { + return wrapModel(this.innerCollection.get(groupName, name)); + } + + @Override + public PagedList listByGroup(String groupName) { + return wrapList(this.innerCollection.list(groupName)); + } + + @Override + public PagedList list() { + return wrapList(this.innerCollection.listAll()); + } + + @Override + public void delete(String id) { + this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); + } + + @Override + public void delete(String groupName, String name) { + this.innerCollection.delete(groupName, name); + } + + @Override + public void deallocate(String groupName, String name) { + this.innerCollection.deallocate(groupName, name); + } + + @Override + public void powerOff(String groupName, String name) { + this.innerCollection.powerOff(groupName, name); + } + + @Override + public void restart(String groupName, String name) { + this.innerCollection.restart(groupName, name); + } + + @Override + public void start(String groupName, String name) { + this.innerCollection.start(groupName, name); + } + + @Override + public void reimage(String groupName, String name) { + this.innerCollection.reimage(groupName, name); + } + + @Override + public VirtualMachineScaleSetImpl define(String name) { + return wrapModel(name); + } + + @Override + protected VirtualMachineScaleSetImpl wrapModel(String name) { + VirtualMachineScaleSetInner inner = new VirtualMachineScaleSetInner(); + + inner.withVirtualMachineProfile(new VirtualMachineScaleSetVMProfile()); + inner.virtualMachineProfile() + .withStorageProfile(new VirtualMachineScaleSetStorageProfile() + .withOsDisk(new VirtualMachineScaleSetOSDisk().withVhdContainers(new ArrayList()))); + inner.virtualMachineProfile() + .withOsProfile(new VirtualMachineScaleSetOSProfile()); + + inner.virtualMachineProfile() + .withNetworkProfile(new VirtualMachineScaleSetNetworkProfile()); + + inner.virtualMachineProfile() + .networkProfile() + .withNetworkInterfaceConfigurations(new ArrayList()); + + VirtualMachineScaleSetNetworkConfigurationInner primaryNetworkInterfaceConfiguration = + new VirtualMachineScaleSetNetworkConfigurationInner() + .withPrimary(true) + .withName("primary-nic-cfg") + .withIpConfigurations(new ArrayList()); + primaryNetworkInterfaceConfiguration + .ipConfigurations() + .add(new VirtualMachineScaleSetIPConfigurationInner() + .withName("primary-nic-ip-cfg")); + + inner.virtualMachineProfile() + .networkProfile() + .networkInterfaceConfigurations() + .add(primaryNetworkInterfaceConfiguration); + + return new VirtualMachineScaleSetImpl(name, + inner, + this.innerCollection, + super.myManager, + this.storageManager, + this.networkManager); + } + + @Override + protected VirtualMachineScaleSetImpl wrapModel(VirtualMachineScaleSetInner inner) { + return new VirtualMachineScaleSetImpl(inner.name(), + inner, + this.innerCollection, + super.myManager, + this.storageManager, + this.networkManager); + } +} diff --git a/azure-mgmt-compute/src/test/assets/install_apache.sh b/azure-mgmt-compute/src/test/assets/install_apache.sh new file mode 100644 index 0000000000000..c2ec797c14c06 --- /dev/null +++ b/azure-mgmt-compute/src/test/assets/install_apache.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +sudo apt-get update + +# install apache +sudo apt-get -y install apache2 + +# restart Apache +sudo apachectl restart \ No newline at end of file diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java index 528c7b8a38a6b..e75941fa34099 100644 --- a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java @@ -3,13 +3,17 @@ import com.microsoft.azure.AzureEnvironment; import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.compute.implementation.ComputeManager; +import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.RestClient; +import com.microsoft.azure.management.storage.implementation.StorageManager; import okhttp3.logging.HttpLoggingInterceptor; public abstract class ComputeManagementTestBase { protected static ResourceManager resourceManager; protected static ComputeManager computeManager; + protected static NetworkManager networkManager; + protected static StorageManager storageManager; public static void createClients() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( @@ -29,5 +33,11 @@ public static void createClients() { computeManager = ComputeManager .authenticate(restClient, System.getenv("subscription-id")); + + networkManager = NetworkManager + .authenticate(restClient, System.getenv("subscription-id")); + + storageManager = StorageManager + .authenticate(restClient, System.getenv("subscription-id")); } } diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java new file mode 100644 index 0000000000000..307f0ad2f3ca0 --- /dev/null +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -0,0 +1,377 @@ +package com.microsoft.azure.management.compute; + +import com.jcraft.jsch.JSch; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.PublicIpAddress; +import com.microsoft.azure.management.network.TransportProtocol; +import com.microsoft.azure.management.resources.ResourceGroup; +import com.microsoft.azure.management.resources.fluentcore.utils.ResourceNamer; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +public class VirtualMachineScaleSetOperationsTests extends ComputeManagementTestBase { + private static final String RG_NAME = ResourceNamer.randomResourceName("javacsmrg", 20); + private static final String LOCATION = "eastasia"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + resourceManager.resourceGroups().delete(RG_NAME); + } + + @Test + public void canCreateVirtualMachineScaleSetWithCustomScriptExtension() throws Exception { + final String vmssName = ResourceNamer.randomResourceName("vmss", 10); + final String apacheInstallScript = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/azure-mgmt-compute/src/test/assets/l_apache.sh"; + final String installCommand = "bash install_apache.sh Abc.123x("; + List fileUris = new ArrayList<>(); + fileUris.add(apacheInstallScript); + + ResourceGroup resourceGroup = this.resourceManager.resourceGroups() + .define(RG_NAME) + .withRegion(LOCATION) + .create(); + + Network network = this.networkManager + .networks() + .define(ResourceNamer.randomResourceName("vmssvnet", 15)) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withAddressSpace("10.0.0.0/28") + .withSubnet("subnet1", "10.0.0.0/28") + .create(); + + LoadBalancer publicLoadBalancer = createHttpLoadBalancers(resourceGroup, "1"); + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() + .define(vmssName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) + .withExistingPrimaryNetworkSubnet(network, "subnet1") + .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) + .withoutPrimaryInternalLoadBalancer() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) + .withRootUserName("jvuser") + .withPassword("123OData!@#123") + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .defineNewExtension("CustomScriptForLinux") + .withPublisher("Microsoft.OSTCExtensions") + .withType("CustomScriptForLinux") + .withVersion("1.4") + .withAutoUpgradeMinorVersionEnabled() + .withPublicSetting("fileUris",fileUris) + .withPublicSetting("commandToExecute", installCommand) + .attach() + .create(); + + List publicIpAddressIds = virtualMachineScaleSet.primaryPublicIpAddressIds(); + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .getById(publicIpAddressIds.get(0)); + + String fqdn = publicIpAddress.fqdn(); + // Assert public load balancing connection + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url("http://" + fqdn) + .build(); + Response response = client.newCall(request).execute(); + Assert.assertEquals(response.code(), 200); + int startPort = 5000; + int endPort = 5001; + for (int port = startPort; port < endPort; port++) { + // Assert public ssh connection to vms + JSch jsch = new JSch(); + com.jcraft.jsch.Session session = null; + try { + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); + session = jsch.getSession("jvuser", fqdn, port); + session.setPassword("123OData!@#123!"); + session.setConfig(config); + session.connect(); + } catch (Exception e) { + Assert.fail("SSH connection failed" + e.getMessage()); + } finally { + if (session != null) { + session.disconnect(); + } + } + } + } + + @Test + public void canCreateVirtualMachineScaleSet() throws Exception { + final String vmss_name = ResourceNamer.randomResourceName("vmss", 10); + ResourceGroup resourceGroup = this.resourceManager.resourceGroups() + .define(RG_NAME) + .withRegion(LOCATION) + .create(); + + Network network = this.networkManager + .networks() + .define("vmssvnet") + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withAddressSpace("10.0.0.0/28") + .withSubnet("subnet1", "10.0.0.0/28") + .create(); + + LoadBalancer publicLoadBalancer = createInternetFacingLoadBalancer(resourceGroup, "1"); + List backends = new ArrayList<>(); + for (String backend : publicLoadBalancer.backends().keySet()) { + backends.add(backend); + } + Assert.assertTrue(backends.size() == 2); + + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() + .define(vmss_name) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) + .withExistingPrimaryNetworkSubnet(network, "subnet1") + .withPrimaryInternetFacingLoadBalancer(publicLoadBalancer) + .withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)) + .withoutPrimaryInternalLoadBalancer() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) + .withRootUserName("jvuser") + .withPassword("123OData!@#123") + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .withNewStorageAccount(ResourceNamer.randomResourceName("stg", 15)) + .create(); + + Assert.assertNull(virtualMachineScaleSet.primaryInternalLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerBackEnds().size() == 0); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerInboundNatPools().size() == 0); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternetFacingLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().size() == 2); + + Assert.assertNotNull(virtualMachineScaleSet.primaryNetwork()); + + Assert.assertEquals(virtualMachineScaleSet.vhdContainers().size(), 2); + Assert.assertEquals(virtualMachineScaleSet.sku(), VirtualMachineScaleSetSkuTypes.STANDARD_A0); + // Check defaults + Assert.assertTrue(virtualMachineScaleSet.upgradeModel() == UpgradeMode.AUTOMATIC); + Assert.assertEquals(virtualMachineScaleSet.capacity(), 2); + // Fetch the primary Virtual network + Network primaryNetwork = virtualMachineScaleSet.primaryNetwork(); + + String inboundNatPoolToRemove = null; + for (String inboundNatPoolName : + virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().keySet()) { + inboundNatPoolToRemove = inboundNatPoolName; + break; + } + + LoadBalancer internalLoadBalancer = createInternalLoadBalancer(resourceGroup, + primaryNetwork, + "1"); + + virtualMachineScaleSet + .update() + .withPrimaryInternalLoadBalancer(internalLoadBalancer) + .withoutPrimaryInternalLoadBalancerNatPools(inboundNatPoolToRemove) + .apply(); + + virtualMachineScaleSet = this.computeManager + .virtualMachineScaleSets() + .getByGroup(RG_NAME, vmss_name); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternetFacingLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternetFacingLoadBalancerInboundNatPools().size() == 1); + + Assert.assertNotNull(virtualMachineScaleSet.primaryInternalLoadBalancer()); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerBackEnds().size() == 2); + Assert.assertTrue(virtualMachineScaleSet.primaryInternalLoadBalancerInboundNatPools().size() == 2); + } + + private LoadBalancer createHttpLoadBalancers(ResourceGroup resourceGroup, + String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("extlb" + id + "-", 18); + final String publicIpName = "pip-" + loadBalancerName; + final String frontendName = loadBalancerName + "-FE1"; + final String backendPoolName = loadBalancerName + "-BAP1"; + final String natPoolName = loadBalancerName + "-INP1"; + + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .define(publicIpName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withLeafDomainLabel(publicIpName) + .create(); + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePublicFrontend(frontendName) + .withExistingPublicIpAddress(publicIpAddress) + .attach() + .defineBackend(backendPoolName) + .attach() + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(80) + .withProbe("httpProbe") + .withBackend(backendPoolName) + .attach() + .defineInboundNatPool(natPoolName) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(5000, 5099) + .withBackendPort(22) + .attach() + .create(); + return loadBalancer; + + } + + private LoadBalancer createInternetFacingLoadBalancer(ResourceGroup resourceGroup, String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("extlb" + id + "-", 18); + final String publicIpName = "pip-" + loadBalancerName; + final String frontendName = loadBalancerName + "-FE1"; + final String backendPoolName1 = loadBalancerName + "-BAP1"; + final String backendPoolName2 = loadBalancerName + "-BAP2"; + final String natPoolName1 = loadBalancerName + "-INP1"; + final String natPoolName2 = loadBalancerName + "-INP2"; + + PublicIpAddress publicIpAddress = this.networkManager.publicIpAddresses() + .define(publicIpName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .withLeafDomainLabel(publicIpName) + .create(); + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePublicFrontend(frontendName) + .withExistingPublicIpAddress(publicIpAddress) + .attach() + // Add two backend one per rule + .defineBackend(backendPoolName1) + .attach() + .defineBackend(backendPoolName2) + .attach() + // Add two probes one per rule + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + .defineHttpProbe("httpsProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(80) + .withProbe("httpProbe") + .withBackend(backendPoolName1) + .attach() + .defineLoadBalancingRule("httpsRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPort(443) + .withProbe("httpsProbe") + .withBackend(backendPoolName2) + .attach() + // Add two nat pools to enable direct VM connectivity to port SSH and 23 + .defineInboundNatPool(natPoolName1) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(5000, 5099) + .withBackendPort(22) + .attach() + .defineInboundNatPool(natPoolName2) + .withProtocol(TransportProtocol.TCP) + .withFrontend(frontendName) + .withFrontendPortRange(6000, 6099) + .withBackendPort(23) + .attach() + .create(); + return loadBalancer; + } + + private LoadBalancer createInternalLoadBalancer(ResourceGroup resourceGroup, + Network network, String id) throws Exception { + final String loadBalancerName = ResourceNamer.randomResourceName("InternalLb" + id + "-", 18); + final String privateFrontEndName = loadBalancerName + "-FE1"; + final String backendPoolName1 = loadBalancerName + "-BAP1"; + final String backendPoolName2 = loadBalancerName + "-BAP2"; + final String natPoolName1 = loadBalancerName + "-INP1"; + final String natPoolName2 = loadBalancerName + "-INP2"; + final String subnetName = "subnet1"; + + LoadBalancer loadBalancer = this.networkManager.loadBalancers() + .define(loadBalancerName) + .withRegion(LOCATION) + .withExistingResourceGroup(resourceGroup) + .definePrivateFrontend(privateFrontEndName) + .withExistingSubnet(network, subnetName) + .attach() + // Add two backend one per rule + .defineBackend(backendPoolName1) + .attach() + .defineBackend(backendPoolName2) + .attach() + // Add two probes one per rule + .defineHttpProbe("httpProbe") + .withRequestPath("/") + .attach() + .defineHttpProbe("httpsProbe") + .withRequestPath("/") + .attach() + // Add two rules that uses above backend and probe + .defineLoadBalancingRule("httpRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPort(1000) + .withProbe("httpProbe") + .withBackend(backendPoolName1) + .attach() + .defineLoadBalancingRule("httpsRule") + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPort(1001) + .withProbe("httpsProbe") + .withBackend(backendPoolName2) + .attach() + // Add two nat pools to enable direct VM connectivity to port 44 and 45 + .defineInboundNatPool(natPoolName1) + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPortRange(8000, 8099) + .withBackendPort(44) + .attach() + .defineInboundNatPool(natPoolName2) + .withProtocol(TransportProtocol.TCP) + .withFrontend(privateFrontEndName) + .withFrontendPortRange(9000, 9099) + .withBackendPort(45) + .attach() + .create(); + return loadBalancer; + } +} diff --git a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java index f4b84f344327b..975ed2ee34c4c 100644 --- a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java +++ b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java @@ -25,7 +25,7 @@ protected static void createClients() { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null); + AzureEnvironment.AZURE); RestClient restClient = AzureEnvironment.AZURE.newRestClientBuilder() .withCredentials(credentials)