use of com.azure.resourcemanager.network.models.PublicIpAddress in project terra-workspace-manager by DataBiosphere.
the class CreateAzureVmStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
ComputeManager computeManager = crlService.getComputeManager(azureCloudContext, azureConfig);
final ControlledAzureIpResource ipResource = resourceDao.getResource(resource.getWorkspaceId(), resource.getIpId()).castByEnum(WsmResourceType.CONTROLLED_AZURE_IP);
final ControlledAzureDiskResource diskResource = resourceDao.getResource(resource.getWorkspaceId(), resource.getDiskId()).castByEnum(WsmResourceType.CONTROLLED_AZURE_DISK);
final ControlledAzureNetworkResource networkResource = resourceDao.getResource(resource.getWorkspaceId(), resource.getNetworkId()).castByEnum(WsmResourceType.CONTROLLED_AZURE_NETWORK);
try {
Disk existingAzureDisk = computeManager.disks().getByResourceGroup(azureCloudContext.getAzureResourceGroupId(), diskResource.getDiskName());
PublicIpAddress existingAzureIp = computeManager.networkManager().publicIpAddresses().getByResourceGroup(azureCloudContext.getAzureResourceGroupId(), ipResource.getIpName());
Network existingNetwork = computeManager.networkManager().networks().getByResourceGroup(azureCloudContext.getAzureResourceGroupId(), networkResource.getNetworkName());
computeManager.virtualMachines().define(resource.getVmName()).withRegion(resource.getRegion()).withExistingResourceGroup(azureCloudContext.getAzureResourceGroupId()).withExistingPrimaryNetwork(existingNetwork).withSubnet(networkResource.getSubnetName()).withPrimaryPrivateIPAddressDynamic().withExistingPrimaryPublicIPAddress(existingAzureIp).withSpecializedLinuxCustomImage(resource.getVmImageUri()).withExistingDataDisk(existingAzureDisk).withTag("workspaceId", resource.getWorkspaceId().toString()).withTag("resourceId", resource.getResourceId().toString()).withSize(VirtualMachineSizeTypes.fromString(resource.getVmSize())).create(Defaults.buildContext(CreateVirtualMachineRequestData.builder().setName(resource.getVmName()).setRegion(Region.fromName(resource.getRegion())).setTenantId(azureCloudContext.getAzureTenantId()).setSubscriptionId(azureCloudContext.getAzureSubscriptionId()).setResourceGroupName(azureCloudContext.getAzureResourceGroupId()).setNetwork(existingNetwork).setSubnetName(networkResource.getSubnetName()).setDisk(existingAzureDisk).setPublicIpAddress(existingAzureIp).setImage(resource.getVmImageUri()).build()));
} catch (ManagementException e) {
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/common-deployment-errors
if (StringUtils.equals(e.getValue().getCode(), "Conflict")) {
logger.info("Azure Vm {} in managed resource group {} already exists", resource.getVmName(), azureCloudContext.getAzureResourceGroupId());
return StepResult.getStepResultSuccess();
}
if (StringUtils.equals(e.getValue().getCode(), "ResourceNotFound")) {
logger.info("Either the disk, ip, or network passed into this createVm does not exist " + String.format("%nResource Group: %s%n\tIp Name: %s%n\tNetwork Name: %s%n\tDisk Name: %s", azureCloudContext.getAzureResourceGroupId(), ipResource.getIpName(), "TODO", diskResource.getDiskName()));
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, e);
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.azure.resourcemanager.network.models.PublicIpAddress in project terra-cloud-resource-lib by DataBiosphere.
the class ComputeRequestDataTest method mockPublicIpAddress.
private static PublicIpAddress mockPublicIpAddress() {
PublicIpAddress mock = mock(PublicIpAddress.class);
when(mock.name()).thenReturn("my-ip");
return mock;
}
Aggregations