mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: hostfile delete validation (#22492)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -138,3 +138,14 @@ func (manager *SHostFileManager) FetchCustomizeColumns(
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
func (hostfile *SHostFile) ValidateDeleteCondition(ctx context.Context, info api.HostFileDetails) error {
|
||||
err := hostfile.SInfrasResourceBase.ValidateDeleteCondition(ctx, jsonutils.Marshal(info))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "SInfrasResourceBase.ValidateDeleteCondition")
|
||||
}
|
||||
if len(info.Hosts) > 0 {
|
||||
return httperrors.NewNotEmptyError("hostfile is used by hosts")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
@@ -52,17 +54,35 @@ type HostFileUpdateOptions struct {
|
||||
options.BaseIdOptions
|
||||
|
||||
computeapi.HostFileUpdateInput
|
||||
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
func (opts *HostFileUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
if len(opts.File) > 0 {
|
||||
cont, err := os.ReadFile(opts.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts.Content = string(cont)
|
||||
}
|
||||
return jsonutils.Marshal(opts), nil
|
||||
}
|
||||
|
||||
type HostFileCreateOptions struct {
|
||||
computeapi.HostFileCreateInput
|
||||
|
||||
File string `json:"file"`
|
||||
}
|
||||
|
||||
func (opts *HostFileCreateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
if len(opts.File) > 0 {
|
||||
cont, err := os.ReadFile(opts.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts.Content = string(cont)
|
||||
}
|
||||
return jsonutils.Marshal(opts), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user