Merge pull request #15486 from swordqiu/automated-cherry-pick-of-#15485-upstream-release-3.10

Automated cherry pick of #15485: feature: allow update hostname
This commit is contained in:
Zexi Li
2022-12-05 18:16:45 +08:00
committed by GitHub
7 changed files with 23 additions and 2 deletions
+2
View File
@@ -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()
+2
View File
@@ -730,6 +730,8 @@ type ServerChangeConfigInput struct {
type ServerUpdateInput struct {
apis.VirtualResourceBaseUpdateInput
HostnameInput
// 删除保护开关
DisableDelete *bool `json:"disable_delete"`
// 启动顺序
+1
View File
@@ -457,6 +457,7 @@ type HostUpdateInput struct {
HostAccessAttributes
HostSizeAttributes
HostIpmiAttributes
HostnameInput
// IPMI info
IpmiInfo jsonutils.JSONObject `json:"ipmi_info"`
+7
View File
@@ -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 {
+2 -2
View File
@@ -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)
}
+7
View File
@@ -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 {
+2
View File
@@ -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) {