diff --git a/internal/osbuild2/stage_test.go b/internal/osbuild2/stage_test.go index 32e8e2651..deabe5b61 100644 --- a/internal/osbuild2/stage_test.go +++ b/internal/osbuild2/stage_test.go @@ -307,6 +307,57 @@ func TestStage_UnmarshalJSON(t *testing.T) { data: []byte(`{"type":"org.osbuild.selinux","options":{"file_contexts":""}}`), }, }, + { + name: "sysconfig", + fields: fields{ + Type: "org.osbuild.sysconfig", + Options: &SysconfigStageOptions{}, + }, + args: args{ + data: []byte(`{"type":"org.osbuild.sysconfig","options":{"kernel":{},"network":{}}}`), + }, + }, + { + name: "sysconfig-data", + fields: fields{ + Type: "org.osbuild.sysconfig", + Options: &SysconfigStageOptions{ + Kernel: SysconfigKernelOptions{ + UpdateDefault: true, + DefaultKernel: "kernel", + }, + Network: SysconfigNetworkOptions{ + Networking: true, + NoZeroConf: true, + }, + NetworkScripts: &NetworkScriptsOptions{ + IfcfgFiles: map[string]IfcfgFile{ + "eth0": { + Device: "eth0", + Bootproto: IfcfgBootprotoDHCP, + OnBoot: common.BoolToPtr(true), + Type: IfcfgTypeEthernet, + UserCtl: common.BoolToPtr(true), + PeerDNS: common.BoolToPtr(true), + IPv6Init: common.BoolToPtr(false), + }, + "eth1": { + Device: "eth1", + Bootproto: IfcfgBootprotoDHCP, + OnBoot: common.BoolToPtr(true), + Type: IfcfgTypeEthernet, + UserCtl: common.BoolToPtr(false), + PeerDNS: common.BoolToPtr(true), + IPv6Init: common.BoolToPtr(true), + }, + }, + }, + }, + }, + args: args{ + data: []byte(`{"type":"org.osbuild.sysconfig","options":{"kernel":{"update_default":true,"default_kernel":"kernel"},"network":{"networking":true,"no_zero_conf":true},"network-scripts":{"ifcfg":{"eth0":{"bootproto":"dhcp","device":"eth0","ipv6init":false,"onboot":true,"peerdns":true,"type":"Ethernet","userctl":true},"eth1":{"bootproto":"dhcp","device":"eth1","ipv6init":true,"onboot":true,"peerdns":true,"type":"Ethernet","userctl":false}}}}}`), + }, + }, { name: "systemd", fields: fields{ diff --git a/internal/osbuild2/sysconfig_stage.go b/internal/osbuild2/sysconfig_stage.go index b133aa066..32258ff69 100644 --- a/internal/osbuild2/sysconfig_stage.go +++ b/internal/osbuild2/sysconfig_stage.go @@ -1,8 +1,18 @@ package osbuild2 type SysconfigStageOptions struct { - Kernel SysconfigKernelOptions `json:"kernel,omitempty"` - Network SysconfigNetworkOptions `json:"network,omitempty"` + Kernel SysconfigKernelOptions `json:"kernel,omitempty"` + Network SysconfigNetworkOptions `json:"network,omitempty"` + NetworkScripts *NetworkScriptsOptions `json:"network-scripts,omitempty"` +} + +func (SysconfigStageOptions) isStageOptions() {} + +func NewSysconfigStage(options *SysconfigStageOptions) *Stage { + return &Stage{ + Type: "org.osbuild.sysconfig", + Options: options, + } } type SysconfigNetworkOptions struct { @@ -15,11 +25,55 @@ type SysconfigKernelOptions struct { DefaultKernel string `json:"default_kernel,omitempty"` } -func (SysconfigStageOptions) isStageOptions() {} - -func NewSysconfigStage(options *SysconfigStageOptions) *Stage { - return &Stage{ - Type: "org.osbuild.sysconfig", - Options: options, - } +type NetworkScriptsOptions struct { + // Keys are interface names, values are objects containing interface configuration + IfcfgFiles map[string]IfcfgFile `json:"ifcfg,omitempty"` +} + +type IfcfgBootprotoValue string + +// Valid values for the 'Bootproto' item of 'IfcfgFile' struct +const ( + IfcfgBootprotoNone IfcfgBootprotoValue = "none" + IfcfgBootprotoBootp IfcfgBootprotoValue = "bootp" + IfcfgBootprotoDHCP IfcfgBootprotoValue = "dhcp" + IfcfgBootprotoStatic IfcfgBootprotoValue = "static" + IfcfgBootprotoIbft IfcfgBootprotoValue = "ibft" + IfcfgBootprotoAutoIP IfcfgBootprotoValue = "autoip" + IfcfgBootprotoShared IfcfgBootprotoValue = "shared" +) + +type IfcfgTypeValue string + +// Valid values for the 'Type' item of 'IfcfgFile' struct +const ( + IfcfgTypeEthernet IfcfgTypeValue = "Ethernet" + IfcfgTypeWireless IfcfgTypeValue = "Wireless" + IfcfgTypeInfiniBand IfcfgTypeValue = "InfiniBand" + IfcfgTypeBridge IfcfgTypeValue = "Bridge" + IfcfgTypeBond IfcfgTypeValue = "Bond" + IfcfgTypeVLAN IfcfgTypeValue = "Vlan" +) + +type IfcfgFile struct { + // Method used for IPv4 protocol configuration + Bootproto IfcfgBootprotoValue `json:"bootproto,omitempty"` + + // Interface name of the device + Device string `json:"device,omitempty"` + + // Whether to initialize this device for IPv6 addressing + IPv6Init *bool `json:"ipv6init,omitempty"` + + // Whether the connection should be autoconnected + OnBoot *bool `json:"onboot,omitempty"` + + // Whether to modify /etc/resolv.conf + PeerDNS *bool `json:"peerdns,omitempty"` + + // Base type of the connection + Type IfcfgTypeValue `json:"type,omitempty"` + + // Whether non-root users are allowed to control the device + UserCtl *bool `json:"userctl,omitempty"` }