Skip to content

Commit

Permalink
Merge pull request #1249 from anuchandy/vm-miscellaneous
Browse files Browse the repository at this point in the history
Vm miscellaneous
  • Loading branch information
Martin Sawicki authored Oct 28, 2016
2 parents 845d4d8 + bb730c3 commit ece6b15
Show file tree
Hide file tree
Showing 26 changed files with 363 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,11 @@ interface Definition extends
DefinitionStages.WithPublicIpAddress,
DefinitionStages.WithPrimaryNetworkInterface,
DefinitionStages.WithOS,
DefinitionStages.WithRootUserName,
DefinitionStages.WithAdminUserName,
DefinitionStages.WithLinuxRootUsername,
DefinitionStages.WithLinuxRootPasswordOrPublicKey,
DefinitionStages.WithWindowsAdminUsername,
DefinitionStages.WithWindowsAdminPassword,
DefinitionStages.WithFromImageCreateOptions,
DefinitionStages.WithLinuxCreate,
DefinitionStages.WithWindowsCreate,
DefinitionStages.WithCreate {
Expand Down Expand Up @@ -406,7 +409,7 @@ interface WithOS {
* @param knownImage enum value indicating known market-place image
* @return the next stage of the virtual machine definition
*/
WithAdminUserName withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage);
WithWindowsAdminUsername withPopularWindowsImage(KnownWindowsVirtualMachineImage knownImage);

/**
* Specifies that the latest version of a marketplace Windows image needs to be used.
Expand All @@ -416,31 +419,31 @@ interface WithOS {
* @param sku specifies the SKU of the image
* @return the next stage of the virtual machine definition
*/
WithAdminUserName withLatestWindowsImage(String publisher, String offer, String sku);
WithWindowsAdminUsername 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 definition
*/
WithAdminUserName withSpecificWindowsImageVersion(ImageReference imageReference);
WithWindowsAdminUsername withSpecificWindowsImageVersion(ImageReference imageReference);

/**
* Specifies the user (generalized) Windows image used for the virtual machine's OS.
*
* @param imageUrl the url the the VHD
* @return the next stage of the virtual machine definition
*/
WithAdminUserName withStoredWindowsImage(String imageUrl);
WithWindowsAdminUsername 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 definition
*/
WithRootUserName withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage);
WithLinuxRootUsername withPopularLinuxImage(KnownLinuxVirtualMachineImage knownImage);

/**
* Specifies that the latest version of a marketplace Linux image needs to be used.
Expand All @@ -450,23 +453,23 @@ interface WithOS {
* @param sku specifies the SKU of the image
* @return the next stage of the virtual machine definition
*/
WithRootUserName withLatestLinuxImage(String publisher, String offer, String sku);
WithLinuxRootUsername 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 definition
*/
WithRootUserName withSpecificLinuxImageVersion(ImageReference imageReference);
WithLinuxRootUsername withSpecificLinuxImageVersion(ImageReference imageReference);

/**
* Specifies the user (generalized) Linux image used for the virtual machine's OS.
*
* @param imageUrl the url the the VHD
* @return the next stage of the virtual machine definition
*/
WithRootUserName withStoredLinuxImage(String imageUrl);
WithLinuxRootUsername withStoredLinuxImage(String imageUrl);

