Search in sources :

Example 1 with VirtualMachineEvictionPolicyTypes

use of com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes in project azure-maven-plugins by microsoft.

the class DraftVirtualMachine method create.

VirtualMachine create(final AzureVirtualMachine module) {
    this.module = module;
    final NetworkInterface.DefinitionStages.WithCreate interfaceWithCreate = module.getVirtualMachinesManager(subscriptionId).manager().networkManager().networkInterfaces().define(name + "-interface-" + Utils.getTimestamp()).withRegion(this.getRegion().getName()).withExistingResourceGroup(this.getResourceGroup()).withExistingPrimaryNetwork(this.getNetworkClient()).withSubnet(subnet.getName()).withPrimaryPrivateIPAddressDynamic();
    if (ipAddress != null) {
        final com.azure.resourcemanager.network.models.PublicIpAddress publicIpAddressClient = getPublicIpAddressClient();
        if (publicIpAddressClient.hasAssignedNetworkInterface()) {
            AzureMessager.getMessager().warning(AzureString.format("Can not assign public ip %s to vm %s, which has been assigned to %s", ipAddress.getName(), name, publicIpAddressClient.getAssignedNetworkInterfaceIPConfiguration().name()));
        } else {
            interfaceWithCreate.withExistingPrimaryPublicIPAddress(getPublicIpAddressClient());
        }
    }
    if (securityGroup != null) {
        interfaceWithCreate.withExistingNetworkSecurityGroup(getSecurityGroupClient());
    }
    final NetworkInterface networkInterface = interfaceWithCreate.create();
    final WithProximityPlacementGroup withProximityPlacementGroup = module.getVirtualMachinesManager(subscriptionId).define(this.getName()).withRegion(this.getRegion().getName()).withExistingResourceGroup(this.getResourceGroup()).withExistingPrimaryNetworkInterface(networkInterface);
    final WithCreate withCreate = configureImage(withProximityPlacementGroup);
    if (StringUtils.isNotEmpty(availabilitySet)) {
        withCreate.withExistingAvailabilitySet(getAvailabilitySetClient());
    }
    if (storageAccount != null) {
        withCreate.withExistingStorageAccount(getStorageAccountClient());
    }
    if (azureSpotConfig != null) {
        final VirtualMachineEvictionPolicyTypes evictionPolicyTypes = azureSpotConfig.getPolicy() == StopAndDeallocate ? DEALLOCATE : DELETE;
        withCreate.withSpotPriority(evictionPolicyTypes).withMaxPrice(azureSpotConfig.getMaximumPrice());
    }
    try {
        this.remote = withCreate.create();
    } catch (Exception e) {
        // clean up resource once creation failed
        networkInterface.manager().networkInterfaces().deleteById(networkInterface.id());
        throw e;
    }
    refreshStatus();
    module.refresh();
    return this;
}
Also used : WithProximityPlacementGroup(com.azure.resourcemanager.compute.models.VirtualMachine.DefinitionStages.WithProximityPlacementGroup) WithCreate(com.azure.resourcemanager.compute.models.VirtualMachine.DefinitionStages.WithCreate) VirtualMachineEvictionPolicyTypes(com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes) NetworkInterface(com.azure.resourcemanager.network.models.NetworkInterface)

Aggregations

WithCreate (com.azure.resourcemanager.compute.models.VirtualMachine.DefinitionStages.WithCreate)1 WithProximityPlacementGroup (com.azure.resourcemanager.compute.models.VirtualMachine.DefinitionStages.WithProximityPlacementGroup)1 VirtualMachineEvictionPolicyTypes (com.azure.resourcemanager.compute.models.VirtualMachineEvictionPolicyTypes)1 NetworkInterface (com.azure.resourcemanager.network.models.NetworkInterface)1