Skip to content

Commit

Permalink
Automated cherry pick of #18822: Automated cherry pick of #18821: Fea…
Browse files Browse the repository at this point in the history
…t/deploy guest (#18823)

* feat(region): add guest rescue api && download initrd from baremetal tftp server && add baremetal agent ip finder & update pic address & support ip kernel config.

* feat(host-deployer): use qemu-kvm as default deploy dirver

---------

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
wanyaoqi and IRONICBo authored Nov 30, 2023
1 parent 127711a commit b58cd52
Show file tree
Hide file tree
Showing 37 changed files with 1,741 additions and 415 deletions.
12 changes: 11 additions & 1 deletion build/docker/Dockerfile.host-deployer
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.5
FROM registry.cn-beijing.aliyuncs.com/yunionio/yunionos:v0.1.9-20231129.0 as yunionos
FROM registry.cn-beijing.aliyuncs.com/yunionio/host-deployer-base:1.4.2

MAINTAINER "Yaoqi Wan [email protected]"

ENV TZ UTC

RUN mkdir -p /opt/yunion/bin
RUN mkdir -p /yunionos/x86_64
RUN mkdir -p /yunionos/aarch64


COPY --from=yunionos /yunionos/x86_64/initramfs /yunionos/x86_64/initramfs
COPY --from=yunionos /yunionos/x86_64/kernel /yunionos/x86_64/kernel
COPY --from=yunionos /yunionos/aarch64/kernel /yunionos/aarch64/kernel
COPY --from=yunionos /yunionos/aarch64/initramfs /yunionos/aarch64/initramfs


ADD ./_output/centos-build/bin/host-deployer /opt/yunion/bin/host-deployer
44 changes: 2 additions & 42 deletions cmd/climc/shell/compute/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func init() {
cmd.Perform("set-nic-traffic-limit", &options.ServerNicTrafficLimitOptions{})
cmd.Perform("add-sub-ips", &options.ServerAddSubIpsOptions{})
cmd.BatchPerform("set-os-info", &options.ServerSetOSInfoOptions{})
cmd.BatchPerform("start-rescue", &options.ServerStartOptions{})
cmd.BatchPerform("stop-rescue", &options.ServerStartOptions{})

cmd.Get("vnc", new(options.ServerVncOptions))
cmd.Get("desc", new(options.ServerIdOptions))
Expand Down Expand Up @@ -953,46 +955,4 @@ func init() {
}
return nil
})

// ServerStartRescueOptions is used to start a rescue os.
type ServerStartRescueOptions struct {
ID string `help:"ID of server" json:"-"`
QemuVersion string `help:"prefer qemu version" json:"qemu_version"`
}
R(&ServerStartRescueOptions{}, "server-start-rescue ", "Start rescu e a guest server", func(s *mcclient.ClientSession, opts *ServerStartRescueOptions) error {
params, err := baseoptions.StructToParams(opts)
if err != nil {
return err
}

result, err := modules.Servers.PerformAction(s, opts.ID, "start-rescue", params)
if err != nil {
return err
}

printObject(result)

return nil
})

// ServerStopRescueOptions is used to stop a rescue os.
type ServerStopRescueOptions struct {
ID string `help:"ID of server" json:"-"`
QemuVersion string `help:"prefer qemu version" json:"qemu_version"`
}
R(&ServerStopRescueOptions{}, "server-stop-rescue", "Stop rescue a guest server", func(s *mcclient.ClientSession, opts *ServerStopRescueOptions) error {
params, err := baseoptions.StructToParams(opts)
if err != nil {
return err
}

result, err := modules.Servers.PerformAction(s, opts.ID, "stop-rescue", params)
if err != nil {
return err
}

printObject(result)

return nil
})
}
2 changes: 1 addition & 1 deletion pkg/apis/compute/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ type GuestJsonDesc struct {

IsDaemon bool `json:"is_daemon"`

RescueMode bool `json:"rescue_mode"`
LightMode bool `json:"light_mode"`
}

