Search in sources :

Example 1 with VirtualMachineSize

use of com.microsoft.azure.management.compute.VirtualMachineSize in project azure-tools-for-java by Microsoft.

the class MachineSettingsStep method getTitle.

@Override
public String getTitle() {
    boolean isLinux;
    if (wizard.isKnownMachineImage()) {
        isLinux = wizard.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = wizard.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBoxSelected(false);
        passwordCheckBox.setSelection(true);
    } else {
        certificateCheckBoxSelected(false);
        passwordCheckBox.setSelection(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (vmSizeComboBox.getItemCount() == 0) {
        vmSizeComboBox.setItems(new String[] { LOADING });
        DefaultLoader.getIdeHelper().runInBackground(null, "Loading VM sizes...", false, true, "", new Runnable() {

            @Override
            public void run() {
                PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = wizard.getAzure().virtualMachines().sizes().listByRegion(wizard.getRegion().name());
                Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                    @Override
                    public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
                        if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                            return t0.name().compareTo(t1.name());
                        } else if (t0.name().contains("Basic")) {
                            return -1;
                        } else if (t1.name().contains("Basic")) {
                            return 1;
                        }
                        int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                        if (coreCompare == 0) {
                            return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                        } else {
                            return coreCompare;
                        }
                    }
                });
                DefaultLoader.getIdeHelper().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        vmSizeComboBox.removeAll();
                        for (VirtualMachineSize size : sizes) {
                            vmSizeComboBox.add(size.name());
                            vmSizeComboBox.setData(size.name(), size);
                        }
                        if (sizes.size() > 0) {
                            vmSizeComboBox.select(0);
                        }
                    //							selectDefaultSize();
                    }
                });
            }
        });
    } else {
        selectDefaultSize();
    }
    return super.getTitle();
}
Also used : VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) PagedList(com.microsoft.azure.PagedList)

Example 2 with VirtualMachineSize

use of com.microsoft.azure.management.compute.VirtualMachineSize in project azure-tools-for-java by Microsoft.

the class MachineSettingsStep method prepare.

@Override
public JComponent prepare(WizardNavigationState wizardNavigationState) {
    rootPanel.revalidate();
    boolean isLinux;
    try {
        AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
        azure = azureManager.getAzure(((VMWizardModel) model).getSubscription().getSubscriptionId());
    } catch (Exception ex) {
        DefaultLoader.getUIHelper().logError("An error occurred when trying to authenticate\n\n" + ex.getMessage(), ex);
    }
    if (model.isKnownMachineImage()) {
        isLinux = model.getKnownMachineImage() instanceof KnownLinuxVirtualMachineImage;
    } else {
        isLinux = model.getVirtualMachineImage().osDiskImage().operatingSystem().equals(OperatingSystemTypes.LINUX);
    }
    if (isLinux) {
        certificateCheckBox.setEnabled(true);
        passwordCheckBox.setEnabled(true);
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
    } else {
        certificateCheckBox.setSelected(false);
        passwordCheckBox.setSelected(true);
        certificateCheckBox.setEnabled(false);
        passwordCheckBox.setEnabled(false);
    }
    validateEmptyFields();
    if (vmSizeComboBox.getItemCount() == 0) {
        vmSizeComboBox.setModel(new DefaultComboBoxModel(new String[] { "<Loading...>" }));
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Loading VM sizes...", false) {

            @Override
            public void run(@NotNull ProgressIndicator progressIndicator) {
                progressIndicator.setIndeterminate(true);
                PagedList<com.microsoft.azure.management.compute.VirtualMachineSize> sizes = azure.virtualMachines().sizes().listByRegion(model.getRegion().name());
                Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                    @Override
                    public int compare(VirtualMachineSize t0, VirtualMachineSize t1) {
                        if (t0.name().contains("Basic") && t1.name().contains("Basic")) {
                            return t0.name().compareTo(t1.name());
                        } else if (t0.name().contains("Basic")) {
                            return -1;
                        } else if (t1.name().contains("Basic")) {
                            return 1;
                        }
                        int coreCompare = Integer.valueOf(t0.numberOfCores()).compareTo(t1.numberOfCores());
                        if (coreCompare == 0) {
                            return Integer.valueOf(t0.memoryInMB()).compareTo(t1.memoryInMB());
                        } else {
                            return coreCompare;
                        }
                    }
                });
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        vmSizeComboBox.setModel(new DefaultComboBoxModel<>(sizes.stream().map(VirtualMachineSize::name).toArray(String[]::new)));
                        selectDefaultSize();
                    }
                }, ModalityState.any());
            }
        });
    } else {
        selectDefaultSize();
    }
    return rootPanel;
}
Also used : Task(com.intellij.openapi.progress.Task) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) PagedList(com.microsoft.azure.PagedList) Comparator(java.util.Comparator) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 3 with VirtualMachineSize

use of com.microsoft.azure.management.compute.VirtualMachineSize in project azure-tools-for-java by Microsoft.

the class AzureNewDockerHostStep method updateDockerHostVMSizeComboBox.

