答案 0 :(得分:0)
尝试以下java脚本:
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();
}
}
如您所见,有必要从您希望显示重新加载选项的服务器定义 packageId 。
不幸的是,使用SoftLayer API Client for Java从服务器获取软件包是不可能的,因为&#34; package&#34;掩模:
https://github.com/softlayer/softlayer-java/pull/37
有一个修复,但该方法的返回类型有问题。所以你需要尝试通过其他方式获取包。
<强>更新强>
很抱歉延迟,做了几次测试我确认Control Portal中的重新加载屏幕目前有问题提供重新加载选项,因为您可以看到 Windows Server 2003 之类的选项,但不可能使用它,因为它已被弃用。
另一个问题,例如,如果我们在第一个磁盘中有一个25 GB的VSI,我们就无法为Windows重新加载操作系统,因为控制门户会显示一个例外情况。必须在第一个磁盘中有100 GB。
我可以提供一个脚本来获取重新加载选项以避免冲突,但脚本将继续显示 Windows Server 2003或Vyatta ,这些是不推荐使用的选项(这些是脚本的唯一情况)提供错误信息,这是因为这些选项尚未从目录中删除 - 另一个问题)对于脚本显示的其他选项,它将显示正确的选项。
对于我之前评论过的问题,您可以提交有关控制门户显示无效/错误选项的原因的故障单。
我希望这个脚本可以帮到你。 让我知道任何评论或怀疑。
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();
}
}
注意:替换用户名, apiKey 和 serverId 值,此脚本仅适用于VSI,相同想法可以应用于BMS