Search in sources :

Example 1 with DraftVirtualMachine

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;
}
Also used : AzureSpotConfig(com.microsoft.azure.toolkit.lib.compute.vm.model.AzureSpotConfig) IOException(java.io.IOException) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) DraftVirtualMachine(com.microsoft.azure.toolkit.lib.compute.vm.DraftVirtualMachine) DraftNetworkSecurityGroup(com.microsoft.azure.toolkit.lib.compute.security.DraftNetworkSecurityGroup)

Aggregations

ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)1 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)1 DraftNetworkSecurityGroup (com.microsoft.azure.toolkit.lib.compute.security.DraftNetworkSecurityGroup)1 DraftVirtualMachine (com.microsoft.azure.toolkit.lib.compute.vm.DraftVirtualMachine)1 AzureSpotConfig (com.microsoft.azure.toolkit.lib.compute.vm.model.AzureSpotConfig)1 IOException (java.io.IOException)1