-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Fisher
committed
Jul 22, 2024
1 parent
3038724
commit 9a09ced
Showing
5 changed files
with
167 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# frozen_string_literal: true | ||
|
||
module Oozone | ||
module ConfigDecorator | ||
# The bhyve installer is strongly opinionated. Here it fills in most of | ||
# the zone config file for you. | ||
class Bhyve | ||
def initialize(config, metadata) | ||
@config = config | ||
@metadata = metadata | ||
@bootdisk = File.join('rpool', 'zones', 'bhyve', @metadata[:zone_name]) | ||
@cloud_init_iso = '/tmp/cloud-init.iso' # THIS WILL BE DYNAMIC | ||
end | ||
|
||
def decorate! | ||
ret = add_zvol_device(@config) | ||
ret = add_cloudinit_cdrom(ret) if @metadata[:cloudinit] | ||
add_boot_attrs(ret) | ||
end | ||
|
||
# rubocop:disable Metrics/MethodLength | ||
def add_boot_attrs(config) | ||
to_add = [ | ||
['add attr', | ||
['set name=bootrom'], | ||
['set type=string'], | ||
['set value=BHYVE_RELEASE'], | ||
'end'], | ||
['add attr', | ||
['set name=bootdisk'], | ||
['set type=string'], | ||
["set value=#{@bootdisk}"], | ||
'end'], | ||
['add attr', | ||
['set name=acpi'], | ||
['set type=string'], | ||
['set value=false'], | ||
'end'] | ||
] | ||
|
||
if @metadata[:cloudinit] | ||
to_add << ['add attr', | ||
['set name=cdrom'], | ||
['set type=string'], | ||
["set value=#{@cloud_init_iso}"], | ||
'end'] | ||
end | ||
|
||
config << to_add | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def add_cloudinit_cdrom(config) | ||
config << [ | ||
['add fs', | ||
["set dir=#{@cloud_init_iso}"], | ||
["set special=#{@cloud_init_iso}"], | ||
['set type=lofs'], | ||
['set options=ro'], | ||
'end'] | ||
] | ||
end | ||
|
||
def add_zvol_device(config) | ||
config << [ | ||
['add device', ["set match=/dev/zvol/rdsk/#{@bootdisk}"], 'end'] | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
brand: bhyve | ||
zonepath: /zones/test-bhyve | ||
autoboot: true | ||
cloudinit: true | ||
net: | ||
- physical: bhyve_net0 | ||
'global-nic': e1000g0 | ||
allowed-address: 192.168.1.80/24 | ||
volume_size: 30G | ||
raw_image: /home/rob/work/noble-server-cloudimg-amd64.img.raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
create -b | ||
set brand=bhyve | ||
set zonepath=/zones/test-bhyve | ||
set autoboot=true | ||
add net | ||
set physical=bhyve_net0 | ||
set global-nic=e1000g0 | ||
set allowed-address=192.168.1.80/24 | ||
end | ||
add device | ||
set match=/dev/zvol/rdsk/rpool/zones/bhyve/test-bhyve | ||
end | ||
add fs | ||
set dir=/tmp/cloud-init.iso | ||
set special=/tmp/cloud-init.iso | ||
set type=lofs | ||
set options=ro | ||
end | ||
add attr | ||
set name=bootrom | ||
set type=string | ||
set value=BHYVE_RELEASE | ||
end | ||
add attr | ||
set name=bootdisk | ||
set type=string | ||
set value=rpool/zones/bhyve/test-bhyve | ||
end | ||
add attr | ||
set name=acpi | ||
set type=string | ||
set value=false | ||
end | ||
add attr | ||
set name=cdrom | ||
set type=string | ||
set value=/tmp/cloud-init.iso | ||
end |