fix(region): server-create add src ip/mac check (#25302)

This commit is contained in:
wanyaoqi
2026-08-13 10:10:17 +08:00
committed by GitHub
parent 212351edf6
commit 7ab03102e2
3 changed files with 53 additions and 30 deletions
+5
View File
@@ -727,6 +727,11 @@ type ServerCreateInput struct {
// 安全组Id列表
Secgroups []string `json:"secgroups"`
// 源 IP 检查
SrcIpCheck *bool `json:"src_ip_check"`
// 源 MAC 检查
SrcMacCheck *bool `json:"src_mac_check"`
// GCP 网络标记(network tags),仅对 Google 云有效
// 传入后可不指定安全组,创建时直接作为实例 tags 下发
// required: false
+8
View File
@@ -2303,6 +2303,14 @@ func (manager *SGuestManager) validateCreateData(
return nil, errors.Wrapf(httperrors.ErrInputParameter, "more than 1 nic(%d) assigned as default gateway", defaultGwCnt)
}
// default: both check on
// switch: mac check off, also implies ip check off
// router: mac check on, ip check off
if input.SrcMacCheck != nil && !*input.SrcMacCheck {
srcIpCheck := false
input.SrcIpCheck = &srcIpCheck
}
isoDevArray := input.IsolatedDevices
for idx := 0; idx < len(isoDevArray); idx += 1 { // .Contains(fmt.Sprintf("isolated_device.%d", idx)); idx += 1 {
if input.Backup {
+40 -30
View File
@@ -480,36 +480,38 @@ type ServerCreateOptionalOptions struct {
EnableMemclean bool `help:"clean guest memory after guest exit" json:"enable_memclean"`
EnableTpm bool `help:"enable tpm device" json:"enable_tpm"`
Keypair string `help:"SSH Keypair" mcp:"true"`
Password string `help:"Default user password" mcp:"true"`
LoginAccount string `help:"Guest login account" mcp:"true"`
Iso string `help:"ISO image ID" metavar:"IMAGE_ID" json:"cdrom" mcp:"true"`
IsoBootIndex *int8 `help:"Iso bootindex" metavar:"IMAGE_BOOT_INDEX" json:"cdrom_boot_index"`
VcpuCount int `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>" json:"vcpu_count" token:"ncpu" mcp:"true"`
ExtraCpuCount int `help:"Extra allocate cpu count" json:"extra_cpu_count"`
InstanceType string `help:"instance flavor" mcp:"true"`
Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl|virtio"`
Vdi string `help:"VDI protocol" choices:"vnc|spice"`
Bios string `help:"BIOS" choices:"BIOS|UEFI" mcp:"true"`
Machine string `help:"Machine type" choices:"pc|q35"`
Desc string `help:"Description" metavar:"<DESCRIPTION>" json:"description"`
Boot string `help:"Boot device" metavar:"<BOOT_DEVICE>" choices:"disk|cdrom" json:"-"`
EnableCloudInit bool `help:"Enable cloud-init service"`
NoAccountInit *bool `help:"Not reset account password"`
AllowDelete *bool `help:"Allow deleting the server (disable_delete=false)" json:"-"`
ShutdownBehavior string `help:"Behavior after VM server shutdown" metavar:"<SHUTDOWN_BEHAVIOR>" choices:"stop|terminate|stop_release_gpu"`
AutoStart bool `help:"Auto start server after it is created" mcp:"true"`
Deploy []string `help:"Specify deploy files in virtual server file system" json:"-"`
DeployTelegraf bool `help:"Deploy telegraf agent if guest os is supported"`
Group []string `help:"Group ID or Name of virtual server"`
System bool `help:"Create a system VM, sysadmin ONLY option" json:"is_system"`
TaskNotify *bool `help:"Setup task notify" json:"-"`
FakeCreate *bool `help:"Fake create server"`
DryRun *bool `help:"Dry run to validate create params (not preschedule)MCP 创建会自动调 scheduler-forecast 预调度,一般无需手动传" json:"-" mcp:"true"`
UserDataFile string `help:"user_data file path" json:"-"`
InstanceSnapshot string `help:"instance snapshot" json:"instance_snapshot"`
Secgroups []string `help:"Security group IDs or names" json:"secgroups"`
NetworkTags []string `help:"GCP network tags, google only; when set, secgroups can be omitted" json:"network_tags"`
Keypair string `help:"SSH Keypair" mcp:"true"`
Password string `help:"Default user password" mcp:"true"`
LoginAccount string `help:"Guest login account" mcp:"true"`
Iso string `help:"ISO image ID" metavar:"IMAGE_ID" json:"cdrom" mcp:"true"`
IsoBootIndex *int8 `help:"Iso bootindex" metavar:"IMAGE_BOOT_INDEX" json:"cdrom_boot_index"`
VcpuCount int `help:"#CPU cores of VM server, default 1" default:"1" metavar:"<SERVER_CPU_COUNT>" json:"vcpu_count" token:"ncpu" mcp:"true"`
ExtraCpuCount int `help:"Extra allocate cpu count" json:"extra_cpu_count"`
InstanceType string `help:"instance flavor" mcp:"true"`
Vga string `help:"VGA driver" choices:"std|vmware|cirrus|qxl|virtio"`
Vdi string `help:"VDI protocol" choices:"vnc|spice"`
Bios string `help:"BIOS" choices:"BIOS|UEFI" mcp:"true"`
Machine string `help:"Machine type" choices:"pc|q35"`
Desc string `help:"Description" metavar:"<DESCRIPTION>" json:"description"`
Boot string `help:"Boot device" metavar:"<BOOT_DEVICE>" choices:"disk|cdrom" json:"-"`
EnableCloudInit bool `help:"Enable cloud-init service"`
NoAccountInit *bool `help:"Not reset account password"`
AllowDelete *bool `help:"Allow deleting the server (disable_delete=false)" json:"-"`
ShutdownBehavior string `help:"Behavior after VM server shutdown" metavar:"<SHUTDOWN_BEHAVIOR>" choices:"stop|terminate|stop_release_gpu"`
AutoStart bool `help:"Auto start server after it is created" mcp:"true"`
Deploy []string `help:"Specify deploy files in virtual server file system" json:"-"`
DeployTelegraf bool `help:"Deploy telegraf agent if guest os is supported"`
Group []string `help:"Group ID or Name of virtual server"`
System bool `help:"Create a system VM, sysadmin ONLY option" json:"is_system"`
TaskNotify *bool `help:"Setup task notify" json:"-"`
FakeCreate *bool `help:"Fake create server"`
DryRun *bool `help:"Dry run to validate create params (not preschedule)MCP 创建会自动调 scheduler-forecast 预调度,一般无需手动传" json:"-" mcp:"true"`
UserDataFile string `help:"user_data file path" json:"-"`
InstanceSnapshot string `help:"instance snapshot" json:"instance_snapshot"`
Secgroups []string `help:"Security group IDs or names" json:"secgroups"`
NetworkTags []string `help:"GCP network tags, google only; when set, secgroups can be omitted" json:"network_tags"`
DisableSrcIpCheck *bool `help:"Disable source IP check" json:"-"`
DisableSrcMacCheck *bool `help:"Disable source MAC check" json:"-"`
OsType string `help:"os type, e.g. Linux, Windows, etc." mcp:"true"`
@@ -644,6 +646,14 @@ func (opts *ServerCreateOptionalOptions) OptionalParams() (*computeapi.ServerCre
if len(opts.EncryptKey) > 0 {
params.EncryptKeyId = &opts.EncryptKey
}
if opts.DisableSrcMacCheck != nil && *opts.DisableSrcMacCheck {
var srcMacCheck = false
params.SrcMacCheck = &srcMacCheck
}
if opts.DisableSrcIpCheck != nil && *opts.DisableSrcIpCheck {
var srcIpCheck = false
params.SrcIpCheck = &srcIpCheck
}
if regutils.MatchSize(opts.MemSpec) {
memSize, err := fileutils.GetSizeMb(opts.MemSpec, 'M', 1024)