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

Add individual VM access info API #1956

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cloud.google.com/go/compute v1.19.1/go.mod h1:6ylj3a05WF8leseCdIf77NK0g1ey+nj5IK
cloud.google.com/go/compute v1.23.3/go.mod h1:VCgBUoMnIVIR0CscqQiPJLAG25E3ZRZMzcFZeQ+h8CI=
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
cloud.google.com/go/contactcenterinsights v1.6.0 h1:jXIpfcH/VYSE1SYcPzO0n1VVb+sAamiLOgCw45JbOQk=
cloud.google.com/go/contactcenterinsights v1.6.0/go.mod h1:IIDlT6CLcDoyv79kDv8iWxMSTZhLxSCofVV5W6YFM/w=
cloud.google.com/go/contactcenterinsights v1.12.1/go.mod h1:HHX5wrz5LHVAwfI2smIotQG9x8Qd6gYilaHcLLLmNis=
Expand Down Expand Up @@ -370,12 +371,15 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/Nerzal/gocloak/v13 v13.9.0 h1:YWsJsdM5b0yhM2Ba3MLydiOlujkBry4TtdzfIzSVZhw=
github.com/Nerzal/gocloak/v13 v13.9.0/go.mod h1:YYuDcXZ7K2zKECyVP7pPqjKxx2AzYSpKDj8d6GuyM10=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/armon/go-metrics v0.4.0/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down Expand Up @@ -407,6 +411,7 @@ github.com/go-resty/resty/v2 v2.11.0 h1:i7jMfNOJYMp69lq7qozJP+bjgzfAzeOhuGlyDrqx
github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gobuffalo/buffalo v1.1.0 h1:6y1fUC47QWevaM1ImukJFHNgxiRIT+Y74VcP4ZQaz80=
github.com/gobuffalo/buffalo v1.1.0/go.mod h1:lLsx9Y8bFYu9uvQyIEB3M0QA908ChHUPjwOGumZWARU=
github.com/gobuffalo/buffalo-pop/v3 v3.0.7 h1:QU2L9cjCIjK+c+2s/3KbxfRSDAc/TC+HccV+f9YqMTs=
Expand Down Expand Up @@ -457,6 +462,8 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
Expand All @@ -472,6 +479,7 @@ github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kX
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/gorilla/sessions v1.3.0 h1:XYlkq7KcpOB2ZhHBPv5WpjMIxrQosiZanfoy1HLZFzg=
github.com/gorilla/sessions v1.3.0/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w=
Expand Down Expand Up @@ -529,10 +537,13 @@ github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADym
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nicksnyder/go-i18n v1.10.3 h1:0U60fnLBNrLBVt8vb8Q67yKNs+gykbQuLsIkiesJL+w=
github.com/nicksnyder/go-i18n v1.10.3/go.mod h1:hvLG5HTlZ4UfSuVLSRuX7JRUomIaoKQM19hm6f+no7o=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo=
github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Qk=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
Expand Down Expand Up @@ -569,6 +580,7 @@ go.etcd.io/etcd/client/v2 v2.305.10/go.mod h1:m3CKZi69HzilhVqtPDcjhSGp+kA1OmbNn0
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
Expand Down Expand Up @@ -601,4 +613,6 @@ golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/api v0.153.0/go.mod h1:3qNJX5eOmhiWYc67jRA/3GsDw97UFb5ivv7Y2PrriAY=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
12 changes: 11 additions & 1 deletion src/api/rest/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4909,12 +4909,19 @@ const docTemplate = `{
"enum": [
"default",
"status",
"idsInDetail"
"idsInDetail",
"accessinfo"
],
"type": "string",
"description": "Option for MCI",
"name": "option",
"in": "query"
},
{
"type": "string",
"description": "(For option=accessinfo) accessInfoOption (showSshKey)",
"name": "accessInfoOption",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -12299,6 +12306,9 @@ const docTemplate = `{
"model.MciVmAccessInfo": {
"type": "object",
"properties": {
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"privateIP": {
"type": "string"
},
Expand Down
12 changes: 11 additions & 1 deletion src/api/rest/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4902,12 +4902,19 @@
"enum": [
"default",
"status",
"idsInDetail"
"idsInDetail",
"accessinfo"
],
"type": "string",
"description": "Option for MCI",
"name": "option",
"in": "query"
},
{
"type": "string",
"description": "(For option=accessinfo) accessInfoOption (showSshKey)",
"name": "accessInfoOption",
"in": "query"
}
],
"responses": {
Expand Down Expand Up @@ -12292,6 +12299,9 @@
"model.MciVmAccessInfo": {
"type": "object",
"properties": {
"connectionConfig": {
"$ref": "#/definitions/model.ConnConfig"
},
"privateIP": {
"type": "string"
},
Expand Down
8 changes: 8 additions & 0 deletions src/api/rest/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3743,6 +3743,12 @@ paths:
- default
- status
- idsInDetail
- accessinfo
- name: accessInfoOption
in: query
description: (For option=accessinfo) accessInfoOption (showSshKey)
schema:
type: string
responses:
"200":
description: Different return structures by the given option param
Expand Down Expand Up @@ -9283,6 +9289,8 @@ components:
model.MciVmAccessInfo:
type: object
properties:
connectionConfig:
$ref: '#/components/schemas/model.ConnConfig'
privateIP:
type: string
privateKey:
Expand Down
8 changes: 7 additions & 1 deletion src/api/rest/server/infra/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ func RestDelAllMci(c echo.Context) error {
// @Param nsId path string true "Namespace ID" default(default)
// @Param mciId path string true "MCI ID" default(mci01)
// @Param vmId path string true "VM ID" default(g1-1)
// @Param option query string false "Option for MCI" Enums(default, status, idsInDetail)
// @Param option query string false "Option for MCI" Enums(default, status, idsInDetail, accessinfo)
// @Param accessInfoOption query string false "(For option=accessinfo) accessInfoOption (showSshKey)"
// @success 200 {object} JSONResult{[DEFAULT]=model.TbVmInfo,[STATUS]=model.TbVmStatusInfo,[IDNAME]=model.TbIdNameInDetailInfo} "Different return structures by the given option param"
// @Failure 404 {object} model.SimpleMsg
// @Failure 500 {object} model.SimpleMsg
Expand All @@ -247,6 +248,7 @@ func RestGetMciVm(c echo.Context) error {
vmId := c.Param("vmId")

option := c.QueryParam("option")
accessInfoOption := c.QueryParam("accessInfoOption")

switch option {
case "status":
Expand All @@ -257,6 +259,10 @@ func RestGetMciVm(c echo.Context) error {
result, err := infra.GetVmIdNameInDetail(nsId, mciId, vmId)
return common.EndRequestWithLog(c, err, result)

case "accessinfo":
result, err := infra.GetMciVmAccessInfo(nsId, mciId, vmId, accessInfoOption)
return common.EndRequestWithLog(c, err, result)

default:
result, err := infra.ListVmInfo(nsId, mciId, vmId)
return common.EndRequestWithLog(c, err, result)
Expand Down
70 changes: 70 additions & 0 deletions src/core/infra/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func GetMciAccessInfo(nsId string, mciId string, option string) (*model.MciAcces
defer wg.Done()
common.RandomSleep(0, len(vmList)/2)
vmInfo, err := GetVmCurrentPublicIp(nsId, mciId, vmId)

vmAccessInfo := model.MciVmAccessInfo{}
if err != nil {
log.Info().Err(err).Msg("")
Expand All @@ -432,6 +433,13 @@ func GetMciAccessInfo(nsId string, mciId string, option string) (*model.MciAcces
}
vmAccessInfo.VmId = vmId

vmObject, err := GetVmObject(nsId, mciId, vmId)
if err != nil {
log.Info().Err(err).Msg("")
} else {
vmAccessInfo.ConnectionConfig = vmObject.ConnectionConfig
}

_, verifiedUserName, privateKey, err := GetVmSshKey(nsId, mciId, vmId)
if err != nil {
log.Error().Err(err).Msg("")
Expand Down Expand Up @@ -462,6 +470,68 @@ func GetMciAccessInfo(nsId string, mciId string, option string) (*model.MciAcces
return output, nil
}

// GetMciVmAccessInfo is func to retrieve MCI Access information
func GetMciVmAccessInfo(nsId string, mciId string, vmId string, option string) (*model.MciVmAccessInfo, error) {

output := &model.MciVmAccessInfo{}

err := common.CheckString(nsId)
if err != nil {
log.Error().Err(err).Msg("")
return output, err
}

err = common.CheckString(mciId)
if err != nil {
log.Error().Err(err).Msg("")
return output, err
}
check, _ := CheckMci(nsId, mciId)

if !check {
err := fmt.Errorf("The mci %s does not exist.", mciId)
return output, err
}

output.VmId = vmId

vmInfo, err := GetVmCurrentPublicIp(nsId, mciId, vmId)

vmAccessInfo := &model.MciVmAccessInfo{}
if err != nil {
log.Info().Err(err).Msg("")
return output, err
} else {
vmAccessInfo.PublicIP = vmInfo.PublicIp
vmAccessInfo.PrivateIP = vmInfo.PrivateIp
vmAccessInfo.SSHPort = vmInfo.SSHPort
}
vmAccessInfo.VmId = vmId

vmObject, err := GetVmObject(nsId, mciId, vmId)
if err != nil {
log.Info().Err(err).Msg("")
return output, err
} else {
vmAccessInfo.ConnectionConfig = vmObject.ConnectionConfig
}

_, verifiedUserName, privateKey, err := GetVmSshKey(nsId, mciId, vmId)
if err != nil {
log.Info().Err(err).Msg("")
return output, err
} else {
if strings.EqualFold(option, "showSshKey") {
vmAccessInfo.PrivateKey = privateKey
}
vmAccessInfo.VmUserName = verifiedUserName
}

output = vmAccessInfo

return output, nil
}

// ListMciInfo is func to get all MCI objects
func ListMciInfo(nsId string, option string) ([]model.TbMciInfo, error) {

Expand Down
15 changes: 8 additions & 7 deletions src/core/model/mci.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,14 @@ type MciSubGroupAccessInfo struct {

// MciVmAccessInfo is struct for MciVmAccessInfo
type MciVmAccessInfo struct {
VmId string `json:"vmId"`
PublicIP string `json:"publicIP"`
PrivateIP string `json:"privateIP"`
SSHPort string `json:"sshPort"`
PrivateKey string `json:"privateKey,omitempty"`
VmUserName string `json:"vmUserName,omitempty"`
VmUserPassword string `json:"vmUserPassword,omitempty"`
VmId string `json:"vmId"`
PublicIP string `json:"publicIP"`
PrivateIP string `json:"privateIP"`
SSHPort string `json:"sshPort"`
PrivateKey string `json:"privateKey,omitempty"`
VmUserName string `json:"vmUserName,omitempty"`
VmUserPassword string `json:"vmUserPassword,omitempty"`
ConnectionConfig ConnConfig `json:"connectionConfig"`
}

// TbVmIdNameInDetailInfo is struct for details related with ID and Name
Expand Down
Loading