use of com.microsoft.azure.management.compute.VirtualMachineSku 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;
}
use of com.microsoft.azure.management.compute.VirtualMachineSku in project azure-tools-for-java by Microsoft.
the class SelectImageStep method fillSkus.
private void fillSkus() {
setPageComplete(false);
imageLabelList.setEnabled(false);
imageLabelList.removeAll();
VirtualMachineOffer offer = (VirtualMachineOffer) offerComboBox.getData(offerComboBox.getText());
if (offerComboBox.getItemCount() > 0) {
DefaultLoader.getIdeHelper().runInBackground(null, "Loading skus...", false, true, "", new Runnable() {
@Override
public void run() {
try {
final java.util.List<VirtualMachineSku> skus = offer.skus().list();
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
for (VirtualMachineSku sku : skus) {
skuComboBox.add(sku.name());
skuComboBox.setData(sku.name(), sku);
}
skuComboBox.setEnabled(true);
if (skus.size() > 0) {
skuComboBox.select(0);
}
fillImages();
}
});
} catch (Exception e) {
String msg = "An error occurred while attempting to retrieve skus list." + "\n" + e.getMessage();
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, msg, e);
}
}
});
} else {
// todo
}
}
use of com.microsoft.azure.management.compute.VirtualMachineSku 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);
}
}
});
}
use of com.microsoft.azure.management.compute.VirtualMachineSku in project azure-tools-for-java by Microsoft.
the class SelectImageStep method fillImages.
private void fillImages() {
disableNext();
final AzureString title = AzureOperationBundle.title("vm|image.list");
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setIndeterminate(true);
VirtualMachineSku sku = (VirtualMachineSku) skuComboBox.getSelectedItem();
if (sku != null) {
RxJavaUtils.unsubscribeSubscription(fillImagesSubscription);
clearSelection(imageLabelList);
fillImagesSubscription = Observable.fromCallable(() -> sku.images().list()).subscribeOn(Schedulers.io()).subscribe(imageList -> DefaultLoader.getIdeHelper().invokeLater(() -> imageLabelList.setListData(imageList.toArray())), error -> {
String msg = String.format(ERROR_MESSAGE_LIST_IMAGES, String.format(message("webappExpMsg"), error.getMessage()));
handleError(msg, error);
});
}
}));
}
use of com.microsoft.azure.management.compute.VirtualMachineSku 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();
}
}
Aggregations