Skip to content

Commit

Permalink
Merge pull request #139 from hadfl/emu
Browse files Browse the repository at this point in the history
add support for emu brand
  • Loading branch information
oetiker authored Jul 3, 2023
2 parents 533b9e4 + 3a3de8c commit a36d1f5
Show file tree
Hide file tree
Showing 13 changed files with 434 additions and 160 deletions.
12 changes: 6 additions & 6 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
requires 'Bytes::Random::Secure::Tiny', '== 1.011';
requires 'Cpanel::JSON::XS', '== 4.32';
requires 'Cpanel::JSON::XS', '== 4.36';
requires 'Curses::UI', '== 0.9609';
requires 'Data::Processor', '== 1.0.9';
requires 'Mojolicious', '== 9.28';
requires 'IO::Socket::SSL', '== 2.075';
requires 'IO::Uncompress::UnXz', '== 2.201';
requires 'IO::Uncompress::UnZstd', '== 2.201';
requires 'Mojolicious', '== 9.32';
requires 'IO::Socket::SSL', '== 2.083';
requires 'IO::Uncompress::UnXz', '== 2.204';
requires 'IO::Uncompress::UnZstd', '== 2.204';
requires 'Regexp::IPv4', '== 0.003';
requires 'Regexp::IPv6', '== 0.03';
requires 'TOML::Tiny', '== 0.15';
requires 'YAML::XS', '== 0.85';
requires 'YAML::XS', '== 0.88';
36 changes: 36 additions & 0 deletions doc/zadm.pod
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,42 @@ where 'command' is one of the following:
man
version

=head1 EMU BRAND SYNOPSIS

B<zadm> I<command> [I<options...>]

where 'command' is one of the following:

create -b <brand> [-i <image_uuid|image_path_or_uri>] [-t <template_path>] <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
list-images [--refresh] [--verbose] [-b <brand>] [-p <provider>]
pull <image_uuid>
vacuum [-d <days>]
brands
start [-c [extra_args]] <zone_name>
stop [-c [extra_args]] <zone_name>
restart [-c [extra_args]] <zone_name>
poweroff <zone_name>
reset <zone_name>
console [extra_args] <zone_name>
monitor <zone_name>
vnc [-w] [<[bind_addr:]port>] <zone_name>
webvnc [<[bind_addr:]port>] <zone_name>
log <zone_name>
snapshot [-d] <zone_name> [<snapname>]
rollback [-r] <zone_name> <snapname>
help [-b <brand>]
doc [-b <brand>] [-a <attribute>]
man
version

=head1 ILLUMOS BRAND SYNOPSIS

B<zadm> I<command> [I<options...>]
Expand Down
4 changes: 3 additions & 1 deletion lib/Zadm/Image/OmniOS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ sub postProcess($self, $json) {
chksum => {
digest => 'sha256',
chksum => $_->{sha256},
}
},
attr => $_->{attr} // {},
res => $_->{resources} || [],
} }
@{$data->{images} // []}
];
Expand Down
6 changes: 3 additions & 3 deletions lib/Zadm/Image/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ has images => sub($self) { Zadm::Images->new(log => $self->log) };
# private methods
my $checkChecksum = sub($self, $file, $digest, $checksum) {
$self->log->debug(q{checking checksum of '} . $file->basename . q{'...});
print "checking image checksum...\n";
print "checking image checksum...\n" if !$self->images->editing;

return Digest::SHA->new($digest)->addfile($file->to_string)->hexdigest eq $checksum;
};
Expand All @@ -49,7 +49,7 @@ sub download($self, $fileName, $url, %opts) {

$self->images->curl([{ path => $file, url => $url }], \%opts) if !-f $file;

return $file if !exists $opts{chksum}
return $file if !exists $opts{chksum} || !$opts{chksum}->{chksum}
|| $self->$checkChecksum($file, $opts{chksum}->{digest}, $opts{chksum}->{chksum});

# re-download since checksum mismatch
Expand Down Expand Up @@ -80,7 +80,7 @@ __END__
=head1 COPYRIGHT
Copyright 2021 OmniOS Community Edition (OmniOSce) Association.
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
13 changes: 3 additions & 10 deletions lib/Zadm/Schema/Bhyve.pm
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,6 @@ $SCHEMA = sub($self) {
validator => $self->sv->bool,
'x-attr' => 1,
},
vga => {
optional => 1,
description => 'type of VGA emulation to use',
example => '"vga" : "on"',
validator => $self->sv->elemOf(qw(on off io)), # change to bool once bhyve supports it
'x-attr' => 1,
},
vnc => {
optional => 1,
description => 'VNC',
Expand Down Expand Up @@ -407,16 +400,16 @@ $SCHEMA = sub($self) {
validator => $self->sv->bool,
'x-attr' => 1,
},

}};
}
};

