Commit 0813b1bd authored by fv3rdugo's avatar fv3rdugo Committed by Francesc Guasch
Browse files

Add option --import-vbox

parent 31587ac6
...@@ -22,6 +22,7 @@ my $FILE_CONFIG; ...@@ -22,6 +22,7 @@ my $FILE_CONFIG;
my $ADD_USER_LDAP; my $ADD_USER_LDAP;
my $IMPORT_DOMAIN; my $IMPORT_DOMAIN;
my $IMPORT_VBOX;
my $CHANGE_PASSWORD; my $CHANGE_PASSWORD;
my $NOFORK; my $NOFORK;
my $MAKE_ADMIN_USER; my $MAKE_ADMIN_USER;
...@@ -33,7 +34,7 @@ my $URL_ISOS; ...@@ -33,7 +34,7 @@ my $URL_ISOS;
my $USAGE = "$0 " my $USAGE = "$0 "
." [--debug] [--config=$FILE_CONFIG_DEFAULT] [--add-user=name] [--add-user-ldap=name]" ." [--debug] [--config=$FILE_CONFIG_DEFAULT] [--add-user=name] [--add-user-ldap=name]"
." [--change-password] [--make-admin=username]" ." [--change-password] [--make-admin=username] [--import-vbox=image_file.vdi]"
." [-X] [start|stop|status]" ." [-X] [start|stop|status]"
."\n" ."\n"
." --add-user : adds a new db user\n" ." --add-user : adds a new db user\n"
...@@ -44,6 +45,7 @@ my $USAGE = "$0 " ...@@ -44,6 +45,7 @@ my $USAGE = "$0 "
." --config : config file, defaults to $FILE_CONFIG_DEFAULT" ." --config : config file, defaults to $FILE_CONFIG_DEFAULT"
." -X : start in foreground\n" ." -X : start in foreground\n"
." --url-isos=(URL|default)\n" ." --url-isos=(URL|default)\n"
." --import-vbox : import a VirtualBox image\n"
; ;
$START = 0 if scalar @ARGV && $ARGV[0] ne '&'; $START = 0 if scalar @ARGV && $ARGV[0] ne '&';
...@@ -59,6 +61,7 @@ GetOptions ( help => \$help ...@@ -59,6 +61,7 @@ GetOptions ( help => \$help
,'change-password'=> \$CHANGE_PASSWORD ,'change-password'=> \$CHANGE_PASSWORD
,'add-user-ldap=s'=> \$ADD_USER_LDAP ,'add-user-ldap=s'=> \$ADD_USER_LDAP
,'import-domain=s' => \$IMPORT_DOMAIN ,'import-domain=s' => \$IMPORT_DOMAIN
,'import-vbox=s' => \$IMPORT_VBOX
) or exit; ) or exit;
$START = 1 if $DEBUG || $FILE_CONFIG || $NOFORK; $START = 1 if $DEBUG || $FILE_CONFIG || $NOFORK;
...@@ -228,6 +231,37 @@ sub import_domain { ...@@ -228,6 +231,37 @@ sub import_domain {
$ravada->import_domain(name => $name, vm => 'KVM', user => $user); $ravada->import_domain(name => $name, vm => 'KVM', user => $user);
} }
sub import_vbox {
my $file_vdi = shift;
if ($file_vdi =~ /\.vdi$/i) {
print "Import VirtualBox image from vdi file\n";
print "Name for the new domain : ";
my $name = <STDIN>;
chomp $name;
print "Change default storage pool in /var/lib/libvirt/images/ [y/N]:";
my $default_pool_q = <STDIN>;
my $storage_pool = "/var/lib/libvirt/images";
if ( $default_pool_q =~ /y/i ) {
print "Insert storage pool path : ";
my $storage_pool = <STDIN>;
chomp $storage_pool;
}
print "STORAGE POOL IS $storage_pool \n";
my @cmd = ("qemu-img convert -p -f vdi -O qcow2 $file_vdi $storage_pool/$name.qcow2");
system(@cmd);
#new machine xml change source file
#remove swap
#remove cdrom
exit;
}
print "Warning: $file_vdi is not a vdi file \n";
print "Check if the path has spaces, if so insert it in quotes \n";
}
sub set_url_isos { sub set_url_isos {
my $url = shift; my $url = shift;
my $rvd_back = Ravada->new(%CONFIG); my $rvd_back = Ravada->new(%CONFIG);
...@@ -258,6 +292,7 @@ add_user($ADD_USER) if $ADD_USER; ...@@ -258,6 +292,7 @@ add_user($ADD_USER) if $ADD_USER;
add_user($ADD_USER_LDAP) if $ADD_USER_LDAP; add_user($ADD_USER_LDAP) if $ADD_USER_LDAP;
change_password() if $CHANGE_PASSWORD; change_password() if $CHANGE_PASSWORD;
import_domain($IMPORT_DOMAIN) if $IMPORT_DOMAIN; import_domain($IMPORT_DOMAIN) if $IMPORT_DOMAIN;
import_vbox($IMPORT_VBOX) if $IMPORT_VBOX;
make_admin($MAKE_ADMIN_USER) if $MAKE_ADMIN_USER; make_admin($MAKE_ADMIN_USER) if $MAKE_ADMIN_USER;
remove_admin($REMOVE_ADMIN_USER) if $REMOVE_ADMIN_USER; remove_admin($REMOVE_ADMIN_USER) if $REMOVE_ADMIN_USER;
set_url_isos($URL_ISOS) if $URL_ISOS; set_url_isos($URL_ISOS) if $URL_ISOS;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment