diff --git a/quick.txt b/quick.txt index 0b7dad2..c75bee7 100644 --- a/quick.txt +++ b/quick.txt @@ -1 +1 @@ -10.42.41.37|techX2019!|nathan.cox@nutanix.com \ No newline at end of file +10.42.9.37|techX2019!|willem@nutanix.com diff --git a/scripts/bootcamp.sh b/scripts/bootcamp.sh index 59ca059..f0a5e60 100755 --- a/scripts/bootcamp.sh +++ b/scripts/bootcamp.sh @@ -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}" \ diff --git a/scripts/lib.common.sh b/scripts/lib.common.sh index 28384ef..8deef1e 100644 --- a/scripts/lib.common.sh +++ b/scripts/lib.common.sh @@ -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 @@ -23,6 +33,8 @@ function args_required() { fi } +################################################################################## + function begin() { local _release @@ -33,6 +45,8 @@ function begin() { log "$(basename ${0})${_release} start._____________________" } +################################################################################## + function dependencies { local _argument local _error @@ -136,6 +150,8 @@ function dependencies { esac } +################################################################################## + function dns_check() { local _dns local _error @@ -158,6 +174,8 @@ function dns_check() { fi } +################################################################################## + function download() { local _attempts=5 local _error=0 @@ -200,6 +218,8 @@ function download() { done } +################################################################################## + function fileserver() { local _action=${1} # REQUIRED local _host=${2} # REQUIRED, TODO: default to PE? @@ -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' @@ -436,6 +462,9 @@ EOF done } +################################################################################## + + function log() { local _caller @@ -443,6 +472,9 @@ function log() { echo "$(date '+%Y-%m-%d %H:%M:%S')|$$|${_caller}|${1}" } +################################################################################## + + function ntnx_cmd() { local _attempts=25 local _error=10 @@ -475,6 +507,9 @@ function ntnx_cmd() { done } +################################################################################## + + function ntnx_download() { local _checksum local _error @@ -597,6 +632,9 @@ function ntnx_download() { fi } +################################################################################## + + function pe_determine() { # ${1} REQUIRED: run on 'PE' or 'PC' local _error @@ -651,6 +689,9 @@ function pe_determine() { fi } +################################################################################## + + function prism_check { # Argument ${1} = REQUIRED: PE or PC # Argument ${2} = OPTIONAL: number of attempts @@ -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 @@ -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 @@ -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=(\ diff --git a/scripts/lib.pc.sh b/scripts/lib.pc.sh index af5456e..a96aeba 100755 --- a/scripts/lib.pc.sh +++ b/scripts/lib.pc.sh @@ -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 @@ -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 @@ -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 } diff --git a/stage_workshop.sh b/stage_workshop.sh old mode 100644 new mode 100755