private void updateDockerHostVMSizeComboBox(boolean prefferedSizesOnly) {
    DefaultComboBoxModel<String> dockerHostVMSizeComboModel = new DefaultComboBoxModel<>();
    if (prefferedSizesOnly) {
        for (KnownDockerVirtualMachineSizes knownDockerVirtualMachineSize : KnownDockerVirtualMachineSizes.values()) {
            dockerHostVMSizeComboModel.addElement(knownDockerVirtualMachineSize.name());
        }
        if (dockerHostVMSizeComboModel.getSize() > 0) {
            dockerHostVMSizeComboModel.setSelectedItem(dockerHostVMSizeComboModel.getElementAt(0));
        }
    } else {
        dockerHostVMSizeComboModel.addElement("<Loading...>");
        ProgressManager.getInstance().run(new Task.Backgroundable(model.getProject(), "Loading VM Sizes...", false) {

            @Override
            public void run(@NotNull ProgressIndicator progressIndicator) {
                progressIndicator.setIndeterminate(true);
                Azure azureClient = ((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem()).azureClient;
                PagedList<VirtualMachineSize> sizes = null;
                try {
                    sizes = azureClient.virtualMachines().sizes().listByRegion(preferredLocation);
                    Collections.sort(sizes, new Comparator<VirtualMachineSize>() {

                        @Override
                        public int compare(VirtualMachineSize size1, VirtualMachineSize size2) {
                            if (size1.name().contains("Basic") && size2.name().contains("Basic")) {
                                return size1.name().compareTo(size2.name());
                            } else if (size1.name().contains("Basic")) {
                                return -1;
                            } else if (size2.name().contains("Basic")) {
                                return 1;
                            }
                            int coreCompare = Integer.valueOf(size1.numberOfCores()).compareTo(size2.numberOfCores());
                            if (coreCompare == 0) {
                                return Integer.valueOf(size1.memoryInMB()).compareTo(size2.memoryInMB());
                            } else {
                                return coreCompare;
                            }
                        }
                    });
                } catch (Exception notHandled) {
                }
                PagedList<VirtualMachineSize> sortedSizes = sizes;
                ApplicationManager.getApplication().invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        dockerHostVMSizeComboModel.removeAllElements();
                        if (sortedSizes != null) {
                            for (VirtualMachineSize vmSize : sortedSizes) {
                                dockerHostVMSizeComboModel.addElement(vmSize.name());
                            }
                        }
                        dockerHostVMSizeComboBox.repaint();
                    }
                }, ModalityState.any());
            }
        });
    }
    dockerHostVMSizeComboBox.setModel(dockerHostVMSizeComboModel);
    dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
    if (!newHost.hostVM.vmSize.equals((String) dockerHostVMSizeComboBox.getSelectedItem())) {
        dockerHostVMSizeComboModel.addElement(newHost.hostVM.vmSize);
        dockerHostVMSizeComboBox.setSelectedItem(newHost.hostVM.vmSize);
    }
    updateDockerSelectStorageComboBox((AzureDockerSubscription) dockerSubscriptionComboBox.getSelectedItem());
}
Also used : Task(com.intellij.openapi.progress.Task) Azure(com.microsoft.azure.management.Azure) PagedList(com.microsoft.azure.PagedList) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 4 with VirtualMachineSize

use of com.microsoft.azure.management.compute.VirtualMachineSize in project azure-sdk-for-java by Azure.

the class TestAvailabilitySet method createResource.

@Override
public AvailabilitySet createResource(AvailabilitySets availabilitySets) throws Exception {
    final String newName = "as" + this.testId;
    AvailabilitySet aset = availabilitySets.define(newName).withRegion(Region.US_EAST).withNewResourceGroup().withFaultDomainCount(2).withUpdateDomainCount(4).withTag("tag1", "value1").create();
    PagedList<VirtualMachineSize> vmSizes = aset.listVirtualMachineSizes();
    Assert.assertTrue(vmSizes.size() > 0);
    for (VirtualMachineSize vmSize : vmSizes) {
        Assert.assertNotNull(vmSize.name());
    }
    return aset;
}
Also used : VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) AvailabilitySet(com.microsoft.azure.management.compute.AvailabilitySet)

Example 5 with VirtualMachineSize

use of com.microsoft.azure.management.compute.VirtualMachineSize in project azure-sdk-for-java by Azure.

the class TestVirtualMachineSizes method createResource.

@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
    List<VirtualMachineSize> availableSizes = virtualMachines.sizes().listByRegion(Region.US_EAST);
    Assert.assertTrue(availableSizes.size() > 0);
    System.out.println("VM Sizes: " + availableSizes);
    final String vmName = "vm" + this.testId;
    VirtualMachine vm = virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup().withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress().withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(// Use the first size
    availableSizes.get(0).name()).create();
    Assert.assertTrue(vm.size().toString().equalsIgnoreCase(availableSizes.get(0).name()));
    return vm;
}
Also used : VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)7 PagedList (com.microsoft.azure.PagedList)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Azure (com.microsoft.azure.management.Azure)2 KnownLinuxVirtualMachineImage (com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage)2 Comparator (java.util.Comparator)2 KnownDockerVirtualMachineSizes (com.microsoft.azure.docker.model.KnownDockerVirtualMachineSizes)1 AvailabilitySet (com.microsoft.azure.management.compute.AvailabilitySet)1 VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1