mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.7.0 -> release/2.8.0
* commit '7b30e84ae87a92ecd5c8f211bf454cd3461dec29': 避免openstack创建机器失败后长时间等待
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user