mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feature: allow update hostname
This commit is contained in:
@@ -174,6 +174,8 @@ func init() {
|
||||
IpmiIpAddr string `help:"IPMI ip_addr"`
|
||||
|
||||
Sn string `help:"serial number"`
|
||||
|
||||
Hostname string `help:"update host name"`
|
||||
}
|
||||
R(&HostUpdateOptions{}, "host-update", "Update information of a host", func(s *mcclient.ClientSession, args *HostUpdateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
|
||||
@@ -730,6 +730,8 @@ type ServerChangeConfigInput struct {
|
||||
type ServerUpdateInput struct {
|
||||
apis.VirtualResourceBaseUpdateInput
|
||||
|
||||
HostnameInput
|
||||
|
||||
// 删除保护开关
|
||||
DisableDelete *bool `json:"disable_delete"`
|
||||
// 启动顺序
|
||||
|
||||
@@ -457,6 +457,7 @@ type HostUpdateInput struct {
|
||||
HostAccessAttributes
|
||||
HostSizeAttributes
|
||||
HostIpmiAttributes
|
||||
HostnameInput
|
||||
|
||||
// IPMI info
|
||||
IpmiInfo jsonutils.JSONObject `json:"ipmi_info"`
|
||||
|
||||
@@ -1137,6 +1137,13 @@ func (self *SGuest) ValidateUpdateData(ctx context.Context, userCred mcclient.To
|
||||
return input, httperrors.NewInputParameterError("name is too short")
|
||||
}
|
||||
|
||||
// validate Hostname
|
||||
if len(input.Hostname) > 0 {
|
||||
if !regutils.MatchDomainName(input.Hostname) {
|
||||
return input, httperrors.NewInputParameterError("hostname should be a legal domain name")
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
input, err = self.GetDriver().ValidateUpdateData(ctx, self, userCred, input)
|
||||
if err != nil {
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
)
|
||||
|
||||
type SHostnameResourceBase struct {
|
||||
Hostname string `width:"60" charset:"ascii" nullable:"true" list:"user" create:"optional"`
|
||||
Hostname string `width:"60" charset:"ascii" nullable:"true" list:"user" create:"optional" update:"user"`
|
||||
}
|
||||
|
||||
type SHostnameResourceBaseManager struct {
|
||||
@@ -59,7 +59,7 @@ func (manager *SHostnameResourceBaseManager) ValidateHostname(name string, osTyp
|
||||
if len(input.Hostname) > 60 {
|
||||
input.Hostname = input.Hostname[:60]
|
||||
}
|
||||
if strings.ToLower(osType) == strings.ToLower(osprofile.OS_TYPE_WINDOWS) {
|
||||
if strings.EqualFold(osType, osprofile.OS_TYPE_WINDOWS) {
|
||||
if num, err := strconv.Atoi(input.Hostname); err == nil && num > 0 {
|
||||
return input, httperrors.NewInputParameterError("hostname cannot be number %d", num)
|
||||
}
|
||||
|
||||
@@ -3675,6 +3675,13 @@ func (manager *SHostManager) ValidateCreateData(
|
||||
}
|
||||
|
||||
func (self *SHost) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.HostUpdateInput) (api.HostUpdateInput, error) {
|
||||
// validate Hostname
|
||||
if len(input.Hostname) > 0 {
|
||||
if !regutils.MatchDomainName(input.Hostname) {
|
||||
return input, httperrors.NewInputParameterError("hostname should be a legal domain name")
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
input.HostAccessAttributes, err = HostManager.inputUniquenessCheck(input.HostAccessAttributes, self.ZoneId, self.Id)
|
||||
if err != nil {
|
||||
|
||||
@@ -642,6 +642,8 @@ type ServerUpdateOptions struct {
|
||||
IsDaemon *bool `help:"Daemon server" negative:"no-daemon"`
|
||||
|
||||
PendingDeletedAt string `help:"change pending deleted time"`
|
||||
|
||||
Hostname string `help:"host name of server"`
|
||||
}
|
||||
|
||||
func (opts *ServerUpdateOptions) Params() (jsonutils.JSONObject, error) {
|
||||
|
||||
Reference in New Issue
Block a user