Skip to content

Commit 067629e

Browse files
jaypifjaimecb
andauthored
F-558: Add missing paramters in OS section of VM template (#579)
* F-558: Add missing paramters in OS section of VM template This commit adds support for missing OS section in VM template. It aligns the OS section with the Documentation: https://docs.opennebula.io/6.10/management_and_operations/references/template.html?highlight=firmware#os-and-boot-options-section A correct fix consist in updating GOCA OSVec structure to reflec the Documentation A dedicated issue has bee openned in the Goca Repo: OpenNebula/one#6782 * F #558: Add usage of new OS params in VM template [skip ci] * F #558: Update docs and goca version with new OSVec --------- Signed-off-by: Jaime <jconchello@opennebula.io> Co-authored-by: Jaime <jconchello@opennebula.io> Co-authored-by: Jaime Conchello <56997708+jaimecb@users.noreply.github.com>
1 parent 878b589 commit 067629e

File tree

7 files changed

+240
-4
lines changed

7 files changed

+240
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
FEATURES:
44

55
* provider: Added a `--debug` flag for enabling provider debugging (#582)
6+
* shared_schemas: Add `machine`, `kernel`, `kernel_ds`, `initrd`, `initrd_ds`, `root`, `kernel_cmd`, `bootloader`, `sd_disk_bus`, `uuid`, `firmware` and `firmware_secure` to OS schema (#558)
67

78
# 1.4.1 (October 22nd, 2024)
89

opennebula/resource_opennebula_virtual_machine_test.go

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,50 @@ func TestAccVirtualMachine(t *testing.T) {
6666
}),
6767
),
6868
},
69+
{
70+
Config: testAccVirtualMachineTemplateConfigOs,
71+
Check: resource.ComposeTestCheckFunc(
72+
testAccSetDSdummy(),
73+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "name", "test-virtual_machine"),
74+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "permissions", "642"),
75+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "memory", "128"),
76+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "cpu", "0.1"),
77+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.%", "3"),
78+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.NETWORK", "YES"),
79+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "context.TESTVAR", "TEST"),
80+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.#", "1"),
81+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.keymap", "en-us"),
82+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.listen", "0.0.0.0"),
83+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "graphics.0.type", "VNC"),
84+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.#", "1"),
85+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.arch", "x86_64"),
86+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.boot", ""),
87+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.firmware", ""),
88+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "os.0.firmware_secure", "false"),
89+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "disk.#", "0"),
90+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.%", "2"),
91+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.env", "prod"),
92+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "tags.customer", "test"),
93+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "description", "VM created for provider acceptance tests"),
94+
resource.TestCheckResourceAttr("opennebula_virtual_machine.testos", "timeout", "5"),
95+
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "uid"),
96+
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "gid"),
97+
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "uname"),
98+
resource.TestCheckResourceAttrSet("opennebula_virtual_machine.testos", "gname"),
99+
testAccCheckVirtualMachinePermissions(&shared.Permissions{
100+
OwnerU: 1,
101+
OwnerM: 1,
102+
GroupU: 1,
103+
OtherM: 1,
104+
}),
105+
resource.TestCheckTypeSetElemNestedAttrs("opennebula_virtual_machine.testos", "template_section.*", map[string]string{
106+
"name": "test_vec_key",
107+
"elements.%": "2",
108+
"elements.testkey1": "testvalue1",
109+
"elements.testkey2": "testvalue2",
110+
}),
111+
),
112+
},
69113
{
70114
Config: testAccVirtualMachineConfigUpdate,
71115
Check: resource.ComposeTestCheckFunc(
@@ -635,7 +679,7 @@ resource "opennebula_virtual_machine" "test" {
635679
os {
636680
arch = "x86_64"
637681
boot = ""
638-
}
682+
}
639683
640684
tags = {
641685
env = "prod"
@@ -656,6 +700,51 @@ resource "opennebula_virtual_machine" "test" {
656700
}
657701
`
658702

703+
var testAccVirtualMachineTemplateConfigOs = `
704+
resource "opennebula_virtual_machine" "testos" {
705+
name = "test-virtual_machine"
706+
group = "oneadmin"
707+
permissions = "642"
708+
memory = 128
709+
cpu = 0.1
710+
description = "VM created for provider acceptance tests"
711+
712+
context = {
713+
TESTVAR = "TEST"
714+
NETWORK = "YES"
715+
SET_HOSTNAME = "$NAME"
716+
}
717+
718+
graphics {
719+
type = "VNC"
720+
listen = "0.0.0.0"
721+
keymap = "en-us"
722+
}
723+
724+
os {
725+
arch = "x86_64"
726+
boot = ""
727+
firmware = ""
728+
firmware_secure = false
729+
}
730+
731+
tags = {
732+
env = "prod"
733+
customer = "test"
734+
}
735+
736+
template_section {
737+
name = "test_vec_key"
738+
elements = {
739+
testkey1 = "testvalue1"
740+
testkey2 = "testvalue2"
741+
}
742+
}
743+
744+
timeout = 5
745+
}
746+
`
747+
659748
var testAccVirtualMachineTemplateConfigCPUModel = `
660749
resource "opennebula_virtual_machine" "test" {
661750
name = "test-virtual_machine-renamed"

opennebula/shared_schemas.go

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func osSchema() *schema.Schema {
430430
Type: schema.TypeList,
431431
Optional: true,
432432
MaxItems: 1,
433-
Description: "Definition of OS boot and type for the Virtual Machine",
433+
Description: "Definition of OS parameters for the Virtual Machine",
434434
Elem: &schema.Resource{
435435
Schema: map[string]*schema.Schema{
436436
"arch": {
@@ -441,6 +441,59 @@ func osSchema() *schema.Schema {
441441
Type: schema.TypeString,
442442
Required: true,
443443
},
444+
"machine": {
445+
Type: schema.TypeString,
446+
Optional: true,
447+
},
448+
"kernel": {
449+
Type: schema.TypeString,
450+
Optional: true,
451+
ConflictsWith: []string{"os.0.kernel_ds"},
452+
},
453+
"kernel_ds": {
454+
Type: schema.TypeString,
455+
Optional: true,
456+
ConflictsWith: []string{"os.0.kernel"},
457+
},
458+
"initrd": {
459+
Type: schema.TypeString,
460+
Optional: true,
461+
ConflictsWith: []string{"os.0.initrd_ds"},
462+
},
463+
"initrd_ds": {
464+
Type: schema.TypeString,
465+
Optional: true,
466+
ConflictsWith: []string{"os.0.initrd"},
467+
},
468+
"root": {
469+
Type: schema.TypeString,
470+
Optional: true,
471+
},
472+
"kernel_cmd": {
473+
Type: schema.TypeString,
474+
Optional: true,
475+
},
476+
"bootloader": {
477+
Type: schema.TypeString,
478+
Optional: true,
479+
},
480+
"sd_disk_bus": {
481+
Type: schema.TypeString,
482+
Optional: true,
483+
},
484+
"uuid": {
485+
Type: schema.TypeString,
486+
Optional: true,
487+
Computed: true,
488+
},
489+
"firmware": {
490+
Type: schema.TypeString,
491+
Optional: true,
492+
},
493+
"firmware_secure": {
494+
Type: schema.TypeBool,
495+
Optional: true,
496+
},
444497
},
445498
},
446499
}
@@ -646,7 +699,19 @@ func addOS(tpl *vm.Template, os []interface{}) {
646699
if os[i] != nil {
647700
osconfig := os[i].(map[string]interface{})
648701
tpl.AddOS(vmk.Arch, osconfig["arch"].(string))
702+
tpl.AddOS(vmk.Machine, osconfig["machine"].(string))
703+
tpl.AddOS(vmk.Kernel, osconfig["kernel"].(string))
704+
tpl.AddOS(vmk.KernelDS, osconfig["kernel_ds"].(string))
705+
tpl.AddOS(vmk.Initrd, osconfig["initrd"].(string))
706+
tpl.AddOS(vmk.InitrdDS, osconfig["initrd_ds"].(string))
707+
tpl.AddOS(vmk.Root, osconfig["root"].(string))
708+
tpl.AddOS(vmk.KernelCmd, osconfig["kernel_cmd"].(string))
709+
tpl.AddOS(vmk.Bootloader, osconfig["bootloader"].(string))
649710
tpl.AddOS(vmk.Boot, osconfig["boot"].(string))
711+
tpl.AddOS(vmk.SDDiskBus, osconfig["sd_disk_bus"].(string))
712+
tpl.AddOS(vmk.UUID, osconfig["uuid"].(string))
713+
tpl.AddOS(vmk.Firmware, osconfig["firmware"].(string))
714+
tpl.AddOS(vmk.FirmwareSecure, osconfig["firmware_secure"].(bool))
650715
}
651716
}
652717

@@ -992,7 +1057,19 @@ func flattenTemplate(d *schema.ResourceData, inheritedVectors map[string]interfa
9921057
// OS
9931058
osMap := make([]map[string]interface{}, 0, 1)
9941059
arch, _ := vmTemplate.GetOS(vmk.Arch)
1060+
machine, _ := vmTemplate.GetOS(vmk.Machine)
1061+
kernel, _ := vmTemplate.GetOS(vmk.Kernel)
1062+
kernelDS, _ := vmTemplate.GetOS(vmk.KernelDS)
1063+
initrd, _ := vmTemplate.GetOS(vmk.Initrd)
1064+
initrdDS, _ := vmTemplate.GetOS(vmk.InitrdDS)
1065+
root, _ := vmTemplate.GetOS(vmk.Root)
1066+
kernelCmd, _ := vmTemplate.GetOS(vmk.KernelCmd)
1067+
bootloader, _ := vmTemplate.GetOS(vmk.Bootloader)
9951068
boot, _ := vmTemplate.GetOS(vmk.Boot)
1069+
sdDiskBus, _ := vmTemplate.GetOS(vmk.SDDiskBus)
1070+
uuid, _ := vmTemplate.GetOS(vmk.UUID)
1071+
firmware, _ := vmTemplate.GetOS(vmk.Firmware)
1072+
firmwareSecure, firmwareSecureErr := vmTemplate.GetOS(vmk.FirmwareSecure)
9961073
// CPU Model
9971074
cpumodelMap := make([]map[string]interface{}, 0, 1)
9981075
cpumodel, _ := vmTemplate.GetCPUModel(vmk.Model)
@@ -1049,9 +1126,26 @@ func flattenTemplate(d *schema.ResourceData, inheritedVectors map[string]interfa
10491126

10501127
// Set OS to resource
10511128
if arch != "" {
1129+
firmwareSecureBool := false
1130+
if firmwareSecureErr == nil && firmwareSecure == "true" {
1131+
firmwareSecureBool = true
1132+
}
1133+
10521134
osMap = append(osMap, map[string]interface{}{
1053-
"arch": arch,
1054-
"boot": boot,
1135+
"arch": arch,
1136+
"machine": machine,
1137+
"kernel": kernel,
1138+
"kernel_ds": kernelDS,
1139+
"initrd": initrd,
1140+
"initrd_ds": initrdDS,
1141+
"root": root,
1142+
"kernel_cmd": kernelCmd,
1143+
"bootloader": bootloader,
1144+
"boot": boot,
1145+
"sd_disk_bus": sdDiskBus,
1146+
"uuid": uuid,
1147+
"firmware": firmware,
1148+
"firmware_secure": firmwareSecureBool,
10551149
})
10561150
_, inherited := inheritedVectors["OS"]
10571151
if !inherited {

website/docs/r/template.html.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ The following arguments are supported:
128128

129129
* `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture.
130130
* `boot` - (Optional) `OS` disk to use to boot on.
131+
* `machine` - (Optional) libvirt machine type.
132+
* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host.
133+
* `kernel_ds` - (Optional) Image to be used as kernel. (see !!)
134+
* `initrd` - (Optional) Path to the initrd image in the host.
135+
* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!)
136+
* `root` - (Optional) Device to be mounted as root.
137+
* `kernel_cmd` - (Optional) Arguments for the booting kernel.
138+
* `bootloader` - (Optional) Path to the bootloader executable.
139+
* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself.
140+
* `uuid` - (Optional) Unique ID of the VM.
141+
* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter.
142+
* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`).
143+
* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`).
131144

132145
### Features parameters
133146

website/docs/r/virtual_machine.html.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ The following arguments are supported:
129129

130130
* `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture.
131131
* `boot` - (Optional) `OS` disk to use to boot on.
132+
* `machine` - (Optional) libvirt machine type.
133+
* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host.
134+
* `kernel_ds` - (Optional) Image to be used as kernel. (see !!)
135+
* `initrd` - (Optional) Path to the initrd image in the host.
136+
* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!)
137+
* `root` - (Optional) Device to be mounted as root.
138+
* `kernel_cmd` - (Optional) Arguments for the booting kernel.
139+
* `bootloader` - (Optional) Path to the bootloader executable.
140+
* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself.
141+
* `uuid` - (Optional) Unique ID of the VM.
142+
* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter.
143+
* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`).
144+
* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`).
132145

133146
### Disk parameters
134147

website/docs/r/virtual_router_instance.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ The following arguments are supported:
118118

119119
* `arch` - (Required) Hardware architecture of the virtual router instance. Must fit the host architecture.
120120
* `boot` - (Optional) `OS` disk to use to boot on.
121+
* `machine` - (Optional) libvirt machine type.
122+
* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host.
123+
* `kernel_ds` - (Optional) Image to be used as kernel. (see !!)
124+
* `initrd` - (Optional) Path to the initrd image in the host.
125+
* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!)
126+
* `root` - (Optional) Device to be mounted as root.
127+
* `kernel_cmd` - (Optional) Arguments for the booting kernel.
128+
* `bootloader` - (Optional) Path to the bootloader executable.
129+
* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself.
130+
* `uuid` - (Optional) Unique ID of the VM.
131+
* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter.
132+
* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`).
133+
* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`).
121134

122135
### Disk parameters
123136

website/docs/r/virtual_router_instance_template.markdown

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ resource "opennebula_virtual_router_instance_template" "example" {
8888

8989
* `arch` - (Required) Hardware architecture of the Virtual machine. Must fit the host architecture.
9090
* `boot` - (Optional) `OS` disk to use to boot on.
91+
* `machine` - (Optional) libvirt machine type.
92+
* `kernel` - (Optional) Path to the `OS` kernel to boot the image in the host.
93+
* `kernel_ds` - (Optional) Image to be used as kernel. (see !!)
94+
* `initrd` - (Optional) Path to the initrd image in the host.
95+
* `initrd_ds` - (Optional) Image to be used as ramdisk. (see !!)
96+
* `root` - (Optional) Device to be mounted as root.
97+
* `kernel_cmd` - (Optional) Arguments for the booting kernel.
98+
* `bootloader` - (Optional) Path to the bootloader executable.
99+
* `sd_disk_bus` - (Optional) Bus for disks with sd prefix, either `scsi` or `sata`, if attribute is missing, libvirt chooses itself.
100+
* `uuid` - (Optional) Unique ID of the VM.
101+
* `firmware` - (Optional) Firmware type or firmware path. Possible values: `BIOS` or path for KVM, `BIOS` or `UEFI` for vCenter.
102+
* `firmware_secure` - (Optional) Enable Secure Boot. (Can be `true` or `false`).
103+
* (!!) Use one of `kernel_ds` or `kernel` (and `initrd` or `initrd_ds`).
91104

92105
### Features parameters
93106

0 commit comments

Comments
 (0)