REST API Examples - cloud-barista/cb-spider GitHub Wiki
CB-Spider REST API νμ© μμ
* λ³Έ κ°μ΄λλ CB-Spiderμ REST APIλ₯Ό μ΄μ©ν λ©ν°ν΄λΌμ°λ μ μ΄μ λν μμλ₯Ό μ 곡νκ³ μμ΅λλ€.
* λ³Έ κ°μ΄λλ AWS VM μμ± λ° μ μ΄ μ€μ¬μΌλ‘ κ°μ΄λνκ³ μμ΅λλ€.
* κ·Έ μΈ CSP λ° μμμ λν νμ©μ λ€μ User Guide λ° API λ¬Έμ λ±μ μ°Έκ³ νμ¬ μ μ¬ν λ°©λ²μΌλ‘ μ μ© κ°λ₯ν©λλ€.
-
[κ΄λ ¨ μ 보]
[μ€ν μ μ°¨]
1. μ¬μ μ€λΉ
-
μ°λ λμ CSP κ³μ μμ± λ° Credential μ€λΉ
- μ°λ λμ CSPμ Credential λ°κΈ κ°μ΄λ μ°Έκ³ νμ¬ Credential μ 보 μ€λΉ
-
Terminal-1: CB-Spider μλ² μ€ν νκ²½
- CB-Spider μ€μΉ λ° μ€ν κ°μ΄λ μ°Έκ³ νμ¬ CB-Spider μλ² μ€ν
- μμ€ κΈ°λ° μ€ν: https://github.com/cloud-barista/cb-spider/wiki/Quick-Start-Guide
- CB-Spider μ€μΉ λ° μ€ν κ°μ΄λ μ°Έκ³ νμ¬ CB-Spider μλ² μ€ν
-
Terminal-2: CB-Spider ν΄λΌμ΄μΈνΈ μ€ν νκ²½
- curlμ μ΄μ©ν CB-Spider REST API κ°λ¨ν μν
- CB-Spider μλ²κ° μ 곡νλ μ°λ λμ CSP λͺ©λ‘ μΆλ ₯
outputcurl -sX GET http://localhost:1024/spider/cloudos |json_pp
{ "cloudos" : [ "AWS", "AZURE", "GCP", "ALIBABA", "TENCENT", "IBM", "OPENSTACK", "NCP", "NCPVPC", "NHNCLOUD", "KTCLOUD", "KTCLOUDVPC", "MOCK" ] }
- CB-Spider μλ²κ° μ 곡νλ μ°λ λμ CSP λͺ©λ‘ μΆλ ₯
- curlμ μ΄μ©ν CB-Spider REST API κ°λ¨ν μν
μ΄ν Terminal-2μμ μ€ν
2. μ°κ²° λ±λ‘
μ°λ λμ ν΄λΌμ°λμ μ°κ²° μ€μ μ μν μ 보λ₯Ό λ±λ‘νλ€.
μ°κ²° μ€μ μ λ±λ‘ν νμλ λ±λ‘ μμ λΆμ¬ν μ°κ²° μ΄λ¦(Connection Name)μ μ΄μ©νμ¬ λμ ν΄λΌμ°λμ μ°κ²° λ° μ μ΄ν μ μλ€.
μ°κ²° μ€μ μ λ€μ μμΌλ‘ μ§ννλ€.
(1) Cloud Driver λ±λ‘
(2) Cloud Credential λ±λ‘
(3) Cloud Region/Zone λ±λ‘
(4) Cloud Connection λ±λ‘
-
(1) Cloud Driver λ±λ‘
- μ°λνκ³ μ νλ λμ Cloud(CSP)μ λ§λ Cloud Driver μ 보λ₯Ό λ±λ‘νλ€.
- λ±λ‘ μμ
outputcurl -sX POST http://localhost:1024/spider/driver \ -H 'Content-Type: application/json' \ -d '{ "DriverName": "aws-driver01", "ProviderName": "AWS", "DriverLibFileName": "aws-driver-v1.0.so" }' | json_pp
{ "DriverLibFileName" : "aws-driver-v1.0.so", "DriverName" : "aws-driver01", "ProviderName" : "AWS" }
-
(2) Cloud Credential λ±λ‘
- μ°λνκ³ μ νλ λμ Cloud(CSP)μ λ§λ Credential μ 보λ₯Ό λ±λ‘νλ€.
- λ±λ‘ μμ(XXXXX: CSPλ‘λΆν° λ°κΈ λ°μ μ λ³΄λ‘ κ΅μ²΄)
outputcurl -sX POST http://localhost:1024/spider/credential \ -H 'Content-Type: application/json' \ -d '{ "CredentialName": "aws-credential01", "ProviderName": "AWS", "KeyValueInfoList": [ {"Key": "aws_access_key_id", "Value": "XXXXXXXXXXXXXXXXXXXXXXX"}, {"Key": "aws_secret_access_key", "Value": "XXXXXXXXXXXXXXXXXXXXXXX"} ] }' | json_pp
{ "CredentialName" : "aws-credential01", "KeyValueInfoList" : [ { "Key" : "ClientId", "Value" : "XXXXXXXXXXXXXXXXXXXXXXX" }, { "Key" : "ClientSecret", "Value" : "XXXXXXXXXXXXXXXXXXXXXXX" } ], "ProviderName" : "AWS" }
-
(3) Cloud Region/Zone λ±λ‘
- μ°λνκ³ μ νλ λμ Cloud(CSP)μ λ§λ Region/Zone μ 보λ₯Ό λ±λ‘νλ€.
- λ±λ‘ μμ(AWSμ ohio, oregon μ§μμ 2κ°μ Region/Zone λ±λ‘ μμ)
outputregions=("aws-ohio:us-east-2:us-east-2a" "aws-oregon:us-west-2:us-west-2a") for region in "${regions[@]}"; do IFS=":" read -r RegionName Region Zone <<< "$region" curl -sX POST http://localhost:1024/spider/region \ -H 'Content-Type: application/json' \ -d '{ "RegionName": "'$RegionName'", "ProviderName": "AWS", "KeyValueInfoList": [ {"Key": "Region", "Value": "'$Region'"}, {"Key": "Zone", "Value": "'$Zone'"} ] }' | json_pp done
{ "AvailableZoneList" : null, "KeyValueInfoList" : [ { "Key" : "Region", "Value" : "us-east-2" }, { "Key" : "Zone", "Value" : "us-east-2a" } ], "ProviderName" : "AWS", "RegionName" : "aws-ohio" } { "AvailableZoneList" : null, "KeyValueInfoList" : [ { "Key" : "Region", "Value" : "us-west-2" }, ... μ€λ΅ ...
-
(4) Cloud Connection λ±λ‘
- μ°λνκ³ μ νλ λμ Cloud(CSP)μ λ§λ Connection μ 보λ₯Ό λ±λ‘νλ€.
- μμμ λ±λ‘ν driver name, credential name, region nameμ μ€μ νλ€.
- λ±λ‘ μμ(AWS ohio, oregon κ΄λ ¨ 2κ°μ Connection λ±λ‘ μμ)
outputconfigs=("aws-ohio-config:aws-ohio" "aws-oregon-config:aws-oregon") for config in "${configs[@]}"; do IFS=":" read -r ConfigName RegionName <<< "$config" curl -sX POST http://localhost:1024/spider/connectionconfig \ -H 'Content-Type: application/json' \ -d '{ "ConfigName": "'$ConfigName'", "ProviderName": "AWS", "DriverName": "aws-driver01", "CredentialName": "aws-credential01", "RegionName": "'$RegionName'" }' | json_pp done
{ "ConfigName" : "aws-ohio-config", "CredentialName" : "aws-credential01", "DriverName" : "aws-driver01", "ProviderName" : "AWS", "RegionName" : "aws-ohio" } { "ConfigName" : "aws-oregon-config", "CredentialName" : "aws-credential01", "DriverName" : "aws-driver01", "ProviderName" : "AWS", "RegionName" : "aws-oregon" }
3. μμ μμ±
μ°λ λμ ν΄λΌμ°λμ VM μΈνλΌ λ° Container(Kubernetes Cluster) μΈνλΌ μμ±μ μν κΈ°λ³Έ μμλ€μ μμ±νλ€.
μμ μμ± μμλ μμμ λ±λ‘ν μ°κ²° μ΄λ¦(Connection Name)μ μ€μ μΌλ‘ λμ CSP, Driver λ° νμ© Credential λ±μ΄ μ§μ λλ€.
κΈ°λ³Έ μμ μμ± νμλ μμ±λ μμ μ΄λ¦μ νμ©νμ¬ VM λ° Clusterλ₯Ό μμ± λ° μ μ΄ν μ μλ€.
κΈ°λ³Έ μμ μμ±μ μμκ° μμ‘΄μ±μ κ³ λ €νμ¬ λ€μ μμΌλ‘ μ§ννλ€.
(1) VPC/Subnet μμ±
(2) Security Group μμ±
(3) SSH KeyPair μμ±
β» μ°Έκ³ : μμ μμ‘΄ κ΄κ³
- VPC μμ± μμλ μ΅μ 1κ° μ΄μμ Subnet μ€μ νμ, VPC μμ± ν Subnet μΆκ°/μμ κ°λ₯
- Subnet, Security Group λ° VM λ±μ νΉμ VPC νμμ μμ± κ°λ₯
- VPC μμ λ λμ VPCλ₯Ό νμ©νλ VMμ ν¬ν¨ν λͺ¨λ μμ μμ ν μμ κ°λ₯
- Subnetμ VPC μμ μ ν¨κ» μμ κ°λ₯
-
(1) VPC/Subnet μμ±
- μμ±νκ³ μ νλ λμ μΈνλΌ μ‘°κ±΄μ λ§λ VPC/Subnetμ μμ±νλ€.
- μμ± μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX POST http://localhost:1024/spider/vpc \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'", "ReqInfo": { "Name": "vpc-01", "IPv4_CIDR": "192.168.0.0/16", "SubnetInfoList": [ { "Name": "subnet-01", "IPv4_CIDR": "192.168.1.0/24" } ] } }' | json_pp
{ "IId" : { "NameId" : "vpc-01", "SystemId" : "vpc-060eb5dc45c1117b0" }, "IPv4_CIDR" : "192.168.0.0/16", "SubnetInfoList" : [ { "IId" : { "NameId" : "subnet-01", "SystemId" : "subnet-0b140aaac2024ef83" }, "IPv4_CIDR" : "192.168.1.0/24", "KeyValueList" : [ { "Key" : "VpcId", "Value" : "vpc-060eb5dc45c1117b0" }, ... μ€λ΅ ... { "Key" : "Status", "Value" : "available" } ], "TagList" : [ { "Key" : "Name", "Value" : "subnet-01-crehtv3p70iugvns0a7g" } ], "Zone" : "us-east-2a" } ], "TagList" : [ { "Key" : "Name", "Value" : "vpc-01-crehtv3p70iugvns0a70" } ] }
-
(2) Security Group μμ±
- μμ±νκ³ μ νλ λμ μΈνλΌ μ‘°κ±΄μ λ§λ Security Groupμ μμ±νλ€.
- μμ± μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX POST http://localhost:1024/spider/securitygroup \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'", "ReqInfo": { "Name": "sg-01", "VPCName": "vpc-01", "SecurityRules": [ { "FromPort": "1", "ToPort" : "65535", "IPProtocol" : "tcp", "Direction" : "inbound" } ] } }' | json_pp
{ "IId" : { "NameId" : "sg-01", "SystemId" : "sg-090b7a22f58bf49f2" }, "KeyValueList" : [ { "Key" : "GroupName", "Value" : "sg01-crehvcbp70iugvns0a80" }, ... μ€λ΅ ... ], "SecurityRules" : [ { "CIDR" : "0.0.0.0/0", "Direction" : "inbound", "FromPort" : "1", "IPProtocol" : "TCP", "ToPort" : "65535" }, { "CIDR" : "0.0.0.0/0", "Direction" : "outbound", "FromPort" : "-1", "IPProtocol" : "ALL", "ToPort" : "-1" } ], "TagList" : [ { "Key" : "Name", "Value" : "sg01-crehvcbp70iugvns0a80" } ], "VpcIID" : { "NameId" : "vpc-01", "SystemId" : "vpc-060eb5dc45c1117b0" } }
-
(3) SSH KeyPair μμ±
- μμ±νκ³ μ νλ λμ μΈνλΌ μ‘°κ±΄μ λ§λ KeyPairλ₯Ό μμ±νλ€.
- μμ± μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX POST http://localhost:1024/spider/keypair \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'", "ReqInfo": { "Name": "keypair-01" } }' | json_pp
{ "Fingerprint" : "2e:b2:3d:0c:b8:19:3e:70:fa:98:a6:c6:f5:d2:b6:bb:03:2c:a8:03", "IId" : { "NameId" : "keypair-01", "SystemId" : "keypair-01-crei0krp70iugvns0a8g" }, "KeyValueList" : [ { "Key" : "KeyMaterial", "Value" : "-----BEGIN RSA PRIVATE KEY-----\n... μ€λ΅ ...\n-----END RSA PRIVATE KEY-----" } ], "PrivateKey" : "-----BEGIN RSA PRIVATE KEY-----\n... μ€λ΅ ...\n-----END RSA PRIVATE KEY-----", "TagList" : [ { "Key" : "Name", "Value" : "keypair-01-crei0krp70iugvns0a8g" } ] }
4. VM μ μ΄
μ°λ λμ ν΄λΌμ°λμ VMμ μμ± λ° μ μ΄κ° κ°λ₯νλ€.
VM μ μ΄ μμλ μμμ λ±λ‘ν μ°κ²° μ΄λ¦(Connection Name)μ μ€μ μΌλ‘ λμ CSP, Driver λ° νμ© Credential λ±μ΄ μ§μ λλ€.
VM μμ± μμλ μμμ μμ±ν κΈ°λ³Έ μμλ€μ νμ©νμ¬ VM μμ±μ΄ κ°λ₯νλ€.
VM μμ± νμλ μμ±λ VMμ νμ©μ±μ λμ΄κΈ° μνμ¬ Disk, MyImage λ° NLB λ±μ μΆκ° μμμ μ°κ³νμ¬ νμ© κ°λ₯νλ€.
λ³Έ κ°μ΄λμμλ μΆκ° μμμ λν νμ©μ μλ΅νκ³ VM μ μ΄μ λν΄μ λ€μ μμΌλ‘ κ°μ΄λνλ€.
(1) VM μμ±
(2) VM μν
(3) VM μμ
-
(1) VM μμ±
- μμ±νκ³ μ νλ λμ μΈνλΌ μ‘°κ±΄μ λ§λ VMμ μμ±νλ€.
- μμ± μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
- IMAGE_NAME,SPEC_NAME: AWSκ° νμ¬ μ 곡νλ μ 보(CSP λ³κ²½μ CSPμ λ§κ² λ³κ²½ νμ)
- κ·ΈμΈ μμ μ΄λ¦: μμμ μμ±ν μμ μ΄λ¦
outputexport CONN_CONFIG=aws-ohio-config export IMAGE_NAME=ami-00978328f54e31526 export SPEC_NAME=t3.micro curl -sX POST http://localhost:1024/spider/vm \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'", "ReqInfo": { "Name": "'${CONN_CONFIG}'-vm-01", "ImageName": "'${IMAGE_NAME}'", "VPCName": "vpc-01", "SubnetName": "subnet-01", "SecurityGroupNames": [ "sg-01" ], "VMSpecName": "'${SPEC_NAME}'", "KeyPairName": "keypair-01" } }' | json_pp
{ "AccessPoint" : "", "IId" : { "NameId" : "aws-ohio-config-vm-01", "SystemId" : "i-0e0267464de62c56f" }, "ImageIId" : { "NameId" : "ami-00978328f54e31526", "SystemId" : "ami-00978328f54e31526" }, "ImageType" : "PublicImage", "KeyPairIId" : { "NameId" : "keypair-01", "SystemId" : "keypair-01-crei0krp70iugvns0a8g" }, "KeyValueList" : [ { "Key" : "State", "Value" : "running" }, { "Key" : "Architecture", "Value" : "x86_64" }, ... μ€λ΅ ... ], "NetworkInterface" : "eni-attach-0dcaaeb4270e4edd0", "Platform" : "LINUX/UNIX", "PrivateDNS" : "ip-192-168-1-64.us-east-2.compute.internal", "PrivateIP" : "192.168.1.64", "PublicIP" : "3.149.245.118", "Region" : { "Region" : "us-east-2", "Zone" : "us-east-2a" }, "RootDeviceName" : "/dev/sda1", "RootDiskSize" : "8", "RootDiskType" : "gp2", "SSHAccessPoint" : "3.149.245.118:22", "SecurityGroupIIds" : [ { "NameId" : "sg-01", "SystemId" : "sg-090b7a22f58bf49f2" } ], "StartTime" : "2024-09-08T04:35:18Z", "SubnetIID" : { "NameId" : "subnet-01", "SystemId" : "subnet-0b140aaac2024ef83" }, "TagList" : [ { "Key" : "Name", "Value" : "aws-ohio-config-vm-01-creij1bp70iugvns0a90" } ], "VMBlockDisk" : "/dev/sda1", "VMSpecName" : "t3.micro", "VMUserId" : "cb-user", "VpcIID" : { "NameId" : "vpc-01", "SystemId" : "vpc-060eb5dc45c1117b0" } }
-
(2) VM μν
- μμ±ν VM μν μ 보λ₯Ό νμΈνλ€.
- νμΈ μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX GET http://localhost:1024/spider/vmstatus \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'" }' | json_pp
{ "vmstatus" : [ { "IId" : { "NameId" : "aws-ohio-config-vm-01", "SystemId" : "i-0e0267464de62c56f" }, "VmStatus" : "Running" } ] }
-
(3) VM μμ
- νμ©ν VMμ μμ νλ€.
- μμ μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX DELETE http://localhost:1024/spider/vm/${CONN_CONFIG}-vm-01 \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'" }' | json_pp
{ "Status" : "Terminated" }
5. μμ μμ
νμ©ν κΈ°λ³Έ μμλ€μ μμ νλ€.
μμ μμ μμλ μμμ λ±λ‘ν μ°κ²° μ΄λ¦(Connection Name)μ μ€μ μΌλ‘ λμ CSP, Driver λ° νμ© Credential λ±μ΄ μ§μ λλ€.
κΈ°λ³Έ μμ μμ λ μμκ° μμ‘΄μ±μ κ³ λ €νμ¬ λ€μκ³Ό κ°μ΄ μμ±ν μμμΌλ‘ μμ νλ€.
(1) SSH KeyPair μμ
(2) Security Group μμ
(3) VPC/Subnet μμ
β» μ°Έκ³ : μμ μμ‘΄ κ΄κ³
- VPC μμ± μμλ μ΅μ 1κ° μ΄μμ Subnet μ€μ νμ, VPC μμ± ν Subnet μΆκ°/μμ κ°λ₯
- Subnet, Security Group λ° VM λ±μ νΉμ VPC νμμ μμ± κ°λ₯
- VPC μμ λ λμ VPCλ₯Ό νμ©νλ VMμ ν¬ν¨ν λͺ¨λ μμ μμ ν μμ κ°λ₯
- Subnetμ VPC μμ μ ν¨κ» μμ κ°λ₯
-
(1) SSH KeyPair μμ
- νμ©ν SSH KeyPairλ₯Ό μμ νλ€.
- μμ μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX DELETE http://localhost:1024/spider/keypair/keypair-01 \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'" }' | json_pp
{ "Result" : "true" }
-
(2) Security Group μμ
- νμ©ν Security Groupμ μμ νλ€.
- μμ μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX DELETE http://localhost:1024/spider/securitygroup/sg-01 \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'" }' | json_pp
{ "Result" : "true" }
-
(3) VPC/Subnet μμ
- νμ©ν VPC/Subnetμ μμ νλ€.
- μμ μμ
- CONN_CONFIG:μμμ λ±λ‘ν Connection Name(CSP λ³κ²½μ λμ Connection NameμΌλ‘ μ€μ νμ)
outputexport CONN_CONFIG=aws-ohio-config curl -sX DELETE http://localhost:1024/spider/vpc/vpc-01 \ -H 'Content-Type: application/json' \ -d '{ "ConnectionName": "'${CONN_CONFIG}'" }' | json_pp
{ "Result" : "true" }