Skip to content

Commit

Permalink
adding state change messages to functions to aid maintainability
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanHoey96 committed Aug 6, 2024
1 parent c5fdad7 commit de1c6e5
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 25 deletions.
11 changes: 9 additions & 2 deletions scripts/aks/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ if [[ "$MODE" != "start" && "$MODE" != "stop" ]]; then
exit 1
fi

function aks_state_messages() {
ts_echo_color GREEN "Running $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
ts_echo_color GREEN "az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster"
}


SUBSCRIPTIONS=$(az account list -o json)
jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
get_subscription_clusters
Expand All @@ -29,11 +35,12 @@ jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do

if [[ $SKIP == "false" ]]; then
if [[ $DEV_ENV != "true" ]]; then
ts_echo_color GREEN "Running $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
aks_state_messages
az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster

else
ts_echo_color BLUE "Development Env: simulating state commands only."
ts_echo_color GREEN "Running $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
aks_state_messages
fi
else
ts_echo_color AMBER "cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
Expand Down
5 changes: 5 additions & 0 deletions scripts/aks/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ function check_cluster_status() {
notification "#aks-monitor-$SLACK_CHANNEL_SUFFIX" "$message"
fi
}

function aks_state_messages() {
ts_echo_color GREEN "Running $MODE operation on cluster $CLUSTER_NAME (rg:$RESOURCE_GROUP)"
ts_echo_color GREEN "az aks $MODE --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --no-wait || echo Ignoring any errors while $MODE operation on cluster"
}
7 changes: 2 additions & 5 deletions scripts/appgateway/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
# If SKIP is false then we progress with the action (stop/start) for the particular App Gateway in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
if [[ $DEV_ENV != "true" ]]; then
ts_echo_color GREEN "About to run $MODE operation on application gateway $APPLICATION_GATEWAY_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az network application-gateway $MODE --resource-group $RESOURCE_GROUP --name $APPLICATION_GATEWAY_NAME --no-wait || echo Ignoring any errors while $MODE operation on application_gateway"
appgateway_state_messages
az network application-gateway $MODE --resource-group $RESOURCE_GROUP --name $APPLICATION_GATEWAY_NAME --no-wait || echo Ignoring any errors while $MODE operation on application_gateway
else
ts_echo_color BLUE "Development Env: simulating state commands only."
ts_echo_color GREEN "About to run $MODE operation on application gateway $APPLICATION_GATEWAY_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az network application-gateway $MODE --resource-group $RESOURCE_GROUP --name $APPLICATION_GATEWAY_NAME --no-wait || echo Ignoring any errors while $MODE operation on application_gateway"
fi
appgateway_state_messages
else
ts_echo_color AMBER "Application_gateway $APPLICATION_GATEWAY_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
fi
Expand Down
5 changes: 5 additions & 0 deletions scripts/appgateway/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ function get_application_gateways_details() {
STARTUP_MODE=$(jq -r '.tags.startupMode' <<< $application_gateway)
APPLICATION_GATEWAY_STATE=$(az network application-gateway show --ids $APPLICATION_GATEWAY_ID | jq -r .operationalState)
}

function appgateway_state_messages() {
ts_echo_color GREEN "About to run $MODE operation on application gateway $APPLICATION_GATEWAY_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az network application-gateway $MODE --resource-group $RESOURCE_GROUP --name $APPLICATION_GATEWAY_NAME --no-wait || echo Ignoring any errors while $MODE operation on application_gateway"
}
10 changes: 7 additions & 3 deletions scripts/blob-storage/disable_sftp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ do

# If SKIP is false then we progress with the action (stop/start) for the particular App Gateway in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
ts_echo_color GREEN "Disabling SFTP on Storage Account: $STORAGE_ACCOUNT_NAME in Resource Group: $RESOURCE_GROUP and Subscription: $SUBSCRIPTION_NAME"
ts_echo_color GREEN "Command to run: az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=false || echo Ignoring errors Disabling $STORAGE_ACCOUNT_NAME"
az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=false || echo Ignoring errors Disabling $STORAGE_ACCOUNT_NAME
if [[ $DEV_ENV != "true" ]]; then
blob_state_messages
az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=false || echo Ignoring errors Disabling $STORAGE_ACCOUNT_NAME
else
ts_echo_color BLUE "Development Env: simulating state commands only."
blob_state_messages
fi
else
ts_echo_color AMBER "Storage account $STORAGE_ACCOUNT_NAME in Resource Group:$RESOURCE_GROUP and Subscription:$SUBSCRIPTION_NAME has been skipped from todays shutdown schedule"
fi
Expand Down
10 changes: 7 additions & 3 deletions scripts/blob-storage/enable_sftp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ do

