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 @@ -3,6 +3,7 @@
package com.azure.resourcemanager.compute.implementation;

import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.management.AzureEnvironment;
import com.azure.core.management.SubResource;
import com.azure.core.util.logging.ClientLogger;
Expand Down Expand Up @@ -72,7 +73,10 @@
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceId;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.GroupableResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.model.Accepted;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.model.Indexable;
import com.azure.resourcemanager.resources.fluentcore.model.implementation.AcceptedImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceNamer;
import com.azure.resourcemanager.resources.fluentcore.utils.Utils;
import com.azure.resourcemanager.storage.models.StorageAccount;
Expand All @@ -83,10 +87,12 @@
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -110,6 +116,7 @@ class VirtualMachineImpl
// Clients
private final StorageManager storageManager;
private final NetworkManager networkManager;
private final AuthorizationManager authorizationManager;
// the name of the virtual machine
private final String vmName;
// used to generate unique name for any dependency resources
Expand Down Expand Up @@ -184,6 +191,7 @@ public JsonProperty.Access findPropertyAccess(Annotated annotated) {
super(name, innerModel, computeManager);
this.storageManager = storageManager;
this.networkManager = networkManager;
this.authorizationManager = authorizationManager;
this.vmName = name;
this.isMarketplaceLinuxImage = false;
this.namer = this.manager().sdkContext().getResourceNamerFactory().createResourceNamer(this.vmName);
Expand Down Expand Up @@ -1675,6 +1683,16 @@ public void beforeGroupCreateOrUpdate() {
@Override
public Mono<VirtualMachine> createResourceAsync() {
// -- set creation-time only properties
return prepareCreateResourceAsync()
.flatMap(virtualMachine -> this.manager().inner().getVirtualMachines()
.createOrUpdateAsync(resourceGroupName(), vmName, inner())
.map(virtualMachineInner -> {
reset(virtualMachineInner);
return this;
}));
}

private Mono<VirtualMachine> prepareCreateResourceAsync() {
setOSDiskDefaults();
setOSProfileDefaults();
setHardwareProfileDefaults();
Expand All @@ -1686,27 +1704,44 @@ public Mono<VirtualMachine> createResourceAsync() {
this.handleUnManagedOSAndDataDisksStorageSettings();
this.bootDiagnosticsHandler.handleDiagnosticsSettings();
this.handleNetworkSettings();
final VirtualMachineImpl self = this;
return this
.createNewProximityPlacementGroupAsync()
.flatMap(
.map(
virtualMachine -> {
this.handleAvailabilitySettings();
this.virtualMachineMsiHandler.processCreatedExternalIdentities();
this.virtualMachineMsiHandler.handleExternalIdentities();
return this
.manager()
.inner()
.getVirtualMachines()
.createOrUpdateAsync(resourceGroupName(), vmName, inner())
.map(
virtualMachineInner -> {
reset(virtualMachineInner);
return self;
});
return virtualMachine;
});
}

public Accepted<VirtualMachine> beginCreate() {
Flux<Indexable> dependencyTasksAsync = taskGroup().invokeDependencyAsync(taskGroup().newInvocationContext());
dependencyTasksAsync.blockLast();

// same as createResourceAsync
prepareCreateResourceAsync().block();

Response<Flux<ByteBuffer>> activationResponse = this.manager().inner().getVirtualMachines()
.createOrUpdateWithResponseAsync(resourceGroupName(), vmName, inner()).block();

if (activationResponse == null) {
throw logger.logExceptionAsError(new NullPointerException());
} else {
Accepted<VirtualMachine> accepted = new AcceptedImpl<VirtualMachineInner, VirtualMachine>(
activationResponse,
this.manager().inner().getSerializerAdapter(),
this.manager().inner().getHttpPipeline(),
VirtualMachineInner.class,
VirtualMachineInner.class,
inner -> new VirtualMachineImpl(inner.name(), inner, this.manager(),
this.storageManager, this.networkManager, this.authorizationManager));

reset(accepted.getAcceptedResult().getValue().inner());
return accepted;
}
}

@Override
public Mono<VirtualMachine> updateResourceAsync() {
if (isManagedDiskEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
package com.azure.resourcemanager.compute.implementation;

import com.azure.core.http.rest.Response;
import com.azure.core.util.logging.ClientLogger;
import com.azure.resourcemanager.compute.ComputeManager;
import com.azure.resourcemanager.compute.models.HardwareProfile;
Expand All @@ -21,12 +22,19 @@
import com.azure.resourcemanager.authorization.AuthorizationManager;
import com.azure.resourcemanager.network.NetworkManager;
import com.azure.resourcemanager.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl;
import com.azure.resourcemanager.resources.fluentcore.model.Accepted;
import com.azure.resourcemanager.resources.fluentcore.model.implementation.AcceptedImpl;
import com.azure.resourcemanager.storage.StorageManager;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import reactor.core.Exceptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/** The implementation for VirtualMachines. */
Expand Down Expand Up @@ -197,6 +205,22 @@ public Mono<RunCommandResult> runCommandAsync(String groupName, String name, Run
return this.inner().runCommandAsync(groupName, name, inputCommand).map(RunCommandResultImpl::new);
}

@Override
public Accepted<Void> beginDeleteByResourceGroup(String resourceGroupName, String name) {
Response<Flux<ByteBuffer>> activationResponse =
this.inner().deleteWithResponseAsync(resourceGroupName, name).block();
if (activationResponse == null) {
throw logger.logExceptionAsError(new NullPointerException());
} else {
return new AcceptedImpl<Void, Void>(activationResponse,
manager().inner().getSerializerAdapter(),
manager().inner().getHttpPipeline(),
Void.class,
Void.class,
Function.identity());
}
}

// Getters
@Override
public VirtualMachineSizes sizes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.azure.resourcemanager.resources.fluentcore.arm.AvailabilityZoneId;
import com.azure.resourcemanager.resources.fluentcore.arm.models.GroupableResource;
import com.azure.resourcemanager.resources.fluentcore.arm.models.Resource;
import com.azure.resourcemanager.resources.fluentcore.model.Accepted;
import com.azure.resourcemanager.resources.fluentcore.model.Appliable;
import com.azure.resourcemanager.resources.fluentcore.model.Creatable;
import com.azure.resourcemanager.resources.fluentcore.model.Refreshable;
Expand Down Expand Up @@ -1636,6 +1637,13 @@ interface WithCreate
DefinitionStages.WithSystemAssignedManagedServiceIdentity,
DefinitionStages.WithUserAssignedManagedServiceIdentity,
DefinitionStages.WithLicenseType {

/**
* Begins creating the virtual machine resource.
*
* @return the accepted create operation
*/
Accepted<VirtualMachine> beginCreate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsCreating;
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsDeletingById;
import com.azure.resourcemanager.resources.fluentcore.collection.SupportsListing;
import com.azure.resourcemanager.resources.fluentcore.model.Accepted;
import com.azure.resourcemanager.resources.fluentcore.model.HasInner;
import java.util.List;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -248,4 +249,13 @@ Mono<RunCommandResult> runShellScriptAsync(
* @return handle to the asynchronous execution
*/
Mono<RunCommandResult> runCommandAsync(String groupName, String name, RunCommandInput inputCommand);

/**
* Begins deleting a virtual machine from Azure, identifying it by its name and its resource group.
*
* @param resourceGroupName the resource group the resource is part of
* @param name the virtual machine name
* @return the accepted deleting operation
*/
Accepted<Void> beginDeleteByResourceGroup(String resourceGroupName, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void canCreateZonedVirtualMachineWithImplicitZoneForRelatedResources() th
.withNewProximityPlacementGroup(proxyGroupName, ProximityPlacementGroupType.STANDARD)
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
// Optionals
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
Expand Down Expand Up @@ -165,7 +165,7 @@ public void canCreateZonedVirtualMachineWithExplicitZoneForRelatedResources() th
.withExistingPrimaryPublicIPAddress(publicIPAddress)
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
// Optionals
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
.withExistingDataDisk(dataDisk)
Expand Down Expand Up @@ -244,7 +244,7 @@ public void canCreateZonedVirtualMachineWithZoneResilientPublicIP() throws Excep
.withExistingPrimaryPublicIPAddress(publicIPAddress)
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
// Optionals
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
Expand Down Expand Up @@ -301,7 +301,7 @@ public void canCreateZonedVirtualMachineWithZoneResilientPublicIP() throws Excep
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
// Optionals
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2);

Expand All @@ -319,7 +319,7 @@ public void canCreateZonedVirtualMachineWithZoneResilientPublicIP() throws Excep
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
// Optionals
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2);

Expand Down Expand Up @@ -454,7 +454,7 @@ public void canCreateZonedVirtualMachinesAndAssociateThemWithSingleBackendPoolOf
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
// Optionals
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2);
Expand All @@ -473,7 +473,7 @@ public void canCreateZonedVirtualMachinesAndAssociateThemWithSingleBackendPoolOf
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withAvailabilityZone(AvailabilityZoneId.ZONE_1)
// Optionals
.withSize(VirtualMachineSizeTypes.STANDARD_D3_V2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void canEnableBootDiagnosticsWithImplicitStorageOnManagedVMCreation() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withBootDiagnostics()
.create();

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

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

Expand Down Expand Up @@ -267,7 +267,7 @@ public void canEnableBootDiagnosticsWithCreatableStorageOnUnManagedVMCreation()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withUnmanagedDisks()
.withBootDiagnostics(
creatableStorageAccount) // This storage account should be used for BDiagnostics not OS disk storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void canCreateUpdateVirtualMachineWithEMSI() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withExistingUserAssignedManagedServiceIdentity(createdIdentity)
.withNewUserAssignedManagedServiceIdentity(creatableIdentity)
.create();
Expand Down Expand Up @@ -315,7 +315,7 @@ public void canCreateVirtualMachineWithLMSIAndEMSI() {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.withSystemAssignedManagedServiceIdentity()
.withSystemAssignedIdentityBasedAccessTo(network.id(), BuiltInRole.CONTRIBUTOR)
.withNewUserAssignedManagedServiceIdentity(creatableIdentity)
Expand Down Expand Up @@ -418,7 +418,7 @@ public void canUpdateVirtualMachineWithEMSIAndLMSI() throws Exception {
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
.withRootUsername("Foo12")
.withRootPassword("abc!@#F0orL")
.withRootPassword(password())
.create();

// Prepare a definition for yet-to-be-created "User Assigned (External) MSI" with contributor access to the
Expand Down
Loading