CLM AWS SDK use cases

The following table lists the use cases and provide the code snippets for each of the CLM AWS SDK use cases. Also provides CLM-AWS-SDK-SAMPLE.zip file, containing the complete E2E use cases code and configurations.

Use caseImplementation taskWho
Onboard Amazon images or VMware templates in CLM as installable resource and create service catalogs
  • Create an instance of CLMEC2Client
  • Pass AMI ID and Instance Type in RunInstancesRequest or provide an on-premise VM template as image ID with IR-
Cloud Administrator
Provision instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Pass service offering name as image id in RunInstancesRequest to CLMEC2lient
  • Pass additional parameters in request

Cloud Administrator

Tenant Administrator

End User

Describe instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in DescribeInstancesRequest
    • Service ID in DescribeInstancesRequest
    • Service Name in DescribeServicesRequest

Cloud Administrator

Tenant Administrator

End User

Describe instance status using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in DescribeInstanceStatusRequest
    • Service ID in DescribeInstanceStatusRequest
    • Service Name in DescribeServicesStatusRequest

Cloud Administrator

Tenant Administrator

End User

Describe instance attribute using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in DescribeInstanceStatusRequest
    • Service ID in DescribeInstanceStatusRequest
    • Service Name in DescribeServicesStatusRequest

Cloud Administrator

Tenant Administrator

End User

Reboot instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in RebootInstancesRequest
    • Service ID in RebootInstancesRequest
    • Service Name in RebootServicesRequest

Cloud Administrator

Tenant Administrator

End User

Start instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in StartInstancesRequest
    • Service ID in StartInstancesRequest
    • Service Name in StartServicesRequest

Cloud Administrator

Tenant Administrator

End User

Stop instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in StopInstancesRequest
    • Service ID in StopInstancesRequest
    • Service Name in StopServicesRequest

Cloud Administrator

Tenant Administrator

End User

Terminate instance using CLM AWS SDK
  • Create an instance of CLMEC2Client
  • Provide server ids through:
    • Server IDs in TerminateInstancesRequest
    • Service ID in TerminateInstancesRequest
    • Service Name in TerminateServicesRequest

Cloud Administrator

Tenant Administrator

End User

Onboard images or templates using CLM AWS SDK

To onboard Amazon images or VMware templates in BMC Cloud Lifecycle Management as installable resource and create service catalogs using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Onboard Amazon images in CLM as Installable Resource and create Service Catalog

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.Properties;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to on board  
 * Amazon images into BMC Cloud LifeCycle Management as Installable Resource and create
 * Service Catalog and Blueprint corresponding to them.
 * AWS RunInstancesRequest is used in this sample.
 */
public class RunInstanceSample1 extends CommonConfig{
	CLMEC2Client ec2Client = null;
	public void run(){
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		
		RunInstancesRequest request = new RunInstancesRequest();
		//Pass ami id and instance type desired here.
		request.withImageId("ami-67bddc5d").withInstanceType("m1.small");
		
		//This will create resources in CLM.
		//However, response will be null in this case since no provisioning is made.
		//If config param PROVISION_AFTER_ONBOARD is set to TRUE, then provisioning will be done after on boarding completes
		//and normal response will be returned containg Reservation/Instances. 
		ec2Client.runInstances(request);
		
	}
	
	public static void main(String[] args) {
		RunInstanceSample1 instanceSample1 = new RunInstanceSample1();
		instanceSample1.run();
	}
	
	
}

Onboard Amazon images in CLM as Installable Resource and create Service Catalog

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.Properties;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.RunServiceInstancesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to on board  
 * Amazon images into CLM as Installable Resource and create
 * Service Catalogs corresponding to them.
 * CLM RunServiceInstancesRequest is used in this sample.
 */
public class RunInstanceSample5 extends CommonConfig{
	CLMEC2Client ec2Client = null;
	public void run(){
		Properties properties = getConfigProperties();
		
		ec2Client = new CLMEC2Client(properties);
		
		RunServiceInstancesRequest request = new RunServiceInstancesRequest();
		//Pass AWS image id here.
		//For on premise, pass vm ware templare name.
		request.withImageId("ami-67bddc5d").withInstanceType("m1.small");
		
		//This will create resources in CLM.
		//However, response will be null in this case since no provisioning is made.
		//If config param PROVISION_AFTER_ONBOARD is set to TRUE, then provisioning will be done after on boarding completes
		//and normal response will be returned containg Reservation/Instances. 
		ec2Client.runInstances(request);
		
	}
	
