Skip to content

Commit

Permalink
Changes to lib.pc.sh and lib.common.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
NutanixTest committed Apr 12, 2019
1 parent d1aca2a commit 2929c44
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 21 deletions.
2 changes: 1 addition & 1 deletion quick.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.42.41.37|techX2019!|nathan.cox@nutanix.com
10.42.9.37|techX2019!|willem@nutanix.com
2 changes: 1 addition & 1 deletion scripts/bootcamp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ case ${1} in
if (( $? == 0 )) ; then
_command="EMAIL=${EMAIL} \
PC_HOST=${PC_HOST} PE_HOST=${PE_HOST} PE_PASSWORD=${PE_PASSWORD} \
PC_LAUNCH=${PC_LAUNCH} PC_VERSION=${PC_VERSION} nohup bash ${HOME}/${PC_LAUNCH} IMAGES"
PC_LAUNCH=${PC_LAUNCH} PC_VERSION=${PC_VERSION} nohup bash -x ${HOME}/${PC_LAUNCH} IMAGES"

cluster_check \
&& log "Remote asynchroneous PC Image import script... ${_command}" \
Expand Down
61 changes: 57 additions & 4 deletions scripts/lib.common.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/usr/bin/env bash
# dependencies: dig

##################################################################################
# List of date, who and change made to the file
# --------------------------------------------------------------------------------
# 12-04-2019 - Willem Essenstam
# Changed the run_once function so it checks not on lines in the log file but
# on if the PC is configured by trying to log in using the set password
##################################################################################

##################################################################################

