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