	public static void main(String[] args) {
		RunInstanceSample5 instanceSample5 = new RunInstanceSample5();
		instanceSample5.run();
	}
	
	
}

Onboard VMware templates in CLM as Installable Resource and create Service Catalog

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.Properties;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client for using already on boarded VM ware template 
 * into BMC Cloud LifeCycle Management and creating Service Blueprint,Service Catalog using it.
 * 
 * AWS RunInstancesRequest is used in this sample.
 */
public class RunInstanceSample3 extends CommonConfig{
	CLMEC2Client ec2Client = null;
	public void run(){
		Properties properties = getConfigProperties();
		
		//Overriding config values as per on premise
		properties.put("NETWORK_CONTAINER_NAME", "VMW_NC");
		properties.put("LHE_NETWORK", "Management");
		properties.put("PRODUCT_CATEGORIZATION_TIER_3", "Bladelogic");
		properties.put("MANUFACTURER", "vmware");
		properties.put("PROVIDER_DEF", "BBSA");
		properties.put("PROVIDER", "BBSA");
		
		//Mandatory for on premise : Pass Blueprint name to be used while creating blueprint in on boarding case.
		//Name should not contain template name in it.
		//Eg  for template VMW-W2K8-64B-20GB 
		properties.put("VMW-W2K8-64B-20GB.blueprintname", "Windows Service");
		
		ec2Client = new CLMEC2Client(properties);
		
		RunInstancesRequest request = new RunInstancesRequest();
		//Prefix template name with IR- for on premise
		request.withImageId("IR-WIN2008R2").withInstanceType("m1.small");
		
		//This will create resources in CLM.
		//However, response will be null in this case since no provisioning is made.
		//If config param PROVISION_AFTER_ONBOARD is set to TRUE, then provisioning will be done after on boarding completes
		//and normal response will be returned containg Reservation/Instances. 
		ec2Client.runInstances(request);
		
	}
	
	public static void main(String[] args) {
		RunInstanceSample3 instanceSample3 = new RunInstanceSample3();
		instanceSample3.run();
	}
	
}

Provision instance using CLM AWS SDK

To provision an instance using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Provision service on Amazon cloud using BMC Cloud Lifecycle Management

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.Properties;
import com.amazonaws.services.ec2.model.Reservation;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.amazonaws.services.ec2.model.RunInstancesResult;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to provision service on Amazon Cloud via BMC Cloud LifeCycleManagement.
 * AWS RunInstancesRequest is used in this sample.
 *
 */
public class RunInstanceSample extends CommonConfig{
	CLMEC2Client ec2Client = null;
	public void run() {
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		RunInstancesRequest request = new RunInstancesRequest();
		// Setting Image id to CLM Service Offering name to provision.
		request.setImageId("ami-67bddc5d_SO");
		RunInstancesResult result = ec2Client.runInstances(request);
		if (result != null) {
			Reservation reservation = result.getReservation();
			
			//Using printReservation method of CLMEC2Client to print reservation.
			CLMEC2Client.printReservation(reservation);
		}
	}
	
	public static void main(String[] args) {
		RunInstanceSample instanceSample = new RunInstanceSample();
		instanceSample.run();
	}
}

Provision AWS instances using CLM Service Offering

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.List;
import java.util.Properties;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.Reservation;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.RunServiceInstancesRequest;
import com.bmc.cloud.sdk.aws.model.RunServiceInstancesResult;
import com.bmc.cloud.sdk.aws.model.RunSingleServiceInstancesResult;
import com.bmc.cloud.sdk.aws.model.ServerInstance;
/**
 * This sample demonstrates use of CLMEC2Client to provision 
 * AWS instances using CLM Service Offering.
 * RunServiceInstancesRequest is used in this sample.
 */
public class RunInstanceSample4 extends CommonConfig{

