mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
temp commit
This commit is contained in:
@@ -142,6 +142,7 @@ 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"`
|
||||
@@ -151,6 +152,9 @@ func init() {
|
||||
if args.Force {
|
||||
params.Add(jsonutils.JSONTrue, "force")
|
||||
}
|
||||
if args.FullSync {
|
||||
params.Add(jsonutils.JSONTrue, "full_sync")
|
||||
}
|
||||
if len(args.Region) > 0 {
|
||||
params.Add(jsonutils.NewStringArray(args.Region), "region")
|
||||
}
|
||||
|
||||
@@ -138,9 +138,6 @@ func (self *SCloudprovider) getPassword() (string, error) {
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) CanSync() bool {
|
||||
if ! self.Enabled {
|
||||
return false
|
||||
}
|
||||
if self.Status == CLOUD_PROVIDER_SYNCING {
|
||||
if self.LastSync.IsZero() || time.Now().Sub(self.LastSync) > 900*time.Second {
|
||||
return true
|
||||
@@ -153,10 +150,11 @@ func (self *SCloudprovider) CanSync() bool {
|
||||
}
|
||||
|
||||
type SSyncRange struct {
|
||||
Force bool
|
||||
Region []string
|
||||
Zone []string
|
||||
Host []string
|
||||
Force bool
|
||||
FullSync bool
|
||||
Region []string
|
||||
Zone []string
|
||||
Host []string
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) AllowPerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
@@ -164,10 +162,13 @@ func (self *SCloudprovider) AllowPerformSync(ctx context.Context, userCred mccli
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformSync(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if ! self.Enabled {
|
||||
return nil, httperrors.NewInvalidStatusError("Cloudprovider disabled")
|
||||
}
|
||||
syncRange := SSyncRange{}
|
||||
err := data.Unmarshal(&syncRange)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalud input %s", err)
|
||||
return nil, httperrors.NewInputParameterError("invalid input %s", err)
|
||||
}
|
||||
if self.CanSync() || syncRange.Force {
|
||||
err = self.startSyncCloudProviderInfoTask(ctx, userCred, &syncRange, "")
|
||||
@@ -180,6 +181,10 @@ func (self *SCloudprovider) AllowPerformUpdateCredential(ctx context.Context, us
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) PerformUpdateCredential(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
if ! self.Enabled {
|
||||
return nil, httperrors.NewInvalidStatusError("Cloudprovider disabled")
|
||||
}
|
||||
|
||||
var err error
|
||||
changed := false
|
||||
secret, _ := data.GetString("secret")
|
||||
|
||||
@@ -80,7 +80,7 @@ func syncCloudProviderInfo(ctx context.Context, provider *models.SCloudprovider,
|
||||
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, task.UserCred)
|
||||
for i := 0; i < len(localRegions); i += 1 {
|
||||
if len(syncRange.Region) > 0 && !utils.IsInStringArray(remoteRegions[i].GetId(), syncRange.Region) {
|
||||
if !syncRange.FullSync && len(syncRange.Region) > 0 && !utils.IsInStringArray(remoteRegions[i].GetId(), syncRange.Region) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ func syncCloudProviderInfo(ctx context.Context, provider *models.SCloudprovider,
|
||||
if localZones != nil && remoteZones != nil {
|
||||
for j := 0; j < len(localZones); j += 1 {
|
||||
|
||||
if len(syncRange.Zone) > 0 && !utils.IsInStringArray(remoteZones[j].GetId(), syncRange.Zone) {
|
||||
if !syncRange.FullSync && len(syncRange.Zone) > 0 && !utils.IsInStringArray(remoteZones[j].GetId(), syncRange.Zone) {
|
||||
continue
|
||||
}
|
||||
syncZoneStorages(ctx, provider, task, &localZones[j], remoteZones[j])
|
||||
@@ -258,7 +258,7 @@ func syncZoneHosts(ctx context.Context, provider *models.SCloudprovider, task *C
|
||||
db.OpsLog.LogEvent(provider, db.ACT_SYNC_HOST_COMPLETE, msg, task.UserCred)
|
||||
|
||||
for i := 0; i < len(localHosts); i += 1 {
|
||||
if len(syncRange.Host) > 0 && !utils.IsInStringArray(remoteHosts[i].GetGlobalId(), syncRange.Host) {
|
||||
if !syncRange.FullSync && len(syncRange.Host) > 0 && !utils.IsInStringArray(remoteHosts[i].GetGlobalId(), syncRange.Host) {
|
||||
continue
|
||||
}
|
||||
syncHostStorages(ctx, provider, task, &localHosts[i], remoteHosts[i])
|
||||
|
||||
Reference in New Issue
Block a user