Skip to content

Commit

Permalink
expand initial KVM/bhyve zone template
Browse files Browse the repository at this point in the history
  • Loading branch information
hadfl committed May 18, 2020
1 parent b0678f2 commit f8c3a38
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
54 changes: 54 additions & 0 deletions lib/Zadm/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ my %CMDS = (
bz2 => -x '/opt/ooce/bin/pbzip2' ? '/opt/ooce/bin/pbzip2' : '/usr/bin/bzip2',
xz => '/usr/bin/xz',
pager => $ENV{PAGER} || '/usr/bin/less -eimnqX',
domainname => '/usr/bin/domainname',
dispadmin => '/usr/sbin/dispadmin',
);

my %ENVARGS = map {
Expand Down Expand Up @@ -252,6 +254,58 @@ sub getZfsProp {
return { map { $prop->[$_] => $vals[$_] } (0 .. $#$prop) };
}

sub domain {
my $self = shift;

my %domain;

my $domainname = $self->pipe('domainname');
my ($domain) = <$domainname> =~ /^\s*(\S+)/;

-r '/etc/resolv.conf' && do {
open my $fh, '<', '/etc/resolv.conf'
or Mojo::Exception->throw("ERROR: cannot read /etc/resolv.conf: $!\n");

while (<$fh>) {
my ($key, $val) = /^\s*(\S+)\s+(\S+)/
or next;
for ($key) {
/^nameserver$/ && do {
push @{$domain{resolvers}}, $val;
last;
};
/^domain$/ && do {
$domain{'dns-domain'} = $val;
last;
};
/^search$/ && do {
$domain{'dns-domain'} ||= $val;
last;
};
}
}
};
$domain{'dns-domain'} = $domain if $domain;
return \%domain;
}
sub scheduler {
my $self = shift;
return {} if !-e '/etc/dispadmin.conf';
my $dispadmin = $self->pipe('dispadmin', [ qw(-d) ]);
return { 'cpu-shares' => 1 } if grep { /^FSS/ } (<$dispadmin>);
return {};
}
sub loadTemplate {
my $self = shift;
my $file = shift;
Expand Down
21 changes: 21 additions & 0 deletions lib/Zadm/Zone/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ my $ZVOLRX = qr!/dev/zvol/r?dsk/!;
my @MON_INFO = qw(block blockstats chardev cpus kvm network pci registers qtree usb version vnc);
my $RCV_TMO = 3;

has template => sub {
my $self = shift;
my $name = $self->name;

my $template = $self->SUPER::template;
# KVM and derived zones do not have 'dns-domain' or 'resolvers' properties; drop them
delete $template->{$_} for qw(dns-domain resolvers);

return {
%$template,
bootdisk => {
path => "rpool/$name/root",
size => "10G",
sparse => 'false',
blocksize => '8k',
},
ram => '2G',
vcpus => '4',
vnc => 'on',
}
};
has options => sub {
my $self = shift;

Expand Down
16 changes: 9 additions & 7 deletions lib/Zadm/Zone/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ has statemap => sub {
has createprop => sub { [ qw(zonename zonepath brand ip-type) ] };
has template => sub {
my $self = shift;

my $name = $self->name;

return {
zonename => $name,
zonepath => ($ENV{__ZADM_ALTROOT} // '') . "/zones/$name",
brand => $self->brand,
'ip-type' => 'exclusive',
autoboot => 'false',
'cpu-shares' => 1,
net => [ { physical => "${name}0" } ],
zonename => $name,
zonepath => ($ENV{__ZADM_ALTROOT} // '') . "/zones/$name",
brand => $self->brand,
'ip-type' => 'exclusive',
autoboot => 'false',
net => [ { physical => "${name}0" } ],
%{$self->utils->domain},
%{$self->utils->scheduler},
}
};
has options => sub {
Expand Down

0 comments on commit f8c3a38

Please sign in to comment.