Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1286,9 +1286,15 @@ public VirtualMachineImpl withUnmanagedDisks() {
return this;
}

@Override
public VirtualMachineImpl withBootDiagnosticsOnManagedStorageAccount() {
this.bootDiagnosticsHandler.withBootDiagnostics(true);
return this;
}

@Override
public VirtualMachineImpl withBootDiagnostics() {
this.bootDiagnosticsHandler.withBootDiagnostics();
this.bootDiagnosticsHandler.withBootDiagnostics(false);
return this;
}

Expand Down Expand Up @@ -2627,9 +2633,14 @@ private StorageAccountTypes getDefaultStorageAccountType() {
private class BootDiagnosticsHandler {
private final VirtualMachineImpl vmImpl;
private String creatableDiagnosticsStorageAccountKey;
private boolean useManagedStorageAccount = false;

BootDiagnosticsHandler(VirtualMachineImpl vmImpl) {
this.vmImpl = vmImpl;
if (isBootDiagnosticsEnabled()
&& this.vmInner().diagnosticsProfile().bootDiagnostics().storageUri() == null) {
this.useManagedStorageAccount = true;
}
}

public boolean isBootDiagnosticsEnabled() {
Expand All @@ -2650,21 +2661,24 @@ public String bootDiagnosticsStorageUri() {
return null;
}

BootDiagnosticsHandler withBootDiagnostics() {
BootDiagnosticsHandler withBootDiagnostics(boolean useManagedStorageAccount) {
// Diagnostics storage uri will be set later by this.handleDiagnosticsSettings(..)
this.enableDisable(true);
this.useManagedStorageAccount = useManagedStorageAccount;
return this;
}

BootDiagnosticsHandler withBootDiagnostics(Creatable<StorageAccount> creatable) {
// Diagnostics storage uri will be set later by this.handleDiagnosticsSettings(..)
this.enableDisable(true);
this.useManagedStorageAccount = false;
this.creatableDiagnosticsStorageAccountKey = this.vmImpl.addDependency(creatable);
return this;
}

BootDiagnosticsHandler withBootDiagnostics(String storageAccountBlobEndpointUri) {
this.enableDisable(true);
this.useManagedStorageAccount = false;
this.vmInner().diagnosticsProfile().bootDiagnostics().withStorageUri(storageAccountBlobEndpointUri);
return this;
}
Expand All @@ -2675,10 +2689,15 @@ BootDiagnosticsHandler withBootDiagnostics(StorageAccount storageAccount) {

BootDiagnosticsHandler withoutBootDiagnostics() {
this.enableDisable(false);
this.useManagedStorageAccount = false;
return this;
}

void prepare() {
if (useManagedStorageAccount) {
return;
}

DiagnosticsProfile diagnosticsProfile = this.vmInner().diagnosticsProfile();
if (diagnosticsProfile == null
|| diagnosticsProfile.bootDiagnostics() == null
Expand Down Expand Up @@ -2719,6 +2738,10 @@ void prepare() {
}

void handleDiagnosticsSettings() {
if (useManagedStorageAccount) {
return;
}

DiagnosticsProfile diagnosticsProfile = this.vmInner().diagnosticsProfile();
if (diagnosticsProfile == null
|| diagnosticsProfile.bootDiagnostics() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2376,9 +2376,15 @@ private void throwIfManagedDiskDisabled(String message) {
}
}

@Override
public VirtualMachineScaleSetImpl withBootDiagnosticsOnManagedStorageAccount() {
this.bootDiagnosticsHandler.withBootDiagnostics(true);
return this;
}

@Override
public VirtualMachineScaleSetImpl withBootDiagnostics() {
this.bootDiagnosticsHandler.withBootDiagnostics();
this.bootDiagnosticsHandler.withBootDiagnostics(false);
return this;
}

Expand Down Expand Up @@ -2851,9 +2857,15 @@ private class BootDiagnosticsHandler {
private String creatableDiagnosticsStorageAccountKey;
private String creatableStorageAccountKey;
private StorageAccount existingStorageAccountToAssociate;
private boolean useManagedStorageAccount = false;

BootDiagnosticsHandler(VirtualMachineScaleSetImpl vmssImpl) {
this.vmssImpl = vmssImpl;
if (isBootDiagnosticsEnabled()
&& this.vmssInner().virtualMachineProfile()
.diagnosticsProfile().bootDiagnostics().storageUri() == null) {
this.useManagedStorageAccount = true;
}
}

public boolean isBootDiagnosticsEnabled() {
Expand All @@ -2875,23 +2887,26 @@ public String bootDiagnosticsStorageUri() {
return null;
}

BootDiagnosticsHandler withBootDiagnostics() {
BootDiagnosticsHandler withBootDiagnostics(boolean useManagedStorageAccount) {
// Diagnostics storage uri will be set later by this.handleDiagnosticsSettings(..)
//
this.enableDisable(true);
this.useManagedStorageAccount = useManagedStorageAccount;
return this;
}

BootDiagnosticsHandler withBootDiagnostics(Creatable<StorageAccount> creatable) {
// Diagnostics storage uri will be set later by this.handleDiagnosticsSettings(..)
//
this.enableDisable(true);
this.useManagedStorageAccount = false;
this.creatableDiagnosticsStorageAccountKey = this.vmssImpl.addDependency(creatable);
return this;
}

BootDiagnosticsHandler withBootDiagnostics(String storageAccountBlobEndpointUri) {
this.enableDisable(true);
this.useManagedStorageAccount = false;
this
.vmssInner()
.virtualMachineProfile()
Expand All @@ -2907,10 +2922,15 @@ BootDiagnosticsHandler withBootDiagnostics(StorageAccount storageAccount) {

BootDiagnosticsHandler withoutBootDiagnostics() {
this.enableDisable(false);
this.useManagedStorageAccount = false;
return this;
}

void prepare() {
if (useManagedStorageAccount) {
return;
}

this.creatableStorageAccountKey = null;
this.existingStorageAccountToAssociate = null;

Expand Down Expand Up @@ -2962,6 +2982,10 @@ void prepare() {
}

void handleDiagnosticsSettings() {
if (useManagedStorageAccount) {
return;
}

DiagnosticsProfile diagnosticsProfile = this.vmssInner().virtualMachineProfile().diagnosticsProfile();
if (diagnosticsProfile == null
|| diagnosticsProfile.bootDiagnostics() == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,14 @@ interface WithPlan {

/** The stage of the virtual machine definition allowing to enable boot diagnostics. */
interface WithBootDiagnostics {
/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
* Managed storage account is used.
*
* @return the next stage of the definition
*/
WithCreate withBootDiagnosticsOnManagedStorageAccount();

/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
*
Expand Down Expand Up @@ -1974,6 +1982,14 @@ interface WithExtension {

/** The stage of the virtual machine definition allowing to enable boot diagnostics. */
interface WithBootDiagnostics {
/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
* Managed storage account is used.
*
* @return the next stage of the update
*/
Update withBootDiagnosticsOnManagedStorageAccount();

/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,14 @@ interface WithUserAssignedManagedServiceIdentity {

/** The stage of the virtual machine scale set definition allowing to enable boot diagnostics. */
interface WithBootDiagnostics {
/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
* Managed storage account is used.
*
* @return the next stage of the definition
*/
WithCreate withBootDiagnosticsOnManagedStorageAccount();

/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine scale set.
*
Expand Down Expand Up @@ -2128,6 +2136,14 @@ interface WithUserAssignedManagedServiceIdentity {

/** The stage of the virtual machine scale set definition allowing to enable boot diagnostics. */
interface WithBootDiagnostics {
/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine.
* Managed storage account is used.
*
* @return the next stage of the update
*/
Update withBootDiagnosticsOnManagedStorageAccount();

/**
* Specifies that boot diagnostics needs to be enabled in the virtual machine scale set.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
import com.azure.resourcemanager.compute.models.VirtualMachine;
import com.azure.core.management.Region;
import com.azure.resourcemanager.compute.models.VirtualMachineSizeTypes;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.core.management.profile.AzureProfile;
import com.azure.resourcemanager.storage.models.StorageAccount;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void canEnableBootDiagnosticsWithImplicitStorageOnManagedVMCreation() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withBootDiagnostics()
.create();

Expand All @@ -69,7 +70,7 @@ public void canEnableBootDiagnosticsWithCreatableStorageOnManagedVMCreation() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withBootDiagnostics(creatableStorageAccount)
.create();
Assertions.assertNotNull(virtualMachine);
Expand Down Expand Up @@ -100,7 +101,7 @@ public void canEnableBootDiagnosticsWithExplicitStorageOnManagedVMCreation() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withBootDiagnostics(storageAccount)
.create();

Expand All @@ -123,7 +124,7 @@ public void canDisableBootDiagnostics() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withBootDiagnostics()
.create();

Expand Down Expand Up @@ -151,7 +152,7 @@ public void bootDiagnosticsShouldUsesOSUnManagedDiskImplicitStorage() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withUnmanagedDisks() // The implicit storage account for OS disk should be used for boot diagnostics as
// well
.withBootDiagnostics()
Expand Down Expand Up @@ -191,7 +192,7 @@ public void bootDiagnosticsShouldUseUnManagedDisksExplicitStorage() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withUnmanagedDisks()
.withBootDiagnostics()
.withExistingStorageAccount(
Expand All @@ -217,7 +218,7 @@ public void canEnableBootDiagnosticsWithImplicitStorageOnUnManagedVMCreation() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withUnmanagedDisks()
.create();

Expand Down Expand Up @@ -267,7 +268,7 @@ public void canEnableBootDiagnosticsWithCreatableStorageOnUnManagedVMCreation()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword(password())
.withSsh(sshPublicKey())
.withUnmanagedDisks()
.withBootDiagnostics(
creatableStorageAccount) // This storage account should be used for BDiagnostics not OS disk storage
Expand All @@ -285,4 +286,35 @@ public void canEnableBootDiagnosticsWithCreatableStorageOnUnManagedVMCreation()
.toLowerCase()
.startsWith(virtualMachine.bootDiagnosticsStorageUri().toLowerCase()));
}

@Test
public void canEnableBootDiagnosticsOnManagedStorageAccount() {
VirtualMachine virtualMachine =
computeManager
.virtualMachines()
.define(vmName)
.withRegion(region)
.withNewResourceGroup(rgName)
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("jvuser")
.withSsh(sshPublicKey())
.withBootDiagnosticsOnManagedStorageAccount()
.withSize(VirtualMachineSizeTypes.fromString("Standard_D2a_v4"))
.create();

Assertions.assertNotNull(virtualMachine);
Assertions.assertTrue(virtualMachine.isBootDiagnosticsEnabled());
Assertions.assertNull(virtualMachine.bootDiagnosticsStorageUri());

virtualMachine = computeManager.virtualMachines().getById(virtualMachine.id());
virtualMachine.update()
.withNewDataDisk(10)
.apply();

Assertions.assertTrue(virtualMachine.isBootDiagnosticsEnabled());
Assertions.assertNull(virtualMachine.bootDiagnosticsStorageUri());
}
}
Loading