try {
String vpxName = "Cloud-VPX-"+cmd.getLoadBalancerIP();
String username = "admin";
String password = "admin";
ns ns_obj = new ns();
ns_obj.set_name(vpxName);
ns_obj.set_ip_address(cmd.getLoadBalancerIP());
ns_obj.set_netmask(cmd.getNetmask());
ns_obj.set_gateway(cmd.getGateway());
ns_obj.set_username(username);
ns_obj.set_password(password);
// configure VPX instances with defaults
ns_obj.set_feature_license("Standard");
ns_obj.set_memory_total(new Double(2048));
ns_obj.set_throughput(new Double(1000));
ns_obj.set_pps(new Double(1000000));
ns_obj.set_number_of_ssl_cores(0);
// use the first device profile available on the SDX to create an instance of VPX
device_profile[] profiles = device_profile.get(_netscalerSdxService);
if (!(profiles != null && profiles.length >= 1)) {
new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip +
" as there are no admin profile to use for creating VPX."));
}
String profileName = profiles[0].get_name();
ns_obj.set_nsroot_profile(profileName);
// use the first VPX image of the available VPX images on the SDX to create an instance of VPX
// TODO: should enable the option to choose the template while adding the SDX device in to CloudStack
xen_vpx_image[] vpxImages = xen_vpx_image.get(_netscalerSdxService);
if (!(vpxImages != null && vpxImages.length >= 1)) {
new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip +
" as there are no VPX images on SDX to use for creating VPX."));
}
String imageName = vpxImages[0].get_file_name();
ns_obj.set_image_name(imageName);
String publicIf = _publicInterface;
String privateIf = _privateInterface;
// enable only the interfaces that will be used by VPX
enableVPXInterfaces(_publicInterface, _privateInterface, ns_obj);
// create new VPX instance
ns newVpx = ns.add(_netscalerSdxService, ns_obj);
if (newVpx == null) {
new Answer(cmd, new ExecutionException("Failed to create VPX instance on the netscaler SDX device " + _ip));
}
// wait for VPX instance to start-up
long startTick = System.currentTimeMillis();
long startWaitMilliSeconds = 600000;
while(!newVpx.get_ns_state().equalsIgnoreCase("up") && System.currentTimeMillis() - startTick < startWaitMilliSeconds) {
try {
Thread.sleep(10000);
} catch(InterruptedException e) {
}
ns refreshNsObj = new ns();
refreshNsObj.set_id(newVpx.get_id());
newVpx = ns.get(_netscalerSdxService, refreshNsObj);
}
// if vpx instance never came up then error out
if (!newVpx.get_ns_state().equalsIgnoreCase("up")) {