Merge pull request #11568 from rainzm/hostdeployer/vg1

Avoid duplicate vg name causing deploy failure
This commit is contained in:
Zexi Li
2021-08-24 11:49:06 +08:00
committed by GitHub
3 changed files with 42 additions and 15 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:0.6
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.0
MAINTAINER "Yaoqi Wan wanyaoqi@yunionyun.com"
+12 -10
View File
@@ -162,16 +162,18 @@ func (d *NBDDriver) setupLVMS() (bool, error) {
lvmPartitions := []fsdriver.IDiskPartition{}
for _, part := range d.partitions {
vgname := d.findLVMPartitions(part.GetPartDev())
if len(vgname) > 0 {
log.Infof("find vg %s from %s", vgname, part.GetPartDev())
lvm := NewKVMGuestLVMPartition(part.GetPartDev(), vgname)
d.lvms = append(d.lvms, lvm)
if lvm.SetupDevice() {
if subparts := lvm.FindPartitions(); len(subparts) > 0 {
for i := 0; i < len(subparts); i++ {
lvmPartitions = append(lvmPartitions, subparts[i])
}
vg, err := findVg(part.GetPartDev())
if err != nil {
log.Errorf("unable to find vg from %s: %v", part.GetPartDev(), err)
continue
}
log.Infof("find vg %s from %s", vg.Name, part.GetPartDev())
lvm := NewKVMGuestLVMPartition(part.GetPartDev(), vg)
d.lvms = append(d.lvms, lvm)
if lvm.SetupDevice() {
if subparts := lvm.FindPartitions(); len(subparts) > 0 {
for i := 0; i < len(subparts); i++ {
lvmPartitions = append(lvmPartitions, subparts[i])
}
}
}
+29 -4
View File
@@ -89,6 +89,7 @@ type SKVMGuestLVMPartition struct {
// if need to modify the name when putting down
needChangeName bool
vgid string
}
func findVgname(partDev string) string {
@@ -108,11 +109,35 @@ func findVgname(partDev string) string {
return ""
}
func NewKVMGuestLVMPartition(partDev, originVgname string) *SKVMGuestLVMPartition {
type SVG struct {
Id string
Name string
}
func findVg(partDev string) (SVG, error) {
command := procutils.NewCommand("vgs", "-v", "--devices", partDev)
output, err := command.Output()
if err != nil {
return SVG{}, errors.Wrapf(err, "unable to exec command %q", command)
}
log.Debugf("command: %s\noutput: %s", command, output)
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
if len(lines) <= 1 {
return SVG{}, fmt.Errorf("unable to find vg, output is %q", output)
}
data := regexp.MustCompile(`\s+`).Split(strings.TrimSpace(lines[len(lines)-1]), -1)
if len(data) < 1 || len(data) < 9 {
return SVG{}, fmt.Errorf("The output is not as expected: %q", output)
}
return SVG{data[8], data[0]}, nil
}
func NewKVMGuestLVMPartition(partDev string, vg SVG) *SKVMGuestLVMPartition {
return &SKVMGuestLVMPartition{
partDev: partDev,
originVgname: originVgname,
originVgname: vg.Name,
vgname: uuidWithoutLine(),
vgid: vg.Id,
}
}
@@ -122,10 +147,10 @@ func uuidWithoutLine() string {
}
func (p *SKVMGuestLVMPartition) SetupDevice() bool {
if len(p.originVgname) == 0 {
if len(p.vgid) == 0 {
return false
}
if !p.vgRename(p.originVgname, p.vgname) {
if !p.vgRename(p.vgid, p.vgname) {
return false
}
p.needChangeName = true