Skip to content

Commit 2023093

Browse files
committed
Undo set_secure_boot_template + feedback
1 parent ffd901e commit 2023093

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

petri/src/vm/hyperv/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ pub struct PetriVmConfigHyperV {
5757
// Specifies the path to a virtual hard disk file(s) to attach to the
5858
// virtual machine as SCSI (Gen2) or IDE (Gen1) drives.
5959
vhd_paths: Vec<Vec<PathBuf>>,
60-
secure_boot_enabled: bool,
6160
secure_boot_template: Option<powershell::HyperVSecureBootTemplate>,
6261
openhcl_igvm: Option<ResolvedArtifact>,
6362
openhcl_command_line: String,
@@ -367,8 +366,8 @@ impl PetriVmConfigHyperV {
367366
})?;
368367
}
369368

370-
if self.generation == powershell::HyperVGeneration::Two {
371-
vm.set_secure_boot_state(self.secure_boot_enabled, self.secure_boot_template)?;
369+
if let Some(secure_boot_template) = self.secure_boot_template {
370+
vm.set_secure_boot_template(secure_boot_template)
372371
}
373372

374373
for (i, vhds) in self.vhd_paths.iter().enumerate() {

petri/src/vm/hyperv/powershell.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ pub struct HyperVSetVMFirmwareArgs<'a> {
392392
/// Specifies the ID of virtual machines for which you want to modify the
393393
/// firmware configuration.
394394
pub vmid: &'a Guid,
395-
/// Specifies whether to enable secure boot for the virtual machine.
396-
pub secure_boot_enabled: bool,
397395
/// Specifies the name of the secure boot template. If secure boot is
398396
/// enabled, you must have a valid secure boot template for the guest
399397
/// operating system to start.
@@ -402,32 +400,24 @@ pub struct HyperVSetVMFirmwareArgs<'a> {
402400

403401
/// Runs Set-VMFirmware with the given arguments.
404402
pub fn run_set_vm_firmware(args: HyperVSetVMFirmwareArgs<'_>) -> anyhow::Result<()> {
405-
// Determine the boot state based on whether secure boot is enabled
406-
let boot_state = if args.secure_boot_enabled {
407-
ps::RawVal::new("On")
408-
} else {
409-
ps::RawVal::new("Off")
410-
};
411-
412-
// Build the PowerShell command
413403
let mut builder = PowerShellBuilder::new()
414404
.cmdlet("Get-VM")
415405
.arg("Id", args.vmid)
416-
.pipeline()
417-
.cmdlet("Set-VMFirmware")
418-
.arg("EnableSecureBoot", boot_state);
406+
.pipeline();
419407

420-
// Add the secure boot template if specified
421-
if let Some(template) = args.secure_boot_template {
422-
builder = builder.arg("SecureBootTemplate", template);
423-
}
408+
builder = match args.secure_boot_template {
409+
None => builder
410+
.cmdlet("Set-VMFirmware")
411+
.arg("EnableSecureBoot", ps::RawVal::new("Off"))
412+
.finish(),
413+
Some(template) => builder
414+
.cmdlet("Set-VMFirmware")
415+
.arg("EnableSecureBoot", ps::RawVal::new("On"))
416+
.arg("SecureBootTemplate", template)
417+
.finish(),
418+
};
424419

425-
// Execute the command
426-
builder
427-
.finish()
428-
.output(true)
429-
.map(|_| ())
430-
.context("set_vm_firmware")
420+
builder.output(true).map(|_| ()).context("set_vm_firmware")
431421
}
432422

433423
/// Runs Set-VMFirmware with the given arguments.

petri/src/vm/hyperv/vm.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,14 @@ impl HyperVVM {
225225
)
226226
}
227227

228-
/// Set the secure boot state
229-
pub fn set_secure_boot_state(
228+
/// Set the secure boot template
229+
pub fn set_secure_boot_template(
230230
&mut self,
231-
enabled: bool,
232-
secure_boot_template: Option<powershell::HyperVSecureBootTemplate>,
231+
secure_boot_template: powershell::HyperVSecureBootTemplate,
233232
) -> anyhow::Result<()> {
234233
powershell::run_set_vm_firmware(powershell::HyperVSetVMFirmwareArgs {
235234
vmid: &self.vmid,
236-
secure_boot_enabled: enabled,
237-
secure_boot_template,
235+
secure_boot_template: Some(secure_boot_template),
238236
})
239237
}
240238

0 commit comments

Comments
 (0)