Order Server with RAID Config
It order a hardware server with raid configuration
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.Hardware;
import com.softlayer.api.service.container.product.order.storage.Group;
import com.softlayer.api.service.container.product.order.storage.group.Partition;
import com.softlayer.api.service.product.Order;
import com.softlayer.api.service.product.item.Price;
public class OrderWithDrivePartition {
public static void main(String[] args) {
String username = "set me";
String apiKey = "set me";
ApiClient client = new RestApiClient().withCredentials(username, apiKey);
long quantity = 1;
long packageId = 257;
List<Hardware> baremetals = new ArrayList<Hardware>();
Hardware server = new Hardware();
server.setHostname("foobar");
server.setDomain("softlayer.local");
baremetals.add(server);
long[] pricesIds = {
77185,
76165,
44988,
74995,
69451,
69451,
50357,
273,
55,
58,
420,
418,
21,
57,
906
};
List<Price> prices = new ArrayList<Price>();
for (int i = 0; i < pricesIds.length; i++) {
Price p = new Price();
p.setId(pricesIds[i]);
prices.add(p);
}
Group group1 = new Group();
group1.setArraySize(new BigDecimal("782"));
group1.setArrayTypeId(1L);
Long[] hardDrives1 = {0L,1L};
group1.getHardDrives().addAll(Arrays.asList(hardDrives1));
group1.setPartitionTemplateId(1L);
Group group2 = new Group();
group2.setArraySize(new BigDecimal("609"));
group2.setArrayTypeId(2L);
Long[] hardDrives2 = {0L, 1L};
group2.getHardDrives().addAll(Arrays.asList(hardDrives2));
Partition partition1 = new Partition();
partition1.setName("/test");
partition1.setIsGrow(false);
partition1.setSize(new BigDecimal("100"));
Partition partition2 = new Partition();
partition2.setName("/test2");
partition2.setIsGrow(true);
partition2.setSize(new BigDecimal("200"));
group1.getPartitions().add(partition1);
group2.getPartitions().add(partition2);
List<Group> storageGroups = new ArrayList<>();
storageGroups.add(group1);
storageGroups.add(group2);
com.softlayer.api.service.container.product.order.hardware.Server orderTemplate;
orderTemplate = new com.softlayer.api.service.container.product.order.hardware.Server();
orderTemplate.setLocation("AMSTERDAM");
orderTemplate.setPackageId(packageId);
orderTemplate.setQuantity(quantity);
orderTemplate.getHardware().addAll(baremetals);
orderTemplate.getPrices().addAll(prices);
orderTemplate.setUseHourlyPricing(Boolean.FALSE);
orderTemplate.getStorageGroups().addAll(storageGroups);
Order.Service orderService = Order.service(client);
try{
com.softlayer.api.service.container.product.Order result = orderService.verifyOrder(orderTemplate);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
System.out.println(gson.toJson(result));
} catch (Exception e)
{
System.out.println("Unable to place the order: " + e);
}
}
}