Skip to content

Commit

Permalink
Merge pull request #9 from openflighthpc/dev/usability
Browse files Browse the repository at this point in the history
General Usability Improvements
  • Loading branch information
ColonelPanics authored Nov 24, 2020
2 parents 55543d1 + 8563a4b commit ee9762a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Currently, this is being developed and tested on Azure.
vim configs/default.sh
```
6. Check/update the application settings
```
vim settings.sh
```
## Create a Cluster
### Cluster Using Default Configuration
Expand Down
15 changes: 10 additions & 5 deletions build-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
# Get directory of script for locating templates and config
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Source variables
# Source application variables
source $DIR/settings.sh

# Source cluster config variables
if [ -z "${CONFIG}" ] ; then
source $DIR/configs/default.sh
else
Expand Down Expand Up @@ -132,7 +135,7 @@ function check_azure() {
function deploy_azure() {
az group create --name "$CLUSTERNAME" --location "$AZURE_LOCATION"
az group deployment create --name "$CLUSTERNAME" --resource-group "$CLUSTERNAME" \
--template-file $DIR/templates/azure/cluster.json \
--template-file $DIR/$AZURE_TEMPLATE \
--parameters sourceimage="$AZURE_SOURCEIMAGE" \
clustername="$CLUSTERNAMEARG" \
computeNodesCount="$COMPUTENODES" \
Expand Down Expand Up @@ -181,7 +184,7 @@ function check_aws() {
function deploy_aws() {
# Deploy resources
aws cloudformation deploy --template-file $DIR/templates/aws/cluster.yaml --stack-name $CLUSTERNAME \
aws cloudformation deploy --template-file $DIR/$AWS_TEMPLATE --stack-name $CLUSTERNAME \
--region "$AWS_LOCATION" \
--parameter-overrides sourceimage="$AWS_SOURCEIMAGE" \
clustername="$CLUSTERNAMEARG" \
Expand Down Expand Up @@ -242,9 +245,11 @@ function run_ansible() {
fi
# Run ansible playbook
cd /root/openflight-ansible-playbook
cd $ANSIBLE_PLAYBOOK_DIR
export ANSIBLE_HOST_KEY_CHECKING=false
ansible-playbook -i /opt/flight/clusters/$CLUSTERNAME --extra-vars "cluster_name=$CLUSTERNAMEARG munge_key=$( (head /dev/urandom | tr -dc a-z0-9 | head -c 18 ; echo '') | sha512sum | cut -d' ' -f1) compute_nodes=node[01-0$COMPUTENODES] $flightenv_dev_var $flightenv_bootstrap_var" openflight.yml
ARGS="cluster_name=$CLUSTERNAMEARG munge_key=$( (head /dev/urandom | tr -dc a-z0-9 | head -c 18 ; echo '') | sha512sum | cut -d' ' -f1) compute_nodes=node[01-0$COMPUTENODES] $flightenv_dev_var $flightenv_bootstrap_var"
echo "$(date +'%Y-%m-%d %H-%M-%S') | $CLUSTERNAME | Start Ansible | ansible-playbook -i /opt/flight/clusters/$CLUSTERNAME --extra-vars \"$ARGS\" openflight.yml" |tee -a $LOG
ansible-playbook -i /opt/flight/clusters/$CLUSTERNAME --extra-vars "$ARGS" openflight.yml
}
#################
Expand Down
26 changes: 25 additions & 1 deletion destroy_cluster.sh → destroy-cluster.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ function destroy_cluster {
cluster=$1
case $PLATFORM in
"azure")
check_cluster_azure $cluster
destroy_cluster_azure $cluster
;;
"aws")
check_cluster_aws $cluster
destroy_cluster_aws $cluster
;;
*)
Expand All @@ -48,16 +50,38 @@ function destroy_cluster {
rm -f /opt/flight/clusters/$cluster
}

function check_cluster_azure {
cluster=$1
if ! az group show --name $cluster &>/dev/null ; then
cluster_error
fi
}

function destroy_cluster_azure {
cluster=$1
az group delete --name $cluster
az group delete -y --name $cluster
}

function check_cluster_aws {
cluster=$1
if ! aws cloudformation describe-stacks --stack-name $cluster --region $AWS_LOCATION &>/dev/null ; then
cluster_error
fi
}

function destroy_cluster_aws {
cluster=$1
aws cloudformation delete-stack --stack-name $cluster --region $AWS_LOCATION
}

function cluster_error {
echo "Cannot find $CLUSTERNAME in specified config."
echo "Perhaps the wrong config has been used or the cluster has been deleted outside of the builder?"
echo
echo "Exiting without action"
exit 1
}

#################
# Run Functions #
#################
Expand Down
7 changes: 7 additions & 0 deletions settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Directory containing the OpenFlight Ansible Playbook
ANSIBLE_PLAYBOOK_DIR=/root/openflight-ansible-playbook

# Cloud Templates (paths must be relative path to the builder install directory)
AZURE_TEMPLATE=templates/azure/cluster.json
AWS_TEMPLATE=templates/aws/cluster.yaml

0 comments on commit ee9762a

Please sign in to comment.