From 39948899106f01516a9a2fe5afe21b68b32c5d67 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Thu, 23 Jul 2020 21:31:39 +0800 Subject: [PATCH] rename vgname centos --- .../hostdeployer/deployserver/deployserver.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pkg/hostman/hostdeployer/deployserver/deployserver.go b/pkg/hostman/hostdeployer/deployserver/deployserver.go index e0c2558844..eb2b89acf2 100644 --- a/pkg/hostman/hostdeployer/deployserver/deployserver.go +++ b/pkg/hostman/hostdeployer/deployserver/deployserver.go @@ -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 }