 CLMEC2Client ec2Client = null;
public void run() {
 Properties properties = getConfigProperties();
 
 ec2Client = new CLMEC2Client(properties);
RunServiceInstancesRequest request = new RunServiceInstancesRequest();
// Setting Image id to CLM Service Offering name to provision.
 request.setImageId("ami-67bddc5d_SO");
 
 //Setting additional preferences
 request.setName("Demo-Instance"); //This will be name of Service provisioned.
 request.setTenant("Demo-Tenant"); //CLM Tenant name.
 request.setHostnamePrefix("Demo"); //This will be name of server provisioned.
 request.setUsername("Demo"); //This will be name of local user in instance.
 request.setPassword("P@ssword123"); //This will be password for local user Demo.
//Using RunServiceInstancesResult to access CLM specific attributes.
 RunServiceInstancesResult result = (RunServiceInstancesResult) ec2Client.runInstances(request);
if (result != null) {
 //Result may contain more than one Service Offering Instances based on config param QUANTITY. Defaults to 1.
 List<RunSingleServiceInstancesResult> services = result.getServiceResultList();
 for(RunSingleServiceInstancesResult instancesResult : services){
 System.out.println("Service id is : "+instancesResult.getServiceId());
 //Obtain all reservations in a Service Offering Instances.
 List<Reservation> reservations = instancesResult.getReservationList();
 for(Reservation reservation : reservations){
 System.out.println("Reservation id is : "+reservation.getReservationId());
 List<Instance> instances = reservation.getInstances();
 
 for(Instance instance : instances){
 ServerInstance serverInstance = (ServerInstance) instance;
 CLMEC2Client.printInstance(serverInstance, reservation.getOwnerId());
 }
 
 }
 }
 
 }
}
 
 public static void main(String[] args) {
 RunInstanceSample4 instanceSample4 = new RunInstanceSample4();
 instanceSample4.run();
 }

}

Provision on premise instances using CLM Service Offering

 Click for code snippet
package com.bmc.awssdk.samples.runinstances;
import java.util.Properties;
import com.amazonaws.services.ec2.model.Reservation;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.amazonaws.services.ec2.model.RunInstancesResult;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to provision 
 * On premise instances using CLM Service Offering.
 * AWS RunInstancesRequest is used in this sample.
 */
public class RunInstanceSample2 extends CommonConfig{
	CLMEC2Client ec2Client = null;
	public void run() {
		Properties properties = getConfigProperties();
		
		ec2Client = new CLMEC2Client(properties);
		RunInstancesRequest request = new RunInstancesRequest();
		// Setting Image id to CLM Service Offering name to provision.
		request.setImageId("VMware Windows 2008R2_SO");
		RunInstancesResult result = ec2Client.runInstances(request);
		if (result != null) {
			Reservation reservation = result.getReservation();
			
			//Using printReservation method of CLMEC2Client to print reservation.
			CLMEC2Client.printReservation(reservation);
		}
	}
	
	public static void main(String[] args) {
		RunInstanceSample2 instanceSample2 = new RunInstanceSample2();
		instanceSample2.run();
	}
	
}

Describe instance using CLM AWS SDK

To describe an instance or a SOI using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Describe an instance

 Click for code snippet.
Describing an instance
package com.bmc.awssdk.samples.describe;
import java.util.List;
import java.util.Properties;
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Reservation;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to describe all servers from BMC Cloud LifeCycle Management.
 */
public class DescribeInstancesSample extends CommonConfig{
CLMEC2Client ec2Client = null;
	
	public void describe(){
		Properties properties = getConfigProperties();
		
		ec2Client = new CLMEC2Client(properties);
		
		DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances();
		if(describeInstancesResult!=null){
			List<Reservation> reservations = describeInstancesResult.getReservations();
			for(Reservation reservation : reservations){
				CLMEC2Client.printReservation(reservation);
			}
		}
	}
	
	public static void main(String[] args) {
		DescribeInstancesSample describeInstancesSample = new DescribeInstancesSample();
		describeInstancesSample.describe();
		System.exit(0);
	}
}

Describe an instance using AWS DescribeInstancesRequest

 Click for code snippet.
Describing an instance
package com.bmc.awssdk.samples.describe;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Reservation;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to describe servers from BMC Cloud LifeCycle Management.
 * AWS DescribeInstancesRequest is used in this sample.
 */
