Search in sources :

Example 26 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription 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 27 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class VMCreationDialog method onSubscriptionChanged.

private void onSubscriptionChanged(final ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() instanceof Subscription) {
        final Subscription subscription = (Subscription) e.getItem();
        this.cbResourceGroup.setSubscription(subscription);
        this.cbRegion.setSubscription(subscription);
        this.cbImage.setSubscription(subscription);
        this.cbAvailabilityOptions.setSubscription(subscription);
        this.cbSize.setSubscription(subscription);
        this.cbVirtualNetwork.setSubscription(subscription);
        this.cbSecurityGroup.setSubscription(subscription);
        this.cbPublicIp.setSubscription(subscription);
        this.cbStorageAccount.setSubscription(subscription);
    }
}
Also used : Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 28 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class BaseStorageAccountCreationDialog method onSubscriptionChanged.

private void onSubscriptionChanged(final ItemEvent e) {
    if (e.getStateChange() == ItemEvent.SELECTED) {
        final Subscription subscription = (Subscription) e.getItem();
        this.resourceGroupComboBox.setSubscription(subscription);
        this.accountNameTextField.setSubscriptionId(subscription.getId());
        this.regionComboBox.setSubscription(subscription);
    } else if (e.getStateChange() == ItemEvent.DESELECTED) {
        this.resourceGroupComboBox.setSubscription(null);
        this.accountNameTextField.setSubscriptionId(null);
        this.regionComboBox.setSubscription(null);
    }
}
Also used : Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Example 29 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class AzureMvpModel method getSelectedSubscriptions.

/**
 * Get list of selected Subscriptions.
 *
 * @return List of Subscription instances
 */
@AzureOperation(name = "account|subscription.get_detail.selected", type = AzureOperation.Type.SERVICE)
public List<Subscription> getSelectedSubscriptions() {
    final List<Subscription> ret = new ArrayList<>();
    final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    ret.addAll(azureManager.getSelectedSubscriptions());
    Collections.sort(ret, getComparator(Subscription::getName));
    return ret;
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) ArrayList(java.util.ArrayList) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 30 with Subscription

use of com.microsoft.azure.toolkit.lib.common.model.Subscription in project azure-tools-for-java by Microsoft.

the class AzureRedisMvpModel method getRedisCaches.

/**
 * Get all redis caches.
 * @return A map containing RedisCaches with subscription id as the key
 */
public HashMap<String, RedisCaches> getRedisCaches() {
    HashMap<String, RedisCaches> redisCacheMaps = new HashMap<>();
    List<Subscription> subscriptions = az(AzureAccount.class).account().getSelectedSubscriptions();
    for (Subscription subscription : subscriptions) {
        Azure azure = AuthMethodManager.getInstance().getAzureClient(subscription.getId());
        if (azure.redisCaches() == null) {
            continue;
        }
        redisCacheMaps.put(subscription.getId(), azure.redisCaches());
    }
    return redisCacheMaps;
}
Also used : Azure(com.microsoft.azure.management.Azure) RedisCaches(com.microsoft.azure.management.redis.RedisCaches) HashMap(java.util.HashMap) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription)

Aggregations

Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)64 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)13 Region (com.microsoft.azure.toolkit.lib.common.model.Region)9 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)9 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)7 ArrayList (java.util.ArrayList)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 Project (com.intellij.openapi.project.Project)4 Azure (com.microsoft.azure.toolkit.lib.Azure)4 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 IOException (java.io.IOException)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 Point (org.eclipse.swt.graphics.Point)4 GridData (org.eclipse.swt.layout.GridData)4 Combo (org.eclipse.swt.widgets.Combo)4 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 EventType (com.microsoft.azuretools.telemetrywrapper.EventType)3 EventUtil (com.microsoft.azuretools.telemetrywrapper.EventUtil)3