Automated cherry pick of #23072: fix(host): cephutil and nbd ipv6 compat (#23073)

* fix(region,host,host-image): host-image and qemu-nbd compat ipv6

* fix(host,host-deployer): cephutils add ipv6 compat
This commit is contained in:
wanyaoqi
2025-08-14 18:34:44 +08:00
committed by GitHub
parent d10a322aec
commit d48bab9ddd
6 changed files with 21 additions and 6 deletions
+3 -1
View File
@@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"fmt"
"net"
"net/http"
"net/url"
"sort"
@@ -1364,7 +1365,8 @@ func (hh *SHost) GetFetchUrl(disableHttps bool) string {
port = 80
}
}
return fmt.Sprintf("%s://%s:%d", managerUrl.Scheme, strings.Split(managerUrl.Host, ":")[0], port+40000)
return fmt.Sprintf("%s://%s", managerUrl.Scheme, net.JoinHostPort(managerUrl.Hostname(), strconv.Itoa(port+40000)))
}
func (hh *SHost) GetAttachedEnabledHostStorages(storageType []string) []SStorage {
+2 -2
View File
@@ -104,14 +104,14 @@ func (m *SNbdExportManager) QemuNbdStartExport(imageInfo qemuimg.SImageInfo, dis
if imageInfo.Encrypted() {
cmd = []string{
qemutils.GetQemuNbd(),
"--read-only", "--persistent", "-x", diskId, "-p", strconv.Itoa(nbdPort),
"--read-only", "--persistent", "-x", diskId, "-b", "::", "-p", strconv.Itoa(nbdPort),
"--object", imageInfo.SecretOptions(),
"--image-opts", imageInfo.ImageOptions(),
}
} else {
cmd = []string{
qemutils.GetQemuNbd(),
"--read-only", "--persistent", "-x", diskId, "-p", strconv.Itoa(nbdPort),
"--read-only", "--persistent", "-x", diskId, "-b", "::", "-p", strconv.Itoa(nbdPort),
imageInfo.Path,
}
}
+1 -1
View File
@@ -660,7 +660,7 @@ func (d *QemuBaseDriver) startCmds(
disksPath = []string{imageInfo.Path}
}
for i, diskPath := range disksPath {
diskDrive := __("-drive file=%s,if=none,id=drive_%d,cache=none", diskPath, i)
diskDrive := __("-drive file=%s,if=none,id=drive_%d,cache=none", strings.ReplaceAll(diskPath, "\\", "\\\\"), i)
if imageInfo.Format != qemuimgfmt.RAW && imageInfo.Encrypted() {
diskDrive += ",encrypt.format=luks,encrypt.key-secret=sec0"
}
+4 -1
View File
@@ -18,8 +18,10 @@ import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"path"
"strconv"
"strings"
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -234,7 +236,8 @@ func (d *SLocalDisk) CreateFromRemoteHostImage(ctx context.Context, url string,
return errors.Wrap(err, "RequestExportNbdImage")
}
remoteHostIp := netutils2.ParseIpFromUrl(url)
nbdImagePath := fmt.Sprintf("nbd://%s:%d/%s", remoteHostIp, nbdPort, d.GetId())
remoteHostAndPort := net.JoinHostPort(remoteHostIp, strconv.Itoa(int(nbdPort)))
nbdImagePath := fmt.Sprintf("nbd://%s/%s", remoteHostAndPort, d.GetId())
log.Infof("remote nbd image exported %s", nbdImagePath)
newImg, err := qemuimg.NewQemuImage(d.getPath())
+4 -1
View File
@@ -17,7 +17,9 @@ package storageman
import (
"context"
"fmt"
"net"
"path"
"strconv"
"strings"
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -184,7 +186,8 @@ func (d *SLVMDisk) CreateFromRemoteHostImage(ctx context.Context, url string, si
log.Infof("Create from remote host image %s", url)
nbdPort, err := d.RequestExportNbdImage(ctx, url, encryptInfo)
remoteHostIp := netutils2.ParseIpFromUrl(url)
nbdImagePath := fmt.Sprintf("nbd://%s:%d/%s", remoteHostIp, nbdPort, d.GetId())
remoteHostAndPort := net.JoinHostPort(remoteHostIp, strconv.Itoa(int(nbdPort)))
nbdImagePath := fmt.Sprintf("nbd://%s/%s", remoteHostAndPort, d.GetId())
log.Infof("remote nbd image exported %s", nbdImagePath)
newImg, err := qemuimg.NewQemuImage(d.GetPath())
+7
View File
@@ -291,6 +291,13 @@ keyring = %s
func CephConfString(monHost, key string, radosMonOpTimeout, radosOsdOpTimeout, clientMountTimeout int64) string {
conf := []string{}
monHosts := strings.Split(monHost, ",")
for i := range monHosts {
if strings.Contains(monHosts[i], ":") {
monHosts[i] = `\[` + strings.ReplaceAll(monHosts[i], ":", `\:`) + `\]`
}
}
monHost = strings.Join(monHosts, ",")
conf = append(conf, "mon_host="+strings.ReplaceAll(monHost, ",", `\;`))
if len(key) > 0 {
for _, k := range []string{":", "@", "="} {