mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
fix: add cancel expire action
This commit is contained in:
@@ -29,4 +29,6 @@ func init() {
|
||||
cmd.Show(&compute.NatGatewayIdOptions{})
|
||||
cmd.Delete(&compute.NatGatewayDeleteOption{})
|
||||
cmd.Perform("syncstauts", &compute.NatGatewayIdOptions{})
|
||||
cmd.Perform("cancel-expire", &compute.NatGatewayIdOptions{})
|
||||
cmd.Perform("postpaid-expire", &compute.NatPostpaidExpireOptions{})
|
||||
}
|
||||
|
||||
+1
-1
@@ -355,7 +355,7 @@ type DistinctFieldInput struct {
|
||||
|
||||
type PostpaidExpireInput struct {
|
||||
Duration string `json:"duration"`
|
||||
ExpireTime time.Time `json:"expireType"`
|
||||
ExpireTime time.Time `json:"expire_time"`
|
||||
}
|
||||
|
||||
type AutoRenewInput struct {
|
||||
|
||||
@@ -889,6 +889,32 @@ func (manager *SNatEntryManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (self *SNatGateway) AllowPerformCancelExpire(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "cancel-expire")
|
||||
}
|
||||
|
||||
func (self *SNatGateway) PerformCancelExpire(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
return nil, self.CancelExpireTime(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SNatGateway) CancelExpireTime(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
if self.BillingType != billing_api.BILLING_TYPE_POSTPAID {
|
||||
return httperrors.NewBadRequestError("nat billing type %s not support cancel expire", self.BillingType)
|
||||
}
|
||||
|
||||
_, err := sqlchemy.GetDB().Exec(
|
||||
fmt.Sprintf(
|
||||
"update %s set expired_at = NULL and billing_cycle = NULL where id = ?",
|
||||
NatGatewayManager.TableSpec().Name(),
|
||||
), self.Id,
|
||||
)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "nat cancel expire time")
|
||||
}
|
||||
db.OpsLog.LogEvent(self, db.ACT_RENEW, "nat cancel expire time", userCred)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SNatGateway) AllowPerformPostpaidExpire(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "postpaid-expire")
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package compute
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
@@ -91,3 +92,12 @@ type NatSCreateOptions struct {
|
||||
SourceCIDR string `help:"Source CIDR"`
|
||||
NetworkID string `help:"Network id"`
|
||||
}
|
||||
|
||||
type NatPostpaidExpireOptions struct {
|
||||
NatGatewayIdOptions
|
||||
apis.PostpaidExpireInput
|
||||
}
|
||||
|
||||
func (opts *NatPostpaidExpireOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(opts.PostpaidExpireInput), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user