Search in sources :

Example 1 with VirtualMachineImage

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

the class ListVirtualMachineImages method runSample.

/**
     * Main function which runs the actual sample.
     * @param azure instance of the azure client
     * @return true if sample runs successfully
     */
public static boolean runSample(Azure azure) {
    final Region region = Region.US_WEST_CENTRAL;
    //=================================================================
    // List all virtual machine image publishers and
    // list all virtual machine images
    // published by Canonical, Red Hat and SUSE
    // by browsing through locations, publishers, offers, SKUs and images
    List<VirtualMachinePublisher> publishers = azure.virtualMachineImages().publishers().listByRegion(region);
    VirtualMachinePublisher chosenPublisher;
    System.out.println("US East data center: printing list of \n" + "a) Publishers and\n" + "b) Images published by Canonical, Red Hat and Suse");
    System.out.println("=======================================================");
    System.out.println("\n");
    for (VirtualMachinePublisher publisher : publishers) {
        System.out.println("Publisher - " + publisher.name());
        if (publisher.name().equalsIgnoreCase("Canonical") | publisher.name().equalsIgnoreCase("Suse") | publisher.name().equalsIgnoreCase("RedHat")) {
            chosenPublisher = publisher;
            System.out.print("\n\n");
            System.out.println("=======================================================");
            System.out.println("Located " + chosenPublisher.name());
            System.out.println("=======================================================");
            System.out.println("Printing entries as publisher/offer/sku/image.version()");
            for (VirtualMachineOffer offer : chosenPublisher.offers().list()) {
                for (VirtualMachineSku sku : offer.skus().list()) {
                    for (VirtualMachineImage image : sku.images().list()) {
                        System.out.println("Image - " + chosenPublisher.name() + "/" + offer.name() + "/" + sku.name() + "/" + image.version());
                    }
                }
            }
            System.out.print("\n\n");
        }
    }
    return true;
}
Also used : VirtualMachineSku(com.microsoft.azure.management.compute.VirtualMachineSku) VirtualMachineImage(com.microsoft.azure.management.compute.VirtualMachineImage) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) VirtualMachinePublisher(com.microsoft.azure.management.compute.VirtualMachinePublisher) VirtualMachineOffer(com.microsoft.azure.management.compute.VirtualMachineOffer)

Example 2 with VirtualMachineImage

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

the class SelectImageStep method imageLabelSelected.

private void imageLabelSelected() {
    VirtualMachineImage virtualMachineImage = (VirtualMachineImage) imageLabelList.getData(imageLabelList.getItem(imageLabelList.getSelectionIndex()));
    wizard.setVirtualMachineImage(virtualMachineImage);
    if (virtualMachineImage != null) {
        //            imageDescription.setText(wizard.getHtmlFromVMImage(virtualMachineImage));
        setPageComplete(true);
        wizard.setSize(null);
    }
}
Also used : VirtualMachineImage(com.microsoft.azure.management.compute.VirtualMachineImage) KnownWindowsVirtualMachineImage(com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage)

Example 3 with VirtualMachineImage

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

the class SelectImageStep method fillImages.

private void fillImages() {
    setPageComplete(false);
    imageLabelList.removeAll();
    VirtualMachineSku sku = (VirtualMachineSku) skuComboBox.getData(skuComboBox.getText());
    DefaultLoader.getIdeHelper().runInBackground(null, "Loading images...", false, true, "", new Runnable() {

        @Override
        public void run() {
            final java.util.List<VirtualMachineImage> images = new ArrayList<VirtualMachineImage>();
            try {
                java.util.List<VirtualMachineImage> skuImages = sku.images().list();
                images.addAll(skuImages);
                DefaultLoader.getIdeHelper().invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        for (VirtualMachineImage image : images) {
                            imageLabelList.add(image.version());
                            imageLabelList.setData(image.version(), image);
                        }
                        imageLabelList.setEnabled(true);
                    }
                });
            } catch (Exception e) {
                String msg = "An error occurred while attempting to retrieve images list." + "\n" + e.getMessage();
                PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, msg, e);
            }
        }
    });
}
Also used : VirtualMachineSku(com.microsoft.azure.management.compute.VirtualMachineSku) VirtualMachineImage(com.microsoft.azure.management.compute.VirtualMachineImage) KnownWindowsVirtualMachineImage(com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with VirtualMachineImage

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

the class AzureTests method testVMImages.

/**
     * Tests VM images.
     * @throws IOException
     * @throws CloudException
     */
@Test
public void testVMImages() throws CloudException, IOException {
    List<VirtualMachinePublisher> publishers = azure.virtualMachineImages().publishers().listByRegion(Region.US_WEST);
    Assert.assertTrue(publishers.size() > 0);
    for (VirtualMachinePublisher p : publishers) {
        System.out.println(String.format("Publisher name: %s, region: %s", p.name(), p.region()));
        try {
            for (VirtualMachineOffer o : p.offers().list()) {
                System.out.println(String.format("\tOffer name: %s", o.name()));
                try {
                    for (VirtualMachineSku s : o.skus().list()) {
                        System.out.println(String.format("\t\tSku name: %s", s.name()));
                    }
                } catch (com.microsoft.rest.RestException e) {
                    e.printStackTrace();
                }
            }
        } catch (com.microsoft.rest.RestException e) {
            e.printStackTrace();
        }
    }
    List<VirtualMachineImage> images = azure.virtualMachineImages().listByRegion(Region.US_WEST);
    Assert.assertTrue(images.size() > 0);
    try {
        // Seems to help avoid connection refused error on subsequent mock test
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : VirtualMachineSku(com.microsoft.azure.management.compute.VirtualMachineSku) VirtualMachineImage(com.microsoft.azure.management.compute.VirtualMachineImage) KnownLinuxVirtualMachineImage(com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage) VirtualMachinePublisher(com.microsoft.azure.management.compute.VirtualMachinePublisher) VirtualMachineOffer(com.microsoft.azure.management.compute.VirtualMachineOffer) Test(org.junit.Test)

Aggregations

VirtualMachineImage (com.microsoft.azure.management.compute.VirtualMachineImage)4 KnownLinuxVirtualMachineImage (com.microsoft.azure.management.compute.KnownLinuxVirtualMachineImage)3 VirtualMachineSku (com.microsoft.azure.management.compute.VirtualMachineSku)3 KnownWindowsVirtualMachineImage (com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage)2 VirtualMachineOffer (com.microsoft.azure.management.compute.VirtualMachineOffer)2 VirtualMachinePublisher (com.microsoft.azure.management.compute.VirtualMachinePublisher)2 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1