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 000000000000..16ee6da1876f --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSet.java @@ -0,0 +1,846 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +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.Wrapper; +import com.microsoft.azure.management.storage.StorageAccount; + +import java.io.IOException; +import java.util.Map; + +/** + * An immutable client-side representation of an Azure virtual machine scale set. + */ +public interface VirtualMachineScaleSet extends + GroupableResource, + Refreshable, + Wrapper { + // 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; + + // 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 upgradePolicy + */ + UpgradePolicy upgradePolicy(); + + /** + * @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 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 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. + */ + interface Definition extends + DefinitionStages.Blank, + DefinitionStages.WithGroup, + DefinitionStages.WithSku, + DefinitionStages.WithNetwork, + DefinitionStages.WithSubnet, + 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. + */ + 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 + */ + WithNetwork 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 + */ + WithNetwork withSku(VirtualMachineScaleSetSku sku); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify virtual network for the primary + * network configuration. + */ + interface WithNetwork { + /** + * Create a new virtual network to associate with the primary network interface of virtual machines in the + * virtual machine scale set, based on the provided definition. + * + * @param creatable a creatable definition for a new virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(Creatable creatable); + + /** + * Creates a new virtual network to associate with the primary network interface of the virtual machines + * in the scale set. + *

+ * the virtual network will be created in the same resource group and region as of virtual machine scale set, + * it will be reated with the specified address space and a default subnet covering the entirety of the + * network IP address space. + *

+ * @param addressSpace the address space for the virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithPrimaryInternetFacingLoadBalancer withNewPrimaryNetwork(String addressSpace); + + /** + * Associate an existing virtual network with the primary network interface of the virtual machines + * in the scale set. + * + * @param network an existing virtual network + * @return the next stage of the virtual machine scale set definition + */ + WithSubnet withExistingPrimaryNetwork(Network network); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify virtual network subnet for the + * virtual machine's primary network interface in the scale set. + * + */ + interface WithSubnet { + /** + * Associates a subnet with the primary network interface of virtual machines in the scale set. + * + * @param name the subnet name + * @return the next stage of the definition + */ + WithPrimaryInternetFacingLoadBalancer withSubnet(String name); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify a public load balancer for + * the primary network interface configuration. + */ + interface WithPrimaryInternetFacingLoadBalancer { + /** + * Specify the public load balancer where it's backends and/or NAT pools can be assigned to the primary network + * interface configuration of virtual machine scale set. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface configuration unless one of them is selected in the next stage + * {@link WithInternalLoadBalancerBackendOrNatPool}. + *

+ * @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 configuration. + */ + interface WithPrimaryInternalLoadBalancer { + /** + * Specify the internal load balancer where it's backends and/or NAT pools can be assigned to the primary + * network interface configuration of the virtual machine scale set. + *

+ * By default all the backend and inbound NAT pool of the load balancer will be associated with the primary + * network interface configuration unless one of them is selected in the next stage + * {@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 virtual machine 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 configuration. + */ + interface WithPrimaryInternetFacingLoadBalancerBackendOrNatPool extends WithPrimaryInternetFacingLoadBalancerNatPool { + /** + * Associate internet facing load balancer backends with the primary network interface configuration of the + * virtual machine scale set. + * + * @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 configuration. + */ + interface WithPrimaryInternetFacingLoadBalancerNatPool extends WithPrimaryInternalLoadBalancer { + /** + * Associate internet facing load balancer inbound NAT pools with the to the primary network interface + * configuration of the virtual machine scale set. + * + * @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 configuration. + */ + interface WithInternalLoadBalancerBackendOrNatPool extends WithCreate { + /** + * Associates internal load balancer backend pools with the primary network interface configuration + * of the virtual machine scale set. + * + * @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 assign inbound NAT pool of the internal + * load balancer selected in the previous state {@link WithPrimaryInternalLoadBalancer} with the + * primary network interface configuration. + */ + interface WithInternalInternalLoadBalancerNatPool extends WithOS { + /** + * Associates internal load balancer inbound NAT pools with the primary network interface configuration + * of the virtual machine scale set. + * + * @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 not be provisioned. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate disableVmAgent(); + + /** + * Specifies that automatic updates should be disabled. + * + * @return the stage representing creatable Windows VM scale set definition + */ + WithWindowsCreate disableAutoUpdate(); + + /** + * 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 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(long capacity); + } + + /** + * The stage of the virtual machine scale set definition allowing to specify upgrade policy. + */ + interface WithUpgradePolicy { + /** + * Specifies virtual machine scale set upgrade policy. + * + * @param upgradePolicy upgrade policy + * @return the stage representing creatable VM scale set definition + */ + WithCreate withUpgradePolicy(UpgradePolicy upgradePolicy); + } + + /** + * 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, + WithCapacity, + DefinitionStages.WithOverProvision, + DefinitionStages.WithStorageAccount, + DefinitionStages.WithExtension, + Resource.DefinitionWithTags { + } + } + + /** + * Grouping of virtual machine scale set update stages. + */ + interface UpdateStages { + /** + * The stage of the virtual machine scale set definition allowing to update 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 + */ + Update 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 + */ + Update 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 + */ + Update withCapacity(long 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 + */ + Update 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 + */ + Update 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 + */ + Update 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 + */ + Update withoutPrimaryInternetFacingLoadBalancerBackend(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 + */ + Update withoutPrimaryInternalLoadBalancerBackend(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 + */ + Update withoutPrimaryInternetFacingLoadBalancerNatPool(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 + */ + Update withoutPrimaryInternalLoadBalancerNatPool(String ...natPoolNames); + } + } + + /** + * The entirety of the load balancer update. + */ + interface Update extends + Appliable, + Resource.UpdateWithTags, + UpdateStages.WithSku, + UpdateStages.WithCapacity, + UpdateStages.WithExtension, + UpdateStages.WithoutPrimaryLoadBalancer, + UpdateStages.WithoutPrimaryLoadBalancerBackend, + UpdateStages.WithoutPrimaryLoadBalancerNatPool { + } +} \ 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 000000000000..576b76cd65f1 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetExtension.java @@ -0,0 +1,463 @@ +package com.microsoft.azure.management.compute; + +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 }. + */ +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(); + + /** + * Grouping of virtual machine scale set extension definition stages as a part of parent virtual machine scale set definition. + */ + 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); + } + } + + /** + * 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()} + */ + 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 part of parent virtual machine scale set update. + */ + 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()} + */ + interface UpdateDefinition extends + UpdateDefinitionStages.Blank, + UpdateDefinitionStages.WithImageOrPublisher, + UpdateDefinitionStages.WithPublisher, + UpdateDefinitionStages.WithType, + UpdateDefinitionStages.WithVersion, + UpdateDefinitionStages.WithAttach { + } + + /** + * Grouping of virtual machine extension update stages. + */ + 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. + */ + 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 000000000000..8fa9043c887c --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSku.java @@ -0,0 +1,21 @@ +package com.microsoft.azure.management.compute; + +/** + * A type representing sku available for virtual machines in a scale set. + */ +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 000000000000..19397a1687a4 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetSkuTypes.java @@ -0,0 +1,244 @@ +package com.microsoft.azure.management.compute; + +/** + * Scale set virtual machine sku types. + */ +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 VirtualMachineSizeTypes)) { + 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 000000000000..15bf4d10ecdf --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/VirtualMachineScaleSets.java @@ -0,0 +1,10 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; + +/** + * Entry point to virtual machine scale set management API. + */ +public interface VirtualMachineScaleSets extends + SupportsCreating { +} 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 50744531ae9a..e48c6854dc8b 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 000000000000..eb1424403777 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetExtensionImpl.java @@ -0,0 +1,174 @@ +package com.microsoft.azure.management.compute.implementation; + +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}. + */ +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 000000000000..c306f08ca66c --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetImpl.java @@ -0,0 +1,1250 @@ +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.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.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.InboundNatPool; +import com.microsoft.azure.management.network.LoadBalancer; +import com.microsoft.azure.management.network.Network; +import com.microsoft.azure.management.network.Subnet; +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}. + */ +public class VirtualMachineScaleSetImpl + extends GroupableParentResourceImpl< + VirtualMachineScaleSet, + VirtualMachineScaleSetInner, + VirtualMachineScaleSetImpl, + ComputeManager> + implements + VirtualMachineScaleSet, + VirtualMachineScaleSet.Definition { + + // 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; + // the name of the virtual machine scale set + private final String scaleSetName; + // Name of the container to store virtual machines disks + private String vhdContainerName; + private boolean isMarketplaceLinuxImage = false; + // reference to the primary internet facing load balancer + private LoadBalancer primaryInternetFacingLoadBalancer; + // reference to the primary internal load balancer + private LoadBalancer primaryInternalLoadBalancer; + // unique key of a creatable network that needs to be used in virtual machine's primary network interface + private String creatablePrimaryNetworkKey; + // reference to an existing network that needs to be used in virtual machine's primary network interface + private Network existingPrimaryNetworkToAssociate; + // name of an existing subnet in the network to use + private String existingSubnetNameToAssociate; + // 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<>(); + private Map extensions; + private PagedListConverter skuConverter; + // 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<>(); + + + 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.scaleSetName = name; + this.namer = new ResourceNamer(this.scaleSetName); + 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 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 UpgradePolicy upgradePolicy() { + return this.inner().upgradePolicy(); + } + + @Override + public boolean overProvisionEnabled() { + return this.inner().overProvision(); + } + + @Override + public VirtualMachineScaleSetSkuTypes sku() { + return new VirtualMachineScaleSetSkuTypes(this.inner().sku()); + } + + @Override + public LoadBalancer primaryInternetFacingLoadBalancer() throws IOException { + 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 { + 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 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 withNewPrimaryNetwork(Creatable creatable) { + this.addCreatableDependency(creatable); + this.creatablePrimaryNetworkKey = creatable.key(); + return this; + } + + @Override + public VirtualMachineScaleSetImpl withNewPrimaryNetwork(String addressSpace) { + Network.DefinitionStages.WithGroup definitionWithGroup = this.networkManager + .networks() + .define(this.namer.randomName("vnet", 20)) + .withRegion(this.region()); + Network.DefinitionStages.WithCreate definitionAfterGroup; + if (this.creatableGroup != null) { + definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup); + } else { + definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName()); + } + return withNewPrimaryNetwork(definitionAfterGroup.withAddressSpace(addressSpace)); + } + + @Override + public VirtualMachineScaleSetImpl withExistingPrimaryNetwork(Network network) { + this.existingPrimaryNetworkToAssociate = network; + return this; + } + + @Override + public VirtualMachineScaleSetImpl withSubnet(String name) { + this.existingSubnetNameToAssociate = name; + 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"); + } + if (isInCreateMode()) { + this.primaryInternalLoadBalancer = loadBalancer; + associateLoadBalancerToIpConfiguration(this.primaryInternalLoadBalancer, + this.primaryNicDefaultIPConfiguration()); + } else { + 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 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() + .withAdminPassword(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 disableVmAgent() { + this.inner() + .virtualMachineProfile() + .osProfile().windowsConfiguration().withProvisionVMAgent(false); + return this; + } + + @Override + public VirtualMachineScaleSetImpl disableAutoUpdate() { + 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 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(long capacity) { + this.inner() + .sku().withCapacity(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(), this); + } + + protected VirtualMachineScaleSetImpl withExtension(VirtualMachineScaleSetExtensionImpl extension) { + this.extensions.put(extension.name(), extension); + 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(), scaleSetName, inner()); + } + }); + } + + @Override + protected void afterCreating() { + this.clearCachedProperties(); + this.initializeChildrenFromInner(); + } + + @Override + public Observable applyAsync() { + return this.createAsync(); + } + + @Override + public VirtualMachineScaleSetImpl refresh() throws Exception { + 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; + } + + 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.scaleSetName + "-os-disk"); + } + + if (osProfile.computerNamePrefix() == null) { + // VM name cannot contain only numeric values and cannot exceed 15 chars + if (this.scaleSetName.matches("[0-9]+")) { + osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } else if (this.scaleSetName.length() <= 12) { + osProfile.withComputerNamePrefix(this.scaleSetName + "-vm"); + } else { + osProfile.withComputerNamePrefix(ResourceNamer.randomResourceName("vmss-vm", 12)); + } + } + } + + private boolean isCustomImage(VirtualMachineScaleSetStorageProfile storageProfile) { + return storageProfile.osDisk().image() == null + || storageProfile.osDisk().image().uri() == null + || storageProfile.osDisk().image().uri() == ""; + } + + 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(storageAccount.endPoints().primary().blob() + "/" + containerName); + vhdContainerName = null; + 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(storageAccount.endPoints().primary().blob() + "/" + containerName); + } + + for (StorageAccount storageAccount : this.existingStorageAccountsToAssociate) { + storageProfile.osDisk() + .vhdContainers() + .add(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(); + if (this.creatablePrimaryNetworkKey != null) { + Network primaryNetwork = (Network) this.createdResource(this.creatablePrimaryNetworkKey); + for (Subnet subnet : primaryNetwork.subnets().values()) { + ipConfig.withSubnet(new ApiEntityReference().withId(subnet.inner().id())); + } + } else if (this.existingPrimaryNetworkToAssociate != null) { + ipConfig.withSubnet(new ApiEntityReference().withId(this.existingPrimaryNetworkToAssociate.id() + + "/" + + "subnets" + + "/" + + existingSubnetNameToAssociate)); + } + this.creatablePrimaryNetworkKey = null; + this.existingPrimaryNetworkToAssociate = 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; + } + + 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()) { + 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()); + } + } + } + } + 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 = 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 = 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 = 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 = 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 toRemoveIndicies = new ArrayList<>(); + int i = 0; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemoveIndicies.add(i); + } + i++; + } + + for (Integer index : toRemoveIndicies) { + ipConfig.loadBalancerBackendAddressPools().remove(index); + } + } + + private static void removeAllInboundNatPoolAssociationFromIpConfiguration(LoadBalancer loadBalancer, + VirtualMachineScaleSetIPConfigurationInner ipConfig) { + List toRemoveIndices = new ArrayList<>(); + int i = 0; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + if (subResource.id().toLowerCase().startsWith(loadBalancer.id().toLowerCase() + "/")) { + toRemoveIndices.add(i); + } + i++; + } + + for (Integer index : toRemoveIndices) { + ipConfig.loadBalancerInboundNatPools().remove(index); + } + } + + private static void removeBackendsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... backendNames) { + List toRemoveIndices = new ArrayList<>(); + for (String backendName : backendNames) { + String backendPoolId = loadBalancerId + "/" + "backendAddressPools" + "/" + backendName; + int index = -1; + for (SubResource subResource : ipConfig.loadBalancerBackendAddressPools()) { + index++; + if (subResource.id().equalsIgnoreCase(backendPoolId)) { + toRemoveIndices.add(index); + break; + } + } + } + + for (Integer index : toRemoveIndices) { + ipConfig.loadBalancerBackendAddressPools().remove(index); + } + } + + private static void removeInboundNatPoolsFromIpConfiguration(String loadBalancerId, + VirtualMachineScaleSetIPConfigurationInner ipConfig, + String... inboundNatPoolNames) { + List toRemoveIndices = new ArrayList<>(); + for (String natPoolName : inboundNatPoolNames) { + String inboundNatPoolId = loadBalancerId + "/" + "inboundNatPools" + "/" + natPoolName; + int index = -1; + for (SubResource subResource : ipConfig.loadBalancerInboundNatPools()) { + index++; + if (subResource.id().equalsIgnoreCase(inboundNatPoolId)) { + toRemoveIndices.add(index); + break; + } + } + } + + for (Integer index : toRemoveIndices) { + ipConfig.loadBalancerInboundNatPools().remove(index); + } + } + + private static void addToList(List list, T...items) { + for (T item : items) { + list.add(item); + } + } +} 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 000000000000..65fbde3779a5 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetSkuImpl.java @@ -0,0 +1,33 @@ +package com.microsoft.azure.management.compute.implementation; + +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}. + */ +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 000000000000..eb7bfb2bd4f9 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/VirtualMachineScaleSetsImpl.java @@ -0,0 +1,100 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.CloudException; +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.collection.implementation.GroupableResourcesImpl; +import com.microsoft.azure.management.storage.implementation.StorageManager; + +import java.io.IOException; +import java.util.ArrayList; + +/** + * The implementation for {@link VirtualMachineScaleSets}. + */ +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 VirtualMachineScaleSetImpl define(String name) { + return wrapModel(name); + } + + @Override + public VirtualMachineScaleSet getByGroup(String groupName, String name) throws CloudException, IOException { + return null; + } + + @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()); + + 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/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeManagementTestBase.java index d592d2da2a92..f09de6974309 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,6 +3,7 @@ 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 okhttp3.logging.HttpLoggingInterceptor; @@ -10,6 +11,7 @@ public abstract class ComputeManagementTestBase { protected static ResourceManager resourceManager; protected static ComputeManager computeManager; + protected static NetworkManager networkManager; public static void createClients() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( @@ -29,5 +31,8 @@ public static void createClients() { computeManager = ComputeManager .authenticate(restClient, System.getenv("subscription-id")); + + networkManager = NetworkManager + .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 000000000000..db62c21beaf1 --- /dev/null +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/VirtualMachineScaleSetOperationsTests.java @@ -0,0 +1,58 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.resources.ResourceGroup; +import org.junit.AfterClass; +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 = "javacsmrg"; + private static final String LOCATION = "southcentralus"; + private static final String VMSCALESETNAME = "javavm"; + + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + resourceManager.resourceGroups().delete(RG_NAME); + } + + @Test + public void canCreateVirtualMachineScaleSet() throws Exception { + final String mySqlInstallScript = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/4397e808d07df60ff3cdfd1ae40999f0130eb1b3/mysql-standalone-server-ubuntu/scripts/install_mysql_server_5.6.sh"; + final String installCommand = "bash install_mysql_server_5.6.sh Abc.123x("; + List fileUris = new ArrayList<>(); + fileUris.add(mySqlInstallScript); + + ResourceGroup.DefinitionStages.WithCreate resourceGroupCreatable = this.resourceManager.resourceGroups() + .define(RG_NAME) + .withRegion(LOCATION); + + VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets() + .define(VMSCALESETNAME) + .withRegion(LOCATION) + .withNewResourceGroup(resourceGroupCreatable) + .withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0) + .withNewPrimaryNetwork("10.0.0.0/28") + .withoutPrimaryInternetFacingLoadBalancer() + .withoutPrimaryInternalLoadBalancer() + .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) + .withRootUserName("jvuser") + .withPassword("123OData!@#123") + .defineNewExtension("CustomScriptForLinux") + .withPublisher("Microsoft.OSTCExtensions") + .withType("CustomScriptForLinux") + .withVersion("1.4") + .withAutoUpgradeMinorVersionEnabled() + .withPublicSetting("fileUris",fileUris) + .withPublicSetting("commandToExecute", installCommand) + .attach() + .create(); + } +}