Search in sources :

Example 1 with DraftNetworkSecurityGroup

use of com.microsoft.azure.toolkit.lib.compute.security.DraftNetworkSecurityGroup 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)

Example 2 with DraftNetworkSecurityGroup

use of com.microsoft.azure.toolkit.lib.compute.security.DraftNetworkSecurityGroup in project azure-tools-for-java by Microsoft.

the class VMCreationDialog method setData.

@Override
public void setData(DraftVirtualMachine data) {
    Optional.ofNullable(data.getResourceGroup()).ifPresent(groupName -> cbResourceGroup.setValue(new AzureComboBox.ItemReference<>(group -> StringUtils.equalsIgnoreCase(group.getName(), groupName))));
    Optional.ofNullable(data.getSubscriptionId()).ifPresent(id -> cbSubscription.setValue(new AzureComboBox.ItemReference<>(subscription -> StringUtils.equalsIgnoreCase(subscription.getId(), id))));
    Optional.ofNullable(data.getName()).ifPresent(name -> txtVisualMachineName.setText(name));
    Optional.ofNullable(data.getRegion()).ifPresent(region -> cbRegion.setValue(region));
    Optional.ofNullable(data.getImage()).ifPresent(image -> cbImage.setValue(image));
    Optional.ofNullable(data.getSize()).ifPresent(size -> cbSize.setValue(size));
    Optional.ofNullable(data.getUserName()).ifPresent(name -> txtUserName.setText(name));
    cbAvailabilityOptions.setValue(data.getAvailabilitySet());
    // skip set value for password/cert
    Optional.ofNullable(data.getNetwork()).ifPresent(network -> cbVirtualNetwork.setData(network));
    Optional.ofNullable(data.getSubnet()).ifPresent(subnet -> cbSubnet.setValue(subnet));
    rdoNoneSecurityGroup.setSelected(data.getSecurityGroup() == null);
    Optional.ofNullable(data.getSecurityGroup()).ifPresent(networkSecurityGroup -> {
        if (networkSecurityGroup instanceof DraftNetworkSecurityGroup) {
            rdoBasicSecurityGroup.setSelected(true);
            final List<SecurityRule> securityRuleList = ((DraftNetworkSecurityGroup) networkSecurityGroup).getSecurityRuleList();
            rdoAllowSelectedInboundPorts.setSelected(!Collections.isEmpty(securityRuleList));
            pnlPorts.setData(securityRuleList);
            pnlBasicPorts.setData(securityRuleList);
        } else if (networkSecurityGroup.exists()) {
            rdoAdvancedSecurityGroup.setSelected(true);
            cbSecurityGroup.setData(networkSecurityGroup);
        }
    });
    cbPublicIp.setData(data.getIpAddress());
    cbStorageAccount.setData(data.getStorageAccount());
    final AzureSpotConfig azureSpotConfig = data.getAzureSpotConfig();
    if (azureSpotConfig == null) {
        chkAzureSpotInstance.setSelected(false);
    } else {
        chkAzureSpotInstance.setSelected(true);
        rdoStopAndDeallocate.setSelected(azureSpotConfig.getPolicy() != AzureSpotConfig.EvictionPolicy.StopAndDeallocate);
        rdoDelete.setSelected(azureSpotConfig.getPolicy() == AzureSpotConfig.EvictionPolicy.StopAndDeallocate);
        txtMaximumPrice.setText(String.valueOf(azureSpotConfig.getMaximumPrice()));
    }
}
Also used : AzureSpotConfig(com.microsoft.azure.toolkit.lib.compute.vm.model.AzureSpotConfig) SecurityRule(com.microsoft.azure.toolkit.lib.compute.security.model.SecurityRule) DraftNetworkSecurityGroup(com.microsoft.azure.toolkit.lib.compute.security.DraftNetworkSecurityGroup)

Aggregations

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