temp commit

This commit is contained in:
Qiu Jian
2018-12-02 02:11:50 +08:00
parent f30c79d969
commit 7aa31407a7
7 changed files with 77 additions and 7 deletions
-1
View File
@@ -16,7 +16,6 @@ import (
"yunion.io/x/pkg/utils"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/compute/models"
+2 -3
View File
@@ -12,7 +12,6 @@ import (
"yunion.io/x/pkg/util/compare"
"yunion.io/x/pkg/utils"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
@@ -344,12 +343,12 @@ func (self *SQcloudGuestDriver) RequestSyncConfigOnHost(ctx context.Context, gue
return nil, err
}
for _, disk := range removed {
if err := iVM.DetachDisk(disk.GetId()); err != nil {
if err := iVM.DetachDisk(ctx, disk.GetId()); err != nil {
return nil, err
}
}
for _, disk := range added {
if err := iVM.AttachDisk(disk.ExternalId); err != nil {
if err := iVM.AttachDisk(ctx, disk.ExternalId); err != nil {
return nil, err
}
}
+2 -2
View File
@@ -8,8 +8,8 @@ const (
)
type SBillingResourceBase struct {
BillingType string `width:"36" charset:"ascii" nullable:"true" default:"postpaid" list:"user" create:"optional"`
ExpiredAt time.Time `nullable:"true" list:"user" create:"optional"`
BillingType string `width:"36" charset:"ascii" nullable:"true" default:"postpaid" list:"user" create:"admin_optional"`
ExpiredAt time.Time `nullable:"true" list:"user" create:"admin_optional"`
}
func (self *SBillingResourceBase) GetChargeType() string {
+6
View File
@@ -1109,6 +1109,9 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
return nil, httperrors.NewBadRequestError("Params vcpu_count parse error")
}
addCpu = int(nVcpu - int64(self.VcpuCount))
if addCpu < 0 {
addCpu = 0
}
}
vmemSize, err := data.GetString("vmem_size")
if err == nil {
@@ -1124,6 +1127,9 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
return nil, httperrors.NewBadRequestError("Params vmem_size parse error")
}
addMem = nVmem - self.VmemSize
if addMem < 0 {
addMem = 0
}
}
}
+37
View File
@@ -0,0 +1,37 @@
package aws
import (
"github.com/aws/aws-sdk-go/service/ec2"
"yunion.io/x/log"
)
func (self *SRegion) GetReservedInstance() error {
params := &ec2.DescribeReservedInstancesInput{}
res, err := self.ec2Client.DescribeReservedInstances(params)
if err != nil {
log.Errorf("DescribeReservedInstances fail %s", err)
return err
}
log.Debugf("%#v", res)
return nil
}
type SReservedHostOffering struct {
Duration int
HourlyPrice float64
InstanceFamily string
OfferingId string
PaymentOption string
UpfrontPrice float64
}
func (self *SRegion) GetReservedHostOfferings() error {
res, err := self.ec2Client.DescribeHostReservationOfferings(nil)
if err != nil {
log.Errorf("DescribeHostReservationOfferings fail %s", err)
return err
}
log.Debugf("%#v", res)
return nil
}
+3 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"context"
"yunion.io/x/onecloud/pkg/util/aws"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
@@ -134,7 +135,8 @@ func init() {
}
shellutils.R(&InstanceRebuildRootOptions{}, "instance-rebuild-root", "Reinstall virtual server system image", func(cli *aws.SRegion, args *InstanceRebuildRootOptions) error {
diskID, err := cli.ReplaceSystemDisk(args.ID, args.Image, args.Size)
ctx := context.Background()
diskID, err := cli.ReplaceSystemDisk(ctx, args.ID, args.Image, args.Size)
if err != nil {
return err
}
+27
View File
@@ -0,0 +1,27 @@
package shell
import (
"yunion.io/x/onecloud/pkg/util/aws"
"yunion.io/x/onecloud/pkg/util/shellutils"
)
func init() {
type ReservedInstanceListOptions struct {
Id []string `help:"IDs of instances to show"`
Zone string `help:"Zone ID"`
Limit int `help:"page size"`
Offset int `help:"page offset"`
}
shellutils.R(&ReservedInstanceListOptions{}, "reserved-instance-list", "List intances", func(cli *aws.SRegion, args *ReservedInstanceListOptions) error {
e := cli.GetReservedInstance()
if e != nil {
return e
}
e = cli.GetReservedHostOfferings()
if e != nil {
return e
}
return nil
})
}