Skip to content

Commit

Permalink
feat : Add support for NHN Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
joowons authored and itnpeople committed Nov 23, 2022
1 parent 508f81a commit 63b5180
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 53 deletions.
15 changes: 12 additions & 3 deletions docs/test/batch-register-cloud-info.sh.example
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export CI_ZONE="default"
./connectioninfo-create.sh CLOUDIT

# NCPVPC

export NCPVPC_CLIENT_ID="XXXXXXXXXXXXXXX"
export NCPVPC_CLIENT_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export NCPVPC_REGION="KR"
Expand All @@ -100,10 +99,20 @@ export NCPVPC_ZONE="KR-1"
./connectioninfo-create.sh NCPVPC

# Ncp

export NCP_CLIENT_ID="XXXXXXXXXXXXXXX"
export NCP_CLIENT_SECRET="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export NCP_REGION="KR"
export NCP_ZONE="KR-1"

./connectioninfo-create.sh NCP
./connectioninfo-create.sh NCP

# NHN Cloud
export NHN_IDENTITY_ENDPOINT="https://api-identity.infrastructure.cloud.toast.com"
export NHN_USERNAME="[email protected]"
export NHN_PASSWORD="XXXXXX"
export NHN_TENANT_ID="xxxxxxxxxxxxxxxxxxxxxx"
export NHN_DOMAINNAME="default"
export NHN_REGION="KR1"
export NHN_ZONE="kr-pub-a"

./connectioninfo-create.sh NHNCLOUD
90 changes: 86 additions & 4 deletions docs/test/connectioninfo-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ------------------------------------------------------------------------------
# usage
if [ "$#" -lt 1 ]; then
echo "./connectioninfo-create.sh [AWS/GCP/AZURE/ALIBABA/TENCENT/OPENSTACK/IBM/CLOUDIT/NCPVPC/NCP] <option>"
echo "./connectioninfo-create.sh [AWS/GCP/AZURE/ALIBABA/TENCENT/OPENSTACK/IBM/CLOUDIT/NCPVPC/NCP/NHNCLOUD] <option>"
echo "./connectioninfo-create.sh GCP"
echo "./connectioninfo-create.sh AWS add"
exit 0
Expand All @@ -21,11 +21,11 @@ source ./conf.env
# 1. CSP
if [ "$#" -gt 0 ]; then v_CSP="$1"; else v_CSP="${CSP}"; fi
if [ "${v_CSP}" == "" ]; then
read -e -p "Cloud ? [AWS(default) or GCP or AZURE or ALIBABA or TENCENT or OPENSTACK or IBM or CLOUDIT or NCPVPC or NCP] : " v_CSP
read -e -p "Cloud ? [AWS(default) or GCP or AZURE or ALIBABA or TENCENT or OPENSTACK or IBM or CLOUDIT or NCPVPC or NCP or NHNCLOUD] : " v_CSP
fi

if [ "${v_CSP}" == "" ]; then v_CSP="AWS"; fi
if [ "${v_CSP}" != "GCP" ] && [ "${v_CSP}" != "AWS" ] && [ "${v_CSP}" != "AZURE" ] && [ "${v_CSP}" != "ALIBABA" ] && [ "${v_CSP}" != "TENCENT" ] && [ "${v_CSP}" != "OPENSTACK" ] && [ "${v_CSP}" != "IBM" ] && [ "${v_CSP}" != "CLOUDIT" ] && [ "${v_CSP}" != "NCPVPC" ] && [ "${v_CSP}" != "NCP" ]; then echo "[ERROR] missing <cloud>"; exit -1;fi
if [ "${v_CSP}" != "GCP" ] && [ "${v_CSP}" != "AWS" ] && [ "${v_CSP}" != "AZURE" ] && [ "${v_CSP}" != "ALIBABA" ] && [ "${v_CSP}" != "TENCENT" ] && [ "${v_CSP}" != "OPENSTACK" ] && [ "${v_CSP}" != "IBM" ] && [ "${v_CSP}" != "CLOUDIT" ] && [ "${v_CSP}" != "NCPVPC" ] && [ "${v_CSP}" != "NCP" ] && [ "${v_CSP}" != "NHNCLOUD" ]; then echo "[ERROR] missing <cloud>"; exit -1;fi

