diff --git a/cmd/climc/climc.go b/cmd/climc/climc.go index fe5e4f8392..95a62e2c24 100644 --- a/cmd/climc/climc.go +++ b/cmd/climc/climc.go @@ -29,7 +29,7 @@ type BaseOptions struct { Debug bool `help:"Show debug information"` Version bool `help:"Show version"` Timeout int `default:"600" help:"Number of seconds to wait for a response"` - Insecure bool `default:"false" help:"Allow skip server cert verification if URL is https" short-token:"k"` + Insecure bool `default:"$YUNION_INSECURE|false" help:"Allow skip server cert verification if URL is https" short-token:"k"` CertFile string `default:"$YUNION_CERT_FILE" help:"certificate file"` KeyFile string `default:"$YUNION_KEY_FILE" help:"private key file"` diff --git a/pkg/compute/guestdrivers/managedvirtual.go b/pkg/compute/guestdrivers/managedvirtual.go index 0f054e822a..9edf528541 100644 --- a/pkg/compute/guestdrivers/managedvirtual.go +++ b/pkg/compute/guestdrivers/managedvirtual.go @@ -580,5 +580,9 @@ func (self *SManagedVirtualizedGuestDriver) RequestRenewInstance(guest *models.S if err != nil { return time.Time{}, err } + err = iVM.Refresh() + if err != nil { + return time.Time{}, err + } return iVM.GetExpiredAt(), nil } diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 7727ad028d..071a077715 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -427,6 +427,7 @@ func (self *SCloudaccount) ImportSubAccount(ctx context.Context, userCred mcclie newCloudprovider := SCloudprovider{} newCloudprovider.Account = subAccount.Account + newCloudprovider.Secret = self.Secret newCloudprovider.CloudaccountId = self.Id newCloudprovider.Provider = self.Provider newCloudprovider.AccessUrl = self.AccessUrl @@ -685,6 +686,7 @@ func migrateCloudprovider(cloudprovider *SCloudprovider) error { if err == sql.ErrNoRows { account.AccessUrl = cloudprovider.AccessUrl account.Account = mainAccount + account.Secret = cloudprovider.Secret account.LastSync = cloudprovider.LastSync // account.Sysinfo = cloudprovider.Sysinfo account.Provider = cloudprovider.Provider diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 8f3e7f02f5..b009681319 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -1201,6 +1201,9 @@ func (self *SGuest) moreExtraInfo(extra *jsonutils.JSONDict) *jsonutils.JSONDict } }*/ + extra.Add(self.getDisksInfoDetails(), "disks_info") + extra.Add(jsonutils.NewString(self.getIsolatedDeviceDetails()), "isolated_devices") + host := self.GetHost() if host != nil { info := host.getCloudProviderInfo() @@ -1225,7 +1228,6 @@ func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.Token extra.Add(jsonutils.NewString(self.getNetworksDetails()), "networks") extra.Add(jsonutils.NewString(self.getDisksDetails()), "disks") - extra.Add(self.getDisksInfoDetails(), "disks_info") extra.Add(jsonutils.NewInt(int64(self.getDiskSize())), "disk") cdrom := self.getCdrom() if cdrom != nil { @@ -1241,7 +1243,6 @@ func (self *SGuest) GetExtraDetails(ctx context.Context, userCred mcclient.Token extra.Add(jsonutils.NewString(strings.Join(self.getIPs(), ",")), "ips") extra.Add(jsonutils.NewString(self.getSecurityGroupsRules()), "security_rules") - extra.Add(jsonutils.NewString(self.getIsolatedDeviceDetails()), "isolated_devices") osName := self.GetOS() if len(osName) > 0 { extra.Add(jsonutils.NewString(osName), "os_name") @@ -3430,6 +3431,7 @@ func (manager *SGuestManager) DeleteExpiredPrepaidServers(ctx context.Context, u } for i := 0; i < len(guests); i += 1 { // fake delete expired prepaid servers + guests[i].SetDisableDelete(false) guests[i].StartDeleteGuestTask(ctx, userCred, "", false, false) } } diff --git a/pkg/compute/models/host_recycle.go b/pkg/compute/models/host_recycle.go index a51321f8d7..ccef50735e 100644 --- a/pkg/compute/models/host_recycle.go +++ b/pkg/compute/models/host_recycle.go @@ -726,3 +726,11 @@ func (self *SHost) DoSaveRenewInfo(ctx context.Context, userCred mcclient.TokenC db.OpsLog.LogEvent(self, db.ACT_RENEW, self.GetShortDesc(ctx), userCred) return nil } + +func (self *SHost) SyncWithRealPrepaidVM(ctx context.Context, userCred mcclient.TokenCredential, iVM cloudprovider.ICloudVM) error { + exp := iVM.GetExpiredAt() + if self.ExpiredAt != exp { + return self.DoSaveRenewInfo(ctx, userCred, nil, &exp) + } + return nil +} diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 414fdfebb5..f004bbd9b6 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -1637,6 +1637,10 @@ func (self *SHost) SyncHostVMs(ctx context.Context, userCred mcclient.TokenCrede vhost := HostManager.GetHostByRealExternalId(added[i].GetGlobalId()) if vhost != nil { // this recycle vm is not build yet, skip synchronize + err = vhost.SyncWithRealPrepaidVM(ctx, userCred, added[i]) + if err != nil { + syncResult.AddError(err) + } continue } } diff --git a/pkg/compute/models/loadbalanceracls.go b/pkg/compute/models/loadbalanceracls.go index 38d1e29fea..b436cc8aa2 100644 --- a/pkg/compute/models/loadbalanceracls.go +++ b/pkg/compute/models/loadbalanceracls.go @@ -319,7 +319,7 @@ func (acl *SLoadbalancerAcl) SyncWithCloudLoadbalancerAcl(ctx context.Context, u if projectSync && len(projectId) > 0 { acl.ProjectId = projectId } - + acl.AclEntries = &SLoadbalancerAclEntries{} return aclEntries.Unmarshal(acl.AclEntries) }) return err diff --git a/pkg/compute/tasks/guest_renew_task.go b/pkg/compute/tasks/guest_renew_task.go index 4401fa2a26..9d8feab26c 100644 --- a/pkg/compute/tasks/guest_renew_task.go +++ b/pkg/compute/tasks/guest_renew_task.go @@ -2,11 +2,11 @@ package tasks import ( "context" + "fmt" "yunion.io/x/jsonutils" - - "fmt" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon/db" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/compute/models" @@ -73,6 +73,8 @@ func (self *PrepaidRecycleHostRenewTask) OnInit(ctx context.Context, obj db.ISta return } + log.Debugf("expire before %s", iVM.GetExpiredAt()) + err = iVM.Renew(bc) if err != nil { msg := fmt.Sprintf("iVM.Renew fail %s", err) @@ -81,6 +83,16 @@ func (self *PrepaidRecycleHostRenewTask) OnInit(ctx context.Context, obj db.ISta return } + err = iVM.Refresh() + if err != nil { + msg := fmt.Sprintf("refresh after renew fail %s", err) + log.Errorf(msg) + self.SetStageFailed(ctx, msg) + return + } + + log.Debugf("expire after %s", iVM.GetExpiredAt()) + exp := iVM.GetExpiredAt() err = host.DoSaveRenewInfo(ctx, self.UserCred, &bc, &exp) diff --git a/pkg/mcclient/modules/modules.go b/pkg/mcclient/modules/modules.go index da1774fbcc..9304a20744 100644 --- a/pkg/mcclient/modules/modules.go +++ b/pkg/mcclient/modules/modules.go @@ -110,11 +110,17 @@ type Manager interface { BatchPerformActionInContext(session *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctx Manager, ctxid string) []SubmitResult BatchPerformActionInContexts(session *mcclient.ClientSession, idlist []string, action string, params jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult Delete(session *mcclient.ClientSession, id string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) + DeleteWithParam(session *mcclient.ClientSession, id string, query jsonutils.JSONObject, body jsonutils.JSONObject) (jsonutils.JSONObject, error) DeleteInContext(session *mcclient.ClientSession, id string, body jsonutils.JSONObject, ctx Manager, ctxid string) (jsonutils.JSONObject, error) + DeleteInContextWithParam(session *mcclient.ClientSession, id string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctx Manager, ctxid string) (jsonutils.JSONObject, error) DeleteInContexts(session *mcclient.ClientSession, id string, body jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) + DeleteInContextsWithParam(session *mcclient.ClientSession, id string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) BatchDelete(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject) []SubmitResult + BatchDeleteWithParam(session *mcclient.ClientSession, idlist []string, query jsonutils.JSONObject, body jsonutils.JSONObject) []SubmitResult BatchDeleteInContext(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject, ctx Manager, ctxid string) []SubmitResult + BatchDeleteInContextWithParam(session *mcclient.ClientSession, idlist []string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctx Manager, ctxid string) []SubmitResult BatchDeleteInContexts(session *mcclient.ClientSession, idlist []string, body jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult + BatchDeleteInContextsWithParam(session *mcclient.ClientSession, idlist []string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctxs []ManagerContext) []SubmitResult } type JointManager interface { diff --git a/pkg/mcclient/modules/resource.go b/pkg/mcclient/modules/resource.go index f7c544aa6c..4c1b1da5f2 100644 --- a/pkg/mcclient/modules/resource.go +++ b/pkg/mcclient/modules/resource.go @@ -485,6 +485,10 @@ func (this *ResourceManager) DeleteInContext(session *mcclient.ClientSession, id return this.DeleteInContexts(session, id, body, []ManagerContext{{ctx, ctxid}}) } +func (this *ResourceManager) DeleteInContextWithParam(session *mcclient.ClientSession, id string, query jsonutils.JSONObject, body jsonutils.JSONObject, ctx Manager, ctxid string) (jsonutils.JSONObject, error) { + return this.DeleteInContextsWithParam(session, id, query, body, []ManagerContext{{ctx, ctxid}}) +} + func (this *ResourceManager) DeleteInContexts(session *mcclient.ClientSession, id string, body jsonutils.JSONObject, ctxs []ManagerContext) (jsonutils.JSONObject, error) { return this.deleteInContexts(session, id, nil, body, ctxs) }