public class DescribeInstancesSample1 extends CommonConfig{

CLMEC2Client ec2Client = null;
	
	public void describe(){
		Properties properties = getConfigProperties();
		
		ec2Client = new CLMEC2Client(properties);
		
		DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
		
		//Pass Server Id from BMC Cloud LifeCycle Management here
		describeInstancesRequest.setInstanceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		
		DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(describeInstancesRequest);
		if(describeInstancesResult!=null){
			List<Reservation> reservations = describeInstancesResult.getReservations();
			for(Reservation reservation : reservations){
				CLMEC2Client.printReservation(reservation);
			}
		}
	}
	
	
	public static void main(String[] args) {
		DescribeInstancesSample1 describeInstancesSample = new DescribeInstancesSample1();
		describeInstancesSample.describe();
		System.exit(0);
	}
}

Describe a SOI

 Click for code snippet.
Describing a SOI
package com.bmc.awssdk.samples.describe;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import com.amazonaws.services.ec2.model.DescribeInstancesResult;
import com.amazonaws.services.ec2.model.Reservation;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.DescribeServicesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to describe Services from BMC Cloud LifeCycle Management.
 * DescribeServicesRequest is used in this sample.
 */
public class DescribeInstancesSample2 extends CommonConfig{
	CLMEC2Client ec2Client = null;
	Properties properties = getConfigProperties();
	
	public void describeByServiceId(){
	
		ec2Client = new CLMEC2Client(properties);
		
		DescribeServicesRequest describeInstancesRequest = new DescribeServicesRequest();
		
		//Pass Service Id from BMC Cloud LifeCycle Management here
		describeInstancesRequest.setServiceIds(Collections.singletonList("145a1c4c-aafa-45e1-a5b8-b13932e6e304"));
		
		DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(describeInstancesRequest);
		if(describeInstancesResult!=null){
			List<Reservation> reservations = describeInstancesResult.getReservations();
			for(Reservation reservation : reservations){
				CLMEC2Client.printReservation(reservation);
			}
		}
	}
	
	public void describeByServiceName(){
		ec2Client = new CLMEC2Client(properties);
		
		DescribeServicesRequest describeInstancesRequest = new DescribeServicesRequest();
		
		//Pass Service name from BMC Cloud LifeCycle Management here
		describeInstancesRequest.setServiceNames(Collections.singletonList("Demo-Service"));
		
		DescribeInstancesResult describeInstancesResult = ec2Client.describeInstances(describeInstancesRequest);
		if(describeInstancesResult!=null){
			List<Reservation> reservations = describeInstancesResult.getReservations();
			for(Reservation reservation : reservations){
				CLMEC2Client.printReservation(reservation);
			}
		}
	}
	
	public static void main(String[] args) {
		DescribeInstancesSample2 describeInstancesSample2 = new DescribeInstancesSample2();
		System.out.println("Describing Services using Service Id...");
		describeInstancesSample2.describeByServiceId();
		
		System.out.println("\n Describing Services using Service names...");
		describeInstancesSample2.describeByServiceName();
		System.exit(0);
	}
}

Describe instance status using CLM AWS SDK

To describe an instance or a service status using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Describe an instance status

 Click for code snippet.
Describing an instance status
package com.bmc.awssdk.samples.describestatus;
import java.util.Collections;
import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest;
import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to describe instances status.
 * AWS DescribeInstanceStatusRequest is used in this sample.
 */
public class DescribeInstanceStatusSample {
	CLMEC2Client ec2Client = null;
	
	public void describeStatus(){
		//Using default constructor requires config.properties to be placed at
		//User's Home Directory/clmsdk
		ec2Client = new CLMEC2Client();
		
		DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest();
		describeInstanceStatusRequest.setInstanceIds(Collections.singletonList("8f4108ff-5738-4c43-a610-4528a78a0c93"));
		DescribeInstanceStatusResult instanceStatusResult = ec2Client.describeInstanceStatus(describeInstanceStatusRequest);
	}
}

Describe a service status

 Click for code snippet.
