mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #1156 in YUNIONIO/onecloud from ~QUXUAN/onecloud:feature/qx-external-project to release/2.7.0
* commit '0ce6b70998e5646b7f1a1f0f610b003132fab980': 更改ProjectSource -> ProjectSrc 同步openstack项目 同步azure项目 腾讯云加入debug信息 external_project去掉cloudregion属性 补充其他资源项目同步 映射表默认指向provider的project init
This commit is contained in:
@@ -20,7 +20,6 @@ func init() {
|
||||
params, err = args.BaseListOptions.Params()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
}
|
||||
result, err := modules.Cloudproviders.List(s, params)
|
||||
@@ -139,12 +138,13 @@ func init() {
|
||||
})
|
||||
|
||||
type CloudproviderSyncOptions struct {
|
||||
ID string `help:"ID or Name of cloud provider"`
|
||||
Force bool `help:"Force sync no matter what"`
|
||||
FullSync bool `help:"Synchronize everything"`
|
||||
Region []string `help:"region to sync"`
|
||||
Zone []string `help:"region to sync"`
|
||||
Host []string `help:"region to sync"`
|
||||
ID string `help:"ID or Name of cloud provider"`
|
||||
Force bool `help:"Force sync no matter what"`
|
||||
FullSync bool `help:"Synchronize everything"`
|
||||
ProjectSync bool `help:"Auto sync project info"`
|
||||
Region []string `help:"region to sync"`
|
||||
Zone []string `help:"region to sync"`
|
||||
Host []string `help:"region to sync"`
|
||||
}
|
||||
R(&CloudproviderSyncOptions{}, "cloud-provider-sync", "Sync of a cloud provider account", func(s *mcclient.ClientSession, args *CloudproviderSyncOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -154,6 +154,9 @@ func init() {
|
||||
if args.FullSync {
|
||||
params.Add(jsonutils.JSONTrue, "full_sync")
|
||||
}
|
||||
if args.ProjectSync {
|
||||
params.Add(jsonutils.JSONTrue, "project_sync")
|
||||
}
|
||||
if len(args.Region) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.Region), "region")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ExternalProjectListOptions struct {
|
||||
options.BaseListOptions
|
||||
}
|
||||
R(&ExternalProjectListOptions{}, "external-project-list", "List public cloud projects", func(s *mcclient.ClientSession, opts *ExternalProjectListOptions) error {
|
||||
params, err := options.ListStructToParams(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := modules.ExternalProjects.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(result, modules.Disks.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
type ExternalProjectUpdateOptions struct {
|
||||
ID string `help:"ExternalProject ID or Name"`
|
||||
PROJECT string `help:"Local project ID or Name"`
|
||||
}
|
||||
|
||||
R(&ExternalProjectUpdateOptions{}, "external-project-update", "Update external project point to local project", func(s *mcclient.ClientSession, args *ExternalProjectUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.PROJECT), "project")
|
||||
result, err := modules.ExternalProjects.Update(s, args.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
)
|
||||
|
||||
type BaseOptions struct {
|
||||
Debug bool `help:"debug mode"`
|
||||
Help bool `help:"Show help"`
|
||||
AppID string `help:"AppID" default:"$QCLOUD_APPID"`
|
||||
SecretID string `help:"Secret" default:"$QCLOUD_SECRET_ID"`
|
||||
@@ -75,7 +76,7 @@ func newClient(options *BaseOptions) (*qcloud.SRegion, error) {
|
||||
account = fmt.Sprintf("%s/%s", account, options.AppID)
|
||||
}
|
||||
|
||||
if cli, err := qcloud.NewQcloudClient("", "", account, options.SecretKey); err != nil {
|
||||
if cli, err := qcloud.NewQcloudClient("", "", account, options.SecretKey, options.Debug); err != nil {
|
||||
return nil, err
|
||||
} else if region := cli.GetRegion(options.RegionId); region == nil {
|
||||
return nil, fmt.Errorf("No such region %s", options.RegionId)
|
||||
|
||||
@@ -127,6 +127,8 @@ const (
|
||||
ACT_SYNCING_HOST = "syncing_host"
|
||||
ACT_SYNC_HOST_COMPLETE = "sync_host_end"
|
||||
|
||||
ACT_SYNC_PROJECT_COMPLETE = "sync_project_end"
|
||||
|
||||
ACT_SYNC_LB_START = "sync_lb_start"
|
||||
ACT_SYNCING_LB = "syncing_lb"
|
||||
ACT_SYNC_LB_COMPLETE = "sync_lb_end"
|
||||
@@ -138,9 +140,10 @@ const (
|
||||
ACT_UNCACHE_IMAGE_FAIL = "uncache_image_fail"
|
||||
ACT_UNCACHED_IMAGE = "uncached_image"
|
||||
|
||||
ACT_SYNC_CLOUD_DISK = "sync_cloud_disk"
|
||||
ACT_SYNC_CLOUD_SERVER = "sync_cloud_server"
|
||||
ACT_SYNC_CLOUD_EIP = "sync_cloud_eip"
|
||||
ACT_SYNC_CLOUD_DISK = "sync_cloud_disk"
|
||||
ACT_SYNC_CLOUD_SERVER = "sync_cloud_server"
|
||||
ACT_SYNC_CLOUD_EIP = "sync_cloud_eip"
|
||||
ACT_SYNC_CLOUD_PROJECT = "sync_cloud_project"
|
||||
|
||||
ACT_PENDING_DELETE = "pending_delete"
|
||||
ACT_CANCEL_DELETE = "cancel_delete"
|
||||
|
||||
@@ -17,6 +17,11 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
)
|
||||
|
||||
const (
|
||||
PROJECT_SOURCE_LOCAL = "local"
|
||||
PROJECT_SOURCE_CLOUD = "cloud"
|
||||
)
|
||||
|
||||
type SVirtualResourceBaseManager struct {
|
||||
SStatusStandaloneResourceBaseManager
|
||||
}
|
||||
@@ -29,7 +34,8 @@ func NewVirtualResourceBaseManager(dt interface{}, tableName string, keyword str
|
||||
type SVirtualResourceBase struct {
|
||||
SStatusStandaloneResourceBase
|
||||
|
||||
ProjectId string `name:"tenant_id" width:"128" charset:"ascii" nullable:"false" index:"true" list:"user"`
|
||||
ProjectId string `name:"tenant_id" width:"128" charset:"ascii" nullable:"false" index:"true" list:"user"`
|
||||
ProjectSrc string `width:"10" charset:"ascii" nullable:"false" list:"user" default:"local"`
|
||||
|
||||
IsSystem bool `nullable:"true" default:"false" list:"admin" create:"optional"`
|
||||
|
||||
@@ -227,6 +233,7 @@ func (model *SVirtualResourceBase) PerformChangeOwner(ctx context.Context, userC
|
||||
}
|
||||
_, err := model.GetModelManager().TableSpec().Update(model, func() error {
|
||||
model.ProjectId = tobj.GetId()
|
||||
model.ProjectSrc = PROJECT_SOURCE_LOCAL
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -43,6 +43,7 @@ type ICloudProvider interface {
|
||||
GetVersion() string
|
||||
|
||||
GetIRegions() []ICloudRegion
|
||||
GetIProjects() ([]ICloudProject, error)
|
||||
GetIRegionById(id string) (ICloudRegion, error)
|
||||
|
||||
GetOnPremiseIRegion() (ICloudRegion, error)
|
||||
|
||||
@@ -25,6 +25,10 @@ type ICloudResource interface {
|
||||
GetMetadata() *jsonutils.JSONDict
|
||||
}
|
||||
|
||||
type IVirtualResource interface {
|
||||
GetProjectId() string
|
||||
}
|
||||
|
||||
type IBillingResource interface {
|
||||
GetBillingType() string
|
||||
GetExpiredAt() time.Time
|
||||
@@ -190,6 +194,7 @@ type ICloudHost interface {
|
||||
type ICloudVM interface {
|
||||
ICloudResource
|
||||
IBillingResource
|
||||
IVirtualResource
|
||||
|
||||
GetCreateTime() time.Time
|
||||
GetIHost() ICloudHost
|
||||
@@ -254,6 +259,7 @@ type ICloudNic interface {
|
||||
type ICloudEIP interface {
|
||||
ICloudResource
|
||||
IBillingResource
|
||||
IVirtualResource
|
||||
|
||||
GetIpAddr() string
|
||||
GetMode() string
|
||||
@@ -276,6 +282,7 @@ type ICloudEIP interface {
|
||||
|
||||
type ICloudSecurityGroup interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetDescription() string
|
||||
GetRules() ([]secrules.SecurityRule, error)
|
||||
@@ -303,6 +310,7 @@ type ICloudRoute interface {
|
||||
type ICloudDisk interface {
|
||||
ICloudResource
|
||||
IBillingResource
|
||||
IVirtualResource
|
||||
|
||||
GetIStorage() (ICloudStorage, error)
|
||||
|
||||
@@ -335,6 +343,8 @@ type ICloudDisk interface {
|
||||
|
||||
type ICloudSnapshot interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetSize() int32
|
||||
GetDiskId() string
|
||||
GetDiskType() string
|
||||
@@ -373,6 +383,7 @@ type ICloudWire interface {
|
||||
|
||||
type ICloudNetwork interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetIWire() ICloudWire
|
||||
// GetStatus() string
|
||||
@@ -401,6 +412,7 @@ type ICloudHostNetInterface interface {
|
||||
|
||||
type ICloudLoadbalancer interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetAddress() string
|
||||
GetAddressType() string
|
||||
@@ -428,6 +440,7 @@ type ICloudLoadbalancer interface {
|
||||
|
||||
type ICloudLoadbalancerListener interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetListenerType() string
|
||||
GetListenerPort() int
|
||||
@@ -487,6 +500,7 @@ type ICloudLoadbalancerListenerRule interface {
|
||||
|
||||
type ICloudLoadbalancerBackendGroup interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
IsDefault() bool
|
||||
GetType() string
|
||||
@@ -500,6 +514,7 @@ type ICloudLoadbalancerBackendGroup interface {
|
||||
|
||||
type ICloudLoadbalancerBackend interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetWeight() int
|
||||
GetPort() int
|
||||
@@ -510,6 +525,7 @@ type ICloudLoadbalancerBackend interface {
|
||||
|
||||
type ICloudLoadbalancerCertificate interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
Sync(name, privateKey, publickKey string) error
|
||||
Delete() error
|
||||
@@ -522,6 +538,7 @@ type ICloudLoadbalancerCertificate interface {
|
||||
|
||||
type ICloudLoadbalancerAcl interface {
|
||||
ICloudResource
|
||||
IVirtualResource
|
||||
|
||||
GetAclEntries() []SLoadbalancerAccessControlListEntry
|
||||
Sync(acl *SLoadbalancerAccessControlList) error
|
||||
@@ -562,3 +579,7 @@ type ICloudSku interface {
|
||||
GetGpuCount() int
|
||||
GetGpuMaxCount() int
|
||||
}
|
||||
|
||||
type ICloudProject interface {
|
||||
ICloudResource
|
||||
}
|
||||
|
||||
@@ -1004,6 +1004,7 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke
|
||||
if provider.GetFactory().IsSupportPrepaidResources() && len(guests) == 1 && guests[0].IsPrepaidRecycle() {
|
||||
recycle = true
|
||||
}
|
||||
storage := self.GetStorage()
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
extDisk.Refresh()
|
||||
// self.Name = extDisk.GetName()
|
||||
@@ -1030,8 +1031,15 @@ func (self *SDisk) syncWithCloudDisk(ctx context.Context, userCred mcclient.Toke
|
||||
}
|
||||
|
||||
// self.ProjectId = userCred.GetProjectId()
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extDisk.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, storage.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -1064,10 +1072,19 @@ func (manager *SDiskManager) newFromCloudDisk(ctx context.Context, userCred mccl
|
||||
disk.Status = extDisk.GetStatus()
|
||||
disk.ExternalId = extDisk.GetGlobalId()
|
||||
disk.StorageId = storage.Id
|
||||
disk.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
disk.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
disk.ProjectId = projectId
|
||||
}
|
||||
if extProjectId := extDisk.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, storage.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
disk.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
disk.DiskFormat = extDisk.GetDiskFormat()
|
||||
disk.DiskSize = extDisk.GetDiskSizeMB()
|
||||
disk.AutoDelete = extDisk.GetIsAutoDelete()
|
||||
|
||||
@@ -302,8 +302,15 @@ func (self *SElasticip) SyncWithCloudEip(userCred mcclient.TokenCredential, prov
|
||||
// self.ManagerId = ext.GetManagerId()
|
||||
self.IsEmulated = ext.IsEmulated()
|
||||
self.ProjectId = userCred.GetProjectId()
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := ext.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, self.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
self.ChargeType = ext.GetInternetChargeType()
|
||||
|
||||
@@ -335,11 +342,21 @@ func (manager *SElasticipManager) newFromCloudEip(ctx context.Context, userCred
|
||||
eip.CloudregionId = region.Id
|
||||
eip.ChargeType = extEip.GetInternetChargeType()
|
||||
|
||||
eip.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
eip.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
eip.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extEip.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, eip.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
eip.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
err := manager.TableSpec().Insert(&eip)
|
||||
if err != nil {
|
||||
log.Errorf("newFromCloudEip fail %s", err)
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"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"
|
||||
"yunion.io/x/pkg/util/compare"
|
||||
)
|
||||
|
||||
type SExternalProjectManager struct {
|
||||
db.SStandaloneResourceBaseManager
|
||||
}
|
||||
|
||||
var ExternalProjectManager *SExternalProjectManager
|
||||
|
||||
func init() {
|
||||
ExternalProjectManager = &SExternalProjectManager{
|
||||
SStandaloneResourceBaseManager: db.NewStandaloneResourceBaseManager(
|
||||
SExternalProject{},
|
||||
"externalprojects_tbl",
|
||||
"externalproject",
|
||||
"externalprojects",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type SExternalProject struct {
|
||||
db.SStandaloneResourceBase
|
||||
SManagedResourceBase
|
||||
|
||||
ProjectId string `name:"tenant_id" width:"128" charset:"ascii" nullable:"true" list:"admin" update:"admin"`
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowList(userCred, manager)
|
||||
}
|
||||
|
||||
func (self *SExternalProject) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool {
|
||||
return db.IsAdminAllowUpdate(userCred, self)
|
||||
}
|
||||
|
||||
func (self *SExternalProject) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
if project := jsonutils.GetAnyString(data, []string{"project_id", "project", "tenant_id", "tenant"}); len(project) > 0 {
|
||||
_project, err := db.TenantCacheManager.FetchByIdOrName(userCred, project)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, httperrors.NewTenantNotFoundError("tenant %s not find", project)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
data.Set("tenant_id", jsonutils.NewString(_project.GetId()))
|
||||
}
|
||||
return self.SStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) getProjectsByProvider(provider *SCloudprovider) ([]SExternalProject, error) {
|
||||
projects := []SExternalProject{}
|
||||
q := manager.Query()
|
||||
if provider != nil {
|
||||
q = q.Equals("manager_id", provider.Id)
|
||||
}
|
||||
err := db.FetchModelObjects(manager, q, &projects)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
func (self *SExternalProject) getMoreDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
tenant, err := db.TenantCacheManager.FetchTenantById(ctx, self.ProjectId)
|
||||
if err == nil {
|
||||
extra.Add(jsonutils.NewString(tenant.GetName()), "tenant")
|
||||
}
|
||||
return extra
|
||||
}
|
||||
|
||||
func (self *SExternalProject) GetCustomizeColumns(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) *jsonutils.JSONDict {
|
||||
extra := self.SStandaloneResourceBase.GetCustomizeColumns(ctx, userCred, query)
|
||||
return self.getMoreDetails(ctx, userCred, query, extra)
|
||||
}
|
||||
|
||||
func (self *SExternalProject) GetExtraDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*jsonutils.JSONDict, error) {
|
||||
extra, err := self.SStandaloneResourceBase.GetExtraDetails(ctx, userCred, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.getMoreDetails(ctx, userCred, query, extra), nil
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) GetProject(externalId string, providerId string) (*SExternalProject, error) {
|
||||
project := &SExternalProject{}
|
||||
project.SetModelManager(manager)
|
||||
q := manager.Query().Equals("external_id", externalId).Equals("manager_id", providerId)
|
||||
count := q.Count()
|
||||
if count == 0 {
|
||||
return nil, fmt.Errorf("no external project record %s for provider %s", externalId, providerId)
|
||||
}
|
||||
if count > 1 {
|
||||
return nil, fmt.Errorf("dumplicate external project record %s for provider %s", externalId, providerId)
|
||||
}
|
||||
return project, q.First(project)
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) SyncProjects(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, projects []cloudprovider.ICloudProject) compare.SyncResult {
|
||||
syncResult := compare.SyncResult{}
|
||||
|
||||
dbProjects, err := manager.getProjectsByProvider(provider)
|
||||
if err != nil {
|
||||
syncResult.Error(err)
|
||||
return syncResult
|
||||
}
|
||||
|
||||
removed := make([]SExternalProject, 0)
|
||||
commondb := make([]SExternalProject, 0)
|
||||
commonext := make([]cloudprovider.ICloudProject, 0)
|
||||
added := make([]cloudprovider.ICloudProject, 0)
|
||||
|
||||
err = compare.CompareSets(dbProjects, projects, &removed, &commondb, &commonext, &added)
|
||||
if err != nil {
|
||||
syncResult.Error(err)
|
||||
return syncResult
|
||||
}
|
||||
|
||||
for i := 0; i < len(removed); i++ {
|
||||
err = removed[i].Delete(ctx, userCred)
|
||||
if err != nil {
|
||||
syncResult.DeleteError(err)
|
||||
} else {
|
||||
syncResult.Delete()
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(commondb); i++ {
|
||||
err = commondb[i].SyncWithCloudProject(ctx, userCred, provider, commonext[i])
|
||||
if err != nil {
|
||||
syncResult.UpdateError(err)
|
||||
} else {
|
||||
syncResult.Update()
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(added); i++ {
|
||||
_, err := manager.newFromCloudProject(ctx, userCred, provider, added[i])
|
||||
if err != nil {
|
||||
syncResult.AddError(err)
|
||||
} else {
|
||||
syncResult.Add()
|
||||
}
|
||||
}
|
||||
return syncResult
|
||||
}
|
||||
|
||||
func (self *SExternalProject) SyncWithCloudProject(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, ext cloudprovider.ICloudProject) error {
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
self.Name = ext.GetName()
|
||||
self.IsEmulated = ext.IsEmulated()
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("SyncWithCloudProject fail %s", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (manager *SExternalProjectManager) newFromCloudProject(ctx context.Context, userCred mcclient.TokenCredential, provider *SCloudprovider, extProject cloudprovider.ICloudProject) (*SExternalProject, error) {
|
||||
project := SExternalProject{}
|
||||
project.SetModelManager(manager)
|
||||
|
||||
project.Name = extProject.GetName()
|
||||
project.ExternalId = extProject.GetGlobalId()
|
||||
project.IsEmulated = extProject.IsEmulated()
|
||||
project.ManagerId = provider.Id
|
||||
project.ProjectId = provider.ProjectId
|
||||
|
||||
err := manager.TableSpec().Insert(&project)
|
||||
if err != nil {
|
||||
log.Errorf("newFromCloudProject fail %s", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
db.OpsLog.LogEvent(&project, db.ACT_SYNC_CLOUD_PROJECT, project.GetShortDesc(ctx), userCred)
|
||||
return &project, nil
|
||||
}
|
||||
@@ -1853,8 +1853,15 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
|
||||
self.VmemSize = extVM.GetVmemSizeMB()
|
||||
}
|
||||
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extVM.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, host.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.Hypervisor = extVM.GetHypervisor()
|
||||
@@ -1978,10 +1985,19 @@ func (manager *SGuestManager) newCloudVM(ctx context.Context, userCred mcclient.
|
||||
guest.VmemSize = extVM.GetVmemSizeMB()
|
||||
}
|
||||
|
||||
guest.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
guest.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
guest.ProjectId = projectId
|
||||
}
|
||||
if extProjectId := extVM.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, host.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
guest.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
extraSecgroups := []*SSecurityGroup{}
|
||||
if metaData != nil && metaData.Contains("secgroupIds") {
|
||||
|
||||
@@ -384,11 +384,21 @@ func (man *SLoadbalancerAclManager) newFromCloudLoadbalancerAcl(ctx context.Cont
|
||||
acl.ManagerId = provider.Id
|
||||
acl.CloudregionId = region.Id
|
||||
|
||||
acl.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
acl.ProjectId = userCred.GetProjectId()
|
||||
if len(provider.ProjectId) > 0 {
|
||||
acl.ProjectId = provider.ProjectId
|
||||
}
|
||||
|
||||
if extProjectId := extAcl.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, acl.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
acl.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
acl.AclEntries = &SLoadbalancerAclEntries{}
|
||||
for _, entry := range extAcl.GetAclEntries() {
|
||||
*acl.AclEntries = append(*acl.AclEntries, &SLoadbalancerAclEntry{Cidr: entry.CIDR, Comment: entry.Comment})
|
||||
@@ -403,8 +413,15 @@ func (acl *SLoadbalancerAcl) SyncWithCloudLoadbalancerAcl(ctx context.Context, u
|
||||
for _, entry := range extAcl.GetAclEntries() {
|
||||
*acl.AclEntries = append(*acl.AclEntries, &SLoadbalancerAclEntry{Cidr: entry.CIDR, Comment: entry.Comment})
|
||||
}
|
||||
if projectSync && len(projectId) > 0 {
|
||||
acl.ProjectId = projectId
|
||||
if projectSync && acl.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extAcl.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, acl.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
acl.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -403,8 +403,15 @@ func (lbbg *SLoadbalancerBackendGroup) SyncWithCloudLoadbalancerBackendgroup(ctx
|
||||
_, err := lbbg.GetModelManager().TableSpec().Update(lbbg, func() error {
|
||||
|
||||
lbbg.constructFieldsFromCloudBackendgroup(lb, extLoadbalancerBackendgroup)
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lbbg.ProjectId = projectId
|
||||
if projectSync && lbbg.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extLoadbalancerBackendgroup.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, lb.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbbg.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if extLoadbalancerBackendgroup.IsDefault() {
|
||||
@@ -433,10 +440,21 @@ func (man *SLoadbalancerBackendGroupManager) newFromCloudLoadbalancerBackendgrou
|
||||
lbbg.ManagerId = lb.ManagerId
|
||||
|
||||
lbbg.constructFieldsFromCloudBackendgroup(lb, extLoadbalancerBackendgroup)
|
||||
lbbg.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lbbg.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
lbbg.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extLoadbalancerBackendgroup.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, lb.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbbg.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
err := man.TableSpec().Insert(lbbg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -354,8 +354,15 @@ func (lbb *SLoadbalancerBackend) constructFieldsFromCloudLoadbalancerBackend(ext
|
||||
|
||||
func (lbb *SLoadbalancerBackend) SyncWithCloudLoadbalancerBackend(ctx context.Context, userCred mcclient.TokenCredential, extLoadbalancerBackend cloudprovider.ICloudLoadbalancerBackend, projectId string, projectSync bool) error {
|
||||
_, err := lbb.GetModelManager().TableSpec().Update(lbb, func() error {
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lbb.ProjectId = projectId
|
||||
if projectSync && lbb.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extLoadbalancerBackend.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, lbb.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbb.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return lbb.constructFieldsFromCloudLoadbalancerBackend(extLoadbalancerBackend)
|
||||
})
|
||||
@@ -376,10 +383,21 @@ func (man *SLoadbalancerBackendManager) newFromCloudLoadbalancerBackend(ctx cont
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lbb.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lbb.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
lbb.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extLoadbalancerBackend.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, loadbalancerBackendgroup.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbb.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
return lbb, man.TableSpec().Insert(lbb)
|
||||
}
|
||||
|
||||
|
||||
@@ -370,11 +370,21 @@ func (man *SLoadbalancerCertificateManager) newFromCloudLoadbalancerCertificate(
|
||||
lbcert.Fingerprint = extCertificate.GetFingerprint()
|
||||
lbcert.NotAfter = extCertificate.GetExpireTime()
|
||||
|
||||
lbcert.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lbcert.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
lbcert.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extCertificate.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, lbcert.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbcert.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
return &lbcert, man.TableSpec().Insert(&lbcert)
|
||||
}
|
||||
|
||||
@@ -386,8 +396,15 @@ func (lbcert *SLoadbalancerCertificate) SyncWithCloudLoadbalancerCertificate(ctx
|
||||
lbcert.Fingerprint = extCertificate.GetFingerprint()
|
||||
lbcert.NotAfter = extCertificate.GetExpireTime()
|
||||
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lbcert.ProjectId = projectId
|
||||
if projectSync && lbcert.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extCertificate.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, lbcert.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lbcert.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -368,23 +368,21 @@ func (man *SLoadbalancerListenerRuleManager) newFromCloudLoadbalancerListenerRul
|
||||
|
||||
lbr.ExternalId = extRule.GetGlobalId()
|
||||
lbr.ListenerId = listener.Id
|
||||
lbr.ManagerId = listener.ManagerId
|
||||
|
||||
lbr.constructFieldsFromCloudListenerRule(extRule)
|
||||
lbr.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
lbr.ProjectId = projectId
|
||||
}
|
||||
lbr.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lbr.ProjectId = listener.ProjectId
|
||||
|
||||
return lbr, man.TableSpec().Insert(lbr)
|
||||
}
|
||||
|
||||
func (lbr *SLoadbalancerListenerRule) SyncWithCloudLoadbalancerListenerRule(ctx context.Context, userCred mcclient.TokenCredential, extRule cloudprovider.ICloudLoadbalancerListenerRule, projectId string, projectSync bool) error {
|
||||
listener := lbr.GetLoadbalancerListener()
|
||||
_, err := lbr.GetModelManager().TableSpec().Update(lbr, func() error {
|
||||
lbr.constructFieldsFromCloudListenerRule(extRule)
|
||||
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lbr.ProjectId = projectId
|
||||
}
|
||||
lbr.ManagerId = listener.ManagerId
|
||||
lbr.ProjectId = listener.ProjectId
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -736,6 +736,7 @@ func (man *SLoadbalancerListenerManager) SyncLoadbalancerListeners(ctx context.C
|
||||
}
|
||||
|
||||
func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(lb *SLoadbalancer, extListener cloudprovider.ICloudLoadbalancerListener) {
|
||||
lblis.ManagerId = lb.ManagerId
|
||||
lblis.Name = extListener.GetName()
|
||||
lblis.ListenerType = extListener.GetListenerType()
|
||||
lblis.ListenerPort = extListener.GetListenerPort()
|
||||
@@ -797,8 +798,15 @@ func (lblis *SLoadbalancerListener) constructFieldsFromCloudListener(lb *SLoadba
|
||||
func (lblis *SLoadbalancerListener) SyncWithCloudLoadbalancerListener(ctx context.Context, userCred mcclient.TokenCredential, lb *SLoadbalancer, extListener cloudprovider.ICloudLoadbalancerListener, projectId string, projectSync bool) error {
|
||||
_, err := lblis.GetModelManager().TableSpec().Update(lblis, func() error {
|
||||
lblis.constructFieldsFromCloudListener(lb, extListener)
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lblis.ProjectId = projectId
|
||||
if projectSync && lblis.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extListener.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, lblis.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lblis.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -813,10 +821,21 @@ func (man *SLoadbalancerListenerManager) newFromCloudLoadbalancerListener(ctx co
|
||||
lblis.ExternalId = extListener.GetGlobalId()
|
||||
lblis.constructFieldsFromCloudListener(lb, extListener)
|
||||
|
||||
lblis.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lblis.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
lblis.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extListener.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, lblis.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lblis.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
return lblis, man.TableSpec().Insert(lblis)
|
||||
}
|
||||
|
||||
|
||||
@@ -550,11 +550,21 @@ func (man *SLoadbalancerManager) newFromCloudLoadbalancer(ctx context.Context, u
|
||||
}
|
||||
}
|
||||
|
||||
lb.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
lb.ProjectId = userCred.GetProjectId()
|
||||
if len(provider.ProjectId) > 0 {
|
||||
lb.ProjectId = provider.ProjectId
|
||||
}
|
||||
|
||||
if extProjectId := extLb.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, lb.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lb.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
if extLb.GetMetadata() != nil {
|
||||
lb.LBInfo = extLb.GetMetadata()
|
||||
}
|
||||
@@ -593,8 +603,15 @@ func (lb *SLoadbalancer) SyncWithCloudLoadbalancer(ctx context.Context, userCred
|
||||
lb.LBInfo = extLb.GetMetadata()
|
||||
}
|
||||
|
||||
if projectSync && len(projectId) > 0 {
|
||||
lb.ProjectId = projectId
|
||||
if projectSync && lb.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extLb.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, lb.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
lb.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -520,6 +520,7 @@ func (manager *SNetworkManager) SyncNetworks(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SNetwork) SyncWithCloudNetwork(userCred mcclient.TokenCredential, extNet cloudprovider.ICloudNetwork, projectId string, projectSync bool) error {
|
||||
vpc := self.GetWire().getVpc()
|
||||
_, err := self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
extNet.Refresh()
|
||||
self.Name = extNet.GetName()
|
||||
@@ -534,8 +535,15 @@ func (self *SNetwork) SyncWithCloudNetwork(userCred mcclient.TokenCredential, ex
|
||||
self.AllocTimoutSeconds = extNet.GetAllocTimeoutSeconds()
|
||||
|
||||
self.ProjectId = userCred.GetProjectId()
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extNet.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, vpc.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -562,10 +570,22 @@ func (manager *SNetworkManager) newFromCloudNetwork(userCred mcclient.TokenCrede
|
||||
|
||||
net.AllocTimoutSeconds = extNet.GetAllocTimeoutSeconds()
|
||||
|
||||
net.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
net.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
net.ProjectId = projectId
|
||||
}
|
||||
|
||||
vpc := wire.getVpc()
|
||||
if extProjectId := extNet.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, vpc.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
net.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
err := manager.TableSpec().Insert(&net)
|
||||
if err != nil {
|
||||
log.Errorf("newFromCloudZone fail %s", err)
|
||||
|
||||
@@ -269,8 +269,15 @@ func (self *SSecurityGroup) SyncWithCloudSecurityGroup(userCred mcclient.TokenCr
|
||||
self.Name = extSec.GetName()
|
||||
self.Description = extSec.GetDescription()
|
||||
self.ProjectId = userCred.GetProjectId()
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := extSec.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, vpc.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
@@ -301,11 +308,22 @@ func (manager *SSecurityGroupManager) newFromCloudVpc(userCred mcclient.TokenCre
|
||||
secgroup.Name = extSec.GetName()
|
||||
secgroup.ExternalId = extSec.GetGlobalId()
|
||||
secgroup.Description = extSec.GetDescription()
|
||||
|
||||
secgroup.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
secgroup.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
secgroup.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extSec.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, vpc.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
secgroup.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
if err := manager.TableSpec().Insert(&secgroup); err != nil {
|
||||
return nil, true, err
|
||||
}
|
||||
|
||||
@@ -536,8 +536,15 @@ func (self *SSnapshot) SyncWithCloudSnapshot(userCred mcclient.TokenCredential,
|
||||
self.Name = ext.GetName()
|
||||
self.Status = ext.GetStatus()
|
||||
self.DiskType = ext.GetDiskType()
|
||||
if projectSync && len(projectId) > 0 {
|
||||
self.ProjectId = projectId
|
||||
if projectSync && self.ProjectSrc != db.PROJECT_SOURCE_LOCAL {
|
||||
if extProjectId := ext.GetProjectId(); len(extProjectId) > 0 {
|
||||
extProject, err := ExternalProjectManager.GetProject(extProjectId, self.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
self.ProjectId = extProject.ProjectId
|
||||
}
|
||||
}
|
||||
}
|
||||
self.CloudregionId = region.Id
|
||||
return nil
|
||||
@@ -569,10 +576,21 @@ func (manager *SSnapshotManager) newFromCloudSnapshot(ctx context.Context, userC
|
||||
snapshot.ManagerId = provider.Id
|
||||
snapshot.CloudregionId = region.Id
|
||||
|
||||
snapshot.ProjectSrc = db.PROJECT_SOURCE_CLOUD
|
||||
snapshot.ProjectId = userCred.GetProjectId()
|
||||
if len(projectId) > 0 {
|
||||
snapshot.ProjectId = projectId
|
||||
}
|
||||
|
||||
if extProjectId := extSnapshot.GetProjectId(); len(extProjectId) > 0 {
|
||||
externalProject, err := ExternalProjectManager.GetProject(extProjectId, snapshot.ManagerId)
|
||||
if err != nil {
|
||||
log.Errorf(err.Error())
|
||||
} else {
|
||||
snapshot.ProjectId = externalProject.ProjectId
|
||||
}
|
||||
}
|
||||
|
||||
err := manager.TableSpec().Insert(&snapshot)
|
||||
if err != nil {
|
||||
log.Errorf("newFromCloudEip fail %s", err)
|
||||
|
||||
@@ -81,6 +81,7 @@ func InitHandlers(app *appsrv.Application) {
|
||||
models.DynamicschedtagManager,
|
||||
|
||||
models.ServerSkuManager,
|
||||
models.ExternalProjectManager,
|
||||
} {
|
||||
db.RegisterModelManager(manager)
|
||||
handler := db.NewModelHandler(manager)
|
||||
|
||||
@@ -149,12 +149,15 @@ func syncPublicCloudProviderInfo(ctx context.Context, provider *models.SCloudpro
|
||||
|
||||
storageCachePairs := make([]sStoragecacheSyncPair, 0)
|
||||
|
||||
syncProjects(ctx, driver, provider, task)
|
||||
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, task.UserCred)
|
||||
// logclient.AddActionLog(provider, getAction(task.Params), "", task.UserCred, true)
|
||||
for i := 0; i < len(localRegions); i += 1 {
|
||||
if len(syncRange.Region) > 0 && !utils.IsInStringArray(localRegions[i].Id, syncRange.Region) {
|
||||
continue
|
||||
}
|
||||
|
||||
syncRegionEips(ctx, provider, task, &localRegions[i], remoteRegions[i], syncRange)
|
||||
|
||||
localZones, remoteZones := syncRegionZones(ctx, provider, task, &localRegions[i], remoteRegions[i])
|
||||
@@ -391,6 +394,25 @@ func syncRegionSnapshots(ctx context.Context, provider *models.SCloudprovider, t
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, task.GetUserCred())
|
||||
}
|
||||
|
||||
func syncProjects(ctx context.Context, driver cloudprovider.ICloudProvider, provider *models.SCloudprovider, task *CloudProviderSyncInfoTask) {
|
||||
projects, err := driver.GetIProjects()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("GetIProjects for provider %s failed %s", provider.GetName(), err)
|
||||
log.Errorf(msg)
|
||||
logSyncFailed(provider, task, msg)
|
||||
return
|
||||
}
|
||||
|
||||
result := models.ExternalProjectManager.SyncProjects(ctx, task.UserCred, provider, projects)
|
||||
msg := result.Result()
|
||||
log.Infof("SyncProjects for provider %s result: %s", provider.Name, msg)
|
||||
if result.IsError() {
|
||||
logSyncFailed(provider, task, msg)
|
||||
return
|
||||
}
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_PROJECT_COMPLETE, msg, task.UserCred)
|
||||
}
|
||||
|
||||
func syncRegionEips(ctx context.Context, provider *models.SCloudprovider, task *CloudProviderSyncInfoTask, localRegion *models.SCloudregion, remoteRegion cloudprovider.ICloudRegion, syncRange *models.SSyncRange) {
|
||||
eips, err := remoteRegion.GetIEips()
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package modules
|
||||
|
||||
var (
|
||||
ExternalProjects ResourceManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
ExternalProjects = NewComputeManager("externalproject", "externalprojects",
|
||||
[]string{"ID", "Name", "ExternalId", "Created_at", "TenantId", "Tenant"},
|
||||
[]string{})
|
||||
|
||||
registerComputeV2(&ExternalProjects)
|
||||
}
|
||||
@@ -242,3 +242,10 @@ func (self *SAliyunClient) GetIStorageById(id string) (cloudprovider.ICloudStora
|
||||
}
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (region *SAliyunClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
// 阿里云并未公布资源组的api地址
|
||||
// params := map[string]string{}
|
||||
// body, err := region.ecsRequest("ListResourceGroups", params)
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -406,3 +406,7 @@ func (self *SRegion) rebuildDisk(diskId string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -326,3 +326,7 @@ func (region *SRegion) UpdateEipBandwidth(eipId string, bw int) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -938,3 +938,7 @@ func (region *SRegion) RenewInstance(instanceId string, bc billing.SBillingCycle
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -336,3 +336,7 @@ func (lb *SLoadbalancer) GetILoadBalancerListeners() ([]cloudprovider.ICloudLoad
|
||||
}
|
||||
return listeners, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -138,3 +138,7 @@ func (acl *SLoadbalancerAcl) Sync(_acl *cloudprovider.SLoadbalancerAccessControl
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (acl *SLoadbalancerAcl) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -84,3 +84,7 @@ func (region *SRegion) GetLoadbalancerBackends(backendgroupId string) ([]SLoadba
|
||||
backends := []SLoadbalancerBackend{}
|
||||
return backends, body.Unmarshal(&backends, "BackendServers", "BackendServer")
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerBackend) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -215,3 +215,7 @@ func (backendgroup *SLoadbalancerBackendGroup) AddBackendServer(serverId string,
|
||||
func (backendgroup *SLoadbalancerBackendGroup) RemoveBackendServer(serverId string, weight, port int) error {
|
||||
return backendgroup.lb.region.RemoveBackendVServer(backendgroup.lb.LoadBalancerId, backendgroup.VServerGroupId, serverId, port)
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerBackendGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -62,3 +62,7 @@ func (backend *SLoadbalancerDefaultBackend) GetBackendRole() string {
|
||||
func (backend *SLoadbalancerDefaultBackend) GetBackendId() string {
|
||||
return backend.ServerId
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerDefaultBackend) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -102,3 +102,7 @@ func (region *SRegion) RemoveBackendServer(loadbalancerId, serverId string) erro
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) RemoveBackendServer(serverId string, weight, port int) error {
|
||||
return backendgroup.lb.region.RemoveBackendServer(backendgroup.lb.LoadBalancerId, serverId)
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerDefaultBackendGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -342,3 +342,7 @@ func (region *SRegion) SyncLoadbalancerHTTPListener(lb *SLoadbalancer, listener
|
||||
func (listerner *SLoadbalancerHTTPListener) Sync(lblis *cloudprovider.SLoadbalancerListener) error {
|
||||
return listerner.lb.region.SyncLoadbalancerHTTPListener(listerner.lb, lblis)
|
||||
}
|
||||
|
||||
func (listerner *SLoadbalancerHTTPListener) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -349,3 +349,7 @@ func (region *SRegion) SyncLoadbalancerHTTPSListener(lb *SLoadbalancer, listener
|
||||
func (listerner *SLoadbalancerHTTPSListener) Sync(lblis *cloudprovider.SLoadbalancerListener) error {
|
||||
return listerner.lb.region.SyncLoadbalancerHTTPSListener(listerner.lb, lblis)
|
||||
}
|
||||
|
||||
func (listerner *SLoadbalancerHTTPSListener) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -65,3 +65,7 @@ func (backend *SLoadbalancerMasterSlaveBackend) GetBackendRole() string {
|
||||
func (backend *SLoadbalancerMasterSlaveBackend) GetBackendId() string {
|
||||
return backend.ServerId
|
||||
}
|
||||
|
||||
func (backend *SLoadbalancerMasterSlaveBackend) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -161,3 +161,7 @@ func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) AddBackendServer(serve
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) RemoveBackendServer(serverId string, weight, port int) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (backendgroup *SLoadbalancerMasterSlaveBackendGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -113,3 +113,7 @@ func (region *SRegion) GetLoadbalancerServerCertificates() ([]SLoadbalancerServe
|
||||
certificates := []SLoadbalancerServerCertificate{}
|
||||
return certificates, body.Unmarshal(&certificates, "ServerCertificates", "ServerCertificate")
|
||||
}
|
||||
|
||||
func (certificate *SLoadbalancerServerCertificate) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -329,3 +329,7 @@ func (region *SRegion) SyncLoadbalancerTCPListener(lb *SLoadbalancer, listener *
|
||||
func (listerner *SLoadbalancerTCPListener) Sync(lblis *cloudprovider.SLoadbalancerListener) error {
|
||||
return listerner.lb.region.SyncLoadbalancerTCPListener(listerner.lb, lblis)
|
||||
}
|
||||
|
||||
func (listerner *SLoadbalancerTCPListener) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -255,3 +255,7 @@ func (region *SRegion) SyncLoadbalancerUDPListener(lb *SLoadbalancer, listener *
|
||||
func (listerner *SLoadbalancerUDPListener) Sync(lblis *cloudprovider.SLoadbalancerListener) error {
|
||||
return listerner.lb.region.SyncLoadbalancerUDPListener(listerner.lb, lblis)
|
||||
}
|
||||
|
||||
func (listerner *SLoadbalancerUDPListener) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package aliyun
|
||||
|
||||
import "time"
|
||||
|
||||
type SProject struct {
|
||||
Status string
|
||||
AccountId string
|
||||
DisplayName string
|
||||
Id string
|
||||
CreateDate time.Time
|
||||
Name string
|
||||
}
|
||||
@@ -129,3 +129,7 @@ func (self *SAliyunProvider) GetBalance() (float64, error) {
|
||||
func (self *SAliyunProvider) GetOnPremiseIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SAliyunProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return self.client.GetIProjects()
|
||||
}
|
||||
|
||||
@@ -543,3 +543,7 @@ func (self *SRegion) DeleteSecurityGroup(vpcId, secGrpId string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/util/aliyun"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ProjectListOptions struct {
|
||||
}
|
||||
shellutils.R(&ProjectListOptions{}, "project-list", "List project", func(cli *aliyun.SRegion, args *ProjectListOptions) error {
|
||||
project, err := cli.GetClient().GetIProjects()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(project, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -179,3 +179,7 @@ func (self *SRegion) DeleteSnapshot(snapshotId string) error {
|
||||
_, err := self.ecsRequest("DeleteSnapshot", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
)
|
||||
@@ -239,3 +240,7 @@ func (vsw *SVSwitch) dissociateWithSNAT() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SVSwitch) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -204,3 +204,7 @@ func (self *SAwsClient) QueryAccountBalance() (*SAccountBalance, error) {
|
||||
// todo: aws 貌似没有余额?
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (self *SAwsClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -480,3 +480,7 @@ func (self *SDisk) Rebuild(ctx context.Context) error {
|
||||
_, err := self.storage.zone.region.resetDisk(self.DiskId, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -304,3 +304,7 @@ func (self *SEipAddress) GetBillingType() string {
|
||||
func (self *SEipAddress) GetExpiredAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -939,3 +939,7 @@ func (self *SInstance) CreateDisk(ctx context.Context, sizeMb int, uuid string,
|
||||
func (self *SInstance) Renew(bc billing.SBillingCycle) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -207,3 +207,7 @@ func (self *SRegion) GetNetwroks(ids []string, vpcId string, limit int, offset i
|
||||
}
|
||||
return subnets, len(subnets), nil
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -132,3 +132,7 @@ func (self *SAwsProvider) GetBalance() (float64, error) {
|
||||
func (self *SAwsProvider) GetOnPremiseIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SAwsProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return self.client.GetIProjects()
|
||||
}
|
||||
|
||||
@@ -474,3 +474,7 @@ func (self *SRegion) GetSecurityGroups(vpcId string, secgroupId string, offset i
|
||||
|
||||
return securityGroups, len(securityGroups), nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -200,3 +200,7 @@ func (self *SRegion) DeleteSnapshot(snapshotId string) error {
|
||||
_, err := self.ec2Client.DeleteSnapshot(params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -768,3 +768,27 @@ type SAccountBalance struct {
|
||||
func (self *SAzureClient) QueryAccountBalance() (*SAccountBalance, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func getResourceGroup(id string) string {
|
||||
if info := strings.Split(id, "/resourceGroups/"); len(info) == 2 {
|
||||
if resourcegroupInfo := strings.Split(info[1], "/"); len(resourcegroupInfo) > 0 {
|
||||
return strings.ToLower(resourcegroupInfo[0])
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SAzureClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
resourceGroups := []SResourceGroup{}
|
||||
if err := self.List("resourcegroups", &resourceGroups); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iprojects := []cloudprovider.ICloudProject{}
|
||||
for i := 0; i < len(resourceGroups); i++ {
|
||||
if groupInfo := strings.Split(resourceGroups[i].ID, "/"); len(groupInfo) > 0 {
|
||||
resourceGroups[i].ID = strings.ToLower(groupInfo[len(groupInfo)-1])
|
||||
}
|
||||
iprojects = append(iprojects, &resourceGroups[i])
|
||||
}
|
||||
return iprojects, nil
|
||||
}
|
||||
|
||||
@@ -223,3 +223,7 @@ func (disk *SClassicDisk) GetAccessPath() string {
|
||||
func (self *SClassicDisk) Rebuild(ctx context.Context) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SClassicDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -151,3 +151,7 @@ func (self *SClassicEipAddress) GetBillingType() string {
|
||||
func (self *SClassicEipAddress) GetExpiredAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SClassicEipAddress) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -535,3 +535,7 @@ func (self *SClassicInstance) CreateDisk(ctx context.Context, sizeMb int, uuid s
|
||||
func (self *SClassicInstance) Renew(bc billing.SBillingCycle) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SClassicInstance) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -112,3 +112,7 @@ func (self *SClassicNetwork) Refresh() error {
|
||||
func (self *SClassicNetwork) GetAllocTimeoutSeconds() int {
|
||||
return 120 // 2 minutes
|
||||
}
|
||||
|
||||
func (self *SClassicNetwork) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -359,3 +359,7 @@ func (region *SRegion) syncClassicSecurityGroup(secgroupId, name, desc string, r
|
||||
}
|
||||
return region.syncClassicSecgroupRules(secgroupId, rules)
|
||||
}
|
||||
|
||||
func (self *SClassicSecurityGroup) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -77,3 +77,7 @@ func (self *SClassicSnapshot) GetRegionId() string {
|
||||
func (self *SClassicSnapshot) GetDiskType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SClassicSnapshot) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -341,3 +341,7 @@ func (self *SDisk) Rebuild(ctx context.Context) error {
|
||||
// TODO
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SDisk) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -242,3 +242,7 @@ func (self *SEipAddress) GetBillingType() string {
|
||||
func (self *SEipAddress) GetExpiredAt() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -1043,3 +1043,7 @@ func (self *SInstance) CreateDisk(ctx context.Context, sizeMb int, uuid string,
|
||||
func (self *SInstance) Renew(bc billing.SBillingCycle) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -112,3 +112,7 @@ func (self *SNetwork) Refresh() error {
|
||||
func (self *SNetwork) GetAllocTimeoutSeconds() int {
|
||||
return 120 // 2 minutes
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -138,3 +138,7 @@ func (self *SAzureProvider) GetBalance() (float64, error) {
|
||||
func (self *SAzureProvider) GetOnPremiseIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SAzureProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return self.client.GetIProjects()
|
||||
}
|
||||
|
||||
@@ -30,3 +30,31 @@ func (self *SRegion) CreateResourceGroup(groupName string) (*SResourceGroup, err
|
||||
resourceGroup := SResourceGroup{Name: groupName, Location: self.Name}
|
||||
return &resourceGroup, self.client.Create(jsonutils.Marshal(resourceGroup), &resourceGroup)
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) GetName() string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) GetId() string {
|
||||
return r.ID
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) GetGlobalId() string {
|
||||
return r.ID
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) GetMetadata() *jsonutils.JSONDict {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *SResourceGroup) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -487,3 +487,7 @@ func (region *SRegion) AssiginSecurityGroup(instanceId, secgroupId string) error
|
||||
}
|
||||
return region.AttachSecurityToInterfaces(secgroupId, nicIds)
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -172,3 +172,7 @@ func (self *SSnapshot) GetDiskId() string {
|
||||
func (self *SSnapshot) GetDiskType() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return getResourceGroup(self.ID)
|
||||
}
|
||||
|
||||
@@ -162,3 +162,7 @@ func (self *SESXiProvider) GetBalance() (float64, error) {
|
||||
func (self *SESXiProvider) GetOnPremiseIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
return self.client, nil
|
||||
}
|
||||
|
||||
func (self *SESXiProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return nil, cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
@@ -244,3 +244,7 @@ func (disk *SVirtualDisk) GetExpiredAt() time.Time {
|
||||
func (disk *SVirtualDisk) Rebuild(ctx context.Context) error {
|
||||
return disk.vm.rebuildDisk(ctx, disk)
|
||||
}
|
||||
|
||||
func (disk *SVirtualDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -718,3 +718,7 @@ func (self *SVirtualMachine) createDiskInternal(ctx context.Context, sizeMb int,
|
||||
func (self *SVirtualMachine) Renew(bc billing.SBillingCycle) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -482,3 +482,7 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) (string, error) {
|
||||
_, err := self.ecsClient.OsSnapshots.PerformAction2("rollback", snapshotId, params, "")
|
||||
return diskId, err
|
||||
}
|
||||
|
||||
func (self *SDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -367,3 +367,7 @@ func (self *SRegion) GetPorts(instanceId string) ([]Port, error) {
|
||||
err := doListAllWithMarker(self.ecsClient.Port.List, querys, &ports)
|
||||
return ports, err
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -1155,3 +1155,7 @@ func (self *SRegion) UnsubscribeInstance(instanceId string, domianId string) (js
|
||||
self.ecsClient.Orders.SetDomainId(domianId)
|
||||
return self.ecsClient.Orders.PerformAction("resources/delete", "", unsubObj)
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -149,3 +149,7 @@ func (self *SRegion) deleteNetwork(vpcId string, networkId string) error {
|
||||
ctx := &modules.SManagerContext{InstanceId: vpcId, InstanceManager: self.ecsClient.Vpcs}
|
||||
return DoDeleteWithSpec(self.ecsClient.Subnets.DeleteInContextWithSpec, ctx, networkId, "", nil, nil)
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/util/huawei/client"
|
||||
)
|
||||
@@ -57,3 +59,7 @@ func (self *SHuaweiClient) GetProjectById(projectId string) (SProject, error) {
|
||||
func (self *SHuaweiClient) GetProjects() ([]SProject, error) {
|
||||
return self.fetchProjects()
|
||||
}
|
||||
|
||||
func (self *SHuaweiClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -132,3 +132,7 @@ func (self *SHuaweiProvider) GetBalance() (float64, error) {
|
||||
func (self *SHuaweiProvider) GetSubAccounts() ([]cloudprovider.SSubAccount, error) {
|
||||
return self.client.GetSubAccounts()
|
||||
}
|
||||
|
||||
func (self *SHuaweiProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return self.client.GetIProjects()
|
||||
}
|
||||
|
||||
@@ -301,3 +301,7 @@ func (self *SRegion) GetSecurityGroups(vpcId string) ([]SSecurityGroup, error) {
|
||||
|
||||
return securitygroups, nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -169,3 +169,7 @@ func (self *SRegion) CreateSnapshot(diskId, name, desc string) (string, error) {
|
||||
err := DoCreate(self.ecsClient.Snapshots.Create, params, &snapshot)
|
||||
return snapshot.ID, err
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -316,3 +316,7 @@ func (disk *SDisk) GetAccessPath() string {
|
||||
func (disk *SDisk) Rebuild(ctx context.Context) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (disk *SDisk) GetProjectId() string {
|
||||
return disk.TenantID
|
||||
}
|
||||
|
||||
@@ -613,3 +613,7 @@ func (instance *SInstance) Renew(bc billing.SBillingCycle) error {
|
||||
func (region *SRegion) RenewInstances(instanceId []string, bc billing.SBillingCycle) error {
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (instance *SInstance) GetProjectId() string {
|
||||
return instance.TenantID
|
||||
}
|
||||
|
||||
@@ -169,3 +169,7 @@ func (region *SRegion) CreateNetwork(vpcId string, name string, cidr string, des
|
||||
}
|
||||
return resp.GetString("subnet", "id")
|
||||
}
|
||||
|
||||
func (network *SNetwork) GetProjectId() string {
|
||||
return network.TenantID
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
"yunion.io/x/onecloud/pkg/util/version"
|
||||
)
|
||||
@@ -183,3 +184,25 @@ func (cli *SOpenStackClient) GetRegions() []SRegion {
|
||||
}
|
||||
return regions
|
||||
}
|
||||
|
||||
func (cli *SOpenStackClient) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
if len(cli.iregions) > 0 {
|
||||
region := cli.iregions[0].(*SRegion)
|
||||
s := cli.client.NewSession(context.Background(), region.Name, "", cli.endpointType, cli.tokenCredential, "")
|
||||
result, err := modules.Projects.List(s, jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iprojects := []cloudprovider.ICloudProject{}
|
||||
for i := 0; i < len(result.Data); i++ {
|
||||
project := &SProject{}
|
||||
if err := result.Data[i].Unmarshal(project); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
iprojects = append(iprojects, project)
|
||||
}
|
||||
return iprojects, nil
|
||||
}
|
||||
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package openstack
|
||||
|
||||
import "yunion.io/x/jsonutils"
|
||||
|
||||
type SProject struct {
|
||||
Description string
|
||||
Enabled bool
|
||||
ID string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (p *SProject) GetId() string {
|
||||
return p.ID
|
||||
}
|
||||
|
||||
func (p *SProject) GetGlobalId() string {
|
||||
return p.GetId()
|
||||
}
|
||||
|
||||
func (p *SProject) GetMetadata() *jsonutils.JSONDict {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *SProject) GetName() string {
|
||||
return p.Name
|
||||
}
|
||||
|
||||
func (p *SProject) GetStatus() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *SProject) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *SProject) Refresh() error {
|
||||
return nil
|
||||
}
|
||||
@@ -175,3 +175,7 @@ func (self *SOpenStackProvider) GetBalance() (float64, error) {
|
||||
func (self *SOpenStackProvider) GetOnPremiseIRegion() (cloudprovider.ICloudRegion, error) {
|
||||
return nil, cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SOpenStackProvider) GetIProjects() ([]cloudprovider.ICloudProject, error) {
|
||||
return self.client.GetIProjects()
|
||||
}
|
||||
|
||||
@@ -351,3 +351,7 @@ func (region *SRegion) CreateSecurityGroup(name, description string) (*SSecurity
|
||||
secgroup := &SSecurityGroup{}
|
||||
return secgroup, resp.Unmarshal(secgroup, "security_group")
|
||||
}
|
||||
|
||||
func (secgroup *SSecurityGroup) GetProjectId() string {
|
||||
return secgroup.TenantID
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/onecloud/pkg/util/openstack"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
type ProjectListOptions struct {
|
||||
}
|
||||
shellutils.R(&ProjectListOptions{}, "project-list", "List project", func(cli *openstack.SRegion, args *ProjectListOptions) error {
|
||||
project, err := cli.GetClient().GetIProjects()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(project, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -163,3 +163,7 @@ func (region *SRegion) CreateSnapshot(diskId, name, desc string) (*SSnapshot, er
|
||||
snapshot := &SSnapshot{region: region}
|
||||
return snapshot, resp.Unmarshal(snapshot, "snapshot")
|
||||
}
|
||||
|
||||
func (self *SSnapshot) GetProjectId() string {
|
||||
return self.ProjectID
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -382,3 +383,7 @@ func (self *SDisk) Rebuild(ctx context.Context) error {
|
||||
// TODO
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (self *SDisk) GetProjectId() string {
|
||||
return strconv.Itoa(self.Placement.ProjectId)
|
||||
}
|
||||
|
||||
@@ -330,3 +330,7 @@ func (region *SRegion) UpdateInstanceBandwidth(instanceId string, bw int) error
|
||||
_, err := region.cvmRequest("ResetInstancesInternetMaxBandwidth", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package qcloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
@@ -821,3 +822,7 @@ func (region *SRegion) RenewInstances(instanceId []string, bc billing.SBillingCy
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetProjectId() string {
|
||||
return strconv.Itoa(self.Placement.ProjectId)
|
||||
}
|
||||
|
||||
@@ -578,3 +578,7 @@ func (self *SRegion) WaitLBTaskSuccess(requestId string, interval time.Duration,
|
||||
|
||||
return cloudprovider.ErrTimeout
|
||||
}
|
||||
|
||||
func (self *SLoadbalancer) GetProjectId() string {
|
||||
return strconv.Itoa(int(self.ProjectID))
|
||||
}
|
||||
|
||||
@@ -40,3 +40,7 @@ func (self *SLBACL) GetMetadata() *jsonutils.JSONDict {
|
||||
func (self *SLBACL) GetAclEntries() *jsonutils.JSONArray {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SLBACL) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -169,3 +169,7 @@ func (self *SRegion) GetLBBackends(t LB_TYPE, lbId, listenerId, ruleId string) (
|
||||
return nil, fmt.Errorf("GetLBBackends unsupported loadbalancer type %d", t)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SLBBackend) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -222,3 +222,7 @@ func (self *SLBBackendGroup) GetBackends() ([]SLBBackend, error) {
|
||||
|
||||
return backends, nil
|
||||
}
|
||||
|
||||
func (self *SLBBackendGroup) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -81,3 +81,7 @@ func (self *SLBCertificate) GetFingerprint() string {
|
||||
func (self *SLBCertificate) GetExpireTime() time.Time {
|
||||
return self.CERTEndTime
|
||||
}
|
||||
|
||||
func (self *SLBCertificate) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -780,3 +780,7 @@ func certificateParams(t LB_TYPE, params map[string]string, cert *certificate, p
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (self *SLBListener) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -139,3 +139,7 @@ func (self *SLocalDisk) Rebuild(ctx context.Context) error {
|
||||
// TODO
|
||||
return cloudprovider.ErrNotSupported
|
||||
}
|
||||
|
||||
func (disk *SLocalDisk) GetProjectId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user