I am implementing Auto Scaling using SoftLayer java client. Can you give me a guide or sample code to add Assets using JAVA API? Please refer to the attached picture.
The next java script can be used to add an asset to SoftLayer Auto Scale:
/**
* This script creates a SoftLayer_Scale_Asset_Virtual_Guest for a
* SoftLayer_Scale_Group
*
* Important manual pages:
* @see http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Asset_Virtual_Guest/createObject
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Asset_Virtual_Guest
*
* @license <http://sldn.softlayer.com/wiki/index.php/License>
* @author SoftLayer Technologies, Inc. <[email protected]>
*/
package SoftLayer_Java_Scripts.Examples;
import com.softlayer.api.*;
import com.softlayer.api.service.scale.asset.virtual.Guest;
import com.google.gson.Gson;
public class CreateScaleAssetVirtualGuest
{
public static void main( String[] args )
{
// Fill with your valid data here.
String user = "set me";
String apiKey = "set me";
long scaleGroupId = 112233;
long virtualGuestId = 44556677;
// Creating a client and the service that’s going to call the API method.
ApiClient client = new RestApiClient().withCredentials(user, apiKey);
Guest.Service service = Guest.service(client);
// A SoftLayer_Scale_Asset_Virtual_Guest container used to store the scale group id and
// the virtual guest id that’s going to be the new asset.
Guest assetVirtualGuestTemplate = new Guest();
assetVirtualGuestTemplate.setScaleGroupId(scaleGroupId);
assetVirtualGuestTemplate.setVirtualGuestId(virtualGuestId);
try
{
Guest assetVirtualGuest = service.createObject(assetVirtualGuestTemplate);
Gson gson = new Gson();
System.out.println(gson.toJson(assetVirtualGuest));
}
catch(Exception e)
{
System.out.println("Script failed, review the next message for further details: " + e);
}
}
}
The next links could also help you: http://sldn.softlayer.com/reference/services/SoftLayer_Scale_Asset_Virtual_Guest/createObject http://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Asset_Virtual_Guest