1;

__END__
=head1 COPYRIGHT
Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
99 changes: 99 additions & 0 deletions lib/Zadm/Schema/Emu.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package Zadm::Schema::Emu;
use Mojo::Base 'Zadm::Schema::KVM', -signatures;

my $SCHEMA;
has schema => sub($self) {
my $kvmschema = $self->SUPER::schema;

my $dp = Data::Processor->new($kvmschema);
my $ec = $dp->merge_schema($self->$SCHEMA);

$ec->count and Mojo::Exception->throw(join ("\n", map { $_->stringify } @{$ec->{errors}}));

return $dp->schema;
};

has archs => sub {
return [
map { /qemu-system-(\w+)$/ } glob '/opt/ooce/qemu/bin/qemu-system-*'
];
};

$SCHEMA = sub($self) {
return {
arch => {
description => 'architecture to emulate',
example => '"arch" : "aarch64"',
validator => $self->sv->elemOf(@{$self->archs}),
'x-attr' => 1,
},
cpu => {
description => 'cpu to emulate',
example => '"cpu" : "cortex-a53"',
validator => $self->sv->regexp(qr/^.+$/, 'expected a string'),
'x-attr' => 1,
},
'cloud-init' => {
optional => 1,
description => 'provide cloud-init data - on|off|file path|URL',
default => 'off',
example => '"cloud-init" : "on"',
validator => $self->sv->cloudinit,
'x-attr' => 1,
},
password => {
optional => 1,
description => 'provide cloud-init password/hash or path to file',
example => '"password" : "$6$SEeDRaFR$...5/"',
validator => $self->sv->stringorfile,
transformer => $self->sv->toPWHash,
'x-attr' => 1,
},
rng => {
optional => 1,
description => 'attach VirtIO random number generator (RNG) to the guest',
default => 'off',
example => '"rng" : "on"',
validator => $self->sv->bool,
'x-attr' => 1,
},
sshkey => {
optional => 1,
description => 'provide cloud-init public SSH key - string or path to file',
example => '"sshkey" : "/root/.ssh/id_rsa.pub"',
validator => $self->sv->stringorfile,
'x-attr' => 1,
},
}
};

1;

__END__
=head1 COPYRIGHT
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see L<http://www.gnu.org/licenses/>.
=head1 AUTHOR
S<Dominik Hassler E<lt>[email protected]E<gt>>
=head1 HISTORY
2020-04-12 had Initial Version
=cut
21 changes: 15 additions & 6 deletions lib/Zadm/Schema/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,23 @@ $SCHEMA = sub($self) {
description => 'disk type',
default => 'virtio',
example => '"diskif" : "virtio"',
validator => $self->sv->elemOf(qw(virtio ahci ide)),
validator => $self->sv->elemOf(qw(virtio ahci ide virtio-blk-device)),
'x-attr' => 1,
},
extra => {
optional => 1,
array => 1,
description => 'extra parameters',
example => '"extra" : "<parameters>"',
example => '"extra" : [ "param1", "param2", ... ]',
validator => $self->sv->regexp(qr/^.+$/, 'expected a string'),
'x-attr' => 1,
transformer => $self->sv->toArray,
},
netif => {
optional => 1,
description => 'network interface type',
default => 'virtio',
example => '"netif" : "virtio"',
validator => $self->sv->elemOf(qw(virtio e1000)),
validator => $self->sv->elemOf(qw(virtio e1000 virtio-net-device)),
'x-attr' => 1,
},
ram => {
Expand Down Expand Up @@ -146,15 +147,23 @@ $SCHEMA = sub($self) {
validator => $self->sv->kvmVNC,
'x-attr' => 1,
},
}};
vga => {
optional => 1,
description => 'type of VGA emulation to use',
example => '"vga" : "on"',
validator => $self->sv->elemOf(qw(on off io)),
'x-attr' => 1,
},
}
};

1;

__END__
=head1 COPYRIGHT
Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
Copyright 2023 OmniOS Community Edition (OmniOSce) Association.
=head1 LICENSE
Expand Down
3 changes: 2 additions & 1 deletion lib/Zadm/Schema/LX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ $SCHEMA = sub($self) {
validator => $self->sv->elemOf(qw(true false)),
'x-attr' => 1,
},
}};
}
};

1;

Expand Down
3 changes: 2 additions & 1 deletion lib/Zadm/Schema/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ has schema => sub($self) {
},
},
},
}};
}
};

1;

Expand Down
Loading

0 comments on commit a36d1f5

Please sign in to comment.