diff --git a/pkg/cloudcommon/types/nic.go b/pkg/cloudcommon/types/nic.go index f37ef5b942..28b222817c 100644 --- a/pkg/cloudcommon/types/nic.go +++ b/pkg/cloudcommon/types/nic.go @@ -47,6 +47,7 @@ func (n Nic) GetMac() net.HardwareAddr { type Route []string type ServerNic struct { + Index int `json:"index"` Bridge string `json:"bridge"` Domain string `json:"domain"` Ip string `json:"ip"` @@ -54,6 +55,7 @@ type ServerNic struct { Driver string `json:"driver"` Masklen int `json:"masklen"` Virtual bool `json:"virtual"` + Manual bool `json:"manual"` NetId string `json:"net_id"` Mac string `json:"mac"` BandWidth int `json:"bw"` diff --git a/pkg/hostman/utils.go b/pkg/cloudcommon/utils.go similarity index 82% rename from pkg/hostman/utils.go rename to pkg/cloudcommon/utils.go index a78f9e0012..cb8aeacb16 100644 --- a/pkg/hostman/utils.go +++ b/pkg/cloudcommon/utils.go @@ -1,4 +1,4 @@ -package hostman +package cloudcommon import ( "bufio" @@ -13,6 +13,8 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon/types" + "yunion.io/x/onecloud/pkg/hostman/options" "yunion.io/x/pkg/util/netutils" ) @@ -255,6 +257,20 @@ func (hf HostsFile) String() string { var PSEUDO_VIP = "169.254.169.231" var MASKS = []string{"0", "128", "192", "224", "240", "248", "252", "254", "255"} +var PRIVATE_PREFIXES = []string{ + "10.0.0.0/8", + "172.16.0.0/12", + "192.168.0.0/16", +} + +func GetPrivatePrefixes() []string { + if options.HostOptions.PrivatePrefixes != nil { + return options.HostOptions.PrivatePrefixes + } else { + return PRIVATE_PREFIXES + } +} + func GetMainNic(nics []jsonutils.JSONObject) (jsonutils.JSONObject, error) { var mainIp netutils.IPV4Addr var mainNic jsonutils.JSONObject @@ -277,7 +293,7 @@ func GetMainNic(nics []jsonutils.JSONObject) (jsonutils.JSONObject, error) { return mainNic, nil } -func Netlen2Mask(netmasklen int64) string { +func Netlen2Mask(netmasklen int) string { var mask = "" var segCnt = 0 for netmasklen > 0 { @@ -312,61 +328,39 @@ func addRoute(routes *[][]string, net, gw string) { *routes = append(*routes, []string{net, gw}) } - - // if len(nic.Routes) != 0 { - // for _, nicRoute := range nic.Routes { - // tRoute, err := parseNicRoute(nicRoute) - // if err != nil { - // log.Errorf("Parse route %v error: %v", nicRoute, err) - // continue - // } - // routes = append(routes, tRoute) - // } - // } - - -func parseNicRoute(route Route) (*types.Route, error) { - if len(route) != 2 { - return nil, fmt.Errorf("Invalid route format: %v", route) - } - _, dstNet, err := net.ParseCIDR(route[0]) - if err != nil { - return nil, err - } - gwIP := net.ParseIP(route[1]) - return &types.Route{ - Dst: *dstNet, - GW: gwIP, - }, nil -} - - - -func extendRoutes(routes *[][]string, nicRoutes []jsonutils.JSONObject) error { +func extendRoutes(routes *[][]string, nicRoutes []types.Route) error { for i := 0; i < len(nicRoutes); i++ { - rt, ok := nicRoutes[i].(*jsonutils.JSONArray) - if !ok { - return fmt.Errorf("Nic routes format error") - } - // 写到这里了 - rts := rt.GetStringArray() - if len(rts) < 2 { - return fmt.Errorf("Nic routes count error") - } - addRoute(routes, rts[0], rts[1]) + addRoute(routes, nicRoutes[i][0], nicRoutes[i][1]) } return nil } -func AddNicRoutes(routes *[][]string, nic jsonutils.JSONObject, mainIp string, nicCnt int) { - var nicDesc = new(SNic) - nic.Unmarshal(nicDesc) - ip, _ := nic.GetString("ip") - if mainIp == ip { +func isExitAddress(ip string) bool { + ipv4, err := netutils.NewIPV4Addr(ip) + if err != nil { + return false + } + return !netutils.IsPrivate(ipv4) || netutils.IsHostLocal(ipv4) || netutils.IsLinkLocal(ipv4) +} + +func AddNicRoutes(routes *[][]string, nicDesc *types.ServerNic, mainIp string, nicCnt int) { + if mainIp == nicDesc.Ip { return } - if nic.Contains("routes") { - nicRoutes, _ := nic.GetArray("routes") - extendRoutes(routes, nicRoutes) - } else if nic.Contains("gateway") && + if len(nicDesc.Routes) > 0 { + extendRoutes(routes, nicDesc.Routes) + } else if len(nicDesc.Gateway) > 0 && isExitAddress(nicDesc.Ip) && + nicCnt == 2 && nicDesc.Ip != mainIp && isExitAddress(mainIp) { + for _, pref := range GetPrivatePrefixes() { + addRoute(routes, pref, nicDesc.Gateway) + } + } +} + +func GetNicDns(nicdesc *types.ServerNic) []string { + dnslist := []string{} + if len(nicdesc.Dns) > 0 { + dnslist = append(dnslist, nicdesc.Dns) + } + return dnslist } diff --git a/pkg/hostman/utils_test.go b/pkg/cloudcommon/utils_test.go similarity index 96% rename from pkg/hostman/utils_test.go rename to pkg/cloudcommon/utils_test.go index e13db0f8bb..a3b4a23b34 100644 --- a/pkg/hostman/utils_test.go +++ b/pkg/cloudcommon/utils_test.go @@ -1,4 +1,4 @@ -package hostman +package cloudcommon import "testing" diff --git a/pkg/hostman/guestfs/core.go b/pkg/hostman/guestfs/core.go index e5c0cc2e62..7b6538f9a8 100644 --- a/pkg/hostman/guestfs/core.go +++ b/pkg/hostman/guestfs/core.go @@ -76,7 +76,7 @@ type IRootFsDriver interface { DeployGuestFs(IRootFsDriver, *jsonutils.JSONDict, *SDeployInfo) (jsonutils.JSONObject, error) - // PrepareFsForTemplate() error + PrepareFsForTemplate() error } type SGuestRootFsDriver struct { @@ -144,6 +144,10 @@ func (d *SGuestRootFsDriver) DeployFiles(deploys []jsonutils.JSONObject) error { return nil } +func (d *SGuestRootFsDriver) PrepareFsForTemplate() error { + return fmt.Errorf("Not Implemented") +} + func (d *SGuestRootFsDriver) DeployHostname(hn, domain string) error { return fmt.Errorf("Not Implemented") } diff --git a/pkg/hostman/guestfs/guestfs.go b/pkg/hostman/guestfs/guestfs.go index 1d99e1b1a8..70ceb2a4c0 100644 --- a/pkg/hostman/guestfs/guestfs.go +++ b/pkg/hostman/guestfs/guestfs.go @@ -8,7 +8,7 @@ import ( "time" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/hostman" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/pkg/utils" ) @@ -24,14 +24,14 @@ func NewKVMGuestDiskPartition(devPath string) *SKVMGuestDiskPartition { var res = new(SKVMGuestDiskPartition) res.partDev = devPath res.fs = res.getFsFormat() - hostman.CleanFailedMountpoints() + cloudcommon.CleanFailedMountpoints() mountPath := fmt.Sprintf("/tmp/%s", strings.Replace(devPath, "/", "_", -1)) res.SLocalGuestFS = NewLocalGuestFS(mountPath) return res } func (p *SKVMGuestDiskPartition) getFsFormat() string { - return hostman.GetFsFormat(p.partDev) + return cloudcommon.GetFsFormat(p.partDev) } func (p *SKVMGuestDiskPartition) Mount() bool { diff --git a/pkg/hostman/guestfs/linux.go b/pkg/hostman/guestfs/linux.go index 672123d8a8..b09062b68b 100644 --- a/pkg/hostman/guestfs/linux.go +++ b/pkg/hostman/guestfs/linux.go @@ -3,14 +3,17 @@ package guestfs import ( "fmt" "path" + "regexp" + "strconv" "strings" "syscall" "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/fstabutils" "yunion.io/x/onecloud/pkg/cloudcommon/sshkeys" - "yunion.io/x/onecloud/pkg/hostman" + "yunion.io/x/onecloud/pkg/cloudcommon/types" "yunion.io/x/onecloud/pkg/hostman/options" "yunion.io/x/onecloud/pkg/util/seclib2" "yunion.io/x/pkg/utils" @@ -41,7 +44,7 @@ func (l *SLinuxRootFs) DeployHost(hn, domain string, ips []string) error { } oldHostFile = string(oldhf) } - hf := make(hostman.HostsFile, 0) + hf := make(cloudcommon.HostsFile, 0) hf.Parse(oldHostFile) hf.Add("127.0.0.1", "localhost") for _, ip := range ips { @@ -324,6 +327,9 @@ func (l *SLinuxRootFs) GetSerialPorts() []string { } } +// TODO: _enable_serial_console_init_centos, _enable_serial_console_init, +// _disable_serial_console_init, _enable_serial_console_systemd, _disable_serial_console_systemd + type SDebianLikeRootFs struct { *SLinuxRootFs } @@ -349,7 +355,7 @@ func (d *SDebianLikeRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) cmds := "" cmds += "auto lo\n" cmds += "iface lo inet loopback\n\n" - mainNic, err := hostman.GetMainNic(nics) + mainNic, err := cloudcommon.GetMainNic(nics) if err != nil { return err } @@ -358,6 +364,11 @@ func (d *SDebianLikeRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) mainIp, _ := mainNic.GetString("ip") } for _, nic := range nics { + var nicDesc = new(types.ServerNic) + err := nic.Unmarshal(nicDesc) + if err != nil { + return err + } nicIdx, err := nic.Int("index") if err != nil { return err @@ -365,15 +376,11 @@ func (d *SDebianLikeRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) cmds += fmt.Sprintf("auto eth%d\n", nicIdx) if jsonutils.QueryBoolean(nic, "virtual", false) { cmds += fmt.Sprintf("iface eth%d inet static\n", nicIdx) - cmds += fmt.Sprintf(" address %s\n", hostman.PSEUDO_VIP) + cmds += fmt.Sprintf(" address %s\n", cloudcommon.PSEUDO_VIP) cmds += " netmask 255.255.255.255\n" cmds += "\n" } else if jsonutils.QueryBoolean(nic, "manual", false) { - masklen, err := nic.Int("masklen") - if err != nil { - return err - } - netmask := hostman.Netlen2Mask(masklen) + netmask := cloudcommon.Netlen2Mask(nicDesc.Masklen) ip, err := nic.GetString("ip") if err != nil { return err @@ -381,14 +388,26 @@ func (d *SDebianLikeRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) cmds += fmt.Sprintf("iface eth%d inet static\n", nicIdx) cmds += fmt.Sprintf(" address %s\n", ip) cmds += fmt.Sprintf(" netmask %s\n", netmask) - if nic.Contains("gateway") && ip == mainIp { - gateway, _ := nic.GetString("gateway") - cmds += fmt.Sprintf(" gateway %s\n", gateway) + if len(nicDesc.Gateway) > 0 && ip == mainIp { + cmds += fmt.Sprintf(" gateway %s\n", nicDesc.Gateway) } var routes = make([][]string, 0) - hostman.AddNicRoutes(&routes, nic, mainIp, len(nics)) + cloudcommon.AddNicRoutes(&routes, nicDesc, mainIp, len(nics)) + for _, r := range routes { + cmds += fmt.Sprintf(" up route add -net %s gw %s || true\n", r[0], r[1]) + cmds += fmt.Sprintf(" down route del -net %s gw %s || true\n", r[0], r[1]) + } + dnslist := cloudcommon.GetNicDns(nicDesc) + if len(dnslist) > 0 { + cmds += fmt.Sprintf(" dns-nameservers %s\n", strings.Join(dnslist, " ")) + cmds += fmt.Sprintf(" dns-search %s\n", nicDesc.Domain) + } + cmds += "\n" + } else { + cmds += fmt.Sprintf("iface eth%d inet dhcp\n\n", nicIdx) } } + return d.rootFs.FilePutContents(fn, cmds, false, false) } type SDebianRootFs struct { @@ -431,6 +450,161 @@ func NewRedhatLikeRootFs(part *SKVMGuestDiskPartition) IRootFsDriver { return &SRedhatLikeRootFs{SLinuxRootFs: NewLinuxRootFs(part).(*SLinuxRootFs)} } +func (r *SRedhatLikeRootFs) RootSignatures() []string { + sig := r.SLinuxRootFs.RootSignatures() + return append([]string{"/etc/sysconfig/network", "/etc/redhat-release"}, sig...) +} + +func (r *SRedhatLikeRootFs) DeployHostname(hn, domain string) error { + var sPath = "/etc/sysconfig/network" + centosHn := "" + centosHn += "NETWORKING=yes\n" + centosHn += fmt.Sprintf("HOSTNAME=%s.%s\n", hn, domain) + if err := r.rootFs.FilePutContents(sPath, centosHn, false, false); err != nil { + return err + } + if r.rootFs.Exists("/etc/hostname", false) { + return r.rootFs.FilePutContents("/etc/hostname", hn, false, false) + } + return nil +} + +/* + udev_path = '/etc/udev/rules.d/' + if self.root_fs.exists(udev_path): + nic_rules = '' + for nic in nics: + nic_rules += 'KERNEL=="eth*", ' + nic_rules += 'SYSFS{address}=="%s", ' % (nic['mac'].lower()) + nic_rules += 'NAME="eth%d"\n' % (nic['index']) + print nic_rules + self.root_fs.file_put_contents(os.path.join(udev_path, '60-net.rules'), nic_rules) +*/ + +func (r *SRedhatLikeRootFs) Centos5DeployNetworkingScripts(nics []jsonutils.JSONObject) error { + var udevPath = "/etc/udev/rules.d/" + if r.rootFs.Exists(udevPath, false) { + var nicRules = "" + for _, nic := range nics { + var nicdesc = new(types.ServerNic) + if err := nic.Unmarshal(nicdesc); err != nil { + return err + } + nicRules += `KERNEL=="eth*", ` + nicRules += fmt.Sprintf(`SYSFS{address}=="%s", `, strings.ToLower(nicdesc.Mac)) + nicRules += fmt.Sprintf(`NAME="eth%d"\`, nicdesc.Index) + } + return r.rootFs.FilePutContents(udevPath, nicRules, false, false) + } + return nil +} + +func (r *SRedhatLikeRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) error { + relinfo := r.GetReleaseInfo() + ver := strings.Split(relinfo[0], ".") + iv, err := strconv.ParseInt(ver[0], 10, 0) + if err != nil { + return err + } + if iv < 6 { + err = r.Centos5DeployNetworkingScripts(nics) + } else { + err = r.SLinuxRootFs.DeployNetworkingScripts(nics) + } + if err != nil { + return err + } + mainNic, err := cloudcommon.GetMainNic(nics) + if err != nil { + return err + } + var mainIp string + if mainNic != nil { + mainIp, _ = mainNic.GetString("ip") + } + for _, nic := range nics { + var cmds string + var nicdesc = new(types.ServerNic) + if err := nic.Unmarshal(nicdesc); err != nil { + return err + } + cmds += fmt.Sprintf("DEVICE=eth%d\n", nicdesc.Index) + cmds += fmt.Sprintf("NAME=eth%d\n", nicdesc.Index) + cmds += fmt.Sprintf("HWADDR=%s\n", nicdesc.Mac) + cmds += fmt.Sprintf("MACADDR=%s\n", nicdesc.Mac) + if nicdesc.Virtual { + cmds += "BOOTPROTO=none\n" + cmds += "NETMASK=255.255.255.255\n" + cmds += fmt.Sprintf("IPADDR=%s\n", cloudcommon.PSEUDO_VIP) + cmds += "USERCTL=no\n" + } else if nicdesc.Manual { + netmask := cloudcommon.Netlen2Mask(nicdesc.Masklen) + cmds += "BOOTPROTO=none\n" + cmds += fmt.Sprintf("NETMASK=%s\n", netmask) + cmds += fmt.Sprintf("IPADDR=%s\n", nicdesc.Ip) + cmds += "USERCTL=no\n" + if len(nicdesc.Gateway) > 0 && nicdesc.Ip == mainIp { + cmds += fmt.Sprintf("GATEWAY=%s\n", nicdesc.Gateway) + } + var routes = make([][]string, 0) + var rtbl string + cloudcommon.AddNicRoutes(&routes, nicdesc, mainIp, len(nics)) + for _, r := range routes { + rtbl += fmt.Sprintf("%s via %s dev eth%d\n", r[0], r[1], nicdesc.Index) + } + if len(rtbl) > 0 { + var fn = fmt.Sprintf("/etc/sysconfig/network-scripts/route-eth%d", nicdesc.Index) + if err := r.rootFs.FilePutContents(fn, rtbl, false, false); err != nil { + return err + } + } + dnslist := cloudcommon.GetNicDns(nicdesc) + if len(dnslist) > 0 { + cmds += "PEERDNS=yes\n" + for i := 0; i < len(dnslist); i++ { + cmds += fmt.Sprintf("DNS%d=%s\n", i+1, dnslist[i]) + } + cmds += fmt.Sprintf("DOMAIN=%s\n", nicdesc.Domain) + } + } else { + cmds += "BOOTPROTO=dhcp\n" + } + var fn = fmt.Sprintf("/etc/sysconfig/network-scripts/ifcfg-eth%d", nicdesc.Index) + if err := r.rootFs.FilePutContents(fn, cmds, false, false); err != nil { + return err + } + } + return nil +} + +func (r *SRedhatLikeRootFs) DeployStandbyNetworkingScripts(nics, nicsStandby []jsonutils.JSONObject) error { + if err := r.SLinuxRootFs.DeployStandbyNetworkingScripts(nics, nicsStandby); err != nil { + return err + } + for _, nic := range nicsStandby { + var cmds string + var nicdesc = new(types.ServerNic) + if err := nic.Unmarshal(nicdesc); err != nil { + return err + } + if nicType, err := nic.GetString("nic_type"); err != nil && nicType != "ipmi" { + cmds += fmt.Sprintf("DEVICE=eth%d\n", nicdesc.Index) + cmds += fmt.Sprintf("NAME=eth%d\n", nicdesc.Index) + cmds += fmt.Sprintf("HWADDR=%s\n", nicdesc.Mac) + cmds += fmt.Sprintf("MACADDR=%s\n", nicdesc.Mac) + cmds += "ONBOOT=no\n" + var fn = fmt.Sprintf("/etc/sysconfig/network-scripts/ifcfg-eth%d", nicdesc.Index) + if err := r.rootFs.FilePutContents(fn, cmds, false, false); err != nil { + return err + } + } + } + return nil +} + +//TODO enable_serial_console +//TODO disable_serial_console + type SCentosRootFs struct { *SRedhatLikeRootFs } @@ -439,6 +613,44 @@ func NewCentosRootFs(part *SKVMGuestDiskPartition) IRootFsDriver { return &SCentosRootFs{SRedhatLikeRootFs: NewRedhatLikeRootFs(part).(*SRedhatLikeRootFs)} } +func (c *SCentosRootFs) RootSignatures() []string { + sig := c.SRedhatLikeRootFs.RootSignatures() + return append([]string{"/etc/centos-release"}, sig...) +} + +func (c *SCentosRootFs) GetReleaseInfo() []string { + rel, _ := c.rootFs.FileGetContents("/etc/centos-release", false) + var version string + if len(rel) > 0 { + re := regexp.MustCompile(`^\d+\.\d+`) + dat := strings.Split(string(rel), " ") + for _, v := range dat { + if re.Match([]byte(v)) { + version = v + break + } + } + } + return []string{"CentOS", version, c.GetArch()} +} + +func (c *SCentosRootFs) DeployNetworkingScripts(nics []jsonutils.JSONObject) error { + if err := c.SRedhatLikeRootFs.DeployNetworkingScripts(nics); err != nil { + return err + } + var udevPath = "/etc/udev/rules.d/" + var files = []string{"60-net.rules", "75-persistent-net-generator.rules"} + for _, f := range files { + sPath := path.Join(udevPath, f) + if !c.rootFs.Exists(sPath, false) { + if err := c.rootFs.FilePutContents(sPath, "", false, false); err != nil { + return err + } + } + } + return nil +} + type SFedoraRootFs struct { *SRedhatLikeRootFs } diff --git a/pkg/hostman/guestfs/localfs.go b/pkg/hostman/guestfs/localfs.go index 716af98d32..2655c0a0c5 100644 --- a/pkg/hostman/guestfs/localfs.go +++ b/pkg/hostman/guestfs/localfs.go @@ -12,8 +12,8 @@ import ( "syscall" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/sshkeys" - "yunion.io/x/onecloud/pkg/hostman" ) type SLocalGuestFS struct { @@ -117,7 +117,7 @@ func (f *SLocalGuestFS) Listdir(sPath string, caseInsensitive bool) []string { func (f *SLocalGuestFS) Cleandir(dir string, keepdir, caseInsensitive bool) error { sPath := f.getLocalPath(dir, caseInsensitive) if len(sPath) > 0 { - return hostman.Cleandir(sPath, keepdir) + return cloudcommon.Cleandir(sPath, keepdir) } return fmt.Errorf("No such file %s", sPath) } @@ -126,7 +126,7 @@ func (f *SLocalGuestFS) Cleandir(dir string, keepdir, caseInsensitive bool) erro func (f *SLocalGuestFS) Zerofiles(dir string, caseInsensitive bool) error { sPath := f.getLocalPath(dir, caseInsensitive) if len(sPath) > 0 { - return hostman.Zerofiles(sPath) + return cloudcommon.Zerofiles(sPath) } return fmt.Errorf("No such file %s", sPath) } @@ -313,7 +313,7 @@ func (f *SLocalGuestFS) FilePutContents(sPath, content string, modAppend, caseIn } } if len(sPath) > 0 { - return hostman.FilePutContents(sPath, content, modAppend) + return cloudcommon.FilePutContents(sPath, content, modAppend) } else { return fmt.Errorf("Cann't put content") } diff --git a/pkg/hostman/guestman/guestman.go b/pkg/hostman/guestman/guestman.go index 81e7887d9d..32fb5b9a15 100644 --- a/pkg/hostman/guestman/guestman.go +++ b/pkg/hostman/guestman/guestman.go @@ -13,10 +13,10 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/httpclients" "yunion.io/x/onecloud/pkg/cloudcommon/sshkeys" "yunion.io/x/onecloud/pkg/cloudcommon/workmanager" - "yunion.io/x/onecloud/pkg/hostman" "yunion.io/x/onecloud/pkg/hostman/guestfs" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/pkg/util/regutils" @@ -86,7 +86,7 @@ func (m *SGuestManager) VerifyExistingGuests(pendingDelete bool) { func (m *SGuestManager) OnVerifyExistingGuestsFail(err error, pendingDelete bool) { log.Errorf("OnVerifyExistingGuestFail: %s, try again 30 seconds later", err.Error()) - hostman.AddTimeout(30*time.Second, func() { m.VerifyExistingGuests(false) }) + cloudcommon.AddTimeout(30*time.Second, func() { m.VerifyExistingGuests(false) }) } func (m *SGuestManager) OnVerifyExistingGuestsSucc(res jsonutils.JSONObject, pendingDelete bool) { diff --git a/pkg/hostman/guestman/qemu-kvm.go b/pkg/hostman/guestman/qemu-kvm.go index 9a6b54026e..4213ca7dbc 100644 --- a/pkg/hostman/guestman/qemu-kvm.go +++ b/pkg/hostman/guestman/qemu-kvm.go @@ -17,8 +17,8 @@ import ( "yunion.io/x/pkg/util/regutils" "yunion.io/x/onecloud/pkg/appctx" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/httpclients" - "yunion.io/x/onecloud/pkg/hostman" "yunion.io/x/onecloud/pkg/hostman/guestfs" "yunion.io/x/onecloud/pkg/hostman/hostinfo" "yunion.io/x/onecloud/pkg/hostman/monitor" @@ -259,7 +259,7 @@ func (s *SKVMGuestInstance) ListStateFilePaths() []string { // Must called in new goroutine func (s *SKVMGuestInstance) StartMonitor(ctx context.Context) { - // delay 100ms start monitor // hostman.AddTimeout(100*time.Millisecond, func() { s.delayStartMonitor(ctx) }) + // delay 100ms start monitor // cloudcommon.AddTimeout(100*time.Millisecond, func() { s.delayStartMonitor(ctx) }) time.Sleep(100 * time.Millisecond) s.delayStartMonitor(ctx) } @@ -368,7 +368,7 @@ func (s *SKVMGuestInstance) SaveDesc(desc jsonutils.JSONObject) error { // bw_info = self._get_bw_info() // netmon_info = self._get_netmon_info() s.Desc = desc.(*jsonutils.JSONDict) - if err := hostman.FilePutContents(s.GetDescFilePath(), desc.String()); err != nil { + if err := cloudcommon.FilePutContents(s.GetDescFilePath(), desc.String()); err != nil { log.Errorln(err) } // TODO diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 0da82ee4ac..e1173a343c 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -8,8 +8,8 @@ import ( "strings" "yunion.io/x/log" + "yunion.io/x/onecloud/pkg/cloudcommon" "yunion.io/x/onecloud/pkg/cloudcommon/qemutils" - "yunion.io/x/onecloud/pkg/hostman" "yunion.io/x/onecloud/pkg/hostman/options" "yunion.io/x/onecloud/pkg/hostman/storageman" ) @@ -90,7 +90,7 @@ func (h *SHostInfo) prepareEnv() error { ioParams["queue/iosched/group_idle"] = "0" ioParams["queue/iosched/quantum"] = "32" } - hostman.ChangeAllBlkdevsParams(ioParams) + cloudcommon.ChangeAllBlkdevsParams(ioParams) _, err = exec.Command("modprobe", "tun").Output() if err != nil { return fmt.Errorf("Failed to activate tun/tap device") @@ -206,7 +206,7 @@ func (h *SHostInfo) EnableNativeHugepages() error { // TODO // h.Memory 还未实现 preAllocPagesNum := h.GetMemory/h.Memory.GetHugepagesizeMb() + 1 - cmd := hostman.CommandWithTimeout(1, "sh", "-c", fmt.Sprintf("echo %d > /proc/sys/vm/nr_hugepages", preAllocPagesNum)) + cmd := cloudcommon.CommandWithTimeout(1, "sh", "-c", fmt.Sprintf("echo %d > /proc/sys/vm/nr_hugepages", preAllocPagesNum)) _, err := cmd.Output() if err != nil { log.Errorln(err) @@ -225,7 +225,7 @@ func (h *SHostInfo) setSysConfig(path, val string) bool { if _, err := os.Stat(path); !os.IsNotExist(err) { oval, _ := ioutil.ReadFile(path) if string(oval) != val { - err = hostman.FilePutContents(path, val, false) + err = cloudcommon.FilePutContents(path, val, false) if err == nil { return true } diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index fdb81d4170..f79d699efd 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -47,6 +47,8 @@ type SHostOptions struct { EnableKsm bool `help:"Enable Kernel Same Page Merging"` HugepagesOption string `help:"Hugepages option: disable|native|transparent" default:"transparent"` EnableQmpMonitor bool `help:"Enable qmp monitor" default:"true"` + + PrivatePrefixes []string `help:"IPv4 private prefixes"` } var HostOptions SHostOptions diff --git a/pkg/hostman/storageman/nbdman.go b/pkg/hostman/storageman/nbdman.go index 5924d5832b..13be225a93 100644 --- a/pkg/hostman/storageman/nbdman.go +++ b/pkg/hostman/storageman/nbdman.go @@ -6,7 +6,7 @@ import ( "sync" "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/hostman" + "yunion.io/x/onecloud/pkg/cloudcommon" ) type SNBDManager struct { @@ -51,7 +51,7 @@ func (m *SNBDManager) AcquireNbddev() string { defer m.nbdLock.Unlock() m.nbdLock.Lock() for nbdDev := range m.nbdDevs { - if hostman.IsBlockDeviceUsed(nbdDev) { + if cloudcommon.IsBlockDeviceUsed(nbdDev) { m.nbdDevs[nbdDev] = true } if !m.nbdDevs[nbdDev] {