mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
Hotfix/qx cloudprovider info (#368)
* 通用返回cloudprovider info信息 * 通用返回cloudprovider info信息
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SCloudregionResourceBase struct {
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
}
|
||||
|
||||
func (self *SCloudregionResourceBase) GetRegion() *SCloudregion {
|
||||
region, err := CloudregionManager.FetchById(self.CloudregionId)
|
||||
if err != nil {
|
||||
log.Errorf("failed to find cloudregion %s error: %v", self.CloudregionId, err)
|
||||
return nil
|
||||
}
|
||||
return region.(*SCloudregion)
|
||||
}
|
||||
|
||||
func (self *SCloudregionResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
region := self.GetRegion()
|
||||
if region == nil {
|
||||
return nil
|
||||
}
|
||||
info := map[string]string{
|
||||
"region": region.GetName(),
|
||||
"region_id": region.GetId(),
|
||||
}
|
||||
if len(region.ExternalId) > 0 {
|
||||
info["region_ext_id"] = fetchExternalId(region.ExternalId)
|
||||
}
|
||||
return jsonutils.Marshal(info).(*jsonutils.JSONDict)
|
||||
}
|
||||
@@ -120,9 +120,9 @@ func init() {
|
||||
type SLoadbalancerAcl struct {
|
||||
db.SSharableVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"required"`
|
||||
AclEntries *SLoadbalancerAclEntries `list:"user" update:"user" create:"required"`
|
||||
AclEntries *SLoadbalancerAclEntries `list:"user" update:"user" create:"required"`
|
||||
}
|
||||
|
||||
func loadbalancerAclsValidateAclEntries(data *jsonutils.JSONDict, update bool) (*jsonutils.JSONDict, error) {
|
||||
@@ -222,6 +222,24 @@ func (lbacl *SLoadbalancerAcl) GetIRegion() (cloudprovider.ICloudRegion, error)
|
||||
return provider.GetIRegionById(region.ExternalId)
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := lbacl.SSharableVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
providerInfo := lbacl.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if providerInfo != nil {
|
||||
extra.Update(providerInfo)
|
||||
}
|
||||
regionInfo := lbacl.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra := lbacl.GetCustomizeColumns(ctx, userCred, query)
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (lbacl *SLoadbalancerAcl) AllowPerformPatch(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) bool {
|
||||
return lbacl.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, lbacl, "patch")
|
||||
}
|
||||
|
||||
@@ -55,8 +55,8 @@ func init() {
|
||||
type SLoadbalancerBackendGroup struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
Type string `width:"36" charset:"ascii" nullable:"false" list:"user" default:"normal" create:"optional"`
|
||||
LoadbalancerId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
}
|
||||
@@ -262,6 +262,10 @@ func (lbbg *SLoadbalancerBackendGroup) GetCustomizeColumns(ctx context.Context,
|
||||
}
|
||||
extra.Set("loadbalancer", jsonutils.NewString(lb.GetName()))
|
||||
}
|
||||
regionInfo := lbbg.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,8 @@ func init() {
|
||||
type SLoadbalancerBackend struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
BackendGroupId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
BackendId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
BackendType string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
@@ -228,6 +228,24 @@ func (lbb *SLoadbalancerBackend) PostCreate(ctx context.Context, userCred mcclie
|
||||
}
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := lbb.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
providerInfo := lbb.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if providerInfo != nil {
|
||||
extra.Update(providerInfo)
|
||||
}
|
||||
regionInfo := lbb.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra := lbb.GetCustomizeColumns(ctx, userCred, query)
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (lbb *SLoadbalancerBackend) StartLoadBalancerBackendCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerBackendCreateTask", lbb, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -64,6 +64,7 @@ func init() {
|
||||
type SLoadbalancerCertificate struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
Certificate string `create:"required" list:"user" update:"user"`
|
||||
PrivateKey string `create:"required" list:"admin" update:"user"`
|
||||
@@ -77,8 +78,6 @@ type SLoadbalancerCertificate struct {
|
||||
NotAfter time.Time `create:"optional" list:"user" update:"user"`
|
||||
CommonName string `create:"optional" list:"user" update:"user"`
|
||||
SubjectAlternativeNames string `create:"optional" list:"user" update:"user"`
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
}
|
||||
|
||||
func (man *SLoadbalancerCertificateManager) pendingDeleteSubs(ctx context.Context, userCred mcclient.TokenCredential, q *sqlchemy.SQuery) {
|
||||
@@ -227,6 +226,24 @@ func (lbcert *SLoadbalancerCertificate) PostCreate(ctx context.Context, userCred
|
||||
}
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := lbcert.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
providerInfo := lbcert.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if providerInfo != nil {
|
||||
extra.Update(providerInfo)
|
||||
}
|
||||
regionInfo := lbcert.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra := lbcert.GetCustomizeColumns(ctx, userCred, query)
|
||||
return extra, nil
|
||||
}
|
||||
|
||||
func (lbcert *SLoadbalancerCertificate) StartLoadBalancerCertificateCreateTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
|
||||
task, err := taskman.TaskManager.NewTask(ctx, "LoadbalancerCertificateCreateTask", lbcert, userCred, nil, parentTaskId, "", nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -54,8 +54,8 @@ func init() {
|
||||
type SLoadbalancerListenerRule struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
ListenerId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
BackendGroupId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional" update:"user"`
|
||||
|
||||
@@ -249,6 +249,11 @@ func (lbr *SLoadbalancerListenerRule) GetCustomizeColumns(ctx context.Context, u
|
||||
return extra
|
||||
}
|
||||
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
|
||||
|
||||
regionInfo := lbr.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
|
||||
@@ -104,8 +104,8 @@ type SLoadbalancerHTTPSListener struct {
|
||||
type SLoadbalancerListener struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
LoadbalancerId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
ListenerType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"required"`
|
||||
ListenerPort int `nullable:"false" list:"user" create:"required"`
|
||||
@@ -500,16 +500,19 @@ func (lblis *SLoadbalancerListener) GetCustomizeColumns(ctx context.Context, use
|
||||
extra.Set("loadbalancer", jsonutils.NewString(lb.GetName()))
|
||||
}
|
||||
{
|
||||
if lblis.BackendGroupId == "" {
|
||||
return extra
|
||||
if lblis.BackendGroupId != "" {
|
||||
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lblis.BackendGroupId)
|
||||
if err != nil {
|
||||
log.Errorf("loadbalancer listener %s(%s): fetch backend group (%s) error: %s",
|
||||
lblis.Name, lblis.Id, lblis.BackendGroupId, err)
|
||||
return extra
|
||||
}
|
||||
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
|
||||
}
|
||||
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lblis.BackendGroupId)
|
||||
if err != nil {
|
||||
log.Errorf("loadbalancer listener %s(%s): fetch backend group (%s) error: %s",
|
||||
lblis.Name, lblis.Id, lblis.BackendGroupId, err)
|
||||
return extra
|
||||
}
|
||||
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
|
||||
}
|
||||
regionInfo := lblis.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ func init() {
|
||||
type SLoadbalancer struct {
|
||||
db.SVirtualResourceBase
|
||||
SManagedResourceBase
|
||||
SCloudregionResourceBase
|
||||
SZoneResourceBase
|
||||
|
||||
Address string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
AddressType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
NetworkType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
VpcId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
ZoneId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
CloudregionId string `width:"36" charset:"ascii" nullable:"false" list:"admin" default:"default" create:"optional"`
|
||||
Address string `width:"16" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
AddressType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
NetworkType string `width:"16" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
NetworkId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
VpcId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
|
||||
ChargeType string `list:"user" get:"user" create:"optional"`
|
||||
LoadbalancerSpec string `list:"user" get:"user" create:"optional"`
|
||||
@@ -407,16 +407,30 @@ func (lb *SLoadbalancer) ValidateUpdateData(ctx context.Context, userCred mcclie
|
||||
|
||||
func (lb *SLoadbalancer) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := lb.SVirtualResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if lb.BackendGroupId == "" {
|
||||
return extra
|
||||
providerInfo := lb.SManagedResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if providerInfo != nil {
|
||||
extra.Update(providerInfo)
|
||||
}
|
||||
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lb.BackendGroupId)
|
||||
if err != nil {
|
||||
log.Errorf("loadbalancer %s(%s): fetch backend group (%s) error: %s",
|
||||
lb.Name, lb.Id, lb.BackendGroupId, err)
|
||||
return extra
|
||||
|
||||
zoneInfo := lb.SZoneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if zoneInfo != nil {
|
||||
extra.Update(zoneInfo)
|
||||
} else {
|
||||
regionInfo := lb.SCloudregionResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
if regionInfo != nil {
|
||||
extra.Update(regionInfo)
|
||||
}
|
||||
}
|
||||
|
||||
if lb.BackendGroupId != "" {
|
||||
lbbg, err := LoadbalancerBackendGroupManager.FetchById(lb.BackendGroupId)
|
||||
if err != nil {
|
||||
log.Errorf("loadbalancer %s(%s): fetch backend group (%s) error: %s",
|
||||
lb.Name, lb.Id, lb.BackendGroupId, err)
|
||||
return extra
|
||||
}
|
||||
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
|
||||
}
|
||||
extra.Set("backend_group", jsonutils.NewString(lbbg.GetName()))
|
||||
return extra
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -26,6 +27,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SManagedResourceBase struct {
|
||||
@@ -47,6 +49,31 @@ func (self *SManagedResourceBase) GetCloudaccount() *SCloudaccount {
|
||||
return cp.GetCloudaccount()
|
||||
}
|
||||
|
||||
func (self *SManagedResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
provider := self.GetCloudprovider()
|
||||
if provider == nil {
|
||||
return nil
|
||||
}
|
||||
info := map[string]string{
|
||||
"manager": provider.GetName(),
|
||||
"manager_id": provider.GetId(),
|
||||
"provider": provider.Provider,
|
||||
}
|
||||
if len(provider.ProjectId) > 0 {
|
||||
info["manager_project_id"] = provider.ProjectId
|
||||
tc, err := db.TenantCacheManager.FetchTenantById(appctx.Background, provider.ProjectId)
|
||||
if err == nil {
|
||||
info["manager_project"] = tc.GetName()
|
||||
}
|
||||
}
|
||||
|
||||
account := provider.GetCloudaccount()
|
||||
info["account"] = account.GetName()
|
||||
info["account_id"] = account.GetId()
|
||||
|
||||
return jsonutils.Marshal(info).(*jsonutils.JSONDict)
|
||||
}
|
||||
|
||||
func (self *SManagedResourceBase) GetProviderFactory() (cloudprovider.ICloudProviderFactory, error) {
|
||||
provider := self.GetCloudprovider()
|
||||
if provider == nil {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
type SZoneResourceBase struct {
|
||||
ZoneId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional"`
|
||||
}
|
||||
|
||||
func (self *SZoneResourceBase) GetZone() *SZone {
|
||||
return ZoneManager.FetchZoneById(self.ZoneId)
|
||||
}
|
||||
|
||||
func (self *SZoneResourceBase) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
zone := self.GetZone()
|
||||
if zone == nil {
|
||||
return nil
|
||||
}
|
||||
info := map[string]string{
|
||||
"zone": zone.GetName(),
|
||||
"zone_id": zone.GetId(),
|
||||
}
|
||||
if len(zone.ExternalId) > 0 {
|
||||
info["zone_ext_id"] = fetchExternalId(zone.ExternalId)
|
||||
}
|
||||
if region := zone.GetRegion(); region != nil {
|
||||
info["region"] = region.GetName()
|
||||
info["region_id"] = region.GetId()
|
||||
if len(region.ExternalId) > 0 {
|
||||
info["region_ext_id"] = fetchExternalId(region.ExternalId)
|
||||
}
|
||||
}
|
||||
return jsonutils.Marshal(info).(*jsonutils.JSONDict)
|
||||
}
|
||||
Reference in New Issue
Block a user