mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Automatic merge from release/2.7.0 -> release/2.8.0
* commit 'd7c587bf4b4ffe939a408707225af52c2859ab33': fix: 1. vmware detch disk logic error 2. host add storage commit_rate 3. host enable netif failed if a fake ipaddr is given
This commit is contained in:
@@ -268,3 +268,7 @@ func (self *SBaseGuestDriver) GetLinuxDefaultAccount(desc cloudprovider.SManaged
|
||||
func (self *SBaseGuestDriver) OnGuestChangeCpuMemFailed(ctx context.Context, guest *models.SGuest, data *jsonutils.JSONDict, task taskman.ITask) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SBaseGuestDriver) RequestSyncConfigOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
return fmt.Errorf("SBaseGuestDriver: Not Implement")
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ func (self *SESXiGuestDriver) GetMinimalSysDiskSizeGb() int {
|
||||
return options.Options.DefaultDiskSizeMB / 1024
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestSyncConfigOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
// func (self *SESXiGuestDriver) RequestSyncConfigOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
// task.ScheduleRun(nil)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (self *SESXiGuestDriver) GetMaxSecurityGroupCount() int {
|
||||
//暂不支持绑定安全组
|
||||
@@ -49,11 +49,11 @@ func (self *SESXiGuestDriver) GetMaxSecurityGroupCount() int {
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) GetDetachDiskStatus() ([]string, error) {
|
||||
return []string{models.VM_READY}, nil
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) GetAttachDiskStatus() ([]string, error) {
|
||||
return []string{models.VM_READY}, nil
|
||||
return []string{models.VM_READY, models.VM_RUNNING}, nil
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) GetChangeConfigStatus() ([]string, error) {
|
||||
@@ -64,14 +64,14 @@ func (self *SESXiGuestDriver) CanKeepDetachDisk() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SESXiGuestDriver) RequestDeleteDetachedDisk(ctx context.Context, disk *models.SDisk, task taskman.ITask, isPurge bool) error {
|
||||
err := disk.RealDelete(ctx, task.GetUserCred())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
task.ScheduleRun(nil)
|
||||
return nil
|
||||
}
|
||||
// func (self *SESXiGuestDriver) RequestDeleteDetachedDisk(ctx context.Context, disk *models.SDisk, task taskman.ITask, isPurge bool) error {
|
||||
// err := disk.RealDelete(ctx, task.GetUserCred())
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// task.ScheduleRun(nil)
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (self *SESXiGuestDriver) RequestGuestHotAddIso(ctx context.Context, guest *models.SGuest, path string, task taskman.ITask) error {
|
||||
task.ScheduleRun(nil)
|
||||
|
||||
@@ -717,7 +717,7 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncConfigOnHost(ctx context.
|
||||
return nil, err
|
||||
}
|
||||
for _, disk := range removed {
|
||||
if err := iVM.DetachDisk(ctx, disk.GetId()); err != nil {
|
||||
if err := iVM.DetachDisk(ctx, disk.GetGlobalId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -731,53 +731,6 @@ func (self *SManagedVirtualizedGuestDriver) RequestSyncConfigOnHost(ctx context.
|
||||
return nil
|
||||
}
|
||||
|
||||
/*func (self *SManagedVirtualizedGuestDriver) RequestSyncConfigOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
|
||||
taskman.LocalTaskRun(task, func() (jsonutils.JSONObject, error) {
|
||||
if ihost, err := host.GetIHost(); err != nil {
|
||||
return nil, err
|
||||
} else if iVM, err := ihost.GetIVMById(guest.ExternalId); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if fw_only, _ := task.GetParams().Bool("fw_only"); fw_only {
|
||||
if err := iVM.SyncSecurityGroup(guest.SecgrpId, guest.GetSecgroupName(), guest.GetSecRules()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if iDisks, err := iVM.GetIDisks(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
disks := make([]models.SDisk, 0)
|
||||
for _, guestdisk := range guest.GetDisks() {
|
||||
disk := guestdisk.GetDisk()
|
||||
disks = append(disks, *disk)
|
||||
}
|
||||
|
||||
added := make([]models.SDisk, 0)
|
||||
commondb := make([]models.SDisk, 0)
|
||||
commonext := make([]cloudprovider.ICloudDisk, 0)
|
||||
removed := make([]cloudprovider.ICloudDisk, 0)
|
||||
|
||||
if err := compare.CompareSets(disks, iDisks, &added, &commondb, &commonext, &removed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, disk := range removed {
|
||||
if err := iVM.DetachDisk(ctx, disk.GetId()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for _, disk := range added {
|
||||
if err := iVM.AttachDisk(ctx, disk.ExternalId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
return nil
|
||||
}*/
|
||||
|
||||
func (self *SManagedVirtualizedGuestDriver) RequestRenewInstance(guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
|
||||
iVM, err := guest.GetIVM()
|
||||
if err != nil {
|
||||
|
||||
+33
-10
@@ -962,24 +962,43 @@ func (self *SHost) GetHardwareSpecification() *jsonutils.JSONDict {
|
||||
}
|
||||
|
||||
type SStorageCapacity struct {
|
||||
Capacity int
|
||||
Used int
|
||||
Wasted int
|
||||
VCapacity int
|
||||
Capacity int `json:"capacity,omitzero"`
|
||||
Used int `json:"used_capacity,omitzero"`
|
||||
Wasted int `json:"waste_capacity,omitzero"`
|
||||
VCapacity int `json:"virtual_capacity,omitzero"`
|
||||
}
|
||||
|
||||
func (capa SStorageCapacity) GetFree() int {
|
||||
return capa.VCapacity - capa.Used - capa.Wasted
|
||||
func (cap *SStorageCapacity) GetFree() int {
|
||||
return cap.VCapacity - cap.Used - cap.Wasted
|
||||
}
|
||||
|
||||
func (cap *SStorageCapacity) GetCommitRate() float64 {
|
||||
if cap.Capacity > 0 {
|
||||
return float64(int(float64(cap.Used)*100.0/float64(cap.Capacity)+0.5) / 100.0)
|
||||
} else {
|
||||
return 0.0
|
||||
}
|
||||
}
|
||||
|
||||
func (cap *SStorageCapacity) Add(cap2 SStorageCapacity) {
|
||||
cap.Capacity += cap2.Capacity
|
||||
cap.Used += cap2.Used
|
||||
cap.Wasted += cap2.Wasted
|
||||
cap.VCapacity += cap2.VCapacity
|
||||
}
|
||||
|
||||
func (cap *SStorageCapacity) ToJson() *jsonutils.JSONDict {
|
||||
ret := jsonutils.Marshal(cap).(*jsonutils.JSONDict)
|
||||
ret.Add(jsonutils.NewFloat(cap.GetCommitRate()), "commit_rate")
|
||||
ret.Add(jsonutils.NewInt(int64(cap.GetFree())), "free_capacity")
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *SHost) GetAttachedStorageCapacity() SStorageCapacity {
|
||||
ret := SStorageCapacity{}
|
||||
storages := self.GetAttachedStorages("")
|
||||
for _, s := range storages {
|
||||
ret.Capacity += s.GetCapacity()
|
||||
ret.Used += s.GetUsedCapacity(tristate.True)
|
||||
ret.Wasted += s.GetUsedCapacity(tristate.False)
|
||||
ret.VCapacity += int(float32(s.GetCapacity()) * s.GetOvercommitBound())
|
||||
ret.Add(s.getStorageCapacity())
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -2186,6 +2205,7 @@ func (self *SHost) getMoreDetails(ctx context.Context, extra *jsonutils.JSONDict
|
||||
extra.Add(jsonutils.NewInt(int64(capa.Wasted)), "storage_waste")
|
||||
extra.Add(jsonutils.NewInt(int64(capa.VCapacity)), "storage_virtual")
|
||||
extra.Add(jsonutils.NewInt(int64(capa.GetFree())), "storage_free")
|
||||
extra.Add(jsonutils.NewFloat(capa.GetCommitRate()), "storage_commit_rate")
|
||||
extra.Add(self.GetHardwareSpecification(), "spec")
|
||||
|
||||
// extra = self.SManagedResourceBase.getExtraDetails(ctx, extra)
|
||||
@@ -3030,6 +3050,9 @@ func (self *SHost) EnableNetif(ctx context.Context, userCred mcclient.TokenCrede
|
||||
} else if requireDesignatedIp {
|
||||
log.Errorf("Cannot allocate IP %s, not reachable", ipAddr)
|
||||
return fmt.Errorf("Cannot allocate IP %s, not reachable", ipAddr)
|
||||
} else {
|
||||
// the ipaddr is not usable, should be reset to empty
|
||||
ipAddr = ""
|
||||
}
|
||||
}
|
||||
wire := netif.GetWire()
|
||||
|
||||
@@ -328,21 +328,21 @@ func (self *SStorage) GetStorageCachePath(mountPoint, imageCachePath string) str
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SStorage) getStorageCapacity() SStorageCapacity {
|
||||
capa := SStorageCapacity{}
|
||||
|
||||
capa.Capacity = self.GetCapacity()
|
||||
capa.Used = self.GetUsedCapacity(tristate.True)
|
||||
capa.Wasted = self.GetUsedCapacity(tristate.False)
|
||||
capa.VCapacity = int(float32(self.GetCapacity()) * self.GetOvercommitBound())
|
||||
|
||||
return capa
|
||||
}
|
||||
|
||||
func (self *SStorage) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict {
|
||||
used := self.GetUsedCapacity(tristate.True)
|
||||
waste := self.GetUsedCapacity(tristate.False)
|
||||
vcapa := float32(self.GetCapacity()) * self.GetOvercommitBound()
|
||||
extra.Add(jsonutils.NewInt(int64(used)), "used_capacity")
|
||||
extra.Add(jsonutils.NewInt(int64(waste)), "waste_capacity")
|
||||
extra.Add(jsonutils.NewFloat(float64(vcapa)), "virtual_capacity")
|
||||
extra.Add(jsonutils.NewFloat(float64(vcapa-float32(used)-float32(waste))), "free_capacity")
|
||||
if self.GetCapacity() > 0 {
|
||||
value := float64(used * 1.0 / self.GetCapacity())
|
||||
value = float64(int(value*100+0.5) / 100.0)
|
||||
extra.Add(jsonutils.NewFloat(value), "commit_rate")
|
||||
} else {
|
||||
extra.Add(jsonutils.NewFloat(0.0), "commit_rate")
|
||||
}
|
||||
capa := self.getStorageCapacity()
|
||||
extra.Update(capa.ToJson())
|
||||
|
||||
extra.Add(jsonutils.NewFloat(float64(self.GetOvercommitBound())), "commit_bound")
|
||||
|
||||
info := self.getCloudProviderInfo()
|
||||
|
||||
@@ -40,6 +40,7 @@ func (self *GuestSyncConfTask) OnSyncComplete(ctx context.Context, obj db.IStand
|
||||
db.OpsLog.LogEvent(guest, db.ACT_SYNC_CONF, nil, self.UserCred)
|
||||
self.SetStageComplete(ctx, guest.GetShortDesc(ctx))
|
||||
} else if data.Contains("task") {
|
||||
// XXX this is only applied to KVM, which will call task_complete twice
|
||||
self.SetStage("on_disk_sync_complete", nil)
|
||||
} else {
|
||||
self.OnDiskSyncComplete(ctx, guest, data)
|
||||
|
||||
@@ -683,3 +683,16 @@ func (self *SDatastore) RemoveDir(ctx context.Context, remotePath string) error
|
||||
func (self *SDatastore) IsSysDiskStore() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SDatastore) MoveVmdk(ctx context.Context, srcPath string, dstPath string) error {
|
||||
dm := object.NewVirtualDiskManager(self.manager.client.Client)
|
||||
defer dm.Destroy(ctx)
|
||||
|
||||
srcUrl := self.GetPathUrl(srcPath)
|
||||
dstUrl := self.GetPathUrl(dstPath)
|
||||
task, err := dm.MoveVirtualDisk(ctx, srcUrl, nil, dstUrl, nil, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return task.Wait(ctx)
|
||||
}
|
||||
|
||||
@@ -120,8 +120,14 @@ func (self *SVirtualMachine) UpdateVM(ctx context.Context, name string) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
}
|
||||
|
||||
// TODO: detach disk to a separate directory, so as to keep disk independent of VM
|
||||
|
||||
func (self *SVirtualMachine) DetachDisk(ctx context.Context, diskId string) error {
|
||||
return cloudprovider.ErrNotImplemented
|
||||
vdisk, err := self.GetIDiskById(diskId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.doDetachDisk(ctx, vdisk.(*SVirtualDisk), false)
|
||||
}
|
||||
|
||||
func (self *SVirtualMachine) AttachDisk(ctx context.Context, diskId string) error {
|
||||
|
||||
Reference in New Issue
Block a user