mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10994 from yousong/automated-cherry-pick-of-#10993-upstream-release-3.7
Automated cherry pick of #10993: Bugfix/yousong cloudproxy wait on error
This commit is contained in:
@@ -898,6 +898,10 @@ func getModelItemDetails(manager IModelManager, item IModel, ctx context.Context
|
||||
}
|
||||
}
|
||||
|
||||
func GetItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential) (jsonutils.JSONObject, error) {
|
||||
return getItemDetails(manager, item, ctx, userCred, nil)
|
||||
}
|
||||
|
||||
func getItemDetails(manager IModelManager, item IModel, ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
metaFields, excludeFields := GetDetailFields(manager, userCred)
|
||||
fieldFilter := jsonutils.GetQueryStringArray(query, "field")
|
||||
|
||||
@@ -186,10 +186,17 @@ func (c *Client) runClientState(ctx context.Context, sshClientC chan *ssh.Client
|
||||
default:
|
||||
}
|
||||
|
||||
cc := c.cc
|
||||
tmoCtx, _ := context.WithTimeout(ctx, 31*time.Second)
|
||||
sshc, err := c.cc.ConnectContext(tmoCtx)
|
||||
sshc, err := cc.ConnectContext(tmoCtx)
|
||||
if err != nil {
|
||||
log.Errorf("ssh connect: %v", err)
|
||||
log.Errorf("ssh connect: %s@%s, port %d: %v", cc.Username, cc.Host, cc.Port, err)
|
||||
waitTmo := time.NewTimer(13 * time.Second)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-waitTmo.C:
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -256,7 +256,11 @@ func (man *SForwardManager) PerformCreateFromServer(ctx context.Context, userCre
|
||||
data, err = man.validatePortReq(ctx, typ, -1, agentId, epId, data)
|
||||
}
|
||||
|
||||
forward := &SForward{}
|
||||
forwardObj, err := db.NewModelObject(man)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
}
|
||||
forward := forwardObj.(*SForward)
|
||||
if err := data.Unmarshal(forward); err != nil {
|
||||
return nil, httperrors.NewServerError("unmarshal create params: %v", err)
|
||||
}
|
||||
@@ -267,7 +271,7 @@ func (man *SForwardManager) PerformCreateFromServer(ctx context.Context, userCre
|
||||
return nil, httperrors.NewServerError("database insertion error: %v", err)
|
||||
}
|
||||
|
||||
return jsonutils.Marshal(forward), nil
|
||||
return db.GetItemDetails(man, forward, ctx, userCred)
|
||||
}
|
||||
|
||||
func (man *SForwardManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) {
|
||||
|
||||
@@ -207,9 +207,22 @@ func (guest *SGuest) sshableTryEach(
|
||||
res, err := cloudproxy_module.Forwards.PerformClassAction(sess, "create-from-server", fwdCreateParams)
|
||||
if err == nil {
|
||||
var fwd cloudproxy_api.ForwardDetails
|
||||
if err := res.Unmarshal(&fwd); err == nil {
|
||||
if ok := guest.sshableTryForward(ctx, tryData, &fwd); ok {
|
||||
return nil
|
||||
if err := res.Unmarshal(&fwd); err != nil {
|
||||
log.Errorf("unmarshal fwd details: %q", res.String())
|
||||
}
|
||||
|
||||
tmo := time.NewTimer(13 * time.Second)
|
||||
tick := time.NewTicker(3 * time.Second)
|
||||
for {
|
||||
select {
|
||||
case <-tmo.C:
|
||||
break
|
||||
case <-tick.C:
|
||||
if ok := guest.sshableTryForward(ctx, tryData, &fwd); ok {
|
||||
return nil
|
||||
}
|
||||
case <-ctx.Done():
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user