From 1f3d7e270357df0f06fdaa20e5525124e5d97296 Mon Sep 17 00:00:00 2001 From: Kristina Solovyova Date: Fri, 27 Sep 2024 16:52:39 +0300 Subject: [PATCH] feat: add device_paths to cluster state --- clusterize/clusterize.go | 28 +++++++++++++++++++++------- deploy/deploy_backend.go | 4 +++- protocol/protocol.go | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/clusterize/clusterize.go b/clusterize/clusterize.go index cbe7332..b8292e9 100644 --- a/clusterize/clusterize.go +++ b/clusterize/clusterize.go @@ -17,6 +17,7 @@ type DataProtectionParams struct { type ClusterParams struct { VMNames []string + VMNamesToDevicePaths []string IPs []string ClusterName string Prefix string @@ -51,6 +52,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string { #!/bin/bash set -ex VMS=(%s) + VMS_TO_DEVICE_PATHS=(%s) IPS=(%s) CLUSTER_NAME=%s HOSTS_NUM=%d @@ -78,9 +80,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string { export WEKA_DEPLOYMENT_PASSWORD="$(echo $fetch_result | jq -r .password)" export WEKA_ADMIN_PASSWORD="$(echo $fetch_result | jq -r .admin_password)" export WEKA_RUN_CREDS="-e WEKA_USERNAME=admin -e WEKA_PASSWORD=$WEKA_ADMIN_PASSWORD" - devices=$(weka local run --container compute0 $WEKA_RUN_CREDS bash -ce 'wapi machine-query-info --info-types=DISKS -J | python3 /opt/weka/tmp/find_drives.py') set -x - devices=($devices) CONTAINER_NAMES=(drives0 compute0) PORTS=(14000 15000) @@ -138,16 +138,29 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string { report "{\"hostname\": \"$HOSTNAME\", \"type\": \"progress\", \"message\": \"Adding drives\"}" DRIVE_NUMS=( $(weka cluster container | grep drives | awk '{print $1;}') ) - for drive_num in "${DRIVE_NUMS[@]}"; do + for drive_container_id in "${DRIVE_NUMS[@]}"; do + drive_container_hostname=( $(weka cluster container $drive_container_id | grep drives | awk '{print $2;}') ) + echo "Processing container $drive_container_id with hostname $drive_container_hostname" + + devices=() + # ------- VMS_TO_DEVICE_PATHS has the format: "drive_container_hostname:dev1,dev2,dev3" ------- + for v in "${VMS_TO_DEVICE_PATHS[@]}"; do + # ------- if v contains 'drive_container_hostname', then get the devices------ + if [[ $v == *"$drive_container_hostname"* ]]; then + devices=( $(echo $v | cut -d':' -f2 | tr ',' ' ') ) + fi + done + echo "Adding drives ${devices[*]} to container $drive_container_id" + bad_drives=false devices_str=$(IFS=' ' ;echo "${devices[*]}") - if ! weka cluster drive add $drive_num $devices_str; then - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"Failed adding drives: $drive_num: $devices_str\"}" + if ! weka cluster drive add $drive_container_id $devices_str; then + report "{\"hostname\": \"$HOSTNAME\", \"type\": \"error\", \"message\": \"Failed adding drives: $drive_container_id: $devices_str\"}" bad_drives=true fi if [ $bad_drives = true ]; then - weka_hostname=$(weka cluster container -c $drive_num | tail -n +2 | awk '{print $2}') + weka_hostname=$(weka cluster container -c $drive_container_id | tail -n +2 | awk '{print $2}') containers=($(weka cluster container | grep $weka_hostname | awk '{print $1}')) for c in "${containers[@]}" do @@ -170,7 +183,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string { done done - report "{\"hostname\": \"$HOSTNAME\", \"type\": \"debug\", \"message\": \"Removing drives: $drive_num\"}" + report "{\"hostname\": \"$HOSTNAME\", \"type\": \"debug\", \"message\": \"Removing drives: $drive_container_id\"}" drives=($(weka cluster drive | grep $weka_hostname | awk '{print $2}')) for d in "${drives[@]}" do @@ -246,6 +259,7 @@ func (c *ClusterizeScriptGenerator) GetClusterizeScript() string { script := fmt.Sprintf( dedent.Dedent(clusterizeScriptTemplate), strings.Join(params.VMNames, " "), + strings.Join(params.VMNamesToDevicePaths, " "), strings.Join(params.IPs, " "), params.ClusterName, params.ClusterizationTarget, diff --git a/deploy/deploy_backend.go b/deploy/deploy_backend.go index 0c2ff8d..5c91442 100644 --- a/deploy/deploy_backend.go +++ b/deploy/deploy_backend.go @@ -118,7 +118,9 @@ func (d *DeployScriptGenerator) GetBackendDeployScript() string { done done - clusterize "{\"name\": \"$VM\"}" > /tmp/clusterize.sh + devices_str=$(printf "\\\"%%s\\\"," "${devices[@]}" | sed 's/,$//') + + clusterize "{\"name\": \"$VM\", \"device_paths\": [$devices_str]}" > /tmp/clusterize.sh chmod +x /tmp/clusterize.sh /tmp/clusterize.sh 2>&1 | tee /tmp/weka_clusterization.log ` diff --git a/protocol/protocol.go b/protocol/protocol.go index 97cfcf0..fbbacad 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -154,6 +154,7 @@ type Vm struct { Protocol ProtocolGW `json:"protocol"` ContainerUid string `json:"container_uid"` // protocol frontend container uid NicName string `json:"nic_name"` // protocol management nic name + DevicePaths []string `json:"device_paths"` // drives to be added to weka on clusterization } type FetchRequest struct {