Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the agent's config and mechanism to assign VM ID #102

Merged

Conversation

yunkon-kim
Copy link
Member

  • Add cb_network, cladnet_id, host_id to config.yaml and config.go
  • Add demo_app, is_run to config.yaml and config.go
  • Improve a script to build and run the cb-network agent
  • Update the cb-network agent's mechnism of agent.go

- Add cb_network, cladnet_id, host_id to config.yaml and config.go
- Add demo_app, is_run to config.yaml and config.go
- Improve a script to build and run the cb-network agent
- Update the cb-network agent's mechnism of agent.go
@yunkon-kim yunkon-kim linked an issue May 17, 2021 that may be closed by this pull request
@yunkon-kim
Copy link
Member Author

Current issue

CB-Tumblebug의 ./command-mcis-vm-custom.sh를 사용하여 cb-network agent 일괄 설치시 이슈 발생
예상원인: parameter passing이 여러차례 일어나면서 몇가지 문자(', ")를 제대로 전달 하지 않는 것으로 보임

  1. ./deploy-cb-network-agent.sh all 1 kimyk02 ../testSet3.env '["xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx"]' c2h0ub854amu4ugrgo90을 수행하면
  2. deploy-cb-network-agent.sh내에서 아래 내용 수행
    ./command-mcis-vm-custom.sh "${1}" "${2}" "${3}" "${4}" "${VMID}" "${BuildAndRunCBNetworkAgentCMD}" & 수행
    참고 - BuildAndRunCBNetworkAgentCMD: "wget https://raw.githubusercontent.com/hermitkim1/cb-larva/assign-VM-ID-to-cb-network-agent/poc-cb-net/scripts/build-agent.sh -O ~/build-agent.sh; chmod +x ~/build-agent.sh; cd ~/; sudo ./build-agent.sh '${ETCD_HOSTS}' ${CLADNET_ID} ${VMID}; cd ~/cb-network-agent; sudo ./agent"
  3. ./command-mcis-vm-custom.sh 내에서 아래 내용 수행
VAR1=$(
  curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID/vm/$VMID -H 'Content-Type: application/json' -d @- <<EOF
  {
    "command"        : "${USERCMD}"
  } 
EOF
)
echo "${VAR1}" | jq ''

시도1

작은 따옴표 있는경우 '["xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx"]'

  • 실행 커맨드(etcd endpoint 정보는 x로 표기): ./deploy-cb-network-agent.sh all 1 kimyk02 ../testSet3.env '["xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx"]' c2h0ub854amu4ugrgo90
  • 에러 메시지
    {
      "message": "Syntax error: offset=230, error=invalid character '1' after object key:value pair"
    }

시도2

작은 따옴표 없는경우 ["xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx"]

  • 실행 커맨드(etcd endpoint 정보는 x로 표기): ./deploy-cb-network-agent.sh all 1 kimyk02 ../testSet3.env ["xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx", "xxx.xxx.xxx.xxx:xxxx"] c2h0ub854amu4ugrgo90
  • 에러 메시지
    {
      "message": "Process exited with status 1"
    }

시도3

\" 사용 [\"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\"]

  • 실행 커맨드(etcd endpoint 정보는 x로 표기): ./deploy-cb-network-agent.sh all 1 kimyk02 ../testSet3.env [\"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\"] c2h0ub854amu4ugrgo90
  • 에러 메시지
    {
      "message": "Syntax error: offset=230, error=invalid character '1' after object key:value pair"
    }

시도4

\" 및 작은따옴표 사용 '[\"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\"]'

  • 실행 커맨드(etcd endpoint 정보는 x로 표기): ./deploy-cb-network-agent.sh all 1 kimyk02 ../testSet3.env '[\"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\", \"xxx.xxx.xxx.xxx:xxxx\"]' c2h0ub854amu4ugrgo90
  • 에러 메시지
    {
      "message": "Syntax error: offset=230, error=invalid character '1' after object key:value pair"
    }

deploy-cb-network-agent.sh

CB-Tumblebug API를 활용하여 MCIS에 cb-network agent를 설치하는 스크립트

  • cb-network agent에 etcd custer의 hosts 정보를 매개변수로 넘겨야함 (보안상의 이슈로 스크립트에 하드코딩 하지 않았음)
    • 형태: [ "xxx.xxx.xxx:xxxx", "xxx.xxx.xxx:xxxx", "xxx.xxx.xxx:xxxx" ]
#!/bin/bash

# Set duration timer to 0
SECONDS=0

# Install jq if the jq package doesn't exist
echo "[Check jq package (if not, install)]"
if ! dpkg-query -W -f='${Status}' jq | grep "ok installed"; then sudo apt install -y jq; fi


# tesetSet.env is default test set.
# If the 4th parameter exists, use the test set.
# Check if the one of the test sets exists or not
TestSetFile=${4:-../testSet.env}
if [ ! -f "$TestSetFile" ]; then
        echo "$TestSetFile does not exist."
        exit
fi
source $TestSetFile
source ../conf.env

echo "####################################################################"
echo "## Command (SSH) to MCIS to run cb-network agent"
echo "####################################################################"

CSP=${1}
REGION=${2:-1}
POSTFIX=${3:-developer}
ETCD_HOSTS=${5:-no}
CLADNET_ID=${6:-no}

#if [ "${ETCD_HOSTS}" == "no" ]; then
#        echo "ETCD_HOSTS parameter is needed."
#        exit
#fi

#if [ "${CLADNET_ID}" == "no" ]; then
#        echo "CLADNET_ID paramater is needed."
#        exit
#fi

source ../common-functions.sh
getCloudIndex $CSP

MCISID=${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}

if [ "${INDEX}" == "0" ]; then
        # MCISPREFIX=avengers
        MCISID=${MCISPREFIX}-${POSTFIX}
fi

# Get MCIS information
MCISINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID})
# Parse VM list
VMARRAY=$(jq -r '.vm' <<<"$MCISINFO")

