summaryrefslogtreecommitdiff
path: root/doc/source/template_guide/basic_resources.rst
blob: a0dcb17bca32bc6c685a9de5c0a29d8c5f349609 (plain)
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
.. highlight: yaml
   :linenothreshold: 5

.. _basic_resources:

=========
Instances
=========

..  For consistency let's define a few values to use in the samples:
    * image name: ubuntu-trusty-x86_64
    * shared/provider network name: "public"
    * tenant network and subnet names: "private" and "private-subnet"

Manage instances
~~~~~~~~~~~~~~~~

Create an instance
------------------
Use the :ref:`OS::Nova::Server` resource to create a Compute instance. The
``flavor`` property is the only mandatory one, but you need to define a boot
source using one of the ``image`` or ``block_device_mapping`` properties.

You also need to define the ``networks`` property to indicate to which networks
your instance must connect if multiple networks are available in your tenant.

The following example creates a simple instance, booted from an image, and
connecting to the ``private`` network:

.. code-block:: yaml

    resources:
      instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          networks:
            - network: private


Connect an instance to a network
--------------------------------
Use the ``networks`` property of an :ref:`OS::Nova::Server` resource to
define which networks an instance should connect to. Define each network as a
YAML map, containing one of the following keys:

``port``
    The ID of an existing Networking port. You usually create this port in the
    same template using an :ref:`OS::Neutron::Port` resource. You will be
    able to associate a floating IP to this port, and the port to your Compute
    instance.

``network``
    The name or ID of an existing network. You don't need to create an
    :ref:`OS::Neutron::Port` resource if you use this property. But you will
    not be able to use neutron floating IP association for this instance
    because there will be no specified port for server.

The following example demonstrates the use of the ``port`` and ``network``
properties:

.. code-block:: yaml

    resources:
      instance_port:
        type: OS::Neutron::Port
        properties:
          network: private
          fixed_ips:
            - subnet_id: "private-subnet"

      instance1:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          networks:
            - port: { get_resource: instance_port }

      instance2:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          networks:
            - network: private


Create and associate security groups to an instance
---------------------------------------------------
Use the :ref:`OS::Neutron::SecurityGroup` resource to create security
groups.

Define the ``security_groups`` property of the :ref:`OS::Neutron::Port`
resource to associate security groups to a port, then associate the port to an
instance.

The following example creates a security group allowing inbound connections on
ports 80 and 443 (web server) and associates this security group to an instance
port:

.. code-block:: yaml

    resources:
      web_secgroup:
        type: OS::Neutron::SecurityGroup
        properties:
          rules:
            - protocol: tcp
              remote_ip_prefix: 0.0.0.0/0
              port_range_min: 80
              port_range_max: 80
            - protocol: tcp
              remote_ip_prefix: 0.0.0.0/0
              port_range_min: 443
              port_range_max: 443

      instance_port:
        type: OS::Neutron::Port
        properties:
          network: private
          security_groups:
            - default
            - { get_resource: web_secgroup }
          fixed_ips:
            - subnet_id: private-subnet

      instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          networks:
            - port: { get_resource: instance_port }


Create and associate a floating IP to an instance
-------------------------------------------------

Use the :ref:`OS::Neutron::FloatingIP` resource to create a floating IP, and
the :ref:`OS::Neutron::FloatingIPAssociation` resource to associate the
floating IP to a port:

.. code-block:: yaml

    parameters:
      net:
        description: name of network used to launch instance.
        type: string
        default: private

    resources:
      inst1:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          networks:
            - network: {get_param: net}

      floating_ip:
        type: OS::Neutron::FloatingIP
        properties:
          floating_network: public

      association:
        type: OS::Neutron::FloatingIPAssociation
        properties:
          floatingip_id: { get_resource: floating_ip }
          port_id: {get_attr: [inst1, addresses, {get_param: net}, 0, port]}

You can also create an OS::Neutron::Port and associate that with the server and
the floating IP. However the approach mentioned above will work better
with stack updates.

.. code-block:: yaml

    resources:
      instance_port:
        type: OS::Neutron::Port
        properties:
          network: private
          fixed_ips:
            - subnet_id: "private-subnet"

      floating_ip:
        type: OS::Neutron::FloatingIP
        properties:
          floating_network: public

      association:
        type: OS::Neutron::FloatingIPAssociation
        properties:
          floatingip_id: { get_resource: floating_ip }
          port_id: { get_resource: instance_port }

Enable remote access to an instance
-----------------------------------
The ``key_name`` attribute of the :ref:`OS::Nova::Server` resource defines
the key pair to use to enable SSH remote access:

.. code-block:: yaml

    resources:
      my_instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          key_name: my_key

.. note::
   For more information about key pairs, see `Configure access and security for
   instances
   <https://docs.openstack.org/ocata/user-guide/cli-nova-configure-access-security-for-instances.html>`_.

Create a key pair
-----------------
You can create new key pairs with the :ref:`OS::Nova::KeyPair` resource. Key
pairs can be imported or created during the stack creation.

If the ``public_key`` property is not specified, the Orchestration module
creates a new key pair. If the ``save_private_key`` property is set to
``true``, the ``private_key`` attribute of the resource holds the private key.

