From 85ec1ef5d8e255cb72bfded9ee44a1029371c1cd Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Wed, 31 Aug 2022 11:21:11 +0800 Subject: [PATCH] feature(host-deployer): support neokylin (#14886) Co-authored-by: Qiu Jian --- pkg/hostman/guestfs/fsdriver/drivers.go | 2 +- pkg/hostman/guestfs/fsdriver/kylin.go | 2 +- pkg/hostman/guestfs/fsdriver/neokylin.go | 82 ++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 pkg/hostman/guestfs/fsdriver/neokylin.go diff --git a/pkg/hostman/guestfs/fsdriver/drivers.go b/pkg/hostman/guestfs/fsdriver/drivers.go index 7039afac5e..2aa69e4ce3 100644 --- a/pkg/hostman/guestfs/fsdriver/drivers.go +++ b/pkg/hostman/guestfs/fsdriver/drivers.go @@ -43,7 +43,7 @@ func Init(initPrivatePrefixes []string, cloudrootDir string) error { linuxFsDrivers := []newRootFsDriverFunc{ NewFangdeRootFs, NewUnionOSRootFs, - NewAnolisRootFs, NewGalaxyKylinRootFs, + NewAnolisRootFs, NewGalaxyKylinRootFs, NewNeoKylinRootFs, NewFangdeDeskRootfs, NewUKylinRootfs, NewCentosRootFs, NewFedoraRootFs, NewRhelRootFs, diff --git a/pkg/hostman/guestfs/fsdriver/kylin.go b/pkg/hostman/guestfs/fsdriver/kylin.go index cfa1b0a6e2..5757718a45 100644 --- a/pkg/hostman/guestfs/fsdriver/kylin.go +++ b/pkg/hostman/guestfs/fsdriver/kylin.go @@ -40,7 +40,7 @@ func (d *SGalaxyKylinRootFs) String() string { } func (d *SGalaxyKylinRootFs) RootSignatures() []string { - sigs := []string{"/etc/kylin-release"} + sigs := []string{"/etc/kylin-release", "/etc/.productinfo"} for _, sig := range d.sRedhatLikeRootFs.RootSignatures() { if sig != "/etc/redhat-release" { sigs = append(sigs, sig) diff --git a/pkg/hostman/guestfs/fsdriver/neokylin.go b/pkg/hostman/guestfs/fsdriver/neokylin.go new file mode 100644 index 0000000000..01791a25f3 --- /dev/null +++ b/pkg/hostman/guestfs/fsdriver/neokylin.go @@ -0,0 +1,82 @@ +// 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 SNeoKylinRootFs struct { + *sRedhatLikeRootFs +} + +func NewNeoKylinRootFs(part IDiskPartition) IRootFsDriver { + return &SNeoKylinRootFs{sRedhatLikeRootFs: newRedhatLikeRootFs(part)} +} + +func (d *SNeoKylinRootFs) GetName() string { + return "NeoKylin" +} + +func (d *SNeoKylinRootFs) String() string { + return "NeoKylinRootFs" +} + +func (d *SNeoKylinRootFs) RootSignatures() []string { + sigs := []string{"/etc/neokylin-release", "/etc/.productinfo"} + for _, sig := range d.sRedhatLikeRootFs.RootSignatures() { + if sig != "/etc/redhat-release" { + sigs = append(sigs, sig) + } + } + return sigs +} + +func (d *SNeoKylinRootFs) GetReleaseInfo(rootFs IDiskPartition) *deployapi.ReleaseInfo { + rel, _ := rootFs.FileGetContents("/etc/neokylin-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 *SNeoKylinRootFs) DeployNetworkingScripts(rootFs IDiskPartition, nics []*types.SServerNic) error { + relInfo := d.GetReleaseInfo(rootFs) + if err := d.sRedhatLikeRootFs.deployNetworkingScripts(rootFs, nics, relInfo); err != nil { + return err + } + return nil +} + +func (c *SNeoKylinRootFs) EnableSerialConsole(rootFs IDiskPartition, sysInfo *jsonutils.JSONDict) error { + return c.enableSerialConsoleSystemd(rootFs) +} + +func (c *SNeoKylinRootFs) DisableSerialConsole(rootFs IDiskPartition) error { + c.disableSerialConsoleSystemd(rootFs) + return nil +}