for row in $(echo "${VMARRAY}" | jq -r '.[] | @base64'); do
        _jq() {
                echo ${row} | base64 --decode | jq -r ${1}
        }

    VMID=$(_jq '.id')
        connectionName=$(_jq '.connectionName')
    publicIP=$(_jq '.publicIP')
    cloudType=$(_jq '.location.cloudType')

    echo "VMID: $VMID"
    echo "connectionName: $connectionName"
    echo "publicIP: $publicIP"

    getCloudIndexGeneral $cloudType

#    ChangeHostCMD="sudo hostnamectl set-hostname ${GeneralINDEX}-${connectionName}-${publicIP}; sudo hostname -f"
    BuildAndRunCBNetworkAgentCMD="wget https://raw.githubusercontent.com/hermitkim1/cb-larva/assign-VM-ID-to-cb-network-agent/poc-cb-net/scripts/build-agent.sh -O ~/build-agent.sh; chmod +x ~/build-agent.sh; cd ~/; sudo ./build-agent.sh '${ETCD_HOSTS}' ${CLADNET_ID} ${VMID}; cd ~/cb-network-agent; sudo ./agent"
    echo "CMD: ${BuildAndRunCBNetworkAgentCMD}"
    ./command-mcis-vm-custom.sh "${1}" "${2}" "${3}" "${4}" "${VMID}" "${BuildAndRunCBNetworkAgentCMD}" &
done
wait

echo "Done!"
duration=$SECONDS

printElapsed $@
echo ""

./command-mcis.sh "$@"

@yunkon-kim
Copy link
Member Author

yunkon-kim commented May 18, 2021

[계획]

./deploy-cb-network-agent.sh
외부 스크립트를 수행하는 ./command-mcis-vm-custom.sh "${1}" "${2}" "${3}" "${4}" "${VMID}" "${BuildAndRunCBNetworkAgentCMD}" & 부분
->
직접 CB-Tumblebug API 호출하는 방법으로 변경하여 시도 예정

VAR1=$(
  curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID/vm/$VMID -H 'Content-Type: application/json' -d @- <<EOF
  {
    "command": "${BuildAndRunCBNetworkAgentCMD}"
  }
EOF
)

@seokho-son
Copy link
Member

@hermitkim1 음.. 스크립트로 하면.. escape 처리가 좀 까다롭지요.. ㅠㅠ

@yunkon-kim yunkon-kim force-pushed the assign-VM-ID-to-cb-network-agent branch from 0519430 to fe764f8 Compare May 18, 2021 04:30
- Perform apt install git, gcc, and go
- Apply reponse template to watch networking rule
  - Add buildResponseBytes() function
  - Improve watchNetworkingRule() function
- Create the agent's script to prepare and build parts(not used now)
- Update script and edit wrong etcd key to get configuration info of cladnet
@yunkon-kim yunkon-kim force-pushed the assign-VM-ID-to-cb-network-agent branch from fb5a946 to f3dd696 Compare May 20, 2021 04:12
@yunkon-kim
Copy link
Member Author

I have squashed previous commits and force-push them as a commit.

@yunkon-kim yunkon-kim merged commit 67d077b into cloud-barista:develop May 20, 2021
@yunkon-kim yunkon-kim deleted the assign-VM-ID-to-cb-network-agent branch May 20, 2021 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assign VM ID (host ID) to cb-network agent
2 participants