The following example creates a new key pair and uses it as authentication key
for an instance:

.. code-block:: yaml

    resources:
      my_key:
        type: OS::Nova::KeyPair
        properties:
          save_private_key: true
          name: my_key

      my_instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64
          key_name: { get_resource: my_key }

    outputs:
      private_key:
        description: Private key
        value: { get_attr: [ my_key, private_key ] }

Manage networks
~~~~~~~~~~~~~~~
Create a network and a subnet
-----------------------------
.. note::
    The Networking service (neutron) must be enabled on your OpenStack
    deployment to create and manage networks and subnets. Networks and subnets
    cannot be created if your deployment uses legacy networking (nova-network).

Use the :ref:`OS::Neutron::Net` resource to create a network, and the
:ref:`OS::Neutron::Subnet` resource to provide a subnet for this network:

.. code-block:: yaml

    resources:
      new_net:
        type: OS::Neutron::Net

      new_subnet:
        type: OS::Neutron::Subnet
        properties:
          network_id: { get_resource: new_net }
          cidr: "10.8.1.0/24"
          dns_nameservers: [ "8.8.8.8", "8.8.4.4" ]
          ip_version: 4


Create and manage a router
--------------------------
Use the :ref:`OS::Neutron::Router` resource to create a router. You can
define its gateway with the ``external_gateway_info`` property:

.. code-block:: yaml

    resources:
      router1:
        type: OS::Neutron::Router
        properties:
          external_gateway_info: { network: public }

You can connect subnets to routers with the
:ref:`OS::Neutron::RouterInterface` resource:

.. code-block:: yaml

    resources:
      subnet1_interface:
        type: OS::Neutron::RouterInterface
        properties:
          router_id: { get_resource: router1 }
          subnet: private-subnet


Complete network example
------------------------
The following example creates a network stack:

* A network and an associated subnet.
* A router with an external gateway.
* An interface to the new subnet for the new router.

In this example, the ``public`` network is an existing shared network:

.. code-block:: yaml

    resources:
      internal_net:
        type: OS::Neutron::Net

      internal_subnet:
        type: OS::Neutron::Subnet
        properties:
          network_id: { get_resource: internal_net }
          cidr: "10.8.1.0/24"
          dns_nameservers: [ "8.8.8.8", "8.8.4.4" ]
          ip_version: 4

      internal_router:
        type: OS::Neutron::Router
        properties:
          external_gateway_info: { network: public }

      internal_interface:
        type: OS::Neutron::RouterInterface
        properties:
          router_id: { get_resource: internal_router }
          subnet: { get_resource: internal_subnet }


Manage volumes
~~~~~~~~~~~~~~
Create a volume
---------------
Use the :ref:`OS::Cinder::Volume` resource to create a new Block Storage
volume.

For example:

.. code-block:: yaml

    resources:
      my_new_volume:
        type: OS::Cinder::Volume
        properties:
          size: 10

The volumes that you create are empty by default. Use the ``image`` property to
create a bootable volume from an existing image:

.. code-block:: yaml

    resources:
      my_new_bootable_volume:
        type: OS::Cinder::Volume
        properties:
          size: 10
          image: ubuntu-trusty-x86_64


You can also create new volumes from another volume, a volume snapshot, or a
volume backup. Use the ``source_volid``, ``snapshot_id`` or ``backup_id``
properties to create a new volume from an existing source.

For example, to create a new volume from a backup:

.. code-block:: yaml

    resources:
      another_volume:
        type: OS::Cinder::Volume
        properties:
          backup_id: 2fff50ab-1a9c-4d45-ae60-1d054d6bc868

In this example the ``size`` property is not defined because the Block Storage
service uses the size of the backup to define the size of the new volume.

Attach a volume to an instance
------------------------------
Use the :ref:`OS::Cinder::VolumeAttachment` resource to attach a volume to
an instance.

The following example creates a volume and an instance, and attaches the volume
to the instance:

.. code-block:: yaml

    resources:
      new_volume:
        type: OS::Cinder::Volume
        properties:
          size: 1

      new_instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          image: ubuntu-trusty-x86_64

      volume_attachment:
        type: OS::Cinder::VolumeAttachment
        properties:
          volume_id: { get_resource: new_volume }
          instance_uuid: { get_resource: new_instance }

Boot an instance from a volume
------------------------------
Use the ``block_device_mapping`` property of the :ref:`OS::Nova::Server`
resource to define a volume used to boot the instance. This property is a list
of volumes to attach to the instance before its boot.

The following example creates a bootable volume from an image, and uses it to
boot an instance:

.. code-block:: yaml

    resources:
      bootable_volume:
        type: OS::Cinder::Volume
        properties:
          size: 10
          image: ubuntu-trusty-x86_64

      instance:
        type: OS::Nova::Server
        properties:
          flavor: m1.small
          networks:
            - network: private
          block_device_mapping:
            - device_name: vda
              volume_id: { get_resource: bootable_volume }
              delete_on_termination: false

.. TODO
  A few elements that probably belong here:
  - OS::Swift::Container
  - OS::Trove::Instance