dfilppi | 9981f55 | 2017-08-07 20:10:53 +0000 | [diff] [blame] | 1 | |
| 2 | .. highlight:: yaml |
| 3 | |
| 4 | Examples |
| 5 | ======== |
| 6 | |
| 7 | Example I |
| 8 | --------- |
| 9 | |
| 10 | This example will show how to use most of the types in this plugin, |
| 11 | as well as how to make the relationships between them. |
| 12 | |
| 13 | We'll see how to create a server with a security group set on it and a floating_ip associated to it, |
| 14 | on a subnet in a network. |
| 15 | |
| 16 | |
| 17 | The following is an excerpt from the blueprint's `blueprint`.`nodes` section:: |
| 18 | |
| 19 | my_floating_ip: |
| 20 | type: cloudify.openstack.nodes.FloatingIP |
| 21 | interfaces: |
| 22 | cloudify.interfaces.lifecycle: |
| 23 | create: |
| 24 | inputs: |
| 25 | args: |
| 26 | floating_network_name: Ext-Net |
| 27 | |
| 28 | |
| 29 | my_network: |
| 30 | type: cloudify.openstack.nodes.Network |
| 31 | properties: |
| 32 | resource_id: my_network_openstack_name |
| 33 | |
| 34 | |
| 35 | my_subnet: |
| 36 | type: cloudify.openstack.nodes.Subnet |
| 37 | properties: |
| 38 | resource_id: my_subnet_openstack_name |
| 39 | interfaces: |
| 40 | cloudify.interfaces.lifecycle: |
| 41 | create: |
| 42 | inputs: |
| 43 | args: |
| 44 | cidr: 1.2.3.0/24 |
| 45 | ip_version: 4 |
| 46 | cloudify.interfaces.validation: |
| 47 | creation: |
| 48 | inputs: |
| 49 | args: |
| 50 | cidr: 1.2.3.0/24 |
| 51 | ip_version: 4 |
| 52 | relationships: |
| 53 | - target: my_network |
| 54 | type: cloudify.relationships.contained_in |
| 55 | |
| 56 | |
| 57 | my_security_group: |
| 58 | type: cloudify.openstack.nodes.SecurityGroup |
| 59 | properties: |
| 60 | resource_id: my_security_group_openstack_name |
| 61 | rules: |
| 62 | - remote_ip_prefix: 0.0.0.0/0 |
| 63 | port: 8080 |
| 64 | |
| 65 | |
| 66 | my_server: |
| 67 | type: cloudify.openstack.nodes.Server |
| 68 | properties: |
| 69 | resource_id: my_server_openstack_name |
| 70 | interfaces: |
| 71 | cloudify.interfaces.lifecycle: |
| 72 | create: |
| 73 | inputs: |
| 74 | args: |
| 75 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 76 | flavor: 101 |
| 77 | cloudify.interfaces.validation: |
| 78 | creation: |
| 79 | inputs: |
| 80 | args: |
| 81 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 82 | flavor: 101 |
| 83 | relationships: |
| 84 | - target: my_network |
| 85 | type: cloudify.relationships.connected_to |
| 86 | - target: my_subnet |
| 87 | type: cloudify.relationships.depends_on |
| 88 | - target: my_floating_ip |
| 89 | type: cloudify.openstack.server_connected_to_floating_ip |
| 90 | - target: my_security_group |
| 91 | type: cloudify.openstack.server_connected_to_security_group |
| 92 | |
| 93 | |
| 94 | 1. Creates a floating IP, whose node name is ``my_floating_ip``, and whose floating_network_name is ``Ext-Net`` (This value represents the name of the external network). |
| 95 | 2. Creates a network, whose node name is ``my_network``, and whose name on Openstack is ``my_network_openstack_name``. |
| 96 | 3. Creates a subnet, whose node name is ``my_subnet``, and whose name on Openstack is ``my_subnet_openstack_name``. The subnet's address range is defined to be 1.2.3.0 - 1.2.3.255 using the ``cidr`` parameter, and the subnet's IP version is set to version 4. The subnet will be set on the ``my_network_openstack_name`` network because of the relationship to the ``my_network`` node. |
| 97 | 4. Creates a security_group, whose node name is ``my_security_group``, and whose name on Openstack is ``my_security_group_openstack_Name``. The security group is set with a single rule, which allows all traffic (since we use the address range ``0.0.0.0/0``) to port ``8080`` (default direction is *ingress*). |
| 98 | 5. Creates a server, whose node name is ``my_server``, and whose name on openstack is ``my_server_openstack_name``. The server is set with an image and flavor IDs. The server is set with multiple relationships: |
| 99 | |
| 100 | - A relationship to the ``my_network`` node: Through this relationship, |
| 101 | the server will be automatically placed on the ``my_network_openstack_name`` network. |
| 102 | - A relationship to the ``my_subnet`` node: |
| 103 | This relationship is strictly for ensuring the order of creation is correct, |
| 104 | as the server requires the ``my_subnet_openstack_name`` subnet to exist before it can be created on it. |
| 105 | - A relationship to the ``my_floating_ip`` node: |
| 106 | This designated relationship type will take care of associating the server with the floating IP represented by the ``my_floating_ip`` node. |
| 107 | - A relationship with the ``my_security_group`` node: |
| 108 | This relationship will take care of setting the server up with the security group represented by the ``my_security_group`` node. |
| 109 | |
| 110 | |
| 111 | Example II |
| 112 | ---------- |
| 113 | |
| 114 | This example will show how to use the ``router`` and ``port`` types, as well as some of the relationships that were missing from Example I. |
| 115 | |
| 116 | We'll see how to create a server connected to a port, where the port is set on a subnet in a network, and has a security group set on it. Finally, we'll see how this subnet connects to a router and from there to the external network. |
| 117 | |
| 118 | |
| 119 | The following is an excerpt from the blueprint's ``blueprint``.``node_templates`` section:: |
| 120 | |
| 121 | my_network: |
| 122 | type: cloudify.openstack.nodes.Network |
| 123 | properties: |
| 124 | resource_id: my_network_openstack_name |
| 125 | |
| 126 | |
| 127 | my_security_group: |
| 128 | type: cloudify.openstack.nodes.SecurityGroup |
| 129 | properties: |
| 130 | resource_id: my_security_group_openstack_name |
| 131 | rules: |
| 132 | - remote_ip_prefix: 0.0.0.0/0 |
| 133 | port: 8080 |
| 134 | |
| 135 | |
| 136 | my_subnet: |
| 137 | type: cloudify.openstack.nodes.Subnet |
| 138 | properties: |
| 139 | resource_id: my_subnet_openstack_name |
| 140 | interfaces: |
| 141 | cloudify.interfaces.lifecycle: |
| 142 | create: |
| 143 | inputs: |
| 144 | args: |
| 145 | cidr: 1.2.3.0/24 |
| 146 | ip_version: 4 |
| 147 | cloudify.interfaces.validation: |
| 148 | creation: |
| 149 | inputs: |
| 150 | args: |
| 151 | cidr: 1.2.3.0/24 |
| 152 | ip_version: 4 |
| 153 | relationships: |
| 154 | - target: my_network |
| 155 | type: cloudify.relationships.contained_in |
| 156 | - target: my_router |
| 157 | type: cloudify.openstack.subnet_connected_to_router |
| 158 | |
| 159 | |
| 160 | my_port: |
| 161 | type: cloudify.openstack.nodes.Port |
| 162 | properties: |
| 163 | resource_id: my_port_openstack_name |
| 164 | relationships: |
| 165 | - target: my_network |
| 166 | type: cloudify.relationships.contained_in |
| 167 | - target: my_subnet |
| 168 | type: cloudify.relationships.depends_on |
| 169 | - target: my_security_group |
| 170 | type: cloudify.openstack.port_connected_to_security_group |
| 171 | |
| 172 | |
| 173 | my_router: |
| 174 | type: cloudify.openstack.nodes.Router |
| 175 | properties: |
| 176 | resource_id: my_router_openstack_Name |
| 177 | |
| 178 | |
| 179 | my_server: |
| 180 | type: cloudify.openstack.nodes.Server |
| 181 | properties: |
| 182 | cloudify_agent: |
| 183 | user: ubuntu |
| 184 | interfaces: |
| 185 | cloudify.interfaces.lifecycle: |
| 186 | create: |
| 187 | inputs: |
| 188 | args: |
| 189 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 190 | flavor: 101 |
| 191 | cloudify.interfaces.validation: |
| 192 | creation: |
| 193 | inputs: |
| 194 | args: |
| 195 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 196 | flavor: 101 |
| 197 | relationships: |
| 198 | - target: my_port |
| 199 | type: cloudify.openstack.server_connected_to_port |
| 200 | |
| 201 | |
| 202 | 1. Creates a network. See Example I for more information. |
| 203 | |
| 204 | 2. Creates a security group. See Example I for more information. |
| 205 | |
| 206 | 3. Creates a subnet. This is again similar to what we've done in Example I. The difference here is that the subnet has an extra relationship set towards a router. |
| 207 | |
| 208 | 4. Creates a port, whose node name is ``my_port``, and whose name on Openstack is ``my_port_openstack_name``. The port is set with multiple relationships: |
| 209 | |
| 210 | - A relationship to the ``my_network`` node: Through this relationship, the port will be automatically placed on the ``my_network_openstack_name`` network. |
| 211 | - A relationship to the ``my_subnet`` node: This relationship is strictly for ensuring the order of creation is correct, as the port requires the ``my_subnet_openstack_name`` subnet to exist before it can be created on it. |
| 212 | - A relationship to the ``my_security_group`` node: This designated relationship type will take care of setting the ``my_security_group_openstack_name`` security group on the port. |
| 213 | |
| 214 | 5. Creates a router, whose node name is ``my_router``, and whose name on Openstack is ``my_router_openstack_name``. The router will automatically have an interface in the external network. |
| 215 | |
| 216 | 6. Creates a server, whose node name is ``my_server``, and whose name on Openstack is **the node's ID** (since no ``name`` parameter was supplied under the ``server`` property). The server is set with an image and flavor IDs. It also overrides the ``cloudify_agent`` property of its parent type to set the username that will be used to connect to the server for installing the Cloudify agent on it. Finally, it is set with a relationship to the ``my_port`` node: This designated relationship type will take care of connecting the server to ``my_port_openstack_name``. |
| 217 | |
| 218 | |
| 219 | Example III |
| 220 | ----------- |
| 221 | |
| 222 | This example will show how to use the ``volume`` type, as well as ``volume_attached_to_server`` relationship. |
| 223 | |
| 224 | The following is an excerpt from the blueprint's ``blueprint``.``node_templates`` section:: |
| 225 | |
| 226 | my_server: |
| 227 | type: cloudify.openstack.nodes.Server |
| 228 | properties: |
| 229 | cloudify_agent: |
| 230 | user: ubuntu |
| 231 | interfaces: |
| 232 | cloudify.interfaces.lifecycle: |
| 233 | create: |
| 234 | inputs: |
| 235 | args: |
| 236 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 237 | flavor: 101 |
| 238 | cloudify.interfaces.validation: |
| 239 | creation: |
| 240 | inputs: |
| 241 | args: |
| 242 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 243 | flavor: 101 |
| 244 | |
| 245 | my_volume: |
| 246 | type: cloudify.openstack.nodes.Volume |
| 247 | properties: |
| 248 | resource_id: my_openstack_volume_name |
| 249 | device_name: /dev/vdb |
| 250 | interfaces: |
| 251 | cloudify.interfaces.lifecycle: |
| 252 | create: |
| 253 | inputs: |
| 254 | args: |
| 255 | size: 1 |
| 256 | relationships: |
| 257 | - target: my_server |
| 258 | type: cloudify.openstack.volume_attached_to_server |
| 259 | |
| 260 | |
| 261 | 1. Creates a server, with name ``my_server``, and with name on Openstack **the node's ID** (since no ``name`` parameter was supplied under the ``server`` property). The server is set with an image and flavor IDs. |
| 262 | 2. Creates a volume. It is set with a relationship to the ``my_server`` node: This designated relationship type will take care of attaching the volume to Openstack server node. |
| 263 | |
| 264 | |
| 265 | |
| 266 | Example IV |
| 267 | ---------- |
| 268 | |
| 269 | This example will show how to use a Windows server with a Cloudify agent on it. |
| 270 | |
| 271 | |
| 272 | The following is an excerpt from the blueprint's ``blueprint``.``node_templates`` section:: |
| 273 | |
| 274 | my_keypair: |
| 275 | type: cloudify.openstack.nodes.KeyPair |
| 276 | properties: |
| 277 | private_key_path: /tmp/windows-test.pem |
| 278 | |
| 279 | my_server: |
| 280 | type: cloudify.openstack.nodes.WindowsServer |
| 281 | relationships: |
| 282 | - type: cloudify.openstack.server_connected_to_keypair |
| 283 | target: keypair |
| 284 | interfaces: |
| 285 | cloudify.interfaces.lifecycle: |
| 286 | create: |
| 287 | inputs: |
| 288 | args: |
| 289 | server: |
| 290 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 291 | flavor: 101 |
| 292 | name: my-server |
| 293 | userdata: | |
| 294 | #ps1_sysnative |
| 295 | winrm quickconfig -q |
| 296 | winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}' |
| 297 | winrm set winrm/config '@{MaxTimeoutms="1800000"}' |
| 298 | winrm set winrm/config/service '@{AllowUnencrypted="true"}' |
| 299 | winrm set winrm/config/service/auth '@{Basic="true"}' |
| 300 | &netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow |
| 301 | &netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow |
| 302 | |
| 303 | msiexec /i https://www.python.org/ftp/python/2.7.6/python-2.7.6.msi TARGETDIR=C:\Python27 ALLUSERS=1 /qn |
| 304 | cloudify.interfaces.validation: |
| 305 | creation: |
| 306 | inputs: |
| 307 | args: |
| 308 | server: |
| 309 | image: 8672f4c6-e33d-46f5-b6d8-ebbeba12fa02 |
| 310 | flavor: 101 |
| 311 | name: my-server |
| 312 | userdata: | |
| 313 | #ps1_sysnative |
| 314 | winrm quickconfig -q |
| 315 | winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}' |
| 316 | winrm set winrm/config '@{MaxTimeoutms="1800000"}' |
| 317 | winrm set winrm/config/service '@{AllowUnencrypted="true"}' |
| 318 | winrm set winrm/config/service/auth '@{Basic="true"}' |
| 319 | &netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow |
| 320 | &netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow |
| 321 | |
| 322 | msiexec /i https://www.python.org/ftp/python/2.7.6/python-2.7.6.msi TARGETDIR=C:\Python27 ALLUSERS=1 /qn |
| 323 | cloudify.interfaces.worker_installer: |
| 324 | install: |
| 325 | inputs: |
| 326 | cloudify_agent: |
| 327 | user: Admin |
| 328 | password: { get_attribute: [SELF, password] } |
| 329 | |
| 330 | |
| 331 | 1. Creates a keypair. the private key will be saved under ``/tmp/windows-test.pem``. |
| 332 | 2. Creates a Windows server: |
| 333 | |
| 334 | * It is set with a relationship to the ``my_keypair`` node, which will make the server use the it as a public key for authentication, and also use this public key to encrypt its password before posting it to the Openstack metadata service. |
| 335 | * The worker-installer interface operations are given values for the user and password for the ``cloudify_agent`` input - the password uses the [get_attribute]({{< relref "blueprints/spec-intrinsic-functions.md#get-attribute" >}}) feature to retrieve the decrypted password from the Server's runtime properties (Note that in this example, only the ``install`` operation was given with this input, but all of the worker installer operations as well as the plugin installer operations should be given with it). |
| 336 | * We define custom userdata which configures WinRM and installs Python on the machine (Windows Server 2012 in this example) once it's up. This is required for the Cloudify agent to be installed on the machine. |
| 337 | |
| 338 | |