...
Code Block |
---|
language | yml |
---|
title | clientserver-lab.yaml |
---|
linenumbers | true |
---|
collapse | true |
---|
|
heat_template_version: 2018-08-31
description: >
This template creates, installs and configures a fileserver, and fileclient
for the heat-guide.
parameters:
flavor:
type: string
label: Fileserver flavor
description: The flavor used to spawn the fileserver
constraints:
- custom_constraint: nova.flavor
ubuntu:
type: string
label: Fileserver image
description: The image used to spawn the fileserver
constraints:
- custom_constraint: glance.image
admin-ssh-key:
type: string
label: SSH Key admin
description: The SSH-key to inject in the fileserver for admin-purposes.
user-ssh-key:
type: string
label: SSH Key User
description: The SSH-key to inject in the fileserver for the user user.
secgroup_generic:
type: string
network:
type: string
volume_type:
type: string
label: Volume type
description: The cinder-type used to create the volume for the fileserver
default: 'HDD-300'
constraints:
- custom_constraint: cinder.vtype
volume_size:
type: number
label: Volume size
default: 2
description: The size of the exported volume from the fileserver
resources:
fileserver:
type: OS::Nova::Server
properties:
name:
str_replace:
template: 'STACK-fileserver'
params:
STACK: { get_param: OS::stack_name }
image: { get_param: ubuntu }
flavor: { get_param: flavor }
networks:
- {"port": { get_resource: fileserver_port }}
user_data_format: RAW
user_data: { get_resource: cloudconf_fileserver }
fileserver_port:
type: OS::Neutron::Port
properties:
admin_state_up: true
network_id: { get_param: network }
security_groups: [{ get_param: secgroup_generic }]
fileserver_floatingip:
type: OS::Neutron::FloatingIP
properties:
floating_network: 'ntnu-internal'
port_id: { get_resource: fileserver_port }
volume:
type: OS::Cinder::Volume
properties:
size: { get_param: volume_size }
volume_type: { get_param: volume_type }
volume_attach:
type: OS::Cinder::VolumeAttachment
properties:
instance_uuid: { get_resource: fileserver }
volume_id: { get_resource: volume }
cloudconf_fileserver:
type: OS::Heat::MultipartMime
properties:
parts:
- config: {get_resource: cloudconf_base}
- config: {get_resource: cloudconf_fileservers}
- config: {get_resource: script_fileserver}
cloudconf_base:
type: OS::Heat::CloudConfig
properties:
cloud_config:
package_update: true
package_upgrade: true
timezone: "Europe/Oslo"
users:
- name: administrator
sudo: ALL=(ALL) NOPASSWD:ALL
lock_passwd: True
shell: /bin/bash
ssh_authorized_keys:
- { get_param: admin-ssh-key }
- name: user
lock_passwd: True
shell: /bin/bash
ssh_authorized_keys:
- { get_param: user-ssh-key }
power_state:
mode: 'reboot'
message: 'Reboots after installing'
condition: True
cloudconf_fileservers:
type: OS::Heat::CloudConfig
properties:
cloud_config:
packages:
- 'nfs-kernel-server'
- 'pwgen'
write_files:
- content: '/opt/data/shared 192.168.0.0/24(rw,sync,no_subtree_check)'
path: '/etc/exports'
- content: |
options lockd nlm_udpport=32768 nlm_tcpport=32768
options nfs callback_tcpport=32764
path: '/etc/modprobe.d/local.conf'
disk_setup:
/dev/vdb:
table_type: gpt
layout: true
overwrite: false
fs_setup:
- filesystem: 'ext4'
label: 'datapartition'
device: '/dev/vdb'
partition: 'auto'
script_fileserver:
type: OS::Heat::SoftwareConfig
properties:
group: ungrouped
config: |
#!/bin/bash
# Restrict NFS ports
sed -i -r 's/STATDOPTS=.*/STATDOPTS="--port 32765 --outgoing-port 32766"/' /etc/default/nfs-common
sed -i -r 's/RPCMOUNTDOPTS=.*/RPCMOUNTDOPTS="-p 32767"/' /etc/default/nfs-kernel-server
# Mount disks
echo "/dev/vdb1 /opt/data ext4 defaults,comment=cloudconfig 0 0" >> /etc/fstab
mkdir /opt/data
mount /dev/vdb1 /opt/data
mkdir /opt/data/shared
chown user:user /opt/data/shared
cloudconf_nfsmount:
type: OS::Heat::CloudConfig
properties:
cloud_config:
packages:
- 'nfs-common'
write_files:
- content:
str_replace:
template: 'IP:/opt/data/shared /mnt/filserver nfs4 defaults 0 0'
params:
IP: { get_attr: [ fileserver, networks, {get_param: network}, 0 ] }
path: '/etc/fstab'
append: true
cloudconf_client:
type: OS::Heat::MultipartMime
properties:
parts:
- config: {get_resource: cloudconf_base}
- config: {get_resource: cloudconf_nfsmount}
nfsclient:
type: OS::Nova::Server
properties:
name:
str_replace:
template: 'STACK-client'
params:
STACK: { get_param: OS::stack_name }
image: { get_param: ubuntu }
flavor: { get_param: flavor }
networks:
- {"port": { get_resource: nfsclient_port }}
user_data_format: RAW
user_data: { get_resource: cloudconf_client }
nfsclient_port:
type: OS::Neutron::Port
properties:
admin_state_up: true
network_id: { get_param: network }
security_groups: [{ get_param: secgroup_generic }]
nfsclient_floatingip:
type: OS::Neutron::FloatingIP
properties:
floating_network: 'ntnu-internal'
port_id: { get_resource: nfsclient_port }
outputs:
fileserver_address:
description: Fileserver address
value: { get_attr: [ fileserver_floatingip, fixed_ip_address ] }
fileserver_floating_address:
description: Fileserver floating IP address
value: { get_attr: [ fileserver_floatingip, floating_ip_address ] }
client_address:
description: Client address
value: { get_attr: [ nfsclient_floatingip, fixed_ip_address ] }
client_floating_address:
description: Client floating IP address
value: { get_attr: [ nfsclient_floatingip, floating_ip_address ] } |
Creating stacks with client/server in it:
Creating a parameter file
The easiest way to create a stack needing parameters is to create a parameter-file. Based on the output of the first heat-stack, and from retrieving ID's using commands like "openstack flavor list" and "openstack image list" we can create a parameter-file like so:
Code Block |
---|
language | yml |
---|
title | clientserver-lab-parameters.yaml |
---|
linenumbers | true |
---|
collapse | true |
---|
|
parameters:
flavor: gx2.2c3r
ubuntu: fe8be799-21f4-489a-9e3f-9b8a2e15c015
user-ssh-key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGOUa4umWBvM+++eVKXHs4CDrir+aWqrcMtLkPhQR1UF eigil@lungo
admin-ssh-key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGOUa4umWBvM+++eVKXHs4CDrir+aWqrcMtLkPhQR1UF eigil@lungo
secgroup_generic: 30586c14-7bc1-4ef4-91dc-2089eb32ec23
network: db265ea1-1d85-47f1-ba3a-714174da114e |
Creating a stack with parameters using the CLI
To create a stack using the CLI you use the openstack stack create command:
Code Block |
---|
title | Displaying Heat Stack - CLI |
---|
collapse | true |
---|
|
$ openstack stack create -t clientserver-lab.yaml -e clientserver-lab-parameters.yaml Group1
+---------------------+-------------------------------------------------------------------------------------------------+
| Field | Value |
+---------------------+-------------------------------------------------------------------------------------------------+
| id | 10ab8264-6a8d-438a-9aa6-05f99a986b87 |
| stack_name | Group1 |
| description | This template creates, installs and configures a fileserver, and fileclient for the heat-guide. |
| | |
| creation_time | 2022-08-31T09:03:59Z |
| updated_time | None |
| stack_status | CREATE_IN_PROGRESS |
| stack_status_reason | Stack CREATE started |
+---------------------+-------------------------------------------------------------------------------------------------+
$ openstack stack show Group1
+-----------------------+-----------------------------------------------------------------------------------------------------------------+
| Field | Value |
+-----------------------+-----------------------------------------------------------------------------------------------------------------+
| id | 10ab8264-6a8d-438a-9aa6-05f99a986b87 |
| stack_name | Group1 |
| description | This template creates, installs and configures a fileserver, and fileclient for the heat-guide. |
| | |
| creation_time | 2022-08-31T09:03:59Z |
| updated_time | None |
| stack_status | CREATE_IN_PROGRESS |
| stack_status_reason | Stack CREATE started |
| parameters | OS::project_id: 74729572aad24d93b9a4cac7301ef9d1 |
| | OS::stack_id: 10ab8264-6a8d-438a-9aa6-05f99a986b87 |
| | OS::stack_name: Group1 |
| | admin-ssh-key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGOUa4umWBvM+++eVKXHs4CDrir+aWqrcMtLkPhQR1UF |
| | eigil@lungo |
| | flavor: gx2.2c3r |
| | network: db265ea1-1d85-47f1-ba3a-714174da114e |
| | secgroup_generic: 30586c14-7bc1-4ef4-91dc-2089eb32ec23 |
| | ubuntu: fe8be799-21f4-489a-9e3f-9b8a2e15c015 |
| | user-ssh-key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGOUa4umWBvM+++eVKXHs4CDrir+aWqrcMtLkPhQR1UF |
| | eigil@lungo |
| | volume_size: '2' |
| | volume_type: HDD-300 |
| | |
| outputs | - description: Client floating IP address |
| | output_key: client_floating_address |
| | output_value: 10.212.25.246 |
| | - description: Fileserver floating IP address |
| | output_key: fileserver_floating_address |
| | output_value: 10.212.26.229 |
| | - description: Client address |
| | output_key: client_address |
| | output_value: 192.168.0.192 |
| | - description: Fileserver address |
| | output_key: fileserver_address |
| | output_value: 192.168.0.177 |
| | |
| links | - href: https://api.stack.it.ntnu.no:8004/v1/74729572aad24d93b9a4cac7301ef9d1/stacks/Group1/10ab8264-6a8d-438a- |
| | 9aa6-05f99a986b87 |
| | rel: self |
| | |
| deletion_time | None |
| notification_topics | [] |
| capabilities | [] |
| disable_rollback | True |
| timeout_mins | None |
| stack_owner | eigilo |
| parent | None |
| stack_user_project_id | 3c919ba549dd4838b7d2b473ac05abf7 |
| tags | [] |
| | |
+-----------------------+-----------------------------------------------------------------------------------------------------------------+ |
At this point there is created two VM's with the floating IP's 10.212.25.246 and 10.212.26.229. Afther they have booted, gotten their updates installed, and being rebooted, they are ready to use. You can then log into them using the username "admin" or "user" if you have the correct SSH private keys. You can also see the servers using the regular openstack commands:
Code Block |
---|
title | Displaying Heat Stack - CLI |
---|
collapse | true |
---|
|
$ openstack server list
+-------------------------------+-------------------+--------+-------------------------------+---------------------------------+----------+
| ID | Name | Status | Networks | Image | Flavor |
+-------------------------------+-------------------+--------+-------------------------------+---------------------------------+----------+
| f87a91d8-2736-47b0-ab21- | Group1-client | ACTIVE | Common-network- | Ubuntu Server 20.04 (Focal) | gx2.2c3r |
| d70da05e50b8 | | | w4u67666kl7f=10.212.25.246, | amd64 20200424 | |
| | | | 192.168.0.192 | | |
| 180542c9-a988-40d7-8bc9- | Group1-fileserver | ACTIVE | Common-network- | Ubuntu Server 20.04 (Focal) | gx2.2c3r |
| 02523b776b3b | | | w4u67666kl7f=10.212.26.229, | amd64 20200424 | |
| | | | 192.168.0.177 | | |
+-------------------------------+-------------------+--------+-------------------------------+---------------------------------+----------+ |
Creating a stack with parameters using the Web-interface