add in cloudinit profile searching
This commit is contained in:
parent
45b7a8a633
commit
a394c8183c
|
@ -375,6 +375,10 @@ Get the VM OS profiles for a specified OS type.
|
|||
|
||||
One argument is required and that is the OS type.
|
||||
|
||||
An optional argument is taken and that is cloudinit. It is a
|
||||
Perl boolean value and if true it will only return profiles
|
||||
with cloudinit support.
|
||||
|
||||
The returned value is a array.
|
||||
|
||||
This will die upon failure.
|
||||
|
@ -382,11 +386,19 @@ This will die upon failure.
|
|||
# list the VM OS profiles for FreeBSD
|
||||
my @profiles=vm 'vm_os_profiles' => 'freebsd';
|
||||
print Dumper @profiles;
|
||||
|
||||
# list the VM OS profiles for FreeBSD
|
||||
@profiles=vm 'vm_os_profiles' => 'freebsd', cloudinit=>1;
|
||||
print Dumper @profiles;
|
||||
|
||||
=head2 vm_os_profiles_hash
|
||||
|
||||
Get the VM OS profiles for a specified OS type.
|
||||
|
||||
One optional argument is taken and that is cloudinit. It is a
|
||||
Perl boolean value and if true it will only return profiles
|
||||
with cloudinit support.
|
||||
|
||||
The returned value is a two level hash. The keys for the first
|
||||
level are the OS types and the keys for the second level are
|
||||
the OS profile names.
|
||||
|
@ -395,9 +407,12 @@ This will die upon failure.
|
|||
|
||||
my %os_profiles=vm 'vm_os_profiles_hash';
|
||||
print Dumper %os_profiles;
|
||||
|
||||
|
||||
# print the OS profiles for FreeBSD
|
||||
print Dumper keys( %{ $os_profiles{freebsd} } );
|
||||
|
||||
my %os_profiles=vm 'vm_os_profiles_hash', cloudinit=>1;
|
||||
print Dumper %os_profiles;
|
||||
|
||||
=head2 vm_os_types
|
||||
|
||||
|
@ -407,7 +422,7 @@ The returned value is a array.
|
|||
|
||||
This will die upon failure.
|
||||
|
||||
# list the VM OS profiles for FreeBSD
|
||||
# get a hash of all OS types and profiles
|
||||
my @os_types=vm 'vm_os_profiles';
|
||||
print Dumper @os_types;
|
||||
|
||||
|
|
|
@ -16,7 +16,12 @@ use Rex::Commands::User;
|
|||
use Rex::Commands::Fs;
|
||||
|
||||
sub execute {
|
||||
my ( $class, $wanted_os ) = @_;
|
||||
my ( $class, $wanted_os, %opts ) = @_;
|
||||
|
||||
# set cloudinit to false by default
|
||||
if ( !defined( $opts{cloudinit} ) ) {
|
||||
$opts{cloudinit} = 0;
|
||||
}
|
||||
|
||||
# the OS we want profiles for
|
||||
if ( !defined($wanted_os) ) {
|
||||
|
@ -41,9 +46,25 @@ sub execute {
|
|||
my %profiles;
|
||||
foreach my $config (@vm_configs) {
|
||||
my ( $vm, $os, $profile ) = split( /\-/, $config, 3 );
|
||||
if ( $os eq $wanted_os ) {
|
||||
$profile =~ s/\.conf$//;
|
||||
$profiles{$profile} = 1;
|
||||
|
||||
my $add_profile = 1;
|
||||
|
||||
# if cloudinit is defined, only add cloudinit images
|
||||
if ( $opts{cloudinit} ) {
|
||||
|
||||
# since we are default adding, make sure it is not a cloudinit
|
||||
# profile and don't add it if it is not
|
||||
if ( $profile !~ /^cloud\-/ ) {
|
||||
$add_profile = 0;
|
||||
}
|
||||
}
|
||||
|
||||
# add the profile if needed
|
||||
if ($add_profile) {
|
||||
if ( $os eq $wanted_os ) {
|
||||
$profile =~ s/\.conf$//;
|
||||
$profiles{$profile} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,15 @@ use Rex::Commands::User;
|
|||
use Rex::Commands::Fs;
|
||||
|
||||
sub execute {
|
||||
my ( $class, $wanted_os ) = @_;
|
||||
my ( $class, %opts ) = @_;
|
||||
|
||||
Rex::Logger::debug("Getting a list of VM OS types for CBSD ");
|
||||
|
||||
# set cloudinit to false by default
|
||||
if ( !defined( $opts{cloudinit} ) ) {
|
||||
$opts{cloudinit} = 0;
|
||||
}
|
||||
|
||||
# get where CBSD is installed to
|
||||
my %cbsd;
|
||||
eval { %cbsd = get_user('cbsd'); } or do {
|
||||
|
@ -37,11 +42,27 @@ sub execute {
|
|||
foreach my $config (@vm_configs) {
|
||||
my ( $vm, $os, $profile ) = split( /\-/, $config, 3 );
|
||||
$profile =~ s/\.conf$//;
|
||||
if ( !defined( $profiles{$os} ) ) {
|
||||
$profiles{$os} = { $profile => 1 };
|
||||
|
||||
my $add_profile = 1;
|
||||
|
||||
# if cloudinit is defined, only add cloudinit images
|
||||
if ( $opts{cloudinit} ) {
|
||||
|
||||
# since we are default adding, make sure it is not a cloudinit
|
||||
# profile and don't add it if it is not
|
||||
if ( $profile !~ /^cloud\-/ ) {
|
||||
$add_profile = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$profiles{$os}{$profile} = 1;
|
||||
|
||||
# add the profile if needed
|
||||
if ($add_profile) {
|
||||
if ( !defined( $profiles{$os} ) ) {
|
||||
$profiles{$os} = { $profile => 1 };
|
||||
}
|
||||
else {
|
||||
$profiles{$os}{$profile} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue