mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(host): lvm disk create from esxi (#22426)
This commit is contained in:
@@ -125,10 +125,12 @@ func DoDeployGuestFs(rootfs fsdriver.IRootFsDriver, guestDesc *deployapi.GuestDe
|
||||
}
|
||||
|
||||
if err := rootfs.DeployHostname(partition, hn, domain); err != nil {
|
||||
return nil, errors.Wrap(err, "DeployHostname")
|
||||
//return nil, errors.Wrap(err, "DeployHostname")
|
||||
log.Errorf("DeployHostname failed %s", err)
|
||||
}
|
||||
if err := rootfs.DeployHosts(partition, hn, domain, ips); err != nil {
|
||||
return nil, errors.Wrap(err, "DeployHosts")
|
||||
//return nil, errors.Wrap(err, "DeployHosts")
|
||||
log.Errorf("DeployHosts failed %s", err)
|
||||
}
|
||||
|
||||
if guestDesc.Hypervisor == comapi.HYPERVISOR_KVM {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostutils"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman/lvmutils"
|
||||
"yunion.io/x/onecloud/pkg/hostman/storageman/storageutils"
|
||||
@@ -112,11 +113,19 @@ func (d *SLVMDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat string,
|
||||
|
||||
img, err := qemuimg.NewQemuImage(d.GetPath())
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
log.Errorf("NewQemuImage failed %s %s", d.GetPath(), err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
qcow2Size := lvmutils.GetQcow2LvSize(int64(sizeMB))
|
||||
if sizeMB <= 0 && back != "" {
|
||||
backImg, err := qemuimg.NewQemuImage(back)
|
||||
if err != nil {
|
||||
log.Errorf("NewQemuImage failed %s %s", back, err)
|
||||
return nil, err
|
||||
}
|
||||
qcow2Size = lvmutils.GetQcow2LvSize(int64(backImg.GetSizeMB()))
|
||||
}
|
||||
err = lvmutils.LvCreate(d.Storage.GetPath(), d.Id, qcow2Size*1024*1024)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "CreateRaw")
|
||||
@@ -146,6 +155,16 @@ func (d *SLVMDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat string,
|
||||
}
|
||||
|
||||
func (d *SLVMDisk) Delete(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
|
||||
p := params.(api.DiskDeleteInput)
|
||||
if p.EsxiFlatFilePath != "" {
|
||||
connections := &deployapi.EsxiDisksConnectionInfo{Disks: []*deployapi.EsxiDiskInfo{{DiskPath: p.EsxiFlatFilePath}}}
|
||||
_, err := deployclient.GetDeployClient().DisconnectEsxiDisks(ctx, connections)
|
||||
if err != nil {
|
||||
log.Errorf("Disconnect %s esxi disks failed %s", p.EsxiFlatFilePath, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := lvmutils.LvRemove(d.GetLvPath()); err != nil {
|
||||
return nil, errors.Wrap(err, "Delete lvremove")
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package storageman
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/cloudmux/pkg/cloudprovider"
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -61,14 +62,16 @@ func (d *SSLVMDisk) Probe() error {
|
||||
}
|
||||
|
||||
diskPath := d.GetPath()
|
||||
storageBasePath := path.Join("/dev", d.Storage.GetPath())
|
||||
for diskPath != "" {
|
||||
qemuImg, err := qemuimg.NewQemuImage(diskPath)
|
||||
if err != nil {
|
||||
log.Errorln(err)
|
||||
return err
|
||||
}
|
||||
diskPath = qemuImg.BackFilePath
|
||||
if qemuImg.BackFilePath != "" {
|
||||
|
||||
if qemuImg.BackFilePath != "" && strings.HasPrefix(qemuImg.BackFilePath, storageBasePath) {
|
||||
diskPath = qemuImg.BackFilePath
|
||||
originActivated, err := lvmutils.LvIsActivated(qemuImg.BackFilePath)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "check lv is activated")
|
||||
@@ -78,6 +81,8 @@ func (d *SSLVMDisk) Probe() error {
|
||||
return errors.Wrap(err, "lv active origin")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
diskPath = ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user