type ServerSetBootIndexInput struct {
Expand Down
5 changes: 2 additions & 3 deletions pkg/cloudcommon/db/opslog_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ const (

ACT_SYNC_TRAFFIC_LIMIT = "sync_traffic_limit"
ACT_SYNC_TRAFFIC_LIMIT_FAIL = "sync_traffic_limit_fail"

ACT_BIND = "bind"
ACT_UNBIND = "unbind"
ACT_BIND = "bind"
ACT_UNBIND = "unbind"

ACT_START_RESCUE = "start_rescue"
ACT_STOP_RESCUE = "stop_rescue"
Expand Down
10 changes: 5 additions & 5 deletions pkg/compute/guestdrivers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,14 @@ func (drv *SBaseGuestDriver) SyncOsInfo(ctx context.Context, userCred mcclient.T
return nil
}

func (drv *SBaseGuestDriver) RequestStartRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) error {
return httperrors.ErrNotImplemented
func (self *SBaseGuestDriver) ValidateSetOSInfo(ctx context.Context, userCred mcclient.TokenCredential, _ *models.SGuest, _ *api.ServerSetOSInfoInput) error {
return nil
}

func (drv *SBaseGuestDriver) RequestStopRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) error {
func (self *SBaseGuestDriver) RequestStartRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) error {
return httperrors.ErrNotImplemented
}

func (self *SBaseGuestDriver) ValidateSetOSInfo(ctx context.Context, userCred mcclient.TokenCredential, _ *models.SGuest, _ *api.ServerSetOSInfoInput) error {
return nil
func (self *SBaseGuestDriver) RequestStopRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *models.SHost, guest *models.SGuest) error {
return httperrors.ErrNotImplemented
}
34 changes: 2 additions & 32 deletions pkg/compute/models/guest_rescue.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@ func (self *SGuest) PerformStartRescue(ctx context.Context, userCred mcclient.To
return nil, httperrors.NewInvalidStatusError("vmem size must be greater than 2G")
}

// Reset index
disks, err := self.GetGuestDisks()
if err != nil || len(disks) < 1 {
return nil, httperrors.NewInvalidStatusError("guest.GetGuestDisks: %s", err.Error())
}
for i := 0; i < len(disks); i++ {
if disks[i].BootIndex >= 0 {
// Move to next index, and easy to rollback
err = disks[i].SetBootIndex(disks[i].BootIndex + 1)
if err != nil {
return nil, httperrors.NewInvalidStatusError("guest.SetBootIndex: %s", err.Error())
}
}
}

// Get baremetal agent
host, err := self.GetHost()
if err != nil {
Expand Down Expand Up @@ -84,23 +69,8 @@ func (self *SGuest) PerformStopRescue(ctx context.Context, userCred mcclient.Tok
return nil, httperrors.NewInvalidStatusError("guest is not in rescue mode")
}

// Recover index
disks, err := self.GetGuestDisks()
if err != nil || len(disks) < 1 {
return nil, httperrors.NewInvalidStatusError("guest.GetGuestDisks: %s", err.Error())
}
for i := 0; i < len(disks); i++ {
if disks[i].BootIndex >= 0 {
// Rollback index
err = disks[i].SetBootIndex(disks[i].BootIndex - 1)
if err != nil {
return nil, httperrors.NewInvalidStatusError("guest.SetBootIndex: %s", err.Error())
}
}
}

// Start rescue vm task
err = self.StopRescueTask(ctx, userCred, data.(*jsonutils.JSONDict), "")
err := self.StopRescueTask(ctx, userCred, data.(*jsonutils.JSONDict), "")
if err != nil {
return nil, httperrors.NewInvalidStatusError("guest.StopGuestRescueTask: %s", err.Error())
}
Expand All @@ -115,7 +85,7 @@ func (self *SGuest) UpdateRescueMode(mode bool) error {
return nil
})
if err != nil {
return errors.Wrap(err, "Update RescueMode")
return errors.Wrap(err, "Update LightMode")
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/compute/models/guestdrivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,9 @@ type IGuestDriver interface {

SyncOsInfo(ctx context.Context, userCred mcclient.TokenCredential, g *SGuest, extVM cloudprovider.IOSInfo) error

ValidateSetOSInfo(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, input *api.ServerSetOSInfoInput) error
RequestStartRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *SHost, guest *SGuest) error
RequestStopRescue(ctx context.Context, task taskman.ITask, body jsonutils.JSONObject, host *SHost, guest *SGuest) error

ValidateSetOSInfo(ctx context.Context, userCred mcclient.TokenCredential, guest *SGuest, input *api.ServerSetOSInfoInput) error
}

var guestDrivers map[string]IGuestDriver
Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/models/guests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4942,7 +4942,7 @@ func (self *SGuest) GetJsonDescAtHypervisor(ctx context.Context, host *SHost) *a

IsDaemon: self.IsDaemon.Bool(),

RescueMode: self.RescueMode,
LightMode: self.RescueMode,
}

if len(self.BackupHostId) > 0 {
Expand Down
42 changes: 42 additions & 0 deletions pkg/hostman/diskutils/deploy_iface/deployer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 deploy_iface

import (
"yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
)

type IDeployer interface {
Connect(desc *apis.GuestDesc) error
Disconnect() error

GetPartitions() []fsdriver.IDiskPartition
IsLVMPartition() bool
Zerofree()
ResizePartition() error
FormatPartition(fs, uuid string) error
MakePartition(fs string) error

MountRootfs(readonly bool) (fsdriver.IRootFsDriver, error)
UmountRootfs(fd fsdriver.IRootFsDriver) error
DetectIsUEFISupport(rootfs fsdriver.IRootFsDriver) bool

DeployGuestfs(req *apis.DeployParams) (res *apis.DeployGuestFsResponse, err error)
ResizeFs() (res *apis.Empty, err error)
FormatFs(req *apis.FormatFsParams) (*apis.Empty, error)
SaveToGlance(req *apis.SaveToGlanceParams) (*apis.SaveToGlanceResponse, error)
ProbeImageInfo(req *apis.ProbeImageInfoPramas) (*apis.ImageInfo, error)
}
15 changes: 15 additions & 0 deletions pkg/hostman/diskutils/deploy_iface/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 deploy_iface // import "yunion.io/x/onecloud/pkg/hostman/diskutils/deploy_iface"
Loading

0 comments on commit b58cd52

Please sign in to comment.