0
# OpenStack Support
1
2
Limited OpenStack Heat template support for organizations using hybrid cloud deployments with both AWS and OpenStack infrastructure.
3
4
## Capabilities
5
6
### Heat Template Support
7
8
Basic OpenStack Heat template functionality for hybrid cloud environments.
9
10
```python { .api }
11
class HeatTemplate:
12
def __init__(self, heat_template_version: str = None):
13
"""
14
OpenStack Heat template.
15
16
Args:
17
heat_template_version: Heat template version (e.g., "2013-05-23")
18
"""
19
20
def add_resource(self, resource) -> resource:
21
"""
22
Add resource to Heat template.
23
24
Args:
25
resource: OpenStack resource object
26
27
Returns:
28
The added resource
29
"""
30
31
def to_dict(self) -> Dict[str, Any]:
32
"""
33
Convert template to dictionary format.
34
35
Returns:
36
dict: Heat template as dictionary
37
"""
38
39
def to_yaml(self) -> str:
40
"""
41
Convert template to YAML string.
42
43
Returns:
44
str: Heat template as YAML
45
"""
46
```
47
48
### Nova Compute Resources
49
50
OpenStack compute resources for virtual machines and compute management.
51
52
```python { .api }
53
class Server:
54
resource_type = "OS::Nova::Server"
55
56
def __init__(self, title: str, image: str, flavor: str,
57
networks: list = None, key_name: str = None, **kwargs):
58
"""
59
Nova server (virtual machine).
60
61
Args:
62
title: Resource logical name
63
image: Image ID or name
64
flavor: Flavor ID or name
65
networks: List of networks to attach
66
key_name: Key pair name for SSH access
67
"""
68
69
class KeyPair:
70
resource_type = "OS::Nova::KeyPair"
71
72
def __init__(self, title: str, name: str, public_key: str = None, **kwargs):
73
"""
74
Nova key pair for SSH access.
75
76
Args:
77
title: Resource logical name
78
name: Key pair name
79
public_key: Public key content (auto-generated if not provided)
80
"""
81
82
class Flavor:
83
resource_type = "OS::Nova::Flavor"
84
85
def __init__(self, title: str, ram: int, vcpus: int, disk: int, **kwargs):
86
"""
87
Nova flavor (instance type).
88
89
Args:
90
title: Resource logical name
91
ram: RAM in MB
92
vcpus: Number of virtual CPUs
93
disk: Disk size in GB
94
"""
95
96
class ServerGroup:
97
resource_type = "OS::Nova::ServerGroup"
98
99
def __init__(self, title: str, policies: list, **kwargs):
100
"""
101
Nova server group for anti-affinity/affinity policies.
102
103
Args:
104
title: Resource logical name
105
policies: List of policies ('anti-affinity', 'affinity', etc.)
106
"""
107
```
108
109
### Neutron Networking Resources
110
111
OpenStack networking resources for virtual networks, subnets, routers, and security groups.
112
113
```python { .api }
114
class Net:
115
resource_type = "OS::Neutron::Net"
116
117
def __init__(self, title: str, name: str = None, admin_state_up: bool = True, **kwargs):
118
"""
119
Neutron network.
120
121
Args:
122
title: Resource logical name
123
name: Network name
124
admin_state_up: Administrative state
125
"""
126
127
class Subnet:
128
resource_type = "OS::Neutron::Subnet"
129
130
def __init__(self, title: str, network_id: str, cidr: str,
131
ip_version: int = 4, **kwargs):
132
"""
133
Neutron subnet.
134
135
Args:
136
title: Resource logical name
137
network_id: Network ID or reference
138
cidr: CIDR block for subnet
139
ip_version: IP version (4 or 6)
140
"""
141
142
class Router:
143
resource_type = "OS::Neutron::Router"
144
145
def __init__(self, title: str, external_gateway_info: dict = None, **kwargs):
146
"""
147
Neutron router.
148
149
Args:
150
title: Resource logical name
151
external_gateway_info: External network gateway configuration
152
"""
153
154
class RouterInterface:
155
resource_type = "OS::Neutron::RouterInterface"
156
157
def __init__(self, title: str, router_id: str, subnet_id: str, **kwargs):
158
"""
159
Neutron router interface.
160
161
Args:
162
title: Resource logical name
163
router_id: Router ID or reference
164
subnet_id: Subnet ID or reference
165
"""
166
167
class SecurityGroup:
168
resource_type = "OS::Neutron::SecurityGroup"
169
170
def __init__(self, title: str, description: str, name: str = None,
171
rules: list = None, **kwargs):
172
"""
173
Neutron security group.
174
175
Args:
176
title: Resource logical name
177
description: Security group description
178
name: Security group name
179
rules: List of security group rules
180
"""
181
182
class SecurityGroupRule:
183
resource_type = "OS::Neutron::SecurityGroupRule"
184
185
def __init__(self, title: str, security_group_id: str, direction: str,
186
protocol: str = None, port_range_min: int = None,
187
port_range_max: int = None, remote_ip_prefix: str = None, **kwargs):
188
"""
189
Neutron security group rule.
190
191
Args:
192
title: Resource logical name
193
security_group_id: Security group ID or reference
194
direction: Traffic direction ('ingress' or 'egress')
195
protocol: Protocol ('tcp', 'udp', 'icmp')
196
port_range_min: Minimum port number
197
port_range_max: Maximum port number
198
remote_ip_prefix: Remote IP prefix (CIDR)
199
"""
200
201
class FloatingIP:
202
resource_type = "OS::Neutron::FloatingIP"
203
204
def __init__(self, title: str, floating_network_id: str,
205
port_id: str = None, **kwargs):
206
"""
207
Neutron floating IP.
208
209
Args:
210
title: Resource logical name
211
floating_network_id: External network ID
212
port_id: Port ID to associate with (optional)
213
"""
214
215
class Port:
216
resource_type = "OS::Neutron::Port"
217
218
def __init__(self, title: str, network_id: str, security_groups: list = None,
219
fixed_ips: list = None, **kwargs):
220
"""
221
Neutron port.
222
223
Args:
224
title: Resource logical name
225
network_id: Network ID or reference
226
security_groups: List of security group IDs
227
fixed_ips: List of fixed IP configurations
228
"""
229
```
230
231
## Usage Examples
232
233
### Basic Heat Template
234
235
```python
236
from troposphere.openstack.heat import HeatTemplate
237
from troposphere.openstack.nova import Server, KeyPair
238
from troposphere.openstack.neutron import Net, Subnet, SecurityGroup
239
240
# Create Heat template
241
template = HeatTemplate(heat_template_version="2015-10-15")
242
243
# Create network
244
network = template.add_resource(Net(
245
"private_network",
246
name="private-net"
247
))
248
249
# Create subnet
250
subnet = template.add_resource(Subnet(
251
"private_subnet",
252
network_id={"get_resource": "private_network"},
253
cidr="192.168.1.0/24",
254
ip_version=4
255
))
256
257
# Create security group
258
security_group = template.add_resource(SecurityGroup(
259
"web_security_group",
260
description="Security group for web servers",
261
rules=[
262
{
263
"direction": "ingress",
264
"protocol": "tcp",
265
"port_range_min": 22,
266
"port_range_max": 22,
267
"remote_ip_prefix": "0.0.0.0/0"
268
},
269
{
270
"direction": "ingress",
271
"protocol": "tcp",
272
"port_range_min": 80,
273
"port_range_max": 80,
274
"remote_ip_prefix": "0.0.0.0/0"
275
}
276
]
277
))
278
279
# Create key pair
280
keypair = template.add_resource(KeyPair(
281
"web_keypair",
282
name="web-key"
283
))
284
285
# Create server
286
server = template.add_resource(Server(
287
"web_server",
288
image="ubuntu-20.04",
289
flavor="m1.small",
290
key_name={"get_resource": "web_keypair"},
291
networks=[{"network": {"get_resource": "private_network"}}],
292
security_groups=[{"get_resource": "web_security_group"}]
293
))
294
295
# Generate Heat template
296
heat_yaml = template.to_yaml()
297
print(heat_yaml)
298
```
299
300
### Multi-Tier Application
301
302
```python
303
from troposphere.openstack.heat import HeatTemplate
304
from troposphere.openstack.nova import Server
305
from troposphere.openstack.neutron import *
306
307
template = HeatTemplate()
308
309
# Database tier network
310
db_network = template.add_resource(Net(
311
"database_network",
312
name="db-tier"
313
))
314
315
db_subnet = template.add_resource(Subnet(
316
"database_subnet",
317
network_id={"get_resource": "database_network"},
318
cidr="10.0.1.0/24"
319
))
320
321
# Application tier network
322
app_network = template.add_resource(Net(
323
"application_network",
324
name="app-tier"
325
))
326
327
app_subnet = template.add_resource(Subnet(
328
"application_subnet",
329
network_id={"get_resource": "application_network"},
330
cidr="10.0.2.0/24"
331
))
332
333
# Web tier network (public)
334
web_network = template.add_resource(Net(
335
"web_network",
336
name="web-tier"
337
))
338
339
web_subnet = template.add_resource(Subnet(
340
"web_subnet",
341
network_id={"get_resource": "web_network"},
342
cidr="10.0.3.0/24"
343
))
344
345
# Router for external connectivity
346
router = template.add_resource(Router(
347
"main_router",
348
external_gateway_info={
349
"network": "public"
350
}
351
))
352
353
# Connect subnets to router
354
template.add_resource(RouterInterface(
355
"web_router_interface",
356
router_id={"get_resource": "main_router"},
357
subnet_id={"get_resource": "web_subnet"}
358
))
359
360
# Security groups
361
db_sg = template.add_resource(SecurityGroup(
362
"database_sg",
363
description="Database security group",
364
rules=[
365
{
366
"direction": "ingress",
367
"protocol": "tcp",
368
"port_range_min": 3306,
369
"port_range_max": 3306,
370
"remote_group_id": {"get_resource": "application_sg"}
371
}
372
]
373
))
374
375
app_sg = template.add_resource(SecurityGroup(
376
"application_sg",
377
description="Application security group",
378
rules=[
379
{
380
"direction": "ingress",
381
"protocol": "tcp",
382
"port_range_min": 8080,
383
"port_range_max": 8080,
384
"remote_group_id": {"get_resource": "web_sg"}
385
}
386
]
387
))
388
389
web_sg = template.add_resource(SecurityGroup(
390
"web_sg",
391
description="Web security group",
392
rules=[
393
{
394
"direction": "ingress",
395
"protocol": "tcp",
396
"port_range_min": 80,
397
"port_range_max": 80,
398
"remote_ip_prefix": "0.0.0.0/0"
399
},
400
{
401
"direction": "ingress",
402
"protocol": "tcp",
403
"port_range_min": 443,
404
"port_range_max": 443,
405
"remote_ip_prefix": "0.0.0.0/0"
406
}
407
]
408
))
409
410
# Servers
411
db_server = template.add_resource(Server(
412
"database_server",
413
image="mysql-8.0",
414
flavor="m1.medium",
415
networks=[{"network": {"get_resource": "database_network"}}],
416
security_groups=[{"get_resource": "database_sg"}]
417
))
418
419
app_server = template.add_resource(Server(
420
"application_server",
421
image="tomcat-9",
422
flavor="m1.large",
423
networks=[{"network": {"get_resource": "application_network"}}],
424
security_groups=[{"get_resource": "application_sg"}]
425
))
426
427
web_server = template.add_resource(Server(
428
"web_server",
429
image="nginx-latest",
430
flavor="m1.small",
431
networks=[{"network": {"get_resource": "web_network"}}],
432
security_groups=[{"get_resource": "web_sg"}]
433
))
434
```
435
436
### Hybrid Cloud Integration
437
438
```python
439
# Example showing potential integration patterns
440
# (Note: This is conceptual - actual integration depends on specific setup)
441
442
from troposphere import Template as AWSTemplate
443
from troposphere.openstack.heat import HeatTemplate
444
from troposphere.ec2 import Instance as AWSInstance
445
from troposphere.openstack.nova import Server as OpenStackServer
446
447
# AWS template
448
aws_template = AWSTemplate(Description="AWS resources")
449
450
aws_instance = aws_template.add_resource(AWSInstance(
451
"AWSWebServer",
452
ImageId="ami-0abcdef1234567890",
453
InstanceType="t3.micro"
454
))
455
456
# OpenStack template
457
heat_template = HeatTemplate(heat_template_version="2015-10-15")
458
459
openstack_server = heat_template.add_resource(OpenStackServer(
460
"OpenStackDBServer",
461
image="mysql-8.0",
462
flavor="m1.medium"
463
))
464
465
# Generate both templates
466
aws_json = aws_template.to_json()
467
heat_yaml = heat_template.to_yaml()
468
469
print("AWS CloudFormation Template:")
470
print(aws_json)
471
print("\nOpenStack Heat Template:")
472
print(heat_yaml)
473
```
474
475
Note: OpenStack support in Troposphere is limited compared to AWS functionality. For production OpenStack deployments, consider using Heat templates directly or specialized OpenStack orchestration tools. The Troposphere OpenStack support is primarily intended for organizations that need to maintain templates for both AWS and OpenStack environments using a similar Python-based approach.