Commit 3500fff8 authored by Roberto P. Rubio's avatar Roberto P. Rubio
Browse files

Issue #1549

parent 90c1f505
......@@ -2332,9 +2332,10 @@ sub clone {
my $request = delete $args{request};
my $memory = delete $args{memory};
my $start = delete $args{start};
my $is_pool = delete $args{is_pool};
my $no_pool = delete $args{no_pool};
my $with_cd = delete $args{with_cd};
my $volatile = delete $args{volatile};
my $id_owner = delete $args{id_owner};
confess "ERROR: Unknown args ".join(",",sort keys %args)
if keys %args;
......@@ -2353,7 +2354,7 @@ sub clone {
delete $args2{from_pool};
return $self->_copy_clone(%args2) if !$self->is_base && $self->id_base();
my $uid = $user->id;
my $uid = $id_owner || $user->id;
if ( !$self->is_base() ) {
$request->status("working","Preparing base") if $request;
......@@ -2367,6 +2368,7 @@ sub clone {
push @args_copy, ( remote_ip => $remote_ip) if $remote_ip;
push @args_copy, ( from_pool => $from_pool) if defined $from_pool;
push @args_copy, ( add_to_pool => $add_to_pool) if defined $add_to_pool;
push @args_copy, ( volatile => $volatile ) if defined $volatile;
my $vm = $self->_vm;
if ($self->volatile_clones ) {
......@@ -2408,6 +2410,9 @@ sub _copy_clone($self, %args) {
my $memory = delete $args{memory};
my $request = delete $args{request};
my $add_to_pool = delete $args{add_to_pool};
my $volatile = delete $args{volatile};
my $id_owner = delete $args{id_owner};
$id_owner = $user->id if (! $id_owner);
confess "ERROR: Unknown arguments ".join(",",sort keys %args)
if keys %args;
......@@ -2416,6 +2421,7 @@ sub _copy_clone($self, %args) {
my @copy_arg;
push @copy_arg, ( memory => $memory ) if $memory;
push @copy_arg, ( volatile => $volatile ) if $volatile;
$request->status("working","Copying domain ".$self->name
." to $name") if $request;
......@@ -2423,7 +2429,7 @@ sub _copy_clone($self, %args) {
my $copy = $self->_vm->create_domain(
name => $name
,id_base => $base->id
,id_owner => $user->id
,id_owner => $id_owner
,from_pool => 0
,@copy_arg
);
......@@ -2455,7 +2461,7 @@ sub _copy_ports($base, $copy) {
for my $port ( $base->list_ports ) {
my %port = %$port;
next if $port_already{$port->{internal_port}};
delete @port{'id','id_domain','public_port'};
delete @port{'id','id_domain','public_port','is_active'};
$copy->expose(%port);
}
......@@ -4379,7 +4385,7 @@ sub _pre_clone($self,%args) {
confess "ERROR: Missing user owner of new domain" if !$user;
for (qw(is_pool start add_to_pool from_pool with_cd)) {
for (qw(is_pool start add_to_pool from_pool with_cd volatile id_owner)) {
delete $args{$_};
}
confess "ERROR: Unknown arguments ".join(",",sort keys %args) if keys %args;
......
......@@ -81,7 +81,7 @@ our %VALID_ARG = (
,check_storage => { uid => 1 }
,set_base_vm=> {uid => 1, id_vm=> 1, id_domain => 1, value => 2 }
,cleanup => { }
,clone => { uid => 1, id_domain => 1, name => 2, memory => 2, number => 2
,clone => { uid => 1, id_domain => 1, name => 2, memory => 2, number => 2, volatile => 2, id_owner => 2
# If base has pools, from_pool = 1 if undefined
# when from_pool is true the clone is picked from the pool
# when from_pool is false the clone is created
......
......@@ -455,7 +455,7 @@ sub _around_create_domain {
}
}
my $user = Ravada::Auth::SQL->search_by_id($id_owner);
$domain->is_volatile(1) if $user->is_temporary() ||($base && $base->volatile_clones());
$domain->is_volatile(1) if $user->is_temporary() ||($base && $base->volatile_clones()) || $volatile;
my @start_args = ( user => $owner );
push @start_args, (remote_ip => $remote_ip) if $remote_ip;
......@@ -801,7 +801,7 @@ sub _check_require_base {
delete $args{start};
delete $args{remote_ip};
delete @args{'_vm','name','vm', 'memory','description','id_iso','listen_ip','spice_password','from_pool'};
delete @args{'_vm','name','vm', 'memory','description','id_iso','listen_ip','spice_password','from_pool', 'volatile'};
confess "ERROR: Unknown arguments ".join(",",keys %args)
if keys %args;
......
......@@ -506,6 +506,9 @@
,'copy_number': $scope.copy_number
,'copy_ram': $scope.copy_ram
,'new_name': $scope.new_name
,'new_owner': $scope.copy_owner
,'copy_is_volatile': $scope.copy_is_volatile
,'copy_is_pool': $scope.copy_is_pool
})
).then(function(response) {
// if there are many , we pick the last one
......
......@@ -2442,9 +2442,18 @@ sub copy_machine {
my $base = $RAVADA->search_domain_by_id($id_base) or confess "I can't find domain $id_base";
my $name = ( $arg->{new_name} or $base->name."-".$USER->name );
$USER = _logged_in($c);
my $owner = $arg->{new_owner};
$owner = undef if (! $USER) || (! $USER->is_admin);
confess "owner do not exists" if ($owner) && (! Ravada::Auth::SQL->new(name => $owner));
my @create_args = ( from_pool => 0 );
push @create_args,( memory => $ram ) if $ram;
push @create_args, ( name => $name ) if $number == 1;
push @create_args, ( id_owner => $owner ) if ($owner);
push @create_args, ( volatile => $arg->{copy_is_volatile} ? 1 : 0 );
push @create_args, ( add_to_pool => $arg->{copy_is_pool} && $base->is_pool() ? 1 : 0 );
my $req2 = Ravada::Request->clone(
uid => $USER->id
, id_domain => $base->id
......
......@@ -33,6 +33,34 @@
<input class="form-control" ng-model="copy_ram" type="text" size="3">
</div>
</div>
<div class="row">
<div class="col-md-12 mt-12">
<input type="checkbox" name="copy_is_volatile" ng-model="copy_is_volatile">
<label class="control-label" for="copy_is_volatile"><%=l 'Volatile' %></label>
</div>
</div>
<div class="row">
<div class="col-md-12 mt-12">
<input type="checkbox" name="copy_is_pool" ng-model="copy_is_pool" ng-disabled="showmachine.is_pool != 1">
<label class="control-label" for="copy_is_pool"><%=l 'Pool' %></label>
</div>
</div>
% if ($USER->is_admin){
<div class="form-group row">
<div class="col-md-2 mt-2">
<label class="control-label" for="copy_owner"><%=l 'Owner' %></label>{{copy_owner_id}}
</div>
<div class="col-md-4">
<select class="form-control" ng-model="copy_owner" name="copy_owner">
<option ng-repeat="user in list_users" value="{{user.id}}">{{user.name}}</option>
</select>
</div>
</div>
% }
<div ng-show="copy_request" class="alert alert-warning">
Copy {{showmachine.name}} {{copy_request.status}}.
<br/>
......
......@@ -185,7 +185,7 @@
<label class="control-label" for="new_owner"><%=l 'Owner' %></label>
</div>
<div class="col-lg-4">
<select ng-model="new_owner" name="id_owner"
<select class="form-control" ng-model="new_owner" name="id_owner"
ng-options="user.name for user in list_users track by user.id"
ng-change="set_value('id_owner',new_owner.id)"
>
......
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