Automatic merge from release/2.7.0 -> release/2.8.0

* commit '7b30e84ae87a92ecd5c8f211bf454cd3461dec29':
  避免openstack创建机器失败后长时间等待
This commit is contained in:
邱剑
2019-03-13 21:37:33 +08:00
11 changed files with 68 additions and 1 deletions
+2
View File
@@ -247,6 +247,8 @@ type ICloudVM interface {
CreateDisk(ctx context.Context, sizeMb int, uuid string, driver string) error
Renew(bc billing.SBillingCycle) error
GetError() error
}
type ICloudNic interface {
+20
View File
@@ -22,6 +22,26 @@ func WaitStatus(res ICloudResource, expect string, interval time.Duration, timeo
return ErrTimeout
}
func WaitStatusWithInstanceErrorCheck(res ICloudResource, expect string, interval time.Duration, timeout time.Duration, errCheck func() error) error {
startTime := time.Now()
for time.Now().Sub(startTime) < timeout {
err := res.Refresh()
if err != nil {
return err
}
log.Debugf("status %s expect %s", res.GetStatus(), expect)
if res.GetStatus() == expect {
return nil
}
err = errCheck()
if err != nil {
return err
}
time.Sleep(interval)
}
return ErrTimeout
}
func WaitDeleted(res ICloudResource, interval time.Duration, timeout time.Duration) error {
startTime := time.Now()
for time.Now().Sub(startTime) < timeout {
+3 -1
View File
@@ -227,7 +227,9 @@ func (self *SManagedVirtualizedGuestDriver) RemoteDeployGuestForCreate(ctx conte
initialState := guest.GetDriver().GetGuestInitialStateAfterCreate()
log.Debugf("VMcreated %s, wait status %s ...", iVM.GetGlobalId(), initialState)
err = cloudprovider.WaitStatus(iVM, initialState, time.Second*5, time.Second*1800)
err = cloudprovider.WaitStatusWithInstanceErrorCheck(iVM, initialState, time.Second*5, time.Second*1800, func() error {
return iVM.GetError()
})
if err != nil {
return nil, err
}
+4
View File
@@ -942,3 +942,7 @@ func (region *SRegion) RenewInstance(instanceId string, bc billing.SBillingCycle
func (self *SInstance) GetProjectId() string {
return ""
}
func (self *SInstance) GetError() error {
return nil
}
+4
View File
@@ -943,3 +943,7 @@ func (self *SInstance) Renew(bc billing.SBillingCycle) error {
func (self *SInstance) GetProjectId() string {
return ""
}
func (self *SInstance) GetError() error {
return nil
}
+4
View File
@@ -539,3 +539,7 @@ func (self *SClassicInstance) Renew(bc billing.SBillingCycle) error {
func (self *SClassicInstance) GetProjectId() string {
return getResourceGroup(self.ID)
}
func (self *SClassicInstance) GetError() error {
return nil
}
+4
View File
@@ -1047,3 +1047,7 @@ func (self *SInstance) Renew(bc billing.SBillingCycle) error {
func (self *SInstance) GetProjectId() string {
return getResourceGroup(self.ID)
}
func (self *SInstance) GetError() error {
return nil
}
+4
View File
@@ -722,3 +722,7 @@ func (self *SVirtualMachine) Renew(bc billing.SBillingCycle) error {
func (self *SVirtualMachine) GetProjectId() string {
return ""
}
func (self *SVirtualMachine) GetError() error {
return nil
}
+4
View File
@@ -1181,3 +1181,7 @@ func (self *SRegion) UnsubscribeInstance(instanceId string, domianId string) (js
func (self *SInstance) GetProjectId() string {
return ""
}
func (self *SInstance) GetError() error {
return nil
}
+15
View File
@@ -2,6 +2,7 @@ package openstack
import (
"context"
"errors"
"fmt"
"time"
@@ -69,6 +70,12 @@ type VolumesAttached struct {
DeleteOnTermination bool
}
type SFault struct {
Message string
Code int
Details string
}
type SInstance struct {
host *SHost
@@ -115,6 +122,7 @@ type SInstance struct {
TrustedImageCertificates []string
Updated time.Time
UserID string
Fault SFault
}
func (region *SRegion) GetSecurityGroupsByInstance(instanceId string) ([]SecurityGroup, error) {
@@ -629,3 +637,10 @@ func (region *SRegion) RenewInstances(instanceId []string, bc billing.SBillingCy
func (instance *SInstance) GetProjectId() string {
return instance.TenantID
}
func (self *SInstance) GetError() error {
if self.Status == INSTANCE_STATUS_ERROR && len(self.Fault.Message) > 0 {
return errors.New(self.Fault.Message)
}
return nil
}
+4
View File
@@ -825,3 +825,7 @@ func (region *SRegion) RenewInstances(instanceId []string, bc billing.SBillingCy
func (self *SInstance) GetProjectId() string {
return strconv.Itoa(self.Placement.ProjectId)
}
func (self *SInstance) GetError() error {
return nil
}