1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
# OpenStack Orchestration
The mission of the OpenStack Orchestration program is to create a human- and machine-accessible service for managing the entire lifecycle of infrastructure and applications within OpenStack clouds.
## Heat
Heat is the main project in the OpenStack Orchestration program. It implements an orchestration engine to launch multiple composite cloud applications based on templates in the form of text files that can be treated like code. A native Heat template format is evolving, but Heat also endeavours to provide compatibility with the AWS CloudFormation template format, so that many existing CloudFormation templates can be launched on OpenStack. Heat provides both an OpenStack-native ReST API and a CloudFormation-compatible Query API.
*Why ‘Heat’? It makes the clouds rise!*
**How it works**
* A Heat template describes the infrastructure for a cloud application in a text file that is readable and writable by humans, and can be checked into version control, diffed, &c.
* Infrastructure resources that can be described include: servers, floating ips, volumes, security groups, users, etc.
* Heat also provides an autoscaling service that integrates with Ceilometer, so you can include a scaling group as a resource in a template.
* Templates can also specify the relationships between resources (e.g. this volume is connected to this server). This enables Heat to call out to the OpenStack APIs to create all of your infrastructure in the correct order to completely launch your application.
* Heat manages the whole lifecycle of the application - when you need to change your infrastructure, simply modify the template and use it to update your existing stack. Heat knows how to make the necessary changes. It will delete all of the resources when you are finished with the application, too.
* Heat primarily manages infrastructure, but the templates integrate well with software configuration management tools such as Puppet and Chef. The Heat team is working on providing even better integration between infrastructure and software.
_Source: [OpenStack Wiki](https://wiki.openstack.org/wiki/Heat)_
# OpenStack Orchestration (Heat) Client
[Full OpenStack Orchestration/Heat API Docs](http://developer.openstack.org/api-ref-orchestration-v1.html)
## Orchestration Service
Get a handle on the Orchestration service:
```ruby
service = Fog::OpenStack::Orchestration.new({
:openstack_auth_url => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint
:openstack_username => OPEN_STACK_USER, # Your OpenStack Username
:openstack_tenant => OPEN_STACK_TENANT, # Your tenant id
:openstack_api_key => OPEN_STACK_PASSWORD, # Your OpenStack Password
:connection_options => {} # Optional
})
```
We will use this `service` to interact with the Orchestration resources, `stack`, `event`, `resource`, and `template`
Read more about the [Optional Connection Parameters](common/connection_params.md)
## Stacks
Get a list of stacks you own:
```ruby
service.stacks
```
This returns a list of stacks with minimum attributes, leaving other attributes empty
```ruby
=> <Fog::OpenStack::Orchestration::Stacks
[
<Fog::OpenStack::Orchestration::Stack
id="0b8e4060-419b-416b-a927-097d4afbf26d",
capabilities=nil,
description="Simple template to deploy a single compute instance",
disable_rollback=nil,
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}],
notification_topics=nil,
outputs=nil,
parameters=nil,
stack_name="stack4",
stack_status="UPDATE_COMPLETE",
stack_status_reason="Stack successfully updated",
template_description=nil,
timeout_mins=nil,
creation_time="2014-08-27T21:25:56Z",
updated_time="2015-01-30T20:10:43Z"
>,
...
```
Create a new `stack` with a [Heat Template (HOT)](http://docs.openstack.org/developer/heat/template_guide/hot_guide.html) or an AWS CloudFormation Template (CFN):
```ruby
raw_template = File.read(TEMPLATE_FILE)
service.stacks.new.save({
:stack_name => "a_name_for_stack",
:template => raw_template,
:parameters => {"flavor" => "m1.small", "image" => "cirror"}
})
```
This returns a JSON blob filled with information about our new stack:
```ruby
{"id"=>"53b35fbe-34f7-4837-b0f8-8863b7263b7d",
"links"=>[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d",
"rel"=>"self"}]}
```
We can get a reference to the stack using its `stack_name` and `id`:
```ruby
stack = service.stacks.get("stack4", "0b8e4060-419b-416b-a927-097d4afbf26d")
```
This returns a stack with all attributes filled
```ruby
=> <Fog::OpenStack::Orchestration::Stack
id="0b8e4060-419b-416b-a927-097d4afbf26d",
capabilities=[],
description="Simple template to deploy a single compute instance",
disable_rollback=true,
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "rel"=>"self"}],
notification_topics=[],
outputs=[],
parameters={"AWS::StackId"=>"arn:openstack:heat::5d139d95546240748508b2a518aa5bef:stacks/stack4/0b8e4060-419b-416b-a927-097d4afbf26d", "AWS::Region"=>"ap-southeast-1", "AWS::StackName"=>"stack4"},
stack_name="stack4",
stack_status="UPDATE_COMPLETE",
stack_status_reason="Stack successfully updated",
template_description="Simple template to deploy a single compute instance",
timeout_mins=60,
creation_time="2014-08-27T21:25:56Z",
updated_time="2015-01-30T20:10:43Z"
>
```
It can be also obtained through the details method of a simple stack object
```ruby
stack.details
```
To update a stack while manipulating a Stack object from the Stack Collection:
```ruby
heat_template = { "template": { "description": "Updated description" } }
stack.save(heat_template)
```
`save` uses the `update_stack` request method, although it expects a Stack object as well:
```ruby
heat_template = { "template": { "description": "Updated description" } }
service.update_stack(stack, heat_template)
```
Alternatively a request only approach can be used, providing a stack id and name:
```ruby
id = "49b83314-d341-468a-aef4-44bbccce251e"
name = "stack_name"
heat_template = { "template": { "description": "Other update description" } }
service.update_stack(id, name, heat_template)
```
A stack knows about related `events`:
```ruby
stack.events
=> <Fog::OpenStack::Orchestration::Events
[
<Fog::OpenStack::Orchestration::Event
id="251",
resource_name="my_instance",
event_time="2015-01-21T20:08:51Z",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance/events/251", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/a_name_for_stack/53b35fbe-34f7-4837-b0f8-8863b7263b7d", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_IN_PROGRESS",
resource_status_reason="state changed",
physical_resource_id=nil
>,
```
A stack knows about related `resources`:
```ruby
stack.resources
=> <Fog::OpenStack::Orchestration::Resources
[
<Fog::OpenStack::Orchestration::Resource
id=nil,
resource_name="my_instance",
description=nil,
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_COMPLETE",
updated_time="2014-09-12T20:44:06Z",
required_by=[],
resource_status_reason="state changed",
resource_type="OS::Nova::Server"
>
]
>
```
You can get a stack's `template`
```ruby
stack.template
=> <Fog::OpenStack::Orchestration::Template
format="HOT",
description="Simple template to deploy a single compute instance",
template_version="2013-05-23",
parameters=nil,
resources=...
```
You can just delete a stack. This deletes associated `resources` :
```ruby
stack.delete
=> #<Excon::Response:0x007fe1066b2af8 @data={:body=>"", :headers=>{"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, :status=>204, :reason_phrase=>"No Content", :remote_ip=>"10.8.96.4", :local_port=>59628, :local_address=>"10.17.68.186"}, @body="", @headers={"Content-Type"=>"text/html; charset=UTF-8", "Content-Length"=>"0", "Date"=>"Wed, 21 Jan 2015 20:38:00 GMT"}, @status=204, @remote_ip="10.8.96.4", @local_port=59628, @local_address="10.17.68.186">
```
Reload any object by calling `reload` on it:
```ruby
stacks.reload
=> <Fog::OpenStack::Orchestration::Stacks
[...]
>
```
## Events
You can list `Events` of a `stack`:
```ruby
stack.events
=> <Fog::OpenStack::Orchestration::Events
[
<Fog::OpenStack::Orchestration::Event
id="15",
resource_name="my_instance",
event_time="2014-09-12T20:43:58Z",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_IN_PROGRESS",
resource_status_reason="state changed",
physical_resource_id=nil
>,
```
`Event` can be got through corresponding `resource`
```ruby
event = service.events.get(stack, resource, event_id)
=> <Fog::OpenStack::Orchestration::Event
id="15",
resource_name="my_instance",
event_time="2014-09-12T20:43:58Z",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance/events/15", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"resource"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_IN_PROGRESS",
resource_status_reason="state changed",
physical_resource_id=nil
>
```
An `event` knows about its associated `stack`:
```ruby
event.stack
=> <Fog::OpenStack::Orchestration::Stack
id="0c9ee370-ef64-4a80-a6cc-65d2277caeb9",
description="Simple template to deploy a single compute instance",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}],
stack_status_reason="Stack create completed successfully",
stack_name="progenerated",
creation_time="2014-09-12T20:43:58Z",
updated_time="2014-09-12T20:44:06Z"
>
```
An `event` has an associated `resource`:
```ruby
resource = event.resource
=> <Fog::OpenStack::Orchestration::Resource
id=nil,
resource_name="my_instance",
description="",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_COMPLETE",
updated_time="2014-09-12T20:44:06Z",
required_by=[],
resource_status_reason="state changed",
resource_type="OS::Nova::Server"
>
```
## Resource
`resources` might be nested:
```ruby
service.resources.all(stack, {:nested_depth => 1})
=> <Fog::OpenStack::Orchestration::Resources
[
<Fog::OpenStack::Orchestration::Resource
id=nil,
resource_name="my_instance",
description=nil,
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9/resources/my_instance", "rel"=>"self"}, {"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"stack"}],
logical_resource_id="my_instance",
resource_status="CREATE_COMPLETE",
updated_time="2014-09-12T20:44:06Z",
required_by=[],
resource_status_reason="state changed",
resource_type="OS::Nova::Server"
>
]
>
```
A `resource` knows about its associated `stack`:
```ruby
resource.stack
=> <Fog::OpenStack::Orchestration::Stack
id="0c9ee370-ef64-4a80-a6cc-65d2277caeb9",
description="Simple template to deploy a single compute instance",
links=[{"href"=>"http://10.8.96.4:8004/v1/5d139d95546240748508b2a518aa5bef/stacks/progenerated/0c9ee370-ef64-4a80-a6cc-65d2277caeb9", "rel"=>"self"}],
stack_status_reason="Stack create completed successfully",
stack_name="progenerated",
creation_time="2014-09-12T20:43:58Z",
updated_time="2014-09-12T20:44:06Z"
>
```
Resource metadata is visible:
```ruby
irb: resource.metadata
=> {}
```
A `resource's` template is visible (if one exists)
```ruby
irb: resource.template
=> nil
```
## Validation
You can validate a template (either HOT or CFN) before using it:
```ruby
service.templates.validate(:template => content)
=> <Fog::OpenStack::Orchestration::Template
format=nil,
description="Simple template to deploy a single compute instance",
template_version=nil,
parameters={},
resources=nil,
content=nil
>
```
## Cancel Update
When the stack is updating, you can cancel the update:
```ruby
# stack.stack_status == 'UPDATE_IN_PROGRESS'
stack.cancel_update
=> nil
```
Then you can see the status changed to ROLLBACK_IN_PROGRESS:
```ruby
stack = service.stacks.get(stack.stack_name, stack.id)
stack.stack_status
=> "ROLLBACK_IN_PROGRESS"
```
|