/**
* Specifies the specialized operating system disk to be attached to the virtual machine.
Expand All @@ -479,37 +482,106 @@ interface WithOS {
}

/**
* The stage of the Linux virtual machine definition allowing to specify root user name.
* The stage of the Linux virtual machine definition allowing to specify SSH root user name.
*/
interface WithRootUserName {
interface WithLinuxRootUsername {
/**
* Specifies the root user name for the Linux virtual machine.
* Specifies the SSH root user name for the Linux virtual machine.
*
* @param rootUserName the Linux root user name. This must follow the required naming convention for Linux user name
* @param rootUserName the Linux SSH root user name. This must follow the required naming convention for Linux user name
* @return the next stage of the Linux virtual machine definition
*/
WithLinuxCreate withRootUserName(String rootUserName);
WithLinuxRootPasswordOrPublicKey withRootUsername(String rootUserName);
}

/**
* The stage of the Linux virtual machine definition allowing to specify SSH root password or public key.
*/
interface WithLinuxRootPasswordOrPublicKey {
/**
* Specifies the SSH root password for the Linux virtual machine.
*
* @param rootPassword the SSH root password. This must follow the criteria for Azure Linux VM password.
* @return the next stage of the Linux virtual machine definition
*/
WithLinuxCreate withRootPassword(String rootPassword);

/**
* Specifies the SSH public key.
* <p>
* 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 next stage of the Linux virtual machine definition
*/
WithLinuxCreate withSsh(String publicKey);
}

/**
* The stage of the Windows virtual machine definition allowing to specify administrator user name.
*/
interface WithAdminUserName {
interface WithWindowsAdminUsername {
/**
* Specifies the administrator user name for the Windows virtual machine.
*
* @param adminUserName the Windows administrator user name. This must follow the required naming convention for Windows user name.
* @return the stage representing creatable Linux VM definition
*/
WithWindowsCreate withAdminUserName(String adminUserName);
WithWindowsAdminPassword withAdminUsername(String adminUserName);
}

/**
* The stage of the Windows virtual machine definition allowing to specify administrator user name.
*/
interface WithWindowsAdminPassword {
/**
* Specifies the administrator password for the Windows virtual machine.
*
* @param adminPassword the administrator password. This must follow the criteria for Azure Windows VM password.
* @return the stage representing creatable Windows VM definition
*/
WithWindowsCreate withAdminPassword(String adminPassword);
}

/**
* The stage of the virtual machine definition allowing to specify the custom data.
*/
interface WithCustomData {
/**
* Specifies the custom data for the virtual machine.
*
* @param base64EncodedCustomData the base64 encoded custom data
* @return the stage representing creatable Windows VM definition
*/
WithFromImageCreateOptions withCustomData(String base64EncodedCustomData);
}

/**
* The stage of the virtual machine definition allowing to specify the computer name.
*/
interface WithComputerName {
/**
* Specifies the computer name for the virtual machine.
*
* @param computerName the computer name
* @return the stage representing creatable VM definition
*/
WithFromImageCreateOptions withComputerName(String computerName);
}

/**
* The stages contains OS agnostics settings when virtual machine is created from image.
*/
interface WithFromImageCreateOptions extends
WithCustomData, WithComputerName, WithCreate {
}

/**
* The stage of the Linux virtual machine 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 {
interface WithLinuxCreate extends WithFromImageCreateOptions {
/**
* Specifies the SSH public key.
* <p>
Expand All @@ -526,22 +598,22 @@ interface WithLinuxCreate extends WithCreate {
* the resource to be created (via {@link WithCreate#create()}, but also allows
* for any other optional settings to be specified.
*/
interface WithWindowsCreate extends WithCreate {
interface WithWindowsCreate extends WithFromImageCreateOptions {
/**
* Specifies that VM Agent should not be provisioned.
*
* @return the stage representing creatable Windows VM definition
*/
@Method
WithWindowsCreate disableVmAgent();
WithWindowsCreate withoutVmAgent();

/**
* Specifies that automatic updates should be disabled.
*
* @return the stage representing creatable Windows VM definition
*/
@Method
WithWindowsCreate disableAutoUpdate();
WithWindowsCreate withoutAutoUpdate();

/**
* Specifies the time-zone.
Expand All @@ -562,19 +634,6 @@ interface WithWindowsCreate extends WithCreate {
WithWindowsCreate withWinRm(WinRMListener listener);
}

/**
* The stage of the virtual machine definition allowing to specify password.
*/
interface WithPassword {
/**
* Specifies the password for the virtual machine.
*
* @param password the password. This must follow the criteria for Azure VM password.
* @return the stage representing creatable VM definition
*/
WithCreate withPassword(String password);
}

/**
* The stage of the virtual machine definition allowing to specify OS disk configurations.
*/
Expand Down Expand Up @@ -810,7 +869,6 @@ interface WithExtension {
interface WithCreate extends
Creatable<VirtualMachine>,
Resource.DefinitionWithTags<WithCreate>,
DefinitionStages.WithPassword,
DefinitionStages.WithOsDiskSettings,
DefinitionStages.WithVMSize,
DefinitionStages.WithStorageAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ public VirtualMachineImpl withOsDisk(String osDiskUrl, OperatingSystemTypes osTy
//

@Override
public VirtualMachineImpl withRootUserName(String rootUserName) {
public VirtualMachineImpl withRootUsername(String rootUserName) {
this.inner().osProfile().withAdminUsername(rootUserName);
return this;
}

@Override
public VirtualMachineImpl withAdminUserName(String adminUserName) {
public VirtualMachineImpl withAdminUsername(String adminUserName) {
this.inner().osProfile().withAdminUsername(adminUserName);
return this;
}
Expand All @@ -451,13 +451,13 @@ public VirtualMachineImpl withSsh(String publicKeyData) {
}

@Override
public VirtualMachineImpl disableVmAgent() {
public VirtualMachineImpl withoutVmAgent() {
this.inner().osProfile().windowsConfiguration().withProvisionVMAgent(false);
return this;
}

@Override
public VirtualMachineImpl disableAutoUpdate() {
public VirtualMachineImpl withoutAutoUpdate() {
this.inner().osProfile().windowsConfiguration().withEnableAutomaticUpdates(false);
return this;
}
Expand All @@ -484,11 +484,29 @@ public VirtualMachineImpl withWinRm(WinRMListener listener) {
}

@Override
public VirtualMachineImpl withPassword(String password) {
public VirtualMachineImpl withRootPassword(String password) {
this.inner().osProfile().withAdminPassword(password);
return this;
}

@Override
public VirtualMachineImpl withAdminPassword(String password) {
this.inner().osProfile().withAdminPassword(password);
return this;
}

@Override
public VirtualMachineImpl withCustomData(String base64EncodedCustomData) {
this.inner().osProfile().withCustomData(base64EncodedCustomData);
return this;
}

@Override
public VirtualMachineImpl withComputerName(String computerName) {
this.inner().osProfile().withComputerName(computerName);
return this;
}

@Override
public VirtualMachineImpl withSize(String sizeName) {
this.inner().hardwareProfile().withVmSize(new VirtualMachineSizeTypes(sizeName));
Expand Down Expand Up @@ -625,10 +643,17 @@ public VirtualMachineImpl withNewAvailabilitySet(Creatable<AvailabilitySet> crea

@Override
public VirtualMachineImpl withNewAvailabilitySet(String name) {
return withNewAvailabilitySet(super.myManager.availabilitySets().define(name)
.withRegion(this.regionName())
.withExistingResourceGroup(this.resourceGroupName())
);
AvailabilitySet.DefinitionStages.WithGroup definitionWithGroup = super.myManager
.availabilitySets()
.define(name)
.withRegion(this.regionName());
Creatable<AvailabilitySet> definitionAfterGroup;
if (this.creatableGroup != null) {
definitionAfterGroup = definitionWithGroup.withNewResourceGroup(this.creatableGroup);
} else {
definitionAfterGroup = definitionWithGroup.withExistingResourceGroup(this.resourceGroupName());
}
return withNewAvailabilitySet(definitionAfterGroup);
}

@Override
Expand Down Expand Up @@ -732,6 +757,10 @@ public VirtualMachineImpl withoutExtension(String name) {

@Override
public String computerName() {
if (inner().osProfile() == null) {
// VM created by attaching a specialized OS Disk VHD will not have the osProfile.
return null;
}
return inner().osProfile().computerName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void canEnableDiagnosticsExtension() throws Exception {
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS)
.withRootUserName("Foo12")
.withPassword("BaR@12abc!")
.withRootUsername("Foo12")
.withRootPassword("BaR@12abc!")
.withSize(VirtualMachineSizeTypes.STANDARD_D3)
.withExistingStorageAccount(storageAccount)
.create();
Expand Down Expand Up @@ -88,8 +88,8 @@ public void canResetPasswordUsingVMAccessExtension() throws Exception {
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS)
.withRootUserName("Foo12")
.withPassword("BaR@12abc!")
.withRootUsername("Foo12")
.withRootPassword("BaR@12abc!")
.withSize(VirtualMachineSizeTypes.STANDARD_D3)
.create();

Expand Down Expand Up @@ -142,8 +142,8 @@ public void canInstallUninstallCustomExtension() throws Exception {
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS)
.withRootUserName("Foo12")
.withPassword("BaR@12abc!")
.withRootUsername("Foo12")
.withRootPassword("BaR@12abc!")
.withSize(VirtualMachineSizeTypes.STANDARD_D3)
.defineNewExtension("CustomScriptForLinux")
.withPublisher("Microsoft.OSTCExtensions")
Expand Down Expand Up @@ -187,8 +187,8 @@ public void canHandleExtensionReference() throws Exception {
.withPrimaryPrivateIpAddressDynamic()
.withoutPrimaryPublicIpAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS)
.withRootUserName("Foo12")
.withPassword("BaR@12abc!")
.withRootUsername("Foo12")
.withRootPassword("BaR@12abc!")
.withSize(VirtualMachineSizeTypes.STANDARD_D3)
.defineNewExtension("VMAccessForLinux")
.withPublisher("Microsoft.OSTCExtensions")
Expand Down
Loading

0 comments on commit ece6b15

Please sign in to comment.