use of com.microsoft.azure.toolkit.lib.compute.vm.DraftVirtualMachine in project azure-tools-for-java by Microsoft.
the class VMCreationDialog method getData.
@Override
public DraftVirtualMachine getData() {
final Subscription subscription = cbSubscription.getValue();
final String subscriptionId = Optional.ofNullable(subscription).map(Subscription::getId).orElse(StringUtils.EMPTY);
final ResourceGroup resourceGroup = cbResourceGroup.getValue();
final String resourceGroupName = Optional.ofNullable(resourceGroup).map(ResourceGroup::getName).orElse(StringUtils.EMPTY);
final String vmName = txtVisualMachineName.getText();
final DraftVirtualMachine draftVirtualMachine = new DraftVirtualMachine();
draftVirtualMachine.setSubscriptionId(subscriptionId);
draftVirtualMachine.setResourceGroup(resourceGroupName);
draftVirtualMachine.setName(vmName);
draftVirtualMachine.setRegion(cbRegion.getValue());
draftVirtualMachine.setNetwork(cbVirtualNetwork.getValue());
draftVirtualMachine.setSubnet(cbSubnet.getValue());
draftVirtualMachine.setImage(cbImage.getValue());
draftVirtualMachine.setIpAddress(cbPublicIp.getValue());
draftVirtualMachine.setUserName(txtUserName.getText());
if (rdoPassword.isSelected()) {
draftVirtualMachine.setAuthenticationType(AuthenticationType.Password);
draftVirtualMachine.setPassword(passwordFieldInput.getValue());
} else if (rdoSshPublicKey.isSelected()) {
draftVirtualMachine.setAuthenticationType(AuthenticationType.SSH);
try {
draftVirtualMachine.setSshKey(readCert(txtCertificate.getValue()));
} catch (final IOException e) {
// swallow exception while get data
}
}
draftVirtualMachine.setSize(cbSize.getValue());
draftVirtualMachine.setAvailabilitySet(cbAvailabilityOptions.getValue());
// Azure Spot
if (chkAzureSpotInstance.isSelected()) {
final AzureSpotConfig.EvictionType evictionType = AzureSpotConfig.EvictionType.CapacityOnly;
final AzureSpotConfig.EvictionPolicy evictionPolicy = rdoStopAndDeallocate.isSelected() ? AzureSpotConfig.EvictionPolicy.StopAndDeallocate : AzureSpotConfig.EvictionPolicy.Delete;
final double maximumPrice = Double.parseDouble(txtMaximumPrice.getText());
final AzureSpotConfig spotConfig = new AzureSpotConfig(maximumPrice, evictionType, evictionPolicy);
draftVirtualMachine.setAzureSpotConfig(spotConfig);
} else {
draftVirtualMachine.setAzureSpotConfig(null);
}
// Security Group
if (rdoAdvancedSecurityGroup.isSelected()) {
draftVirtualMachine.setSecurityGroup(cbSecurityGroup.getValue());
} else if (rdoBasicSecurityGroup.isSelected()) {
final DraftNetworkSecurityGroup draftNetworkSecurityGroup = new DraftNetworkSecurityGroup();
draftNetworkSecurityGroup.setSubscriptionId(subscriptionId);
draftNetworkSecurityGroup.setResourceGroup(resourceGroupName);
draftNetworkSecurityGroup.setName(vmName + "-sg" + Utils.getTimestamp());
draftNetworkSecurityGroup.setRegion(cbRegion.getValue());
draftNetworkSecurityGroup.setSecurityRuleList(pnlPorts.getData());
draftVirtualMachine.setSecurityGroup(draftNetworkSecurityGroup);
}
draftVirtualMachine.setStorageAccount(cbStorageAccount.getValue());
return draftVirtualMachine;
}
Aggregations