Describing a service status
package com.bmc.awssdk.samples.describestatus;
import java.util.Collections;
import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.DescribeServicesStatusRequest;
/**
 * This sample demonstrates use of CLMEC2Client to describe instances status.
 * CLM DescribeServicesStatusRequest is used in this sample.
 */
public class DescribeInstanceStatusSample1 {
	
	CLMEC2Client ec2Client = null;
	
	public void describeStatus(){
		//Using default constructor requires config.properties to be placed at
		//User's Home Directory/clmsdk
		ec2Client = new CLMEC2Client();
		
		//Usage of DescribeServicesStatusRequest by passing Service Ids
		DescribeServicesStatusRequest describeServicesStatusRequest = new DescribeServicesStatusRequest();
		describeServicesStatusRequest.setServiceIds(Collections.singletonList("8f4108ff-5738-4c43-a610-4528a78a0c93"));
		DescribeInstanceStatusResult instanceStatusResult = ec2Client.describeInstanceStatus(describeServicesStatusRequest);
		
		//Usage of DescribeServicesStatusRequest by passing Service Names
		DescribeServicesStatusRequest describeServicesStatusRequest1 = new DescribeServicesStatusRequest();
		describeServicesStatusRequest1.setServiceNames(Collections.singletonList("Win2008Service"));
		DescribeInstanceStatusResult instanceStatusResult1 = ec2Client.describeInstanceStatus(describeServicesStatusRequest1);
		
	}
}

Describe instance attribute using CLM AWS SDK

To describe the attributes of an instance using CLM AWS SDK, you can use CLMEC2Client.

 Click for code snippet.
Describing attributes of an instance
package com.bmc.awssdk.samples.describeattribute;
import com.amazonaws.services.ec2.model.DescribeInstanceAttributeRequest;
import com.amazonaws.services.ec2.model.DescribeInstanceAttributeResult;
import com.amazonaws.services.ec2.model.InstanceAttributeName;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to describe instances attribute.
 * AWS DescribeInstanceAttributeRequest is used in this sample.
 */
public class DescribeInstanceAttributeSample {
	CLMEC2Client ec2Client = null;
	public void describeAttribute() {
		// Using default constructor requires config.properties to be placed at
		// User's Home Directory/clmsdk
		ec2Client = new CLMEC2Client();
		DescribeInstanceAttributeRequest describeInstanceAttributeRequest = new DescribeInstanceAttributeRequest();
		describeInstanceAttributeRequest.setAttribute(InstanceAttributeName.InstanceType);
		describeInstanceAttributeRequest.setInstanceId("dfbb7d4f-196e-462a-b0c6-4f96e51eccbd");
		DescribeInstanceAttributeResult attributeResult = ec2Client.describeInstanceAttribute(describeInstanceAttributeRequest);
		
		
	}
}

Reboot instance using CLM AWS SDK

To reboot an instance or a SOI using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Reboot an instance

 Click for code snippet.
Rebooting an instance
package com.bmc.awssdk.samples.reboot;
import java.util.Collections;
import java.util.Properties;
import com.amazonaws.services.ec2.model.RebootInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to reboot server in BMC Cloud LifeCycleManagement.
 * AWS RebootInstancesRequest is used in this sample.
 */
public class RebootInstancesSample extends CommonConfig{
	CLMEC2Client ec2Client = null;
	
	public void reboot(){
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		
		RebootInstancesRequest rebootInstancesRequest = new RebootInstancesRequest();
		//Pass server id here
		rebootInstancesRequest.withInstanceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.rebootInstances(rebootInstancesRequest);
	}
	
	public static void main(String[] args) {
		RebootInstancesSample rebootInstancesSample = new RebootInstancesSample();
		rebootInstancesSample.reboot();
		
	}
}

Reboot a SOI

 Click for code snippet.
Rebooting a SOI
package com.bmc.awssdk.samples.reboot;
import java.util.Collections;
import java.util.Properties;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.RebootServicesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to reboot CLM Service in BMC
 * Cloud LifeCycle Management . CLM's RebootServicesRequest is used in this
 * sample.
 */
