rename vgname centos

This commit is contained in:
wanyaoqi
2020-07-23 21:31:39 +08:00
parent 00b9ebf049
commit 3994889910
@@ -19,6 +19,7 @@ import (
"fmt"
"net"
"os"
"regexp"
"runtime/debug"
"strings"
"time"
@@ -28,6 +29,7 @@ import (
execlient "yunion.io/x/executor/client"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/stringutils"
comapi "yunion.io/x/onecloud/pkg/apis/compute"
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
@@ -43,6 +45,8 @@ import (
"yunion.io/x/onecloud/pkg/util/winutils"
)
const CENTOS_VGNAME = "centos"
type DeployerServer struct{}
func (*DeployerServer) DeployGuestFs(ctx context.Context, req *deployapi.DeployParams,
@@ -337,6 +341,27 @@ func (s *SDeployService) PrepareEnv() error {
if err != nil {
log.Errorf("Failed exec lvm command pvscan: %s", output)
}
output, err = procutils.NewCommand("vgdisplay").Output()
if err == nil {
re := regexp.MustCompile(`\s+`)
for _, line := range strings.Split(string(output), "\n") {
s := strings.TrimSpace(line)
if strings.HasPrefix(s, "VG Name") {
data := re.Split(s, -1)
if len(data) == 3 {
vgName := data[2]
if vgName == CENTOS_VGNAME {
vgNewName := stringutils.UUID4()
output, err := procutils.NewCommand("vgrename", vgName, vgNewName).Output()
if err != nil {
log.Errorf("vg rename failed %s %s", err, output)
}
log.Infof("vg name %s rename to %s success", vgName, vgNewName)
}
}
}
}
}
return nil
}