v_CSP_LOWER="$(echo ${v_CSP} | tr [:upper:] [:lower:])"

Expand Down Expand Up @@ -53,7 +53,9 @@ elif [ "${v_CSP}" == "CLOUDIT" ]; then
elif [ "${v_CSP}" == "NCPVPC" ]; then
v_DRIVER="${c_NCPVPC_DRIVER}"
elif [ "${v_CSP}" == "NCP" ]; then
v_DRIVER="${c_NCP_DRIVER}"
v_DRIVER="${c_NHNCLOUD_DRIVER}"
elif [ "${v_CSP}" == "NHNCLOUD" ]; then
v_DRIVER="${c_NHNCLOUD_DRIVER}"
fi


Expand Down Expand Up @@ -448,6 +450,64 @@ if [ "${v_CSP}" == "NCP" ]; then
if [ "${v_ZONE}" == "" ]; then v_ZONE="${v_REGION}-1";fi
fi
fi

# NHNCLOUD
if [ "${v_CSP}" == "NHNCLOUD" ]; then

if [ "${v_OPTION}" != "add" ]; then

v_NHNCLOUD_ENDPOINT="${NHN_IDENTITY_ENDPOINT}"
if [ "${v_NHNCLOUD_ENDPOINT}" == "" ]; then
read -e -p "Identity Endpoint ? [예:https://api-identity.infrastructure.cloud.toast.com] : " v_NHNCLOUD_ENDPOINT
if [ "${v_NHNCLOUD_ENDPOINT}" == "" ]; then echo "[ERROR] missing <nhncloud identity endpoint>"; exit -1;fi
fi

v_NHNCLOUD_USERNAME="${NHN_USERNAME}"
if [ "${v_NHNCLOUD_USERNAME}" == "" ]; then
read -e -p "Username ? [예:mcks] : " v_NHNCLOUD_USERNAME
if [ "${v_NHNCLOUD_USERNAME}" == "" ]; then echo "[ERROR] missing <nhncloud username>"; exit -1;fi
fi

v_NHNCLOUD_PASSWORD="${NHN_PASSWORD}"
if [ "${v_NHNCLOUD_PASSWORD}" == "" ]; then
read -e -p "Password ? [예:asdfqwer12] : " v_NHNCLOUD_PASSWORD
if [ "${v_NHNCLOUD_PASSWORD}" == "" ]; then echo "[ERROR] missing <nhncloud password>"; exit -1;fi
fi

v_NHNCLOUD_TENANT_ID="${NHN_TENANT_ID}"
if [ "${v_NHNCLOUD_TENANT_ID}" == "" ]; then
read -e -p "Tenant Id ? [예:edfasdfsasdff] : " v_NHNCLOUD_TENANT_ID
if [ "${v_NHNCLOUD_TENANT_ID}" == "" ]; then echo "[ERROR] missing <nhncloud tenant id>"; exit -1;fi
fi

v_NHNCLOUD_DOMAIN="${NHN_DOMAINNAME}"
if [ "${v_NHNCLOUD_DOMAIN}" == "" ]; then
read -e -p "Domain Name ? [예:default] : " v_NHNCLOUD_DOMAIN
if [ "${v_NHNCLOUD_DOMAIN}" == "" ]; then echo "[ERROR] missing <nhncloud domainname>"; exit -1;fi
fi

fi

# region
v_REGION="${NHN_REGION}"
if [ "${v_REGION}" == "" ]; then
read -e -p "region ? [예:KR1] : " v_REGION
if [ "${v_REGION}" == "" ]; then echo "[ERROR] missing region"; exit -1;fi
fi