public class RebootInstancesSample1 extends CommonConfig {
	CLMEC2Client ec2Client = null;
	Properties properties = getConfigProperties();
	public void rebootUsingId() {
		ec2Client = new CLMEC2Client(properties);
		RebootServicesRequest rebootServicesRequest = new RebootServicesRequest();
		// Pass CLM Service id here
		rebootServicesRequest.setServiceIds(Collections
				.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.rebootInstances(rebootServicesRequest);
	}
	public void rebootUsingName() {
		ec2Client = new CLMEC2Client(properties);
		RebootServicesRequest rebootServicesRequest = new RebootServicesRequest();
		// Pass CLM Service name here
		rebootServicesRequest.setServiceNames(Collections
				.singletonList("Demo-Service"));
		ec2Client.rebootInstances(rebootServicesRequest);
	}
	public static void main(String[] args) {
		RebootInstancesSample1 rebootInstancesSample1 = new RebootInstancesSample1();
		System.out.println("Rebooting using service id ...");
		rebootInstancesSample1.rebootUsingId();
		System.out.println("Rebooting using service name ...");
		rebootInstancesSample1.rebootUsingName();
	}
}

Start instance using CLM AWS SDK

To start an instance or a SOI using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Start an instance

 Click for code snippet.
Starting an instance
package com.bmc.awssdk.samples.startinstances;
import java.util.Collections;
import java.util.Properties;
import com.amazonaws.services.ec2.model.StartInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to start instances in BMC Cloud LifeCycle Management.
 * AWS StartInstancesRequest is used in this sample.
 */
public class StartInstancesSample extends CommonConfig{
	CLMEC2Client ec2Client = null;
	
	public void start(){
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		
		StartInstancesRequest startInstanceRequest = new StartInstancesRequest();
		//Pass Server id here. 
		startInstanceRequest.withInstanceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.startInstances(startInstanceRequest);
	}
	
	public static void main(String[] args) {
		StartInstancesSample instancesSample = new StartInstancesSample();
		instancesSample.start();
	}
}

Start a SOI

 Click for code snippet.
Starting an SOI
package com.bmc.awssdk.samples.startinstances;
import java.util.Collections;
import java.util.Properties;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.StartServicesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to start Services in BMC Cloud
 * LifeCycle Management. StartServicesRequest is used in this sample.
 */
public class StartInstancesSample1 extends CommonConfig {
	CLMEC2Client ec2Client = null;
	Properties properties = getConfigProperties();
	public void startUsingId() {
		ec2Client = new CLMEC2Client(properties);
		StartServicesRequest startInstanceRequest = new StartServicesRequest();
		// Pass CLM Service id here.
		startInstanceRequest.setServiceIds(Collections
				.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.startInstances(startInstanceRequest);
	}
	public void startUsingName() {
		ec2Client = new CLMEC2Client(properties);
		StartServicesRequest startInstanceRequest = new StartServicesRequest();
		// Pass CLM Service name here.
		startInstanceRequest.setServiceNames(Collections
				.singletonList("Demo-Service"));
		ec2Client.startInstances(startInstanceRequest);
	}
	public static void main(String[] args) {
		StartInstancesSample1 instancesSample1 = new StartInstancesSample1();
		System.out.println("Starting Service using Id...");
		instancesSample1.startUsingId();
		
		System.out.println("Starting Service using name...");
		instancesSample1.startUsingName();
	}
}

Stop instance using CLM AWS SDK

To stop an instance or a SOI using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Stop an instance

 Click for code snippet.
Stopping an instance
package com.bmc.awssdk.samples.stopinstances;
import java.util.Collections;
import java.util.Properties;
import com.amazonaws.services.ec2.model.StopInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;

/**
 * This sample demonstrates use of CLMEC2Client to stop instances.
 * AWS StopInstancesRequest is used in this sample.
 */
public class StopInstancesSample extends CommonConfig{
	CLMEC2Client ec2Client = null;
	
	public void stop(){
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		
		StopInstancesRequest stopInstanceRequest = new StopInstancesRequest();
		//Pass Server id here. 
		stopInstanceRequest.withInstanceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.stopInstances(stopInstanceRequest);
	}
	
	public static void main(String[] args) {
		StopInstancesSample instancesSample = new StopInstancesSample();
		instancesSample.stop();
	}
}

Stop a SOI

