I am trying to get OS options to reload, but I can't find APIs to get options. How can I get OS names, their installation time, and prices using Java client ? If you provide me a sample or guide, it will be appreciated.
Try the following java script:
package com.softlayer.api.Prices;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.product.Package;
import com.softlayer.api.service.product.item.Category;
import com.softlayer.api.service.product.item.Price;
/**
* This script Retrieves options for OS reload as Control Portal
*
* Important Manual Page:
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
*
* @license <http://sldn.softlayer.com/article/License>
* @authon SoftLayer Technologies, Inc. <sldn@softlayer.com>
* @version 0.2.2
*/
public class GetItemPrices {
/**
* This is the constructor, is used to Route
*/
public GetItemPrices() {
// Declare your SoftLayer username and apiKey
String username = "set me";
String apiKey = "set me";
// Define the server's identifier
Long packageId = new Long(46);
// Create client and Search Service
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
Package.Service packageService = Package.service(client, packageId);
// Define an object mask to get additional properties
packageService.withMask().itemPrices().categories();
packageService.withMask().itemPrices().item().softwareDescription().averageInstallationDuration();
// Define the Manufactures that you want to display
String[] manufactures = {"CentOS", "Citrix", "CloudLinux", "Debian", "FreeBSD", "Microsoft", "Other", "Parallels", "Redhat", "Ubuntu", "VMware", "Vyatta"};
try {
for(String manu : manufactures) {
System.out.println(manu);
for (Price price : packageService.getObject().getItemPrices()) {
for (Category category : price.getCategories()) {
if (category.getCategoryCode().equals("os")) {
if (price.getItem().getSoftwareDescription().getManufacturer().equals(manu)) {
System.out.printf("Price Id: %-10s Description: %-70s Time To Install: %-4s Monthly: %-7s Setup: %-7s\n",
price.getId(), price.getItem().getDescription(), price.getItem().getSoftwareDescription().getAverageInstallationDuration(),
price.getRecurringFee(), price.getSetupFee());
}
}
}
}
}
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
/**
* This is the main method which makes use of Get Item Prices
*
* @param args
* @return Nothing
*/
public static void main(String[] args) {
new GetItemPrices();
}
}
As you can see, it's necessary to define the packageId from the server that you wish to display the options for reload.
Unfortunately it's not possible to get the package from servers using SoftLayer API Client for Java, because there is an issue with "package" mask:
https://github.com/softlayer/softlayer-java/pull/37
There is a fix, but there is something wrong with the return type of the method. So you need to try get the package by other way.
Updated
Sorry for delay, doing several tests I verified that reload screen in Control Portal has an issue at the moment to provide options for reloading, because you can see Windows Server 2003 like an option, but there is not possible to use it, because it is deprecated.
Another issue, for example, if we had a VSI with 25 GB in the first disk, we cannot reload OS for Windows, because the Control Portal will show an exception that it's necessary to have 100 GB in the first disk.
I can provide a script to get reload options avoiding conflicts, but the script will continue displaying Windows Server 2003 or Vyatta, which are options that are deprecated (these are the only cases for the script to provide wrong information, this is caused because these options have not yet removed from the catalog - another issue) for the other options that script shows, it will display correct options.
For the issues that I commented before, you can submit a ticket about why Control Portal displays invalid/wrong options.
I hope this script can help you. Let me know any comment or doubt.
package com.softlayer.api.Prices;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.billing.Order;
import com.softlayer.api.service.billing.order.Item;
import com.softlayer.api.service.product.Package;
import com.softlayer.api.service.product.item.Category;
import com.softlayer.api.service.product.item.Price;
import com.softlayer.api.service.product.item.resource.Conflict;
import com.softlayer.api.service.virtual.Guest;
import java.util.List;
/**
* This script Retrieves options for OS reload as Control Portal
*
* Important Manual Page:
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
*
* @license <http://sldn.softlayer.com/article/License>
* @authon SoftLayer Technologies, Inc. <sldn@softlayer.com>
* @version 0.2.2
*/
public class GetItems {
/**
* This is the constructor, is used to Route
*/
public GetItems() {
// Declare your SoftLayer username and apiKey
String username = "set me";
String apiKey = "set me";
// Define the package's identifier
Long packageId = new Long(46);
// Define the server's identifier
Long serverId = new Long(24453061);
// Create client and Search Service
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
Package.Service packageService = Package.service(client, packageId);
Guest.Service guestService = Guest.service(client, serverId);
// Get Items
guestService.withNewMask().maxCpu();
guestService.withNewMask().billingItem().orderItem().order();
System.out.println(guestService.getObject().getBillingItem().getOrderItem().getOrder().getId());
Order.Service orderService = Order.service(client, guestService.getObject().getBillingItem().getOrderItem().getOrder().getId());
orderService.withNewMask().items().item();
List<Conflict> conflicts = packageService.getItemConflicts();
List<Item> billingOrderItems = orderService.getObject().getItems();
// Define an object mask to get additional properties
packageService.withMask().itemPrices().categories();
packageService.withMask().itemPrices().item().softwareDescription().averageInstallationDuration();
packageService.withMask().itemPrices().capacityRestrictionMaximum();
packageService.withMask().itemPrices().capacityRestrictionMinimum();
// Define the Manufactures that you want to display
String[] manufactures = {"CentOS", "Citrix", "CloudLinux", "Debian", "FreeBSD", "Microsoft", "Other", "Parallels", "Redhat", "Ubuntu", "VMware", "Vyatta"};
boolean product;
try {
for(String manu : manufactures) {
System.out.println(manu);
for (Price price : packageService.getObject().getItemPrices()) {
product = true;
for (Category category : price.getCategories()) {
if (category.getCategoryCode().equals("os")) {
if (price.getItem().getSoftwareDescription().getManufacturer().equals(manu)) {
if (price.getCapacityRestrictionMaximum() != null && price.getCapacityRestrictionMinimum() != null) {
if (guestService.getObject().getMaxCpu() < Long.parseLong(price.getCapacityRestrictionMinimum())){
product = false;
}
}
if(product == true) {
System.out.printf("Price Id: %-10s Item Id: %-10s Description: %-70s Time To Install: %-4s Monthly: %-7s Setup: %-7s Min Cores: %-5s Max Cores: %-5s\n",
price.getId(), price.getItemId(), price.getItem().getDescription(), price.getItem().getSoftwareDescription().getAverageInstallationDuration(),
price.getRecurringFee(), price.getSetupFee(), price.getCapacityRestrictionMinimum(), price.getCapacityRestrictionMaximum());
}
}
}
}
}
}
} catch (Exception e) {
System.out.println("Error: " + e);
}
}
/**
* This is the main method which makes use of Get Item Prices
*
* @param args
* @return Nothing
*/
public static void main(String[] args) {
new GetItems();
}
}
Note: Replace username, apiKey and serverId values, this script only works for VSIs, the same idea could be applied for BMSs