• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. JAVA
  6. RTS Java SDK Demo

RTS Java SDK Demo

Preparing a Heat Template

A Heat template describes the infrastructure for a cloud application in a text file that is readable and writable by humans.

Prepare the Heat template file, for example, heatTemplate.yaml, as shown in the following.

--- 
description: "Simple template to deploy a single compute instance" 
heat_template_version: 2013-05-23 
parameters: 
flavor: 
type: string 
image: 
type: string 
key_name: 
type: string 
network: 
type: string 
resources: 
my_instance: 
properties: 
availability_zone: az_name
flavor: 
get_param: flavor 
image: 
get_param: image 
key_name: 
get_param: key_name 
networks: 
- 
network: 
get_param: network 
type: "OS::Nova::Server"

Creating a Stack

The templates enable the creation of most OpenStack resource types, such as instances, EIPs, volumes, security groups, and users. The resources, once created, are referred to as stacks.

You can create a stack based on the following code:

public void heatStackTest() throws IOException, InterruptedException{ 
String testStackName = "test-25"; 
Map<String, String> stackparams = new HashMap<String, String>(); 
stackparams.put("network", "network_id"); 
stackparams.put("flavor", "s1.large"); 
stackparams.put("image", "imageId"); 
stackparams.put("key_name", "key_name"); 

StackCreate stackCreate = Builders.stack() 
.name(testStackName) 
.templateFromFile("heattemplate.yaml") 
.parameters(stackparams) 
.build(); 
Stack stack = os.heat().stacks().create(stackCreate); 

//judge the state of the stack 
int count = 1; 
String getStaus = os.heat().stacks().getDetails(testStackName, stack.getId()).getStatus().toString(); 
while ((!getStaus.equals("CREATE_COMPLETE")) && count < 50) { 
System.out.println(!getStaus.equals("CREATE_COMPLETE")); 
System.out.println(count); 
getStaus = os.heat().stacks().getDetails(testStackName, stack.getId()).getStatus().toString(); 
System.out.println(getStaus); 
Thread.sleep(5000); 
count++; 
} 
}

Deleting a Stack

You can delete a stack based on the following code:

os.heat().stacks().delete(stackName, stackId);