 Click for code snippet.
Stopping an SOI
package com.bmc.awssdk.samples.stopinstances;
import java.util.Collections;
import java.util.Properties;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.StopServicesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to stop services in BMC Cloud
 * LifeCycle Management. StopServicesRequest is used in this sample.
 */
public class StopInstancesSample1 extends CommonConfig {
	CLMEC2Client ec2Client = null;
	Properties properties = getConfigProperties();
	public void stopUsingId() {
		ec2Client = new CLMEC2Client(properties);
		StopServicesRequest stopInstanceRequest = new StopServicesRequest();
		// Pass CLM Service id here.
		stopInstanceRequest.setServiceIds(Collections
				.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.stopInstances(stopInstanceRequest);
	}
	
	public void stopUsingName() {
		ec2Client = new CLMEC2Client(properties);
		StopServicesRequest stopInstanceRequest = new StopServicesRequest();
		// Pass CLM Service name here.
		stopInstanceRequest.setServiceNames(Collections
				.singletonList("Demo-Service"));
		ec2Client.stopInstances(stopInstanceRequest);
	}
	
	public static void main(String[] args) {
		StopInstancesSample1 instancesSample1 = new StopInstancesSample1();
		System.out.println("Stopping Service using id ...");
		instancesSample1.stopUsingId();
		
		System.out.println("Stopping Service using name ...");
		instancesSample1.stopUsingName();
	}
}

Terminate instance using CLM AWS SDK

To terminate an instance or a SOI using CLM AWS SDK, you can use CLMEC2Client and perform the following actions:

Terminate an instance

 Click for code snippet.
Terminating an instance
package com.bmc.awssdk.samples.terminate;
import java.util.Collections;
import java.util.Properties;
import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
/**
 * This sample demonstrates use of CLMEC2Client to terminate instances in BMC Cloud LifeCycle Management.
 * AWS TerminateInstancesRequest is used in this sample.
 */
public class TerminateInstancesSample extends CommonConfig{
	CLMEC2Client ec2Client = null;
	
	public void terminate(){
		Properties properties = getConfigProperties();
		ec2Client = new CLMEC2Client(properties);
		TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest();
		//Pass Server id here
		terminateInstancesRequest.setInstanceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.terminateInstances(terminateInstancesRequest);
	}
	
	public static void main(String[] args) {
		TerminateInstancesSample instancesSample = new TerminateInstancesSample();
		instancesSample.terminate();
	}
}

Terminate a SOI

 Click for code snippet.
Terminating an SOI
package com.bmc.awssdk.samples.terminate;
import java.util.Collections;
import java.util.Properties;
import com.bmc.awssdk.samples.common.CommonConfig;
import com.bmc.cloud.sdk.aws.CLMEC2Client;
import com.bmc.cloud.sdk.aws.model.TerminateServicesRequest;
/**
 * This sample demonstrates use of CLMEC2Client to terminate CLM Service in BMC Cloud LifeCycle Management.
 * CLM TerminateServicesRequest is used in this sample.
 */
public class TerminateInstancesSample1 extends CommonConfig{
	
CLMEC2Client ec2Client = null;
	Properties properties = getConfigProperties();
	
	public void terminateUsingId(){
		ec2Client = new CLMEC2Client(properties);
		TerminateServicesRequest terminateServicesRequest = new TerminateServicesRequest();
		//Pass CLM Service id here.
		terminateServicesRequest.setServiceIds(Collections.singletonList("484189ef-1b71-4693-a877-efd480b448bb"));
		ec2Client.terminateInstances(terminateServicesRequest);
	}
	public void terminateUsingName(){
		ec2Client = new CLMEC2Client(properties);
		TerminateServicesRequest terminateServicesRequest = new TerminateServicesRequest();
		//Pass CLM Service name here.
		terminateServicesRequest.setServiceNames(Collections.singletonList("Demo-Service1"));
		ec2Client.terminateInstances(terminateServicesRequest);
	}
	
	public static void main(String[] args) {
		TerminateInstancesSample1 instancesSample1 = new TerminateInstancesSample1();
		instancesSample1.terminateUsingId();
		
		instancesSample1.terminateUsingName();
	}
	
}

Related topics

onboarding
Was this page helpful? Yes No Submitting... Thank you

Comments