From a350ed998440fd92cc3280501a9acaff63da5a5d Mon Sep 17 00:00:00 2001 From: stevenpan Date: Tue, 30 Apr 2019 08:16:48 +0800 Subject: [PATCH 1/4] add karbon enable and update --- scripts/calm.sh | 3 ++- scripts/lib.pc.sh | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/scripts/calm.sh b/scripts/calm.sh index eecb729..2b19e08 100755 --- a/scripts/calm.sh +++ b/scripts/calm.sh @@ -97,9 +97,10 @@ case ${1} in # if calm is enabling, lcm will failed due to epilson service failed # added some codes in calm_enable() to wait task complete ssp_auth \ + && karbon_enable \ && calm_enable \ && lcm \ - && lcm_calm + && lcm_calm_karbon images \ && pc_cluster_img_import \ diff --git a/scripts/lib.pc.sh b/scripts/lib.pc.sh index 85af218..5c64eaa 100755 --- a/scripts/lib.pc.sh +++ b/scripts/lib.pc.sh @@ -75,6 +75,37 @@ function flow_enable() { log "_test=|${_test}|" } +function karbon_enable() { + local _http_body + local _pc_version + local _test + local _task_uuid + local _result + local _sleep=60 + + # shellcheck disable=2206 + _pc_version=(${PC_VERSION//./ }) + + if (( ${_pc_version[0]} >= 5 && ${_pc_version[1]} >= 9 )); then + log "PC_VERSION ${PC_VERSION} >= 5.9, starting Karbon Enable ..." + _http_body='{"value":"{\".oid\":\"ClusterManager\",\".method\":\"enable_service_with_prechecks\",\".kwargs\":{\"service_list_json\":\"{\\\"service_list\\\":[\\\"KarbonUIService\\\",\\\"KarbonCoreService\\\"]}\"}}"}' + _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ + https://localhost:9440/PrismGateway/services/rest/v1/genesis) + log "inventory _test=|${_test}|" + _task_uuid=$(echo ${_test} |awk -F':' '{print $NF}' |egrep -o '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}') + + #wait task complete + while true ; do + lcm_running ${_task_uuid} + if [[ $? -eq 0 ]]; then + return 0 + else + sleep ${_sleep} + fi + done + fi +} + function lcm_running() { local _pc_version local _result @@ -127,7 +158,7 @@ function lcm() { fi } -function lcm_calm() { +function lcm_calm_karbon() { local _http_body local _pc_version local _test @@ -142,7 +173,7 @@ function lcm_calm() { if (( ${_pc_version[0]} >= 5 && ${_pc_version[1]} >= 9 )); then # get lcm entity uuid of Calm and Epsilon i=0 - for _model_name in Calm Epsilon; do + for _model_name in Calm Epsilon Karbon; do _http_body='{ "entity_type": "lcm_entity", "grouping_attribute": "entity_class", @@ -162,14 +193,14 @@ function lcm_calm() { i=$((i+1)) done - log "PC_VERSION ${PC_VERSION} >= 5.9, LCM upgrade calm to 2.6.0.4 ..." + log "PC_VERSION ${PC_VERSION} >= 5.9, LCM upgrade Calm to 2.6.0.4, Karbon to 1.0.1 ..." #generate_plan (this step maybe optional) - _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"generate_plan\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"]]]}}"}' + _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"generate_plan\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"],[\"'"${_uuid[2]}"'\",\"1.0.1\"]]]}}"}' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/PrismGateway/services/rest/v1/genesis) log "generate_plan _test=|${_test}|" #perform_update - _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"perform_update\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"]]]}}"}' + _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"perform_update\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"],[\"'"${_uuid[2]}"'\",\"1.0.1\"]]]}}"}' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/PrismGateway/services/rest/v1/genesis) log "perform_update _test=|${_test}|" From 3c401c298f46524d93806656ac6ddba392b447b7 Mon Sep 17 00:00:00 2001 From: stevenpan Date: Tue, 30 Apr 2019 09:23:00 +0800 Subject: [PATCH 2/4] comment --- scripts/calm.sh | 4 +++- scripts/lib.pc.sh | 11 ----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/scripts/calm.sh b/scripts/calm.sh index 2b19e08..2f02cd5 100755 --- a/scripts/calm.sh +++ b/scripts/calm.sh @@ -94,8 +94,10 @@ case ${1} in && pc_auth \ && pc_smtp - # if calm is enabling, lcm will failed due to epilson service failed + # 1. if calm is enabling, lcm will failed due to epilson service failed # added some codes in calm_enable() to wait task complete + # 2. enable karbon before calm, due to no task uuid return when enabling karbon + # but enabling karbon is much quick than enabling calm ssp_auth \ && karbon_enable \ && calm_enable \ diff --git a/scripts/lib.pc.sh b/scripts/lib.pc.sh index 5c64eaa..7c40ec1 100755 --- a/scripts/lib.pc.sh +++ b/scripts/lib.pc.sh @@ -92,17 +92,6 @@ function karbon_enable() { _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/PrismGateway/services/rest/v1/genesis) log "inventory _test=|${_test}|" - _task_uuid=$(echo ${_test} |awk -F':' '{print $NF}' |egrep -o '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}') - - #wait task complete - while true ; do - lcm_running ${_task_uuid} - if [[ $? -eq 0 ]]; then - return 0 - else - sleep ${_sleep} - fi - done fi } From 86dffc87faa28fb3bae2bb61ad8f007bcc4c0efb Mon Sep 17 00:00:00 2001 From: stevenpan Date: Thu, 2 May 2019 20:21:40 +0800 Subject: [PATCH 3/4] get version of calm karbon --- scripts/lib.pc.sh | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/scripts/lib.pc.sh b/scripts/lib.pc.sh index 7c40ec1..19a7f63 100755 --- a/scripts/lib.pc.sh +++ b/scripts/lib.pc.sh @@ -148,13 +148,15 @@ function lcm() { } function lcm_calm_karbon() { - local _http_body - local _pc_version - local _test - local _model_name - local _uuid - local _task_uuid - local _sleep=60 + local _http_body + local _pc_version + local _test + local _model_name + local _entity_uuid + local _entity_ver + local _entity_ver_all + local _task_uuid + local _sleep=60 # shellcheck disable=2206 _pc_version=(${PC_VERSION//./ }) @@ -177,19 +179,37 @@ function lcm_calm_karbon() { }' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/api/nutanix/v3/groups) - _uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .entity_id') - log "${_model_name} uuid[$i]=${_uuid[${i}]}" + #_entity_uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .entity_id') + _entity_uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="uuid" ) | .values[] | .values[] ') + log "${_model_name} uuid[$i]=${_entity_uuid[${i}]}" + + _http_body='{ + "entity_type": "lcm_available_version", + "group_member_attributes": [ + { + "attribute": "version" + } + ], + "query_name": "prism:BaseGroupModel", + "filter_criteria": "entity_uuid=='"${_entity_uuid[${i}]}"'" + }' + _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ + https://localhost:9440/api/nutanix/v3/groups) + _entity_ver_all=$(echo $_test|jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="version" ) | .values[] | .values[] ') + _entity_ver[${i}]=$(echo ${_entity_ver_all} |xargs -n 1 |sort -t '.' -n -k1,4 |tail -n 1) + log "${_model_name} _entity_uuid[$i]=${_entity_uuid[${i}]} _entity_ver[${i}]=${_entity_ver[${i}]} (${_entity_ver_all})" + i=$((i+1)) done log "PC_VERSION ${PC_VERSION} >= 5.9, LCM upgrade Calm to 2.6.0.4, Karbon to 1.0.1 ..." #generate_plan (this step maybe optional) - _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"generate_plan\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"],[\"'"${_uuid[2]}"'\",\"1.0.1\"]]]}}"}' + _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"generate_plan\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_entity_uuid[0]}"'\",\"'"${_entity_ver[0]}"'\"],[\"'"${_entity_uuid[1]}"'\",\"'"${_entity_ver[1]}"'\"],[\"'"${_entity_uuid[2]}"'\",\"'"${_entity_ver[2]}"'\"]]]}}"}' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/PrismGateway/services/rest/v1/genesis) log "generate_plan _test=|${_test}|" #perform_update - _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"perform_update\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_uuid[0]}"'\",\"2.6.0.4\"],[\"'"${_uuid[1]}"'\",\"2.6.0.4\"],[\"'"${_uuid[2]}"'\",\"1.0.1\"]]]}}"}' + _http_body='{"value": "{\".oid\":\"LifeCycleManager\",\".method\":\"lcm_framework_rpc\",\".kwargs\":{\"method_class\":\"LcmFramework\",\"method\":\"perform_update\",\"args\":[\"http://download.nutanix.com/lcm/2.0\",[[\"'"${_entity_uuid[0]}"'\",\"'"${_entity_ver[0]}"'\"],[\"'"${_entity_uuid[1]}"'\",\"'"${_entity_ver[1]}"'\"],[\"'"${_entity_uuid[2]}"'\",\"'"${_entity_ver[2]}"'\"]]]}}"}' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/PrismGateway/services/rest/v1/genesis) log "perform_update _test=|${_test}|" From ba7c8a7d1197b13981b7355da63f486751209331 Mon Sep 17 00:00:00 2001 From: stevenpan Date: Thu, 2 May 2019 20:57:34 +0800 Subject: [PATCH 4/4] minor --- scripts/lib.pc.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/lib.pc.sh b/scripts/lib.pc.sh index 19a7f63..1374ab2 100755 --- a/scripts/lib.pc.sh +++ b/scripts/lib.pc.sh @@ -180,7 +180,7 @@ function lcm_calm_karbon() { _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/api/nutanix/v3/groups) #_entity_uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .entity_id') - _entity_uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="uuid" ) | .values[] | .values[] ') + _entity_uuid[${i}]=$(echo ${_test} |jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="uuid" ) | .values[] | .values[]') log "${_model_name} uuid[$i]=${_entity_uuid[${i}]}" _http_body='{ @@ -195,7 +195,7 @@ function lcm_calm_karbon() { }' _test=$(curl ${CURL_POST_OUTPUT_OPTS} --user ${PRISM_ADMIN}:${PE_PASSWORD} -X POST --data "${_http_body}" \ https://localhost:9440/api/nutanix/v3/groups) - _entity_ver_all=$(echo $_test|jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="version" ) | .values[] | .values[] ') + _entity_ver_all=$(echo $_test |jq -r '.group_results[] | .entity_results[] | .data[] | select ( .name=="version" ) | .values[] | .values[]' |xargs ) _entity_ver[${i}]=$(echo ${_entity_ver_all} |xargs -n 1 |sort -t '.' -n -k1,4 |tail -n 1) log "${_model_name} _entity_uuid[$i]=${_entity_uuid[${i}]} _entity_ver[${i}]=${_entity_ver[${i}]} (${_entity_ver_all})"