# zone
v_ZONE="${NHN_ZONE}"
if [ "${v_ZONE}" == "" ]; then
read -e -p "zone ? [예:kr-pub-a] : " v_ZONE
if [ "${v_ZONE}" == "" ]; then
if [[ "${v_REGION}" =~ "1" ]]; then
v_REGION_LOWER="$(echo ${v_REGION} | tr [:upper:] [:lower:] | tr -cd 'a-z')"
else
v_REGION_LOWER="$(echo ${v_REGION} | tr [:upper:] [:lower:])"
fi
v_ZONE="${v_REGION_LOWER}-pub-a";fi
fi
fi
v_REGION_LOWER="$(echo ${v_REGION} | tr [:upper:] [:lower:])"

NM_CREDENTIAL="credential-${v_CSP_LOWER}"
Expand Down Expand Up @@ -509,6 +569,13 @@ elif [ "${v_CSP}" == "NCP" ]; then
echo "- Zone is '${v_ZONE}'"
echo "- ncp_client_id is '${v_NCP_ID}'"
echo "- ncp_client_secret is '${v_NCP_SECRET}'"
elif [ "${v_CSP}" == "NHNCLOUD" ]; then
echo "- Zone is '${v_ZONE}'"
echo "- nhncloud_identity_endpoint is '${v_NHNCLOUD_ENDPOINT}'"
echo "- nhncloud_username is '${v_NHNCLOUD_USERNAME}'"
echo "- nhncloud_password is '${v_NHNCLOUD_PASSWORD}'"
echo "- nhncloud_domainname is '${v_NHNCLOUD_DOMAIN}'"
echo "- nhncloud_tenantid is '${v_NHNCLOUD_TENANT_ID}'"
fi
echo "- (Name of credential) is '${NM_CREDENTIAL}'"
echo "- (Name of region) is '${NM_REGION}'"
Expand Down Expand Up @@ -660,6 +727,21 @@ EOF
{"Key" : "ClientSecret", "Value" : "${v_NCP_SECRET}"}
]
}
EOF
elif [ "${v_CSP}" == "NHNCLOUD" ]; then
curl -sX DELETE ${c_URL_SPIDER}/credential/${NM_CREDENTIAL} -H "${c_CT}" -o /dev/null -w "CREDENTIAL.delete():%{http_code}\n"
curl -sX POST ${c_URL_SPIDER}/credential -H "${c_CT}" -o /dev/null -w "CREDENTIAL.regist():%{http_code}\n" -d @- <<EOF
{
"CredentialName":"${NM_CREDENTIAL}",
"ProviderName":"${v_CSP}",
"KeyValueInfoList": [
{"Key":"IdentityEndpoint", "Value":"${v_NHNCLOUD_ENDPOINT}"},
{"Key":"Username", "Value":"${v_NHNCLOUD_USERNAME}"},
{"Key":"Password", "Value":"${v_NHNCLOUD_PASSWORD}"},
{"Key":"DomainName", "Value":"${v_NHNCLOUD_DOMAIN}"},
{"Key":"TenantId", "Value":"${v_NHNCLOUD_TENANT_ID}"}
]
}
EOF
fi

Expand Down
1 change: 1 addition & 0 deletions src/core/app/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
CSP_NCPVPC CSP = "ncpvpc"
CSP_NCP CSP = "ncp"
CSP_CLOUDIT CSP = "cloudit"
CSP_NHNCLOUD CSP = "nhncloud"

CONTROL_PLANE ROLE = "control-plane"
WORKER ROLE = "worker"
Expand Down
2 changes: 1 addition & 1 deletion src/core/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Node struct {
PublicIP string `json:"publicIp"`
Role app.ROLE `json:"role" enums:"control-plane,worker"`
Spec string `json:"spec"`
Csp app.CSP `json:"csp" enums:"aws,gcp,azure,alibaba,tencent,openstack,ibm,cloudit,ncp,ncpvpc"`
Csp app.CSP `json:"csp" enums:"aws,gcp,azure,alibaba,tencent,openstack,ibm,cloudit,ncp,ncpvpc,nhncloud"`
CreatedTime string `json:"createdTime" example:"2022-01-02T12:00:00Z" default:""`
CspLabel string `json:"cspLabel"`
RegionLabel string `json:"regionLabel"`
Expand Down
76 changes: 32 additions & 44 deletions src/core/service/csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
)

