region: guests: sshable: add field sshable_last_state

This commit is contained in:
Yousong Zhou
2021-04-15 17:51:16 +08:00
parent 4ab5c2c29a
commit db0e28434f
2 changed files with 20 additions and 0 deletions
+18
View File
@@ -20,6 +20,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/tristate"
"yunion.io/x/sqlchemy"
cloudproxy_api "yunion.io/x/onecloud/pkg/apis/cloudproxy"
@@ -91,6 +92,23 @@ func (guest *SGuest) GetDetailsSshable(
if err := guest.sshableTryEach(ctx, userCred, tryData); err != nil {
return nil, err
}
{
sshable := false
for i := range tryData.MethodTried {
if tryData.MethodTried[i].Sshable {
sshable = true
break
}
}
if _, err := db.Update(guest, func() error {
guest.SshableLastState = tristate.NewFromBool(sshable)
return nil
}); err != nil {
log.Errorf("update guest %s(%s) sshable_last_state to %v: %v", guest.Name, guest.Id, sshable, err)
}
}
return tryData.outputJSON(), nil
}
+2
View File
@@ -151,6 +151,8 @@ type SGuest struct {
// 套餐名称
InstanceType string `width:"64" charset:"utf8" nullable:"true" list:"user" create:"optional"`
SshableLastState tristate.TriState `nullable:"false" default:"false" list:"user"`
}
func (manager *SGuestManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool {