This lab accompanies the "Blueprints" section of the training. It is meant to be completed incrementally, alongside the presentation of the training slide deck.
Create a new directory:
mkdir ~/my_bp
cd ~/my_bp
Copy the contents of the solution/scripts
directory into your blueprint's directory:
cp -R ~/cloudify-training-labs/blueprints/solution/scripts ~/my_bp
Now, copy the contents of the solution/resources
directory into your blueprint's directory:
cp -R ~/cloudify-training-labs/blueprints/solution/resources ~/my_bp
Create a new file to contain the blueprint:
vi blueprint.yaml
Add the TOSCA definitions version directive at the top of the file:
tosca_definitions_version: <add_version_here>
- Add Cloudify's global
types.yaml
file using animport
statement. The file's URL is: http://www.getcloudify.org/spec/cloudify/4.3.1/types.yaml - Add an import statement to a file called
include/type-definitions.yaml
.
We will create our type definitions in a separate file located in include/type-definitions.yaml
relative to the
main blueprint file's root. While this is not a requirement, typically, reusable definitions are placed in YAML files
external to the main blueprint, and included from there.
-
Add a node type called
apache
:- Derived from
cloudify.nodes.Root
. - Containing a property called
port
, of typeinteger
, with the default value of80
. - Containing a property called
document_root
, of typestring
, with the default value of/var/www/html
. - Implementing the
cloudify.interfaces.lifecycle
interface, and:- Mapping the
create
operation toscripts/apache-install.sh
- Mapping the
configure
operation toscripts/apache-configure.sh
- Mapping the
start
operation toscripts/apache-start.sh
- Mapping the
stop
operation toscripts/apache-stop.sh
- Mapping the
delete
operation toscripts/apache-uninstall.sh
- Mapping the
- Derived from
-
Add a node type called
static_web_app
:- Derived from
cloudify.nodes.Root
. - Containing the following properties:
- Name:
web_page
, type:string
(no default value)
- Name:
- Implementing the
cloudify.interfaces.lifecycle
interface, and:- Mapping the
create
operation toscripts/static-app-install.sh
- Mapping the
delete
operation toscripts/static-app-uninstall.sh
- Mapping the
- Derived from
VERY IMPORTANT: the script located in scripts/static-app-install.sh
defines a runtime property
called target_dir
on the node instance for which the operation is running. You will need this information
later.
Back in ~/my_bp/blueprint.yaml
, we will now create some node templates.
-
Add a node template called
host
, of typecloudify.nodes.Compute
.-
Add a property called
ip
, with the value being the IP address of your App VM. -
Add a property called
agent_config
, with the value being a dictionary containing the following:user: centos key: /etc/cloudify/cfy-training.pem
For example:
host: <...> properties: ip: 192.178.0.10 agent_config: user: centos key: /etc/cloudify/cfy-training.pem
-
-
Add a node template called
web_server
, of typeapache
.- Provide an override to the
port
property. The default is80
, but we want port8080
here.
- Provide an override to the
-
Add a node template called
my_app
, of typestatic_web_app
.- Provide the following property values:
web_page
:resources/hello.html
- Provide the following property values:
Back in ~/my_bp/include/type-definitions.yaml
, add a relationship type called app_contained_in_apache
.
The relationship type should be derived from the built-in cloudify.relationships.contained_in
type.
The relationship type will map the establish
operation in the cloudify.interfaces.relationship_lifecycle
source interface, to scripts/app-to-apache.sh
.
Back in ~/my_bp/blueprint.yaml
:
- To the
web_server
node:- Add a relationship where the target is the
host
node, and the type is the standard containment type (cloudify.relationships.contained_in
).
- Add a relationship where the target is the
- To the
my_app
node:- Add a relationship where the target is the
web_server
node, and the type isapp_contained_in_apache
.
- Add a relationship where the target is the
(This should be done in ~/my_bp/blueprint.yaml
)
- Add a blueprint input for the Apache listening port. The input name should be
apache_listening_port
, the type should beinteger
, with no default. - Change the
web_server
node so the value of theport
property is taken from theapache_listening_port
input. - Add a blueprint input for the App VM's IP address. The input name should be
ip
, the type should bestring
, with no default. - Change the
host
node so the value of theip
property is taken from theip
input.
Open include/type-definitions.yaml
. For the configure
operation in the apache
node type, add an operation input called port
,
of type integer
. The default value for the input should be defined so the following happens: when the configure
operation is called, Cloudify retrieves the value of the port
property for the same node instance that the
operation runs on.
In a previous step, you created a relationship type called app_contained_in_apache
. Edit the definition of the
establish
operation there. The operation should now receive the following inputs:
app_dir
: the default value should be an attribute reference, retrieving the value of thetarget_dir
attribute from whoever is at the source end of the relationship.document_root
: the default value should be a property reference, retrieving the value of thedocument_root
property from whoever is at the target end of the relationship.
Edit the main blueprint file again (blueprint.yaml
) and add an outputs
section. The outputs
section should contain
only one item called installation_info
. Its value should be a dictionary containing two elements:
-
url
: the value should be a string of the form:http://<ip-address>:<port>/app/hello.html
, where:ip-address
is the IP address of the VM running the exampleport
is the port on which Apache is going to listen (hint: useget_property
to obtain the value of the relevant property fromweb_server
)
(hint: use the
concat
function) -
app_dir
: the value should be an attribute reference, obtaining the value of thetarget_dir
attribute frommy_app
.
Now that the blueprint is ready, try running it:
cfy install ~/my_bp/blueprint.yaml -i apache_listening_port=8080 -i ip=<your-app-VM-public-IP> -b bp_test -d dep1
(Replace <your-app-VM-IP>
with your App VM's IP address)
When installation is done, obtain the outputs:
cfy deployments outputs dep1
You should receive the value of the outputs
section defined in the blueprint, with values calculated in
real time.
You should now be able to point your browser at http://<app-vm-public-ip>:8080/app/hello.html
and get the static
app that had just been deployed.
Once done, invoke the uninstall
workflow to clean up:
cfy uninstall dep1