mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-31 21:12:07 +08:00
postpaid expire support premise
This commit is contained in:
@@ -239,6 +239,10 @@ func (self *SBaseGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle)
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) IsSupportPostpaidExpire() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestRenewInstance(guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
return time.Time{}, nil
|
||||
}
|
||||
|
||||
@@ -235,6 +235,10 @@ func (self *SESXiGuestDriver) CancelExpireTime(
|
||||
return guest.CancelExpireTime(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) IsSupportPostpaidExpire() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
@@ -480,3 +480,7 @@ func (self *SKVMGuestDriver) CancelExpireTime(
|
||||
func (self *SKVMGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *SKVMGuestDriver) IsSupportPostpaidExpire() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -155,6 +155,10 @@ func (self *SOpenStackGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCy
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) IsSupportPostpaidExpire() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SOpenStackGuestDriver) CancelExpireTime(
|
||||
ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest) error {
|
||||
return guest.CancelExpireTime(ctx, userCred)
|
||||
|
||||
@@ -165,6 +165,10 @@ func (self *SZStackGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SZStackGuestDriver) IsSupportPostpaidExpire() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SZStackGuestDriver) CancelExpireTime(
|
||||
ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest) error {
|
||||
return guest.CancelExpireTime(ctx, userCred)
|
||||
|
||||
@@ -3247,6 +3247,29 @@ func (self *SGuest) PerformCancelExpire(ctx context.Context, userCred mcclient.T
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformPostpaidExpire(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return self.IsOwner(userCred) || db.IsAdminAllowPerform(userCred, self, "postpaid-expire")
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformPostpaidExpire(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
durationStr := jsonutils.GetAnyString(data, []string{"duration"})
|
||||
if len(durationStr) == 0 {
|
||||
return nil, httperrors.NewInputParameterError("missong duration")
|
||||
}
|
||||
|
||||
bc, err := billing.ParseBillingCycle(durationStr)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid duration %s: %s", durationStr, err)
|
||||
}
|
||||
|
||||
if !self.GetDriver().IsSupportPostpaidExpire() {
|
||||
return nil, httperrors.NewBadRequestError("guest %s unsupport postpaid expire", self.Hypervisor)
|
||||
}
|
||||
|
||||
err = self.SaveRenewInfo(ctx, userCred, &bc, nil)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (self *SGuest) AllowPerformRenew(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool {
|
||||
return db.IsAdminAllowPerform(userCred, self, "renew")
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ type IGuestDriver interface {
|
||||
GetMinimalSysDiskSizeGb() int
|
||||
|
||||
IsSupportedBillingCycle(bc billing.SBillingCycle) bool
|
||||
IsSupportPostpaidExpire() bool
|
||||
|
||||
RequestRenewInstance(guest *SGuest, bc billing.SBillingCycle) (time.Time, error)
|
||||
|
||||
|
||||
@@ -2198,7 +2198,9 @@ func (self *SGuest) syncWithCloudVM(ctx context.Context, userCred mcclient.Token
|
||||
|
||||
self.IsEmulated = extVM.IsEmulated()
|
||||
|
||||
if provider.GetFactory().IsSupportPrepaidResources() && !recycle {
|
||||
if provider.GetFactory().IsSupportPrepaidResources() && !recycle &&
|
||||
!extVM.GetExpiredAt().IsZero() {
|
||||
|
||||
self.BillingType = extVM.GetBillingType()
|
||||
self.ExpiredAt = extVM.GetExpiredAt()
|
||||
}
|
||||
|
||||
@@ -773,6 +773,27 @@ func (d *SUbuntuRootFs) DisableSerialConcole(rootFs IDiskPartition) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type SKylinRootfs struct {
|
||||
*SUbuntuRootFs
|
||||
}
|
||||
|
||||
func NewKylinRootfs(part IDiskPartition) *SKylinRootfs {
|
||||
return &SKylinRootfs{SUbuntuRootFs: NewUbuntuRootFs(part).(*SUbuntuRootFs)}
|
||||
}
|
||||
|
||||
func (d *SKylinRootfs) GetName() string {
|
||||
return "Kylin"
|
||||
}
|
||||
|
||||
func (d *SKylinRootfs) String() string {
|
||||
return "KylinuRootFs"
|
||||
}
|
||||
|
||||
func (d *SKylinRootfs) RootSignatures() []string {
|
||||
sig := d.sDebianLikeRootFs.RootSignatures()
|
||||
return append([]string{"/etc/lsb-release", "/etc/kylin-build"}, sig...)
|
||||
}
|
||||
|
||||
type sRedhatLikeRootFs struct {
|
||||
*sLinuxRootFs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user