mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
Merge pull request #15382 from swordqiu/hotfix/qj-separate-region-cloudmux-import
feature: separate region and cloudmux
This commit is contained in:
@@ -282,10 +282,12 @@ dep:
|
||||
@echo "$$depDeprecated"
|
||||
@$(MAKE) mod
|
||||
|
||||
RELEASE_BRANCH:=master
|
||||
GOPROXY ?= direct
|
||||
|
||||
mod:
|
||||
GOPROXY=$(GOPROXY) go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p'))
|
||||
GOPROXY=$(GOPROXY) go get -d yunion.io/x/cloudmux@$(RELEASE_BRANCH)
|
||||
GOPROXY=$(GOPROXY) go get -d $(patsubst %,%@master,$(shell GO111MODULE=on go mod edit -print | sed -n -e 's|.*\(yunion.io/x/[a-z].*\) v.*|\1|p' | grep -v '/cloudmux$$'))
|
||||
go mod tidy
|
||||
go mod vendor -v
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "yunion.io/x/cloudmux/pkg/multicloud/loader"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/compute/service"
|
||||
"yunion.io/x/onecloud/pkg/util/atexit"
|
||||
)
|
||||
|
||||
@@ -83,7 +83,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221116084146-820fb31ddff8
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1162,8 +1162,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd h1:zcUjAzwGTPaAxQUrE/uUPY3u3baqPMJMcAW3lnyzHaE=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221116084146-820fb31ddff8 h1:n1yIfyx/jK3BiWIYdq9hZBR/pokTyiourwSTdXFWbVk=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221116084146-820fb31ddff8/go.mod h1:drc/WDD65r6wI1tSejk19xcl9QwmzZlgJGXN7a9o2KQ=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/multicloud/esxi"
|
||||
_ "yunion.io/x/cloudmux/pkg/multicloud/loader"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
_ "yunion.io/x/sqlchemy/backends"
|
||||
|
||||
Vendored
+1
-1
@@ -1428,7 +1428,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221112124251-e086cfa622dd
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20221116084146-820fb31ddff8
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+1
@@ -23,6 +23,7 @@ type ModelartsPoolCreateOption struct {
|
||||
InstanceType string
|
||||
NodeCount int
|
||||
NetworkId string
|
||||
Cidr string
|
||||
|
||||
WorkType string
|
||||
}
|
||||
|
||||
+14
@@ -146,6 +146,12 @@ func (self *SHuaweiClient) modelartsPoolNetworkList(params map[string]interface{
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolNetworkDetail(networkName string) (jsonutils.JSONObject, error) {
|
||||
endpoint := cli.resetEndpoint(cli.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v1/%s/networks/%s", endpoint, cli.projectId, networkName)
|
||||
return cli.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolNetworkCreate(params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
endpoint := self.resetEndpoint(self.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v1/%s/networks", endpoint, self.projectId)
|
||||
@@ -158,6 +164,14 @@ func (self *SHuaweiClient) modelartsPoolById(poolName string) (jsonutils.JSONObj
|
||||
return self.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolListWithStatus(resource, status string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
endpoint := cli.resetEndpoint(cli.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v2/%s/pools", endpoint, cli.projectId)
|
||||
value := url.Values{}
|
||||
value.Add("status", status)
|
||||
return cli.request(httputils.GET, uri, value, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolList(params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
endpoint := self.resetEndpoint(self.endpoints.Modelarts, "modelarts")
|
||||
uri := fmt.Sprintf("https://%s/v2/%s/pools", endpoint, self.projectId)
|
||||
|
||||
+46
-6
@@ -94,6 +94,16 @@ type SModelartsPoolStatus struct {
|
||||
|
||||
type SModelartsPoolNetwork struct {
|
||||
Metadata SModelartsPoolNetworkMetadata `json:"metadata"`
|
||||
Spec SModelartsNetworkSpce `json:"spec"`
|
||||
Status SModelartsNetworkStatus `json:"status"`
|
||||
}
|
||||
|
||||
type SModelartsNetworkSpce struct {
|
||||
Cidr string `json:"cidr"`
|
||||
}
|
||||
|
||||
type SModelartsNetworkStatus struct {
|
||||
Phase string `json:"phase"`
|
||||
}
|
||||
|
||||
type SModelartsPoolNetworkMetadata struct {
|
||||
@@ -128,14 +138,30 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
netRes := make([]SModelartsPoolNetwork, 0)
|
||||
netObj.Unmarshal(&netRes, "items")
|
||||
netId := ""
|
||||
if len(netRes) != 0 {
|
||||
netId = netRes[0].Metadata.Name
|
||||
} else {
|
||||
createNetObj, err := self.client.CreatePoolNetworks()
|
||||
for _, net := range netRes {
|
||||
if net.Spec.Cidr == args.Cidr {
|
||||
netId = net.Metadata.Name
|
||||
}
|
||||
}
|
||||
|
||||
if len(netId) == 0 {
|
||||
createNetObj, err := self.client.CreatePoolNetworks(args.Cidr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.CreatePoolNetworks")
|
||||
}
|
||||
netId, _ = createNetObj.GetString("metadata", "name")
|
||||
for i := 0; i < 10; i++ {
|
||||
netDetailObj, err := self.client.modelartsPoolNetworkDetail(netId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.NetworkDetail")
|
||||
}
|
||||
netStatus, _ := netDetailObj.GetString("status", "phase")
|
||||
if netStatus == "Creating" {
|
||||
time.Sleep(10 * time.Second)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scopeArr := strings.Split(args.WorkType, ",")
|
||||
@@ -248,7 +274,7 @@ func (self *SHuaweiClient) GetPoolNetworks(poolName string) (jsonutils.JSONObjec
|
||||
return self.modelartsPoolNetworkList(nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) CreatePoolNetworks() (jsonutils.JSONObject, error) {
|
||||
func (self *SHuaweiClient) CreatePoolNetworks(cidr string) (jsonutils.JSONObject, error) {
|
||||
params := map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Network",
|
||||
@@ -259,7 +285,7 @@ func (self *SHuaweiClient) CreatePoolNetworks() (jsonutils.JSONObject, error) {
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"cidr": "192.168.20.0/24",
|
||||
"cidr": cidr,
|
||||
},
|
||||
}
|
||||
return self.modelartsPoolNetworkCreate(params)
|
||||
@@ -344,6 +370,20 @@ func (self *SModelartsPool) SetAutoRenew(bc billing.SBillingCycle) error {
|
||||
}
|
||||
|
||||
func (self *SModelartsPool) Refresh() error {
|
||||
pools := make([]SModelartsPool, 0)
|
||||
resObj, err := self.region.client.modelartsPoolListWithStatus("pools", "failed", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "modelartsPoolListWithStatus")
|
||||
}
|
||||
err = resObj.Unmarshal(&pools, "items")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "resObj unmarshal")
|
||||
}
|
||||
for _, pool := range pools {
|
||||
if pool.GetId() == self.GetId() {
|
||||
self.Status.Phase = "CreationFailed"
|
||||
}
|
||||
}
|
||||
self.Status.Resource = SNodeStatus{}
|
||||
pool, err := self.region.client.modelartsPoolById(self.GetId())
|
||||
if err != nil {
|
||||
|
||||
+12
@@ -241,6 +241,11 @@ func (self *SHuaweiClient) modelartsPoolNetworkCreate(params map[string]interfac
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolNetworkDetail(networkName string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v1/%s/networks/%s", cli.clientRegion, cli.projectId, networkName)
|
||||
return cli.request(httputils.GET, uri, url.Values{}, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolById(poolName string) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/pools/%s", self.clientRegion, self.projectId, poolName)
|
||||
return self.request(httputils.GET, uri, url.Values{}, nil)
|
||||
@@ -251,6 +256,13 @@ func (self *SHuaweiClient) modelartsPoolList(resource string, params map[string]
|
||||
return self.request(httputils.GET, uri, url.Values{}, params)
|
||||
}
|
||||
|
||||
func (cli *SHuaweiClient) modelartsPoolListWithStatus(resource, status string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/%s", cli.clientRegion, cli.projectId, resource)
|
||||
value := url.Values{}
|
||||
value.Add("status", status)
|
||||
return cli.request(httputils.GET, uri, value, params)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) modelartsPoolCreate(resource string, params map[string]interface{}) (jsonutils.JSONObject, error) {
|
||||
uri := fmt.Sprintf("https://modelarts.%s.myhuaweicloud.com/v2/%s/%s", self.clientRegion, self.projectId, resource)
|
||||
return self.request(httputils.POST, uri, url.Values{}, params)
|
||||
|
||||
+46
-6
@@ -93,6 +93,8 @@ type SModelartsPoolStatus struct {
|
||||
|
||||
type SModelartsPoolNetwork struct {
|
||||
Metadata SModelartsPoolNetworkMetadata `json:"metadata"`
|
||||
Spec SModelartsNetworkSpce `json:"spec"`
|
||||
Status SModelartsNetworkStatus `json:"status"`
|
||||
}
|
||||
|
||||
type SModelartsPoolNetworkMetadata struct {
|
||||
@@ -100,6 +102,14 @@ type SModelartsPoolNetworkMetadata struct {
|
||||
CreationTimestamp string `json:"creationTimestamp"`
|
||||
}
|
||||
|
||||
type SModelartsNetworkSpce struct {
|
||||
Cidr string `json:"cidr"`
|
||||
}
|
||||
|
||||
type SModelartsNetworkStatus struct {
|
||||
Phase string `json:"phase"`
|
||||
}
|
||||
|
||||
func (self *SRegion) GetIModelartsPools() ([]cloudprovider.ICloudModelartsPool, error) {
|
||||
pools := make([]SModelartsPool, 0)
|
||||
resObj, err := self.client.modelartsPoolList("pools", nil)
|
||||
@@ -127,14 +137,30 @@ func (self *SRegion) CreateIModelartsPool(args *cloudprovider.ModelartsPoolCreat
|
||||
netRes := make([]SModelartsPoolNetwork, 0)
|
||||
netObj.Unmarshal(&netRes, "items")
|
||||
netId := ""
|
||||
if len(netRes) != 0 {
|
||||
netId = netRes[0].Metadata.Name
|
||||
} else {
|
||||
createNetObj, err := self.client.CreatePoolNetworks()
|
||||
for _, net := range netRes {
|
||||
if net.Spec.Cidr == args.Cidr {
|
||||
netId = net.Metadata.Name
|
||||
}
|
||||
}
|
||||
|
||||
if len(netId) == 0 {
|
||||
createNetObj, err := self.client.CreatePoolNetworks(args.Cidr)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.CreatePoolNetworks")
|
||||
}
|
||||
netId, _ = createNetObj.GetString("metadata", "name")
|
||||
for i := 0; i < 10; i++ {
|
||||
netDetailObj, err := self.client.modelartsPoolNetworkDetail(netId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "SHuaweiClient.NetworkDetail")
|
||||
}
|
||||
netStatus, _ := netDetailObj.GetString("status", "phase")
|
||||
if netStatus == "Creating" {
|
||||
time.Sleep(10 * time.Second)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scopeArr := strings.Split(args.WorkType, ",")
|
||||
@@ -247,7 +273,7 @@ func (self *SHuaweiClient) GetPoolNetworks(poolName string) (jsonutils.JSONObjec
|
||||
return self.modelartsPoolNetworkList(poolName, nil)
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) CreatePoolNetworks() (jsonutils.JSONObject, error) {
|
||||
func (self *SHuaweiClient) CreatePoolNetworks(cidr string) (jsonutils.JSONObject, error) {
|
||||
params := map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Network",
|
||||
@@ -258,7 +284,7 @@ func (self *SHuaweiClient) CreatePoolNetworks() (jsonutils.JSONObject, error) {
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"cidr": "192.168.20.0/24",
|
||||
"cidr": cidr,
|
||||
},
|
||||
}
|
||||
return self.modelartsPoolNetworkCreate(params)
|
||||
@@ -343,6 +369,20 @@ func (self *SModelartsPool) SetAutoRenew(bc billing.SBillingCycle) error {
|
||||
}
|
||||
|
||||
func (self *SModelartsPool) Refresh() error {
|
||||
pools := make([]SModelartsPool, 0)
|
||||
resObj, err := self.region.client.modelartsPoolListWithStatus("pools", "failed", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "modelartsPoolListWithStatus")
|
||||
}
|
||||
err = resObj.Unmarshal(&pools, "items")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "resObj unmarshal")
|
||||
}
|
||||
for _, pool := range pools {
|
||||
if pool.GetId() == self.GetId() {
|
||||
self.Status.Phase = "CreationFailed"
|
||||
}
|
||||
}
|
||||
self.Status.Resource = SNodeStatus{}
|
||||
pool, err := self.region.client.modelartsPoolById(self.GetId())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user