feature: support galaxy kylin guest OS

This commit is contained in:
Qiu Jian
2021-12-11 13:29:04 +08:00
parent c0d255ebc2
commit d1225d226a
4 changed files with 172 additions and 21 deletions
+73
View File
@@ -0,0 +1,73 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
)
type SAnolisRootFs struct {
*sRedhatLikeRootFs
}
func NewAnolisRootFs(part IDiskPartition) IRootFsDriver {
return &SAnolisRootFs{sRedhatLikeRootFs: newRedhatLikeRootFs(part)}
}
func (d *SAnolisRootFs) GetName() string {
return "Anolis"
}
func (d *SAnolisRootFs) String() string {
return "AnolisRootFs"
}
func (d *SAnolisRootFs) RootSignatures() []string {
sig := d.sRedhatLikeRootFs.RootSignatures()
return append([]string{"/etc/anolis-release"}, sig...)
}
func (d *SAnolisRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {
rel, _ := rootFs.FileGetContents("/etc/anolis-release", false)
var version string
if len(rel) > 0 {
dat := strings.Split(string(rel), " ")
if len(dat) > 3 {
version = dat[3]
}
}
return deployapi.NewReleaseInfo(d.GetName(), version, d.GetArch(rootFs))
}
func (d *SAnolisRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := d.GetReleaseInfo(rootFs)
if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, false); err != nil {
return err
}
return nil
}
func (c *SAnolisRootFs) EnableSerialConsole(rootFs IDiskPartition, sysInfo *jsonutils.JSONDict) error {
return c.enableSerialConsole(c, rootFs, sysInfo)
}
func (c *SAnolisRootFs) DisableSerialConsole(rootFs IDiskPartition) error {
return c.disableSerialConcole(c, rootFs)
}
+1 -1
View File
@@ -42,7 +42,7 @@ func Init(initPrivatePrefixes []string, cloudrootDir string) error {
}
linuxFsDrivers := []newRootFsDriverFunc{
NewCentosRootFs, NewFedoraRootFs, NewRhelRootFs,
NewCentosRootFs, NewFedoraRootFs, NewAnolisRootFs, NewGalaxyKylinRootFs, NewRhelRootFs,
NewDebianRootFs, NewCirrosRootFs, NewCirrosNewRootFs, NewUbuntuRootFs,
NewGentooRootFs, NewArchLinuxRootFs, NewOpenWrtRootFs, NewCoreOsRootFs,
NewOpenEulerRootFs,
+81
View File
@@ -0,0 +1,81 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fsdriver
import (
"strings"
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/cloudcommon/types"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
)
type SGalaxyKylinRootFs struct {
*sRedhatLikeRootFs
}
func NewGalaxyKylinRootFs(part IDiskPartition) IRootFsDriver {
return &SGalaxyKylinRootFs{sRedhatLikeRootFs: newRedhatLikeRootFs(part)}
}
func (d *SGalaxyKylinRootFs) GetName() string {
return "Kylin"
}
func (d *SGalaxyKylinRootFs) String() string {
return "KylinRootFs"
}
func (d *SGalaxyKylinRootFs) RootSignatures() []string {
sigs := []string{"/etc/kylin-release"}
for _, sig := range d.sRedhatLikeRootFs.RootSignatures() {
if sig != "/etc/redhat-release" {
sigs = append(sigs, sig)
}
}
return sigs
}
func (d *SGalaxyKylinRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo {
rel, _ := rootFs.FileGetContents("/etc/kylin-release", false)
var version string
if len(rel) > 0 {
relStr := string(rel)
endPos := strings.IndexByte(relStr, '(')
if endPos > 0 {
relStr = strings.TrimSpace(relStr[:endPos])
}
dat := strings.Split(relStr, " ")
version = dat[len(dat)-1]
}
return deployapi.NewReleaseInfo(d.GetName(), version, d.GetArch(rootFs))
}
func (d *SGalaxyKylinRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := d.GetReleaseInfo(rootFs)
if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, true); err != nil {
return err
}
return nil
}
func (c *SGalaxyKylinRootFs) EnableSerialConsole(rootFs IDiskPartition, sysInfo *jsonutils.JSONDict) error {
return c.enableSerialConsole(c, rootFs, sysInfo)
}
func (c *SGalaxyKylinRootFs) DisableSerialConsole(rootFs IDiskPartition) error {
return c.disableSerialConcole(c, rootFs)
}
+17 -20
View File
@@ -928,23 +928,23 @@ func (d *SUbuntuRootFs) DisableSerialConcole(rootFs IDiskPartition) error {
return nil
}
type SKylinRootfs struct {
type SUKylinRootfs struct {
*SUbuntuRootFs
}
func NewKylinRootfs(part IDiskPartition) *SKylinRootfs {
return &SKylinRootfs{SUbuntuRootFs: NewUbuntuRootFs(part).(*SUbuntuRootFs)}
func NewUKylinRootfs(part IDiskPartition) *SUKylinRootfs {
return &SUKylinRootfs{SUbuntuRootFs: NewUbuntuRootFs(part).(*SUbuntuRootFs)}
}
func (d *SKylinRootfs) GetName() string {
return "Kylin"
func (d *SUKylinRootfs) GetName() string {
return "UbuntuKylin"
}
func (d *SKylinRootfs) String() string {
return "KylinuRootFs"
func (d *SUKylinRootfs) String() string {
return "UKylinuRootFs"
}
func (d *SKylinRootfs) RootSignatures() []string {
func (d *SUKylinRootfs) RootSignatures() []string {
sig := d.sDebianLikeRootFs.RootSignatures()
return append([]string{"/etc/lsb-release", "/etc/kylin-build"}, sig...)
}
@@ -1048,17 +1048,14 @@ func (r *sRedhatLikeRootFs) enableBondingModule(rootFs IDiskPartition, bondNics
return rootFs.FilePutContents("/etc/modprobe.d/bonding.conf", content.String(), false, false)
}
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo) error {
func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic, relInfo *deployapi.ReleaseInfo, forceEnableNM bool) error {
if err := r.sLinuxRootFs.DeployNetworkingScripts(rootFs, nics); err != nil {
return err
}
ver := strings.Split(relInfo.Version, ".")
iv, err := strconv.ParseInt(ver[0], 10, 0)
if err != nil {
return fmt.Errorf("Failed to get release version: %v", err)
}
if iv < 6 {
if err == nil && iv < 6 {
err = r.Centos5DeployNetworkingScripts(rootFs, nics)
} else {
err = r.sLinuxRootFs.DeployNetworkingScripts(rootFs, nics)
@@ -1092,10 +1089,10 @@ func (r *sRedhatLikeRootFs) deployNetworkingScripts(rootFs IDiskPartition, nics
cmds.WriteString(nicDesc.Name)
cmds.WriteString("\n")
cmds.WriteString("ONBOOT=yes\n")
if iv < 8 {
cmds.WriteString("NM_CONTROLLED=no\n")
} else {
if iv >= 8 || forceEnableNM {
cmds.WriteString("NM_CONTROLLED=yes\n")
} else {
cmds.WriteString("NM_CONTROLLED=no\n")
}
cmds.WriteString("USERCTL=no\n")
if nicDesc.Mtu > 0 {
@@ -1272,7 +1269,7 @@ func (c *SCentosRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.Release
func (c *SCentosRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := c.GetReleaseInfo(rootFs)
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil {
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, false); err != nil {
return err
}
var udevPath = "/etc/udev/rules.d/"
@@ -1335,7 +1332,7 @@ func (c *SFedoraRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.Release
func (c *SFedoraRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := c.GetReleaseInfo(rootFs)
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil {
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, false); err != nil {
return err
}
return nil
@@ -1379,7 +1376,7 @@ func (d *SRhelRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseIn
func (d *SRhelRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := d.GetReleaseInfo(rootFs)
if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil {
if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, false); err != nil {
return err
}
return nil
@@ -1435,7 +1432,7 @@ func (c *SOpenEulerRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.Rele
func (c *SOpenEulerRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error {
relInfo := c.GetReleaseInfo(rootFs)
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil {
if err := c.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo, false); err != nil {
return err
}
return nil