// region별 AMI : (AMI 이름 : ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20200908, 소유자:099720109477 )
var imageMap = map[string]string{
var awsImageMap = map[string]string{
"us-east-1": "ami-0817d428a6fb68645", //미국 동부 (버지니아 북부)
"us-east-2": "ami-0e82959d4ed12de3f", //미국 동부 (오하이오)
"us-west-1": "ami-03fac5402e10ea93b", //미국서부 (캘리포니아)
Expand Down Expand Up @@ -58,6 +58,12 @@ var ibmImageMap = map[string]string{
"jp-tok": "r022-61fdadec-6b03-4bd2-bfca-62cd16f5673f", //일본 (도쿄)
}

var nhnImageMap = map[string]string{
"KR1": "5396655e-166a-4875-80d2-ed8613aa054f", //판교
"KR2": "71893505-923c-4982-b0eb-844eb520661c", //평촌
"JP1": "ca69fad9-92f3-4c9b-a6e4-7e8b0e4d3a58", //일본
}

// get a cidr-block
func getCSPCidrBlock(csp app.CSP) string {

Expand All @@ -79,8 +85,9 @@ func getCSPCidrBlock(csp app.CSP) string {
case app.CSP_CLOUDIT:
return "10.0.244.0/22"
case app.CSP_NCPVPC:
case app.CSP_NCP:
return fmt.Sprintf("192.168.%d.0/24", 80+rand.Intn(10))
case app.CSP_NCP:
return fmt.Sprintf("192.168.%d.0/24", 90+rand.Intn(10))
}

return "192.168.255.0/24"
Expand All @@ -103,27 +110,7 @@ func getCSPImageId(csp app.CSP, configName string, region *tumblebug.Region) (st
return NCP_IMAGE_ID, nil
} else if csp == app.CSP_NCPVPC {
return NCPVPC_IMAGE_ID, nil
} else if csp == app.CSP_OPENSTACK {
// openstack : lookupImages를 통해 사용자가 등록한 이미지를 검색하여, 이미지 이름에 'ubuntu'와 '1804'가 포함된 이미지 정보 가져오기
lookupImages := tumblebug.NewLookupImages(configName)
if exist, err := lookupImages.GET(); err != nil {
return "", errors.New(fmt.Sprintf("Failed to lookup a images on openstack. (connection=%s, cause='%v')", configName, err))
} else if !exist {
return "", errors.New(fmt.Sprintf("Could not be found a image on openstack. (connection=%s)", configName))
}

for _, image := range lookupImages.Images {
id := strings.ToLower(lang.GetOnlyLettersAndNumbers(image.IId.NameId))
guestOs := strings.ToLower(lang.GetOnlyLettersAndNumbers(image.GuestOS))
if (strings.Contains(id, "ubuntu") && strings.Contains(id, "1804")) || (strings.Contains(guestOs, "ubuntu") && strings.Contains(guestOs, "1804")) {
return image.IId.NameId, nil
}
}

return "", errors.New(fmt.Sprintf("Could not be found a ubuntu 18.04 image on openstack. please create an image based on Ubuntu 18.04 The image name must include 'ubuntu' and '18.04'. (connection=%s)", configName))

} else if csp == app.CSP_AWS {
// AWS : 리전별 AMI 가져오기
} else if csp == app.CSP_NHNCLOUD || csp == app.CSP_AWS || csp == app.CSP_IBM {
regionName := ""
for _, info := range region.KeyValueInfoList {
if info.Key == "Region" {
Expand All @@ -133,38 +120,39 @@ func getCSPImageId(csp app.CSP, configName string, region *tumblebug.Region) (st
}

if regionName == "" {
return "", errors.New(fmt.Sprintf("Could not be found a AMI on AWS. (cause = region name is empty, connection=%s, region=%s)", configName, region.RegionName))
return "", errors.New(fmt.Sprintf("Could not be found a image. (cause = region name is empty, connection=%s, region=%s)", configName, region.RegionName))
}
imageId := ibmImageMap[regionName]
if csp == app.CSP_NHNCLOUD {
imageId = nhnImageMap[regionName]
} else if csp == app.CSP_AWS {
imageId = awsImageMap[regionName]
}

// TODO [update/hard-coding] region별 image id
imageId := imageMap[regionName]
if imageId == "" {
return "", errors.New(fmt.Sprintf("Could not be found a AMI on AWS image map. (connection=%s, region=%s)", configName, regionName))
return "", errors.New(fmt.Sprintf("Could not be found a image map. (connection=%s, region=%s)", configName, regionName))
}

return imageId, nil

} else if csp == app.CSP_IBM {
// IBM : 리전별 image 가져오기
regionName := ""
for _, info := range region.KeyValueInfoList {
if info.Key == "Region" {
regionName = info.Value //get region name
break
}
} else if csp == app.CSP_OPENSTACK {
// openstack : lookupImages를 통해 사용자가 등록한 이미지를 검색하여, 이미지 이름에 'ubuntu'와 '1804'가 포함된 이미지 정보 가져오기
lookupImages := tumblebug.NewLookupImages(configName)
if exist, err := lookupImages.GET(); err != nil {
return "", errors.New(fmt.Sprintf("Failed to lookup a images on openstack. (connection=%s, cause='%v')", configName, err))
} else if !exist {
return "", errors.New(fmt.Sprintf("Could not be found a image on openstack. (connection=%s)", configName))
}

if regionName == "" {
return "", errors.New(fmt.Sprintf("Could not be found a image on IBM. (cause = region name is empty, connection=%s, region=%s)", configName, region.RegionName))
for _, image := range lookupImages.Images {
id := strings.ToLower(lang.GetOnlyLettersAndNumbers(image.IId.NameId))
guestOs := strings.ToLower(lang.GetOnlyLettersAndNumbers(image.GuestOS))
if (strings.Contains(id, "ubuntu") && strings.Contains(id, "1804")) || (strings.Contains(guestOs, "ubuntu") && strings.Contains(guestOs, "1804")) {
return image.IId.NameId, nil
}
}

// TODO [update/hard-coding] region별 image id
imageId := ibmImageMap[regionName]
if imageId == "" {
return "", errors.New(fmt.Sprintf("Could not be found a image on IBM image map. (connection=%s, region=%s)", configName, regionName))
}
return "", errors.New(fmt.Sprintf("Could not be found a ubuntu 18.04 image on openstack. please create an image based on Ubuntu 18.04 The image name must include 'ubuntu' and '18.04'. (connection=%s)", configName))

return imageId, nil
} else {
return "", errors.New(fmt.Sprintf("CSP '%s' is not supported. (could not be found 'vm-machine-image')", csp))
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/service/mcir.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (self *MCIR) CreateIfNotExist() (model.ClusterReason, string) {

//validate a CSP
exists := false
for _, c := range []string{string(app.CSP_AWS), string(app.CSP_GCP), string(app.CSP_AZURE), string(app.CSP_ALIBABA), string(app.CSP_TENCENT), string(app.CSP_OPENSTACK), string(app.CSP_IBM), string(app.CSP_CLOUDIT), string(app.CSP_NCPVPC), string(app.CSP_NCP)} {
for _, c := range []string{string(app.CSP_AWS), string(app.CSP_GCP), string(app.CSP_AZURE), string(app.CSP_ALIBABA), string(app.CSP_TENCENT), string(app.CSP_OPENSTACK), string(app.CSP_IBM), string(app.CSP_CLOUDIT), string(app.CSP_NCPVPC), string(app.CSP_NCP), string(app.CSP_NHNCLOUD)} {
if string(self.csp) == c {
exists = true
break
Expand Down

0 comments on commit 63b5180

Please sign in to comment.