Skip to content

Commit

Permalink
add command to update resources
Browse files Browse the repository at this point in the history
  • Loading branch information
hadfl committed Jul 28, 2024
1 parent 4262540 commit a01d996
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions doc/zadm.pod
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ where 'command' is one of the following:
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall [-f] <zone_name>
updateres -i <image_uuid> <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down
36 changes: 28 additions & 8 deletions lib/Zadm/Zone/Emu.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ use Mojo::URL;

has ibrand => sub($self) { $self->brand };
has template => sub($self) {
my $template = $self->SUPER::template;

return {
%{$self->SUPER::template},
$self->hasimg ? %{$self->image->metadata->{attr} || {}} : (),
}
};
has public => sub($self) { [ @{$self->SUPER::public}, qw(updateres) ] };
has options => sub($self) {
return {
%{$self->SUPER::options},
updateres => {
image => {
getopt => 'image|i=s',
},
},
}
};

# public methods
sub install($self, @args) {
$self->SUPER::install(@args);
sub updateres($self, @args) {
return 1 if $ENV{__ZADM_ALTROOT};

return 1 if $ENV{__ZADM_ALTROOT} || !$self->hasimg
|| !$self->utils->isArrRef($self->image->metadata->{res});
$self->usage if !$self->hasimg;

return 1 if !$self->utils->isArrRef($self->image->metadata->{res});

# TODO: we could parallelise this; however, we just have one resource so far at maximum
# we could parallelise this; however, we just have a few resources and they are small
# the advantage of doing it sequentially is that we can print progress
for my $res (@{$self->image->metadata->{res}}) {
my $file = Mojo::File->new($self->config->{zonepath}, 'root', Mojo::File->new($res)->basename);
Expand All @@ -31,6 +41,15 @@ sub install($self, @args) {
}
}

sub install($self, @args) {
$self->SUPER::install(@args);

return 1 if $ENV{__ZADM_ALTROOT} || !$self->hasimg
|| !$self->utils->isArrRef($self->image->metadata->{res});

$self->updateres;
}

1;

__END__
Expand All @@ -47,6 +66,7 @@ where 'command' is one of the following:
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall [-f] <zone_name>
updateres -i <image_uuid> <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand All @@ -73,7 +93,7 @@ where 'command' is one of the following:
=head1 COPYRIGHT
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down

0 comments on commit a01d996

Please sign in to comment.