Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #1102: fix(ctyun): prepaid status #1103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions pkg/multicloud/ctyun/eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/timeutils"
"yunion.io/x/pkg/utils"

billing_api "yunion.io/x/cloudmux/pkg/apis/billing"
Expand All @@ -45,12 +44,12 @@ type SEip struct {
Tags string
CreatedAt time.Time
UpdatedAt time.Time
ExpiredAt string
ExpiredAt time.Time
ProjectId string
}

func (self *SEip) GetBillingType() string {
if len(self.ExpiredAt) > 0 {
if !self.ExpiredAt.IsZero() {
return billing_api.BILLING_TYPE_PREPAID
}
return billing_api.BILLING_TYPE_POSTPAID
Expand All @@ -61,11 +60,7 @@ func (self *SEip) GetCreatedAt() time.Time {
}

func (self *SEip) GetExpiredAt() time.Time {
if len(self.ExpiredAt) > 0 {
t, _ := timeutils.ParseTimeStr(self.ExpiredAt)
return t
}
return time.Time{}
return self.ExpiredAt
}

func (self *SEip) GetId() string {
Expand Down Expand Up @@ -133,7 +128,10 @@ func (self *SEip) GetBandwidth() int {
}

func (self *SEip) GetInternetChargeType() string {
return ""
if self.GetBillingType() == billing_api.BILLING_TYPE_PREPAID {
return api.EIP_CHARGE_TYPE_BY_BANDWIDTH
}
return api.EIP_CHARGE_TYPE_BY_TRAFFIC
}

func (self *SEip) Delete() error {
Expand Down
11 changes: 3 additions & 8 deletions pkg/multicloud/ctyun/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package ctyun
import (
"context"
"fmt"
"strconv"
"strings"
"time"

Expand All @@ -41,7 +40,7 @@ type SInstance struct {
image *SImage

AzName string
ExpiredTime string
ExpiredTime time.Time
CreatedTime time.Time
ProjectId string
AttachedVolume []string
Expand Down Expand Up @@ -96,7 +95,7 @@ type SInstance struct {
}

func (self *SInstance) GetBillingType() string {
if len(self.ExpiredTime) > 0 {
if !self.OnDemand {
return billing_api.BILLING_TYPE_PREPAID
}
return billing_api.BILLING_TYPE_POSTPAID
Expand All @@ -107,11 +106,7 @@ func (self *SInstance) GetCreatedAt() time.Time {
}

func (self *SInstance) GetExpiredAt() time.Time {
if len(self.ExpiredTime) > 0 {
expire, _ := strconv.Atoi(self.ExpiredTime)
return time.Unix(int64(expire/1000), 0)
}
return time.Time{}
return self.ExpiredTime
}

func (self *SInstance) GetId() string {
Expand Down
Loading