diff options
Diffstat (limited to 'azure/aria/aria-extension-cloudify/examples/openstack-hello-world')
6 files changed, 242 insertions, 0 deletions
diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/images/aria-logo.png b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/images/aria-logo.png Binary files differnew file mode 100644 index 0000000..3505844 --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/images/aria-logo.png diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/index.html b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/index.html new file mode 100644 index 0000000..597632b --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/index.html @@ -0,0 +1,14 @@ +<html> + <header> + <title>ARIA Hello World</title> + </header> +<body> + <h1>Hello, World!</h1> + <p> + service_template_name = {{ ctx.service_template.name }}<br/> + service_name = {{ ctx.service.name }}<br/> + node_name = {{ ctx.node.name }} + </p> + <img src="aria-logo.png"> +</body> +</html>
\ No newline at end of file diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/openstack-helloworld.yaml b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/openstack-helloworld.yaml new file mode 100644 index 0000000..1fb031c --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/openstack-helloworld.yaml @@ -0,0 +1,144 @@ +tosca_definitions_version: tosca_simple_yaml_1_0 + +imports: + - https://raw.githubusercontent.com/cloudify-cosmo/aria-extension-cloudify/master/plugins/openstack/plugin.yaml + - aria-1.0 + +node_types: + web_app: + derived_from: tosca.nodes.WebApplication + properties: + port: + type: integer + default: + +topology_template: + + inputs: + ssh_username: + type: string + default: ubuntu + external_network_name: + type: string + webserver_port: + type: integer + private_key_path: + type: string + image: + type: string + flavor: + type: string + openstack_config: + type: map + entry_schema: string + + node_templates: + network: + type: aria.openstack.nodes.Network + properties: + resource_id: aria_helloworld_network + create_if_missing: true + openstack_config: { get_input: openstack_config } + + router: + type: aria.openstack.nodes.Router + properties: + external_network: { get_input: external_network_name } + create_if_missing: true + resource_id: aria_helloworld_rtr + openstack_config: { get_input: openstack_config } + + subnet: + type: aria.openstack.nodes.Subnet + properties: + resource_id: aria_helloworld_subnet + create_if_missing: true + openstack_config: { get_input: openstack_config } + requirements: + - router: router + - network: network + + port: + type: aria.openstack.nodes.Port + properties: + create_if_missing: true + resource_id: aria_helloworld_port + openstack_config: { get_input: openstack_config } + requirements: + - security_group: security_group + - subnet: subnet + - network: network + + virtual_ip: + type: aria.openstack.nodes.FloatingIP + properties: + resource_id: aria_helloworld_floatingip + create_if_missing: true + openstack_config: { get_input: openstack_config } + floatingip: + floating_network_name: { get_input: external_network_name } + + security_group: + type: aria.openstack.nodes.SecurityGroup + properties: + create_if_missing: true + resource_id: aria_helloworld_sg + openstack_config: { get_input: openstack_config } + rules: + - remote_ip_prefix: 0.0.0.0/0 + port: { get_input: webserver_port } + - port: 22 + remote_ip_prefix: 0.0.0.0/0 + + keypair: + type: aria.openstack.nodes.KeyPair + properties: + create_if_missing: true + resource_id: aria_helloworld_kp + private_key_path: { get_input: private_key_path } + openstack_config: { get_input: openstack_config } + + vm: + type: aria.openstack.nodes.Server + properties: + image: { get_input: image } + flavor: { get_input: flavor } + create_if_missing: true + resource_id: aria_helloworld_vm + management_network_name: aria_helloworld_network + openstack_config: { get_input: openstack_config } + requirements: + - floating_ip: virtual_ip + - security_group: security_group + - key_pair: keypair + - port: port + + web_app: + type: web_app + properties: + port: { get_input: webserver_port } + requirements: + - host: vm + interfaces: + Standard: + configure: + implementation: + primary: scripts/configure.sh + dependencies: + - "ssh.user > { get_input: ssh_username }" + - "ssh.key_filename > { get_input: private_key_path }" + - "ssh.address > { get_attribute: [ virtual_ip, floating_ip_address ] }" + start: + implementation: + primary: scripts/start.sh + dependencies: + - "ssh.user > { get_input: ssh_username }" + - "ssh.key_filename > { get_input: private_key_path }" + - "ssh.address > { get_attribute: [ virtual_ip, floating_ip_address ] }" + stop: + implementation: + primary: scripts/stop.sh + dependencies: + - "ssh.user > { get_input: ssh_username }" + - "ssh.key_filename > { get_input: private_key_path }" + - "ssh.address > { get_attribute: [ virtual_ip, floating_ip_address ] }" diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/configure.sh b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/configure.sh new file mode 100644 index 0000000..400ae71 --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/configure.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +TEMP_DIR=/tmp +PYTHON_FILE_SERVER_ROOT="$TEMP_DIR/python-simple-http-webserver" +INDEX_PATH=index.html +IMAGE_PATH=images/aria-logo.png + +if [ -d "$PYTHON_FILE_SERVER_ROOT" ]; then + ctx logger info [ "Removing old web server root folder: $PYTHON_FILE_SERVER_ROOT." ] + rm -rf "$PYTHON_FILE_SERVER_ROOT" +fi + +ctx logger info [ "Creating web server root folder: $PYTHON_FILE_SERVER_ROOT." ] + +mkdir -p "$PYTHON_FILE_SERVER_ROOT" +cd "$PYTHON_FILE_SERVER_ROOT" + +ctx logger info [ "Downloading service template resources..." ] +ctx download-resource-and-render [ "$PYTHON_FILE_SERVER_ROOT/index.html" "$INDEX_PATH" ] +ctx download-resource [ "$PYTHON_FILE_SERVER_ROOT/aria-logo.png" "$IMAGE_PATH" ] diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/start.sh b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/start.sh new file mode 100644 index 0000000..7471cfc --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/start.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -e + +TEMP_DIR=/tmp +PYTHON_FILE_SERVER_ROOT="$TEMP_DIR/python-simple-http-webserver" +PID_FILE=server.pid +PORT=$(ctx node properties port) +URL="http://localhost:$PORT" + +ctx logger info [ "Starting web server at: $PYTHON_FILE_SERVER_ROOT." ] + +cd "$PYTHON_FILE_SERVER_ROOT" +nohup python -m SimpleHTTPServer "$PORT" > /dev/null 2>&1 & +echo $! > "$PID_FILE" + +server_is_up() { + if which wget >/dev/null; then + if wget "$URL" >/dev/null; then + return 0 + fi + elif which curl >/dev/null; then + if curl "$URL" >/dev/null; then + return 0 + fi + else + ctx logger error [ "Both curl and wget were not found in path." ] + exit 1 + fi + return 1 +} + +ctx logger info [ "Waiting for web server to launch on port $PORT..." ] +STARTED=false +for i in $(seq 1 15) +do + if server_is_up; then + ctx logger info [ "Web server is up." ] + STARTED=true + break + else + ctx logger info [ "Web server not up. waiting 1 second." ] + sleep 1 + fi +done + +if [ "$STARTED" = false ]; then + ctx logger error [ "Web server did not start within 15 seconds." ] + exit 1 +fi diff --git a/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/stop.sh b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/stop.sh new file mode 100644 index 0000000..9f3bfc5 --- /dev/null +++ b/azure/aria/aria-extension-cloudify/examples/openstack-hello-world/scripts/stop.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +TEMP_DIR=/tmp +PYTHON_FILE_SERVER_ROOT="${TEMP_DIR}/python-simple-http-webserver" +PID_FILE=server.pid +PID=$(cat "$PYTHON_FILE_SERVER_ROOT/$PID_FILE") + +ctx logger info [ "Shutting down web server, pid = ${PID}." ] +kill -9 "$PID" || exit $? + +ctx logger info [ "Removing web server root folder: $PYTHON_FILE_SERVER_ROOT." ] +rm -rf "$PYTHON_FILE_SERVER_ROOT" |