From bf170f8cdf5b7b6219d4c10373b398e73a035bc8 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Mon, 6 Dec 2021 21:18:27 +0800 Subject: [PATCH] feature: support Anolis OS --- pkg/hostman/guestfs/fsdriver/anolis.go | 73 +++++++++++++++++++++++++ pkg/hostman/guestfs/fsdriver/drivers.go | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 pkg/hostman/guestfs/fsdriver/anolis.go diff --git a/pkg/hostman/guestfs/fsdriver/anolis.go b/pkg/hostman/guestfs/fsdriver/anolis.go new file mode 100644 index 0000000000..76a6f9c70a --- /dev/null +++ b/pkg/hostman/guestfs/fsdriver/anolis.go @@ -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); 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) +} diff --git a/pkg/hostman/guestfs/fsdriver/drivers.go b/pkg/hostman/guestfs/fsdriver/drivers.go index 47c3212fe0..b1bd1edff9 100644 --- a/pkg/hostman/guestfs/fsdriver/drivers.go +++ b/pkg/hostman/guestfs/fsdriver/drivers.go @@ -42,7 +42,7 @@ func Init(initPrivatePrefixes []string, cloudrootDir string) error { } linuxFsDrivers := []newRootFsDriverFunc{ - NewCentosRootFs, NewFedoraRootFs, NewRhelRootFs, + NewCentosRootFs, NewFedoraRootFs, NewAnolisRootFs, NewRhelRootFs, NewDebianRootFs, NewCirrosRootFs, NewCirrosNewRootFs, NewUbuntuRootFs, NewGentooRootFs, NewArchLinuxRootFs, NewOpenWrtRootFs, NewCoreOsRootFs, NewOpenEulerRootFs,