# If SKIP is false then we progress with the action (stop/start) for the particular App Gateway in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
ts_echo_color GREEN "Enabling SFTP on Storage Account: $STORAGE_ACCOUNT_NAME in Resource Group: $RESOURCE_GROUP and Subscription: $SUBSCRIPTION_NAME"
ts_echo_color GREEN "Command to run: az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=true || echo Ignoring errors Enabling $STORAGE_ACCOUNT_NAME"
az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=true || echo Ignoring errors Enabling $STORAGE_ACCOUNT_NAME
if [[ $DEV_ENV != "true" ]]; then
blob_state_messages
az storage account update -g $RESOURCE_GROUP -n $STORAGE_ACCOUNT_NAME --enable-sftp=true || echo Ignoring errors Enabling $STORAGE_ACCOUNT_NAME
else
ts_echo_color BLUE "Development Env: simulating state commands only."
blob_state_messages
fi
else
ts_echo_color AMBER "Storage account $STORAGE_ACCOUNT_NAME in Resource Group:$RESOURCE_GROUP and Subscription:$SUBSCRIPTION_NAME has been skipped from todays startup schedule"
fi
Expand Down
6 changes: 2 additions & 4 deletions scripts/flexible-server/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
# If SKIP is false then we progress with the action (stop/start) for the particular App Gateway in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
if [[ $DEV_ENV != "true" ]]; then
ts_echo_color GREEN "About to run $MODE operation on flexible sql server $SERVER_NAME Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az postgres flexible sql server $MODE --resource-group $RESOURCE_GROUP --name $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
flexible_server_state_messages
az postgres flexible-server $MODE --resource-group $RESOURCE_GROUP --name $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server
else
ts_echo_color BLUE "Development Env: simulating state commands only."
ts_echo_color GREEN "About to run $MODE operation on flexible sql server $SERVER_NAME Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az postgres flexible sql server $MODE --resource-group $RESOURCE_GROUP --name $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
flexible_server_state_messages
fi
else
ts_echo_color AMBER "SQL server $SERVER_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
Expand Down
5 changes: 5 additions & 0 deletions scripts/flexible-server/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ function get_flexible_sql_server_details() {
SERVER_STATE=$(az postgres flexible-server show --ids $SERVER_ID --query "state" | jq -r)

}

function flexible_server_state_messages() {
ts_echo_color GREEN "About to run $MODE operation on flexible sql server $SERVER_NAME Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az postgres flexible sql server $MODE --resource-group $RESOURCE_GROUP --name $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
}
6 changes: 2 additions & 4 deletions scripts/sqlmi/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ jq -c '.[]' <<< $SUBSCRIPTIONS | while read subscription; do
# If SKIP is false then we progress with the action (stop/start) for the particular Managed SQL Instance in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
if [[ $DEV_ENV != "true" ]]; then
ts_echo_color GREEN "About to run $MODE operation on sql server $SERVER_NAME (rg:$RESOURCE_GROUP)"
ts_echo_color GREEN "Command to run: az sql mi $MODE --resource-group $RESOURCE_GROUP --mi $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
sqlmi_state_messages
az sql mi $MODE --resource-group $RESOURCE_GROUP --mi $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server
else
ts_echo_color BLUE "Development Env: simulating state commands only."
ts_echo_color GREEN "About to run $MODE operation on sql server $SERVER_NAME (rg:$RESOURCE_GROUP)"
ts_echo_color GREEN "Command to run: az sql mi $MODE --resource-group $RESOURCE_GROUP --mi $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
sqlmi_state_messages
fi
else
ts_echo_color AMBER "SQL server $SERVER_NAME (rg:$RESOURCE_GROUP) has been skipped from today's $MODE operation schedule"
Expand Down
5 changes: 5 additions & 0 deletions scripts/sqlmi/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ function get_sql_mi_server_details() {
SERVER_STATE=$(az sql mi show --ids $SERVER_ID --query "state")
STARTUP_MODE=$(jq -r '.tags.startupMode' <<< $server)
}

function sqlmi_state_messages() {
ts_echo_color GREEN "About to run $MODE operation on sql server $SERVER_NAME (rg:$RESOURCE_GROUP)"
ts_echo_color GREEN "Command to run: az sql mi $MODE --resource-group $RESOURCE_GROUP --mi $SERVER_NAME --no-wait || echo Ignoring any errors while $MODE operation on sql server"
}
6 changes: 2 additions & 4 deletions scripts/vm/auto-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ jq -c '.[]' <<< $SORTED_SUBSCRIPTIONS | while read subscription; do
# If SKIP is false then we progress with the action (deallocate/start) for the particular VM in this loop run, if not skip and print message to the logs
if [[ $SKIP == "false" ]]; then
if [[ $DEV_ENV != "true" ]]; then
ts_echo_color GREEN "About to run $MODE operation on VM: $VM_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az vm $MODE --ids $VM_ID --no-wait || echo Ignoring any errors while $MODE operation on vm"
vm_state_messages
az vm $MODE --ids $VM_ID --no-wait || echo Ignoring any errors while $MODE operation on vm
else
ts_echo_color BLUE "Development Env: simulating state commands only."
ts_echo_color GREEN "About to run $MODE operation on VM: $VM_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az vm $MODE --ids $VM_ID --no-wait || echo Ignoring any errors while $MODE operation on vm"
vm_state_messages
fi
else
ts_echo_color AMBER "VM: $VM_NAME in Resource Group: $RESOURCE_GROUP has been skipped from today's $MODE operation schedule"
Expand Down
5 changes: 5 additions & 0 deletions scripts/vm/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ function get_vm_details() {
VM_STATE=$(az vm show -d --ids $VM_ID --query "powerState" | jq -r)

}

function vm_state_messages() {
ts_echo_color GREEN "About to run $MODE operation on VM: $VM_NAME in Resource Group: $RESOURCE_GROUP"
ts_echo_color GREEN "Command to run: az vm $MODE --ids $VM_ID --no-wait || echo Ignoring any errors while $MODE operation on vm"
}

0 comments on commit de1c6e5

Please sign in to comment.