From 6285f13983a254af057f96b7f6d4bb5114e3a71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 9 Jan 2019 16:08:08 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=9B=A0secret=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=EF=BC=8C=E5=AF=BC=E8=87=B4=E6=8F=92=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=97=B6=E6=8A=A5=E9=94=99:=20Field=20'secre?= =?UTF-8?q?t'=20doesn't=20have=20a=20default=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/cloudaccounts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 44d60cde38..b9430ea7ea 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -425,6 +425,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 @@ -586,6 +587,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 From 4fb3974367f5435985fe86d2dbae4b0aed4c129b Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 9 Jan 2019 16:42:59 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AF=B9=E5=8C=85?= =?UTF-8?q?=E5=B9=B4=E5=8C=85=E6=9C=88=E4=B8=BB=E6=9C=BA=E7=BB=AD=E8=B4=B9?= =?UTF-8?q?=E5=90=8E=E6=B2=A1=E6=9C=89=E6=95=88=E6=9E=9C=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/climc/climc.go | 2 +- pkg/cloudprovider/retry.go | 16 ++++++++++++++++ pkg/compute/guestdrivers/managedvirtual.go | 4 ++++ pkg/compute/models/host_recycle.go | 8 ++++++++ pkg/compute/models/hosts.go | 4 ++++ pkg/compute/tasks/guest_renew_task.go | 16 ++++++++++++++-- 6 files changed, 47 insertions(+), 3 deletions(-) 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/cloudprovider/retry.go b/pkg/cloudprovider/retry.go index 7fb70fd6da..6c07b7b2ff 100644 --- a/pkg/cloudprovider/retry.go +++ b/pkg/cloudprovider/retry.go @@ -3,6 +3,8 @@ package cloudprovider import ( "strings" "time" + + "yunion.io/x/log" ) func IsError(err error, errs []string) bool { @@ -29,3 +31,17 @@ func RetryOnError(tryFunc func() error, errs []string, maxTries int) error { } return ErrTimeout } + +func Retry(tryFunc func() error, maxTries int) error { + tried := 0 + for tried < maxTries { + err := tryFunc() + if err == nil { + return nil + } + tried += 1 + log.Errorf("Tried %d fail %s", tried, err) + time.Sleep(10 * time.Duration(tried) * time.Second) + } + return ErrTimeout +} 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/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/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) From d809566780d8e066e201afe21f58b92d18dc71a4 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 9 Jan 2019 16:44:58 +0800 Subject: [PATCH 3/7] minor fixes --- pkg/cloudprovider/retry.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pkg/cloudprovider/retry.go b/pkg/cloudprovider/retry.go index 6c07b7b2ff..7fb70fd6da 100644 --- a/pkg/cloudprovider/retry.go +++ b/pkg/cloudprovider/retry.go @@ -3,8 +3,6 @@ package cloudprovider import ( "strings" "time" - - "yunion.io/x/log" ) func IsError(err error, errs []string) bool { @@ -31,17 +29,3 @@ func RetryOnError(tryFunc func() error, errs []string, maxTries int) error { } return ErrTimeout } - -func Retry(tryFunc func() error, maxTries int) error { - tried := 0 - for tried < maxTries { - err := tryFunc() - if err == nil { - return nil - } - tried += 1 - log.Errorf("Tried %d fail %s", tried, err) - time.Sleep(10 * time.Duration(tried) * time.Second) - } - return ErrTimeout -} From d3d7d395f3c1230a86c0e8eef3621ef243dfb08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Wed, 9 Jan 2019 17:19:31 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E9=81=BF=E5=85=8Dunmarshal=20nil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/loadbalanceracls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 50b3603d9d534e333412c03bcf6fd005ab6eda42 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 9 Jan 2019 17:25:16 +0800 Subject: [PATCH 5/7] =?UTF-8?q?mcclient=20module=E5=A2=9E=E5=8A=A0DeleteWi?= =?UTF-8?q?thParam=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=85=81=E8=AE=B8=E6=8A=8Aqu?= =?UTF-8?q?eryString=E4=BC=A0=E9=80=92=E5=88=B0=E5=90=8E=E7=AB=AF=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=89=8D=E7=AB=AF=E6=97=A0=E6=B3=95=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=9B=9E=E6=94=B6=E7=AB=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/mcclient/modules/modules.go | 6 ++++++ pkg/mcclient/modules/resource.go | 4 ++++ 2 files changed, 10 insertions(+) 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) } From a14fad1b9cd1b7fcd3ede71ad35d2e120155fef1 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Wed, 9 Jan 2019 18:26:42 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=88=B0=E6=9C=9F=E5=8C=85=E5=B9=B4=E5=8C=85=E6=9C=88?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E9=9C=80=E8=A6=81=E6=8A=8A=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4=E5=8E=BB=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/compute/models/guests.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 8f3e7f02f5..25cd278f68 100644 --- a/pkg/compute/models/guests.go +++ b/pkg/compute/models/guests.go @@ -3430,6 +3430,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) } } From b9a788018460e811717552c19281a0a4e8533b4e Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Wed, 9 Jan 2019 18:33:54 +0800 Subject: [PATCH 7/7] server-list add disks info and isolated_device info --- pkg/compute/models/guests.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/compute/models/guests.go b/pkg/compute/models/guests.go index 8f3e7f02f5..423d8f86e0 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")