mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
feat(region,climc): server-set-root-disk-matcher (#21547)
This commit is contained in:
@@ -127,6 +127,7 @@ func init() {
|
||||
cmd.BatchPerform("start-rescue", &options.ServerStartOptions{})
|
||||
cmd.BatchPerform("stop-rescue", &options.ServerStartOptions{})
|
||||
cmd.BatchPerform("sync-os-info", &options.ServerIdsOptions{})
|
||||
cmd.BatchPerform("set-root-disk-matcher", &options.ServerSetRootDiskMatcher{})
|
||||
|
||||
cmd.Get("vnc", new(options.ServerVncOptions))
|
||||
cmd.Get("desc", new(options.ServerIdOptions))
|
||||
|
||||
@@ -55,6 +55,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/userdata"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/compute/baremetal"
|
||||
guestdriver_types "yunion.io/x/onecloud/pkg/compute/guestdrivers/types"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -6576,3 +6577,16 @@ func (self *SGuest) PerformSyncOsInfo(ctx context.Context, userCred mcclient.Tok
|
||||
return nil, self.startQgaSyncOsInfoTask(ctx, userCred, "")
|
||||
}
|
||||
}
|
||||
|
||||
func (g *SGuest) PerformSetRootDiskMatcher(ctx context.Context, userCred mcclient.TokenCredential, _ jsonutils.JSONObject, data *api.BaremetalRootDiskMatcher) (jsonutils.JSONObject, error) {
|
||||
if g.GetHypervisor() != api.HYPERVISOR_BAREMETAL {
|
||||
return nil, httperrors.NewNotAcceptableError("only %s support for setting root disk matcher", api.HYPERVISOR_BAREMETAL)
|
||||
}
|
||||
if err := baremetal.ValidateRootDiskMatcher(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := g.SetMetadata(ctx, api.BAREMETAL_SERVER_METATA_ROOT_DISK_MATCHER, jsonutils.Marshal(data), userCred); err != nil {
|
||||
return nil, errors.Wrapf(err, "set %s", api.BAREMETAL_SERVER_METATA_ROOT_DISK_MATCHER)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -1538,3 +1538,16 @@ type ServerSetOSInfoOptions struct {
|
||||
func (o *ServerSetOSInfoOptions) Params() (jsonutils.JSONObject, error) {
|
||||
return jsonutils.Marshal(o), nil
|
||||
}
|
||||
|
||||
type ServerSetRootDiskMatcher struct {
|
||||
ROOTDISKMATCHER string `help:"Baremetal root disk matcher, e.g. 'device=/dev/sdb' 'size=900G' 'size_start=800G,size_end=900G'" json:"-"`
|
||||
ServerIdsOptions
|
||||
}
|
||||
|
||||
func (o *ServerSetRootDiskMatcher) Params() (jsonutils.JSONObject, error) {
|
||||
matcher, err := cmdline.ParseBaremetalRootDiskMatcher(o.ROOTDISKMATCHER)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return jsonutils.Marshal(matcher), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user