mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
utils pkg unify
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/compute/baremetal"
|
||||
"yunion.io/x/onecloud/pkg/util/fileutils"
|
||||
fileutils "yunion.io/x/onecloud/pkg/util/fileutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/ssh"
|
||||
"yunion.io/x/onecloud/pkg/util/sysutils"
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/types"
|
||||
"yunion.io/x/onecloud/pkg/util/procutils"
|
||||
"yunion.io/x/onecloud/pkg/util/ssh"
|
||||
stage_stringutils "yunion.io/x/onecloud/pkg/util/stringutils"
|
||||
stage_stringutils "yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/sysutils"
|
||||
)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/compute/baremetal"
|
||||
"yunion.io/x/onecloud/pkg/hostman/guestfs"
|
||||
"yunion.io/x/onecloud/pkg/util/ssh"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils"
|
||||
stringutils "yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
)
|
||||
|
||||
type SSHPartition struct {
|
||||
|
||||
@@ -111,7 +111,7 @@ func IsBlockDeviceUsed(dev string) bool {
|
||||
if strings.HasPrefix(dev, "/dev/") {
|
||||
dev = dev[strings.LastIndex(dev, "/")+1:]
|
||||
}
|
||||
devStr := fmt.Sprint(" %s\n", dev)
|
||||
devStr := fmt.Sprintf(" %s\n", dev)
|
||||
devs, _ := exec.Command("cat", "/proc/partitions").Output()
|
||||
if idx := strings.Index(string(devs), devStr); idx > 0 {
|
||||
return false
|
||||
@@ -525,15 +525,15 @@ func ResizePartitionFs(fpath, fs string) error {
|
||||
)
|
||||
if strings.HasPrefix(fs, "linux-swap") {
|
||||
if v, ok := uuids["UUID"]; ok {
|
||||
cmds = [][]string{[]string{"mkswap", "-U", v, fpath}}
|
||||
cmds = [][]string{{"mkswap", "-U", v, fpath}}
|
||||
} else {
|
||||
cmds = [][]string{[]string{"mkswap", fpath}}
|
||||
cmds = [][]string{{"mkswap", fpath}}
|
||||
}
|
||||
} else if strings.HasPrefix(fs, "ext") {
|
||||
if !FsckExtFs(fpath) {
|
||||
return fmt.Errorf("Failed to fsck ext fs %s", fpath)
|
||||
}
|
||||
cmds = [][]string{[]string{"resize2fs", fpath}}
|
||||
cmds = [][]string{{"resize2fs", fpath}}
|
||||
} else if fs == "xfs" {
|
||||
var tmpPoint = fmt.Sprintf("/tmp/%s", strings.Replace(fpath, "/", "_", -1))
|
||||
if err := exec.Command("mountpoint", tmpPoint).Run(); err == nil {
|
||||
@@ -544,14 +544,14 @@ func ResizePartitionFs(fpath, fs string) error {
|
||||
}
|
||||
}
|
||||
FsckXfsFs(fpath)
|
||||
cmds = [][]string{[]string{"mkdir", "-p", tmpPoint},
|
||||
[]string{"mount", fpath, tmpPoint},
|
||||
[]string{"sleep", "2"},
|
||||
[]string{"xfs_growfs", tmpPoint},
|
||||
[]string{"sleep", "2"},
|
||||
[]string{"umount", tmpPoint},
|
||||
[]string{"sleep", "2"},
|
||||
[]string{"rm", "-fr", tmpPoint}}
|
||||
cmds = [][]string{{"mkdir", "-p", tmpPoint},
|
||||
{"mount", fpath, tmpPoint},
|
||||
{"sleep", "2"},
|
||||
{"xfs_growfs", tmpPoint},
|
||||
{"sleep", "2"},
|
||||
{"umount", tmpPoint},
|
||||
{"sleep", "2"},
|
||||
{"rm", "-fr", tmpPoint}}
|
||||
}
|
||||
|
||||
if len(cmds) > 0 {
|
||||
|
||||
@@ -13,12 +13,12 @@ func TestIsBlockDeviceUsed(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "nbd1",
|
||||
args: {"/dev/nbd1"},
|
||||
args: args{"/dev/nbd1"},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "sda",
|
||||
args: {"/dev/sda"},
|
||||
args: args{"/dev/sda"},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package fileutils
|
||||
package fileutils2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/util/regutils"
|
||||
regutils "yunion.io/x/onecloud/pkg/util/regutils2"
|
||||
)
|
||||
|
||||
type Partition struct {
|
||||
@@ -111,16 +111,3 @@ func isPartedFsString(fs string) bool {
|
||||
"ntfs", "reiserfs", "ufs", "btrfs",
|
||||
})
|
||||
}
|
||||
|
||||
func FsFormatToDiskType(fsFormat string) string {
|
||||
if fsFormat == "swap" {
|
||||
return "linux-swap"
|
||||
} else if strings.HasPrefix(fsFormat, "ext") || fsFormat == "xfs" {
|
||||
return "ext2"
|
||||
} else if strings.HasPrefix(fsFormat, "fat") {
|
||||
return "fat32"
|
||||
} else if fsFormat == "ntfs" {
|
||||
return "ntfs"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package fileutils
|
||||
package fileutils2
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -1,20 +0,0 @@
|
||||
package regutils
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func SubGroupMatch(pattern string, line string) map[string]string {
|
||||
regEx := regexp.MustCompile(pattern)
|
||||
params := make(map[string]string)
|
||||
matches := regEx.FindStringSubmatch(line)
|
||||
if len(matches) == 0 {
|
||||
return params
|
||||
}
|
||||
for i, name := range regEx.SubexpNames() {
|
||||
if i > 0 && i <= len(matches) {
|
||||
params[name] = matches[i]
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
@@ -17,3 +17,18 @@ func GetParams(compRegEx *regexp.Regexp, val string) map[string]string {
|
||||
}
|
||||
return paramsMap
|
||||
}
|
||||
|
||||
func SubGroupMatch(pattern string, line string) map[string]string {
|
||||
regEx := regexp.MustCompile(pattern)
|
||||
params := make(map[string]string)
|
||||
matches := regEx.FindStringSubmatch(line)
|
||||
if len(matches) == 0 {
|
||||
return params
|
||||
}
|
||||
for i, name := range regEx.SubexpNames() {
|
||||
if i > 0 && i <= len(matches) {
|
||||
params[name] = matches[i]
|
||||
}
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package regutils
|
||||
package regutils2
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -1,4 +1,4 @@
|
||||
package stringutils
|
||||
package stringutils2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package stringutils
|
||||
package stringutils2
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
Reference in New Issue
Block a user