Merge pull request #1801 from tb365/feature/tb-ucloud-bugfix

ucloud bugfix
This commit is contained in:
yunion-ci-robot
2019-07-19 15:40:06 +08:00
committed by GitHub
10 changed files with 86 additions and 12 deletions
+5
View File
@@ -24,6 +24,7 @@ import (
func init() {
type ParametersListOptions struct {
Name string `help:"List parameter of specificated name"`
NamespaceId string `help:"List parameter of specificated namespace id, ADMIN only"`
User string `help:"List parameter of specificated user id, ADMIN only" token:"user-id"`
Service string `help:"List parameter of specificated service id, ADMIN only"`
@@ -36,6 +37,10 @@ func init() {
return err
}
if len(args.Name) > 0 {
params.Add(jsonutils.NewString(args.Name), "name")
}
var result *modules.ListResult
if len(args.NamespaceId) > 0 {
params.Add(jsonutils.NewString(args.NamespaceId), "namespace_id")
+18 -1
View File
@@ -695,7 +695,8 @@ func (self *SManagedVirtualizedGuestDriver) RequestChangeVmConfig(ctx context.Co
return nil, err
}
}
return nil, cloudprovider.WaitCreated(time.Second*5, time.Minute*5, func() bool {
err := cloudprovider.WaitCreated(time.Second*5, time.Minute*5, func() bool {
err := iVM.Refresh()
if err != nil {
return false
@@ -706,6 +707,22 @@ func (self *SManagedVirtualizedGuestDriver) RequestChangeVmConfig(ctx context.Co
}
return false
})
if err != nil {
return nil, err
}
instanceType := iVM.GetInstanceType()
if len(instanceType) > 0 {
_, err := db.Update(guest, func() error {
guest.InstanceType = instanceType
return nil
})
if err != nil {
return nil, err
}
}
return nil, nil
})
return nil
+18
View File
@@ -818,6 +818,24 @@ func (manager *SServerSkuManager) GetSkuCountByZone(zoneId string) []SServerSku
return skus
}
func (manager *SServerSkuManager) GetSkus(provider string, cpu, memMB int) ([]SServerSku, error) {
skus := []SServerSku{}
q := manager.Query()
if provider == api.CLOUD_PROVIDER_ONECLOUD {
providerFilter := sqlchemy.OR(sqlchemy.Equals(q.Field("provider"), provider), sqlchemy.IsNullOrEmpty(q.Field("provider")))
q = q.Equals("cpu_core_count", cpu).Equals("memory_size_mb", memMB).Filter(providerFilter)
} else {
q = q.Equals("cpu_core_count", cpu).Equals("memory_size_mb", memMB).Equals("provider", provider)
}
if err := db.FetchModelObjects(manager, q, &skus); err != nil {
log.Errorf("failed to get skus with provider %s cpu %d mem %d error: %v", provider, cpu, memMB, err)
return nil, err
}
return skus, nil
}
// 删除表中zone not found的记录
func (manager *SServerSkuManager) PendingDeleteInvalidSku() error {
sq := ZoneManager.Query("id").Distinct().SubQuery()
@@ -164,6 +164,13 @@ func (self *GuestChangeConfigTask) OnGuestChangeCpuMemSpecComplete(ctx context.C
addCpu := int(vcpuCount - int64(guest.VcpuCount))
addMem := int(vmemSize - int64(guest.VmemSize))
if len(instanceType) == 0 {
skus, err := models.ServerSkuManager.GetSkus(api.CLOUD_PROVIDER_ONECLOUD, int(vcpuCount), int(vmemSize))
if err == nil && len(skus) > 0 {
instanceType = skus[0].GetName()
}
}
_, err := db.Update(guest, func() error {
if vcpuCount > 0 {
guest.VcpuCount = int(vcpuCount)
+1 -1
View File
@@ -44,7 +44,7 @@ func (this *ParametersManager) GetGlobalSettings(s *mcclient.ClientSession, para
adminSession := auth.GetAdminSession(context.Background(), "", "")
p := jsonutils.NewDict()
p.Add(jsonutils.NewString("system"), "scope")
p.Add(jsonutils.NewString("name"), "global-settings")
p.Add(jsonutils.NewString("global-settings"), "name")
parameters, err := this.ListInContext(adminSession, p, &ServicesV3, "yunionagent")
if err != nil {
return nil, err
+2 -1
View File
@@ -147,7 +147,8 @@ func (self *SRegion) GetILoadBalancerById(loadbalancerId string) (cloudprovider.
lbs[0].region = self
return &lbs[0], nil
} else {
return nil, fmt.Errorf("GetILoadBalancerById %d loadbalancer found", len(lbs))
log.Debugf("GetILoadBalancerById %s %d loadbalancer found", loadbalancerId, len(lbs))
return nil, cloudprovider.ErrNotFound
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ const (
DIGITS = "23456789"
LETTERS = "abcdefghjkmnpqrstuvwxyz"
UPPERS = "ABCDEFGHJKMNPRSTUVWXYZ"
PUNC = "()~@#$%^&*-+={}[]:;<>,.?/"
PUNC = "@$%^-+={}[]:,.?/"
ALL_DIGITS = "0123456789"
ALL_LETTERS = "abcdefghijklmnopqrstuvwxyz"
+4 -2
View File
@@ -20,6 +20,8 @@ import (
"strings"
"time"
"github.com/pkg/errors"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/utils"
@@ -233,7 +235,7 @@ func (self *SDisk) CreateISnapshot(ctx context.Context, name string, desc string
err = cloudprovider.WaitStatus(isnapshot, api.SNAPSHOT_READY, time.Second*10, time.Second*300)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "CreateISnapshot")
}
return isnapshot, nil
@@ -280,7 +282,7 @@ func (self *SDisk) Resize(ctx context.Context, newSizeMB int64) error {
defer self.storage.zone.region.AttachDisk(self.Zone, self.UHostID, self.UDiskID)
err = cloudprovider.WaitStatusWithDelay(self, api.DISK_READY, 10*time.Second, 5*time.Second, 60*time.Second)
if err != nil {
return err
return errors.Wrap(err, "DiskResize")
}
}
+26 -5
View File
@@ -21,6 +21,7 @@ import (
"strings"
"time"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
"yunion.io/x/jsonutils"
@@ -392,7 +393,12 @@ func (self *SInstance) StartVM(ctx context.Context) error {
if err != nil {
return err
}
return cloudprovider.WaitStatusWithDelay(self, api.VM_RUNNING, 10*time.Second, 10*time.Second, 600*time.Second)
err = cloudprovider.WaitStatusWithDelay(self, api.VM_RUNNING, 10*time.Second, 10*time.Second, 600*time.Second)
if err != nil {
return errors.Wrap(err, "StartVM")
}
return nil
}
func (self *SInstance) StopVM(ctx context.Context, isForce bool) error {
@@ -400,7 +406,12 @@ func (self *SInstance) StopVM(ctx context.Context, isForce bool) error {
if err != nil {
return err
}
return cloudprovider.WaitStatusWithDelay(self, api.VM_READY, 10*time.Second, 10*time.Second, 600*time.Second)
err = cloudprovider.WaitStatusWithDelay(self, api.VM_READY, 10*time.Second, 10*time.Second, 600*time.Second)
if err != nil {
return errors.Wrap(err, "StopVM")
}
return nil
}
func (self *SInstance) DeleteVM(ctx context.Context) error {
@@ -451,7 +462,7 @@ func (self *SInstance) RebuildRoot(ctx context.Context, imageId string, passwd s
err = cloudprovider.WaitStatusWithDelay(self, api.VM_RUNNING, 10*time.Second, 15*time.Second, 300*time.Second)
if err != nil {
return "", err
return "", errors.Wrap(err, "RebuildRoot")
}
disks, err := self.GetIDisks()
@@ -482,7 +493,12 @@ func (self *SInstance) DeployVM(ctx context.Context, name string, password strin
}
}
return cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second)
err := cloudprovider.WaitStatus(self, api.VM_READY, 10*time.Second, 300*time.Second)
if err != nil {
return errors.Wrap(err, "DeployVM")
}
return nil
}
func (self *SInstance) ChangeConfig(ctx context.Context, ncpu int, vmem int) error {
@@ -518,7 +534,12 @@ func (self *SInstance) DetachDisk(ctx context.Context, diskId string) error {
}
disk.storage = &SStorage{zone: self.host.zone, storageType: disk.GetStorageType()}
return cloudprovider.WaitStatusWithDelay(disk, api.DISK_READY, 10*time.Second, 10*time.Second, 60*time.Second)
err = cloudprovider.WaitStatusWithDelay(disk, api.DISK_READY, 10*time.Second, 10*time.Second, 60*time.Second)
if err != nil {
return errors.Wrap(err, "DetachDisk")
}
return nil
}
func (self *SInstance) CreateDisk(ctx context.Context, sizeMb int, uuid string, driver string) error {
+4 -1
View File
@@ -23,6 +23,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/utils"
api "yunion.io/x/onecloud/pkg/apis/compute"
@@ -233,7 +234,9 @@ func (self *SStoragecache) uploadImage(ctx context.Context, userCred mcclient.To
return false
})
if err != nil {
return "", errors.Wrap(err, "UploadImage")
}
return imgId, err
}