function args_required() {
local _argument
local _error=88
Expand All @@ -23,6 +33,8 @@ function args_required() {
fi
}

##################################################################################

function begin() {
local _release

Expand All @@ -33,6 +45,8 @@ function begin() {
log "$(basename ${0})${_release} start._____________________"
}

##################################################################################

function dependencies {
local _argument
local _error
Expand Down Expand Up @@ -136,6 +150,8 @@ function dependencies {
esac
}

##################################################################################

function dns_check() {
local _dns
local _error
Expand All @@ -158,6 +174,8 @@ function dns_check() {
fi
}

##################################################################################

function download() {
local _attempts=5
local _error=0
Expand Down Expand Up @@ -200,6 +218,8 @@ function download() {
done
}

##################################################################################

function fileserver() {
local _action=${1} # REQUIRED
local _host=${2} # REQUIRED, TODO: default to PE?
Expand Down Expand Up @@ -245,11 +265,17 @@ function fileserver() {
esac
}

##################################################################################


function finish() {
log "${0} ran for ${SECONDS} seconds._____________________"
echo
}

##################################################################################


function images() {
# https://portal.nutanix.com/#/page/docs/details?targetId=Command-Ref-AOS-v59:acl-acli-image-auto-r.html
local _cli='acli'
Expand Down Expand Up @@ -436,13 +462,19 @@ EOF
done
}

##################################################################################


function log() {
local _caller

_caller=$(echo -n "$(caller 0 | awk '{print $2}')")
echo "$(date '+%Y-%m-%d %H:%M:%S')|$$|${_caller}|${1}"
}

##################################################################################


function ntnx_cmd() {
local _attempts=25
local _error=10
Expand Down Expand Up @@ -475,6 +507,9 @@ function ntnx_cmd() {
done
}

##################################################################################


function ntnx_download() {
local _checksum
local _error
Expand Down Expand Up @@ -597,6 +632,9 @@ function ntnx_download() {
fi
}

##################################################################################


function pe_determine() {
# ${1} REQUIRED: run on 'PE' or 'PC'
local _error
Expand Down Expand Up @@ -651,6 +689,9 @@ function pe_determine() {
fi
}

##################################################################################


function prism_check {
# Argument ${1} = REQUIRED: PE or PC
# Argument ${2} = OPTIONAL: number of attempts
Expand Down Expand Up @@ -716,6 +757,9 @@ function prism_check {
done
}

##################################################################################


function remote_exec() {
# Argument ${1} = REQUIRED: ssh or scp
# Argument ${2} = REQUIRED: PE, PC, or AUTH_SERVER
Expand Down Expand Up @@ -805,6 +849,9 @@ function remote_exec() {
done
}

##################################################################################


function repo_source() {
# https://stackoverflow.com/questions/1063347/passing-arrays-as-parameters-in-bash#4017175
local _candidates=("${!1}") # REQUIRED
Expand Down Expand Up @@ -872,16 +919,22 @@ function repo_source() {
fi
}

##################################################################################


function run_once() {
# TODO: PC dependent
if [[ ! -z ${PC_LAUNCH} ]] && (( $(cat ${HOME}/${PC_LAUNCH%%.sh}.log | wc ${WC_ARG}) > 20 )); then
finish
# Try to login to the PC UI using an API and use the NEW to be password so we can check if PC config has run....
_Configured_PC=$(curl -X POST https://${PC_HOST}:9440/api/nutanix/v3/clusters/list --user ${PRISM_ADMIN}:${PE_PASSWORD} -H 'Content-Type: application/json' -d '{ "kind": "cluster" }' --insecure --silent | grep "AUTHENTICATION_REQUIRED" | wc -l)
if [[ $_Configured_PC -lt 1 ]]; then
_error=2
log "Warning ${_error}: ${PC_LAUNCH} already ran, exit!"
log "Warning ${_error}: ${PC_LAUNCH} already ran and configured PRISM Central, exit!"
exit ${_error}
fi
}

##################################################################################


function ssh_pubkey() {
local _dir
local _directories=(\
Expand Down
46 changes: 31 additions & 15 deletions scripts/lib.pc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# -x
# Dependencies: curl, ncli, nuclei, jq

###############################################################################################################################################################################
# 12th of April 2019 - Willem Essenstam
# Added a "-d" character in the flow_enable so the command would run.
# Changed the Karbon Eanable function so it also checks that Karbon has been enabled.
###############################################################################################################################################################################


###############################################################################################################################################################################
# Routine to enable Flow
Expand All @@ -20,7 +26,7 @@ function flow_enable() {
log "Enable Nutanix Flow..."

# Enabling Flow and put the task id in a variable
_task_id=$(curl -X POST $_json_data $CURL_HTTP_OPTS --user ${PRISM_ADMIN}:${PE_PASSWORD} $_url_flow)
_task_id=$(curl -X POST -d $_json_data $CURL_HTTP_OPTS --user ${PRISM_ADMIN}:${PE_PASSWORD} $_url_flow)

# Try one more time then fail, but continue
if [ -z $_task_id ]; then
Expand Down Expand Up @@ -171,27 +177,37 @@ function lcm() {
function karbon_enable() {
local CURL_HTTP_OPTS=' --max-time 25 --silent --header Content-Type:application/json --header Accept:application/json --insecure '
local _loop=0
local _json_data_enable="-d '{\"value\":\"{\\\".oid\\\":\\\"ClusterManager\\\",\\\".method\\\":\\\"enable_service_with_prechecks\\\",\\\".kwargs\\\":{\\\"service_list_json\\\":\\\"{\\\\\\\"service_list\\\\\\\":[\\\\\\\"KarbonUIService\\\\\\\",\\\\\\\"KarbonCoreService\\\\\\\"]}\\\"}}\"}'"
local _json_data_set_enable="-d '{\"value\":\"{\\\".oid\\\":\\\"ClusterManager\\\",\\\".method\\\":\\\"enable_service_with_prechecks\\\",\\\".kwargs\\\":{\\\"service_list_json\\\":\\\"{\\\\\\\"service_list\\\\\\\":[\\\\\\\"KarbonUIService\\\\\\\",\\\\\\\"KarbonCoreService\\\\\\\"]}\\\"}}\"}'"
local _json_is_enable="-d '{\"value\":\"{\\\".oid\\\":\\\"ClusterManager\\\",\\\".method\\\":\\\"is_service_enabled\\\",\\\".kwargs\\\":{\\\"service_name\\\":\\\"KarbonUIService\\\"}}\"}' "
local _httpURL="https://localhost:9440/PrismGateway/services/rest/v1/genesis"

# Send the enable command to the PC IP using localhost
log "Enable the Karbon service on the PC..."

_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_data_enable ${_httpURL}| grep true | wc -l)
# Start the enablement process
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_data_set_enable ${_httpURL}| grep true | wc -l)

if [[ $_response -le 0 ]]; then
log "Retrying to enable Karbon services one more time...."
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_data_enable ${_httpURL} | grep true | wc -l)

if [[ $_response -le 0 ]]; then
log "Unable to enable Karbon. As there are more dependencies on Karbon we stop the script....."
exit 1
else
log "Karbon has been enabled..."
fi
# Check if we got a "1" back (start sequence received). If not, retry. If yes, check if enabled...
if [[ $_response -eq 1 ]]; then
# Check if Karbon has been enabled
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_is_enable ${_httpURL}| grep true | wc -l)
while [ $_response -ne 1 ]; do
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_is_enable ${_httpURL}| grep true | wc -l)
done
log "Karbon has been enabled."
break
else
log "Karbon has been enabled..."
fi
log "Retrying to enable Karbon one more time."
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_data_set_enable ${_httpURL}| grep true | wc -l)
if [[ $_response -eq 1 ]]; then
_response=$(curl ${CURL_HTTP_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST $_json_is_enable ${_httpURL}| grep true | wc -l)
if [ $_response -lt 1 ]; then
log "Karbon isn't enabled. Please use the UI to enable it."
else
log "Karbon has been enabled."
fi
fi
fi
}


Expand Down
Empty file modified stage_workshop.sh
100644 → 100755
Empty file.

0 comments on commit 2929c44

Please sign in to comment.