SL 中的 OsReload 软件集
OsReload Software Collection in SL
我正在尝试获取 OS 选项以重新加载,但我找不到获取选项的 API。如何使用 Java 客户端获取 OS 名称、安装时间和价格?如果您能提供样品或指南,我们将不胜感激。
尝试以下 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 从服务器获取包,因为 "package" 掩码存在问题:
https://github.com/softlayer/softlayer-java/pull/37
已修复,但方法的 return 类型有问题。所以你需要尝试通过其他方式获取包裹。
Updated
抱歉延迟,做了几次测试我确认 Control Portal 中的重新加载屏幕目前有问题提供重新加载选项,因为你可以看到 Windows 服务器2003 就像一个选项,但不可能使用它,因为它已被弃用。
另一个问题,例如,如果我们在第一个磁盘中有一个 25 GB 的 VSI,我们无法为 Windows 重新加载 OS,因为Control Portal 将显示第一个磁盘中必须有 100 GB 的异常。
我可以提供一个脚本来获取避免冲突的重新加载选项,但该脚本将继续显示 Windows Server 2003 或 Vyatta,这些选项已弃用(这些是脚本提供错误信息的唯一情况,这是因为这些选项尚未从目录中删除 - 另一个问题)对于脚本显示的其他选项,它将显示正确的选项。
对于我之前评论的问题,您可以提交工单,了解为什么控制门户显示 invalid/wrong 个选项。
希望这个脚本能帮到你。
让我知道任何意见或疑问。
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
我正在尝试获取 OS 选项以重新加载,但我找不到获取选项的 API。如何使用 Java 客户端获取 OS 名称、安装时间和价格?如果您能提供样品或指南,我们将不胜感激。
尝试以下 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 从服务器获取包,因为 "package" 掩码存在问题:
https://github.com/softlayer/softlayer-java/pull/37
已修复,但方法的 return 类型有问题。所以你需要尝试通过其他方式获取包裹。
Updated
抱歉延迟,做了几次测试我确认 Control Portal 中的重新加载屏幕目前有问题提供重新加载选项,因为你可以看到 Windows 服务器2003 就像一个选项,但不可能使用它,因为它已被弃用。
另一个问题,例如,如果我们在第一个磁盘中有一个 25 GB 的 VSI,我们无法为 Windows 重新加载 OS,因为Control Portal 将显示第一个磁盘中必须有 100 GB 的异常。
我可以提供一个脚本来获取避免冲突的重新加载选项,但该脚本将继续显示 Windows Server 2003 或 Vyatta,这些选项已弃用(这些是脚本提供错误信息的唯一情况,这是因为这些选项尚未从目录中删除 - 另一个问题)对于脚本显示的其他选项,它将显示正确的选项。
对于我之前评论的问题,您可以提交工单,了解为什么控制门户显示 invalid/wrong 个选项。
希望这个脚本能帮到你。 让我知道任何意见或疑问。
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