1 package PVE
::API2
::LXC
;
7 use PVE
::Tools
qw(extract_param run_command);
8 use PVE
::Exception
qw(raise raise_param_exc);
10 use PVE
::Cluster
qw(cfs_read_file);
11 use PVE
::AccessControl
;
15 use PVE
::RPCEnvironment
;
18 use PVE
::LXC
::Migrate
;
19 use PVE
::API2
::LXC
::Config
;
20 use PVE
::API2
::LXC
::Status
;
21 use PVE
::API2
::LXC
::Snapshot
;
23 use PVE
::JSONSchema
qw(get_standard_option);
24 use base
qw(PVE::RESTHandler);
26 use Data
::Dumper
; # fixme: remove
28 __PACKAGE__-
>register_method ({
29 subclass
=> "PVE::API2::LXC::Config",
30 path
=> '{vmid}/config',
33 __PACKAGE__-
>register_method ({
34 subclass
=> "PVE::API2::LXC::Status",
35 path
=> '{vmid}/status',
38 __PACKAGE__-
>register_method ({
39 subclass
=> "PVE::API2::LXC::Snapshot",
40 path
=> '{vmid}/snapshot',
43 __PACKAGE__-
>register_method ({
44 subclass
=> "PVE::API2::Firewall::CT",
45 path
=> '{vmid}/firewall',
48 my $destroy_disks = sub {
49 my ($storecfg, $vollist) = @_;
51 foreach my $volid (@$vollist) {
52 eval { PVE
::Storage
::vdisk_free
($storecfg, $volid); };
60 PVE
::Tools
::run_command
(['mkfs.ext4', '-O', 'mmp', $dev]);
64 my ($storage_cfg, $volid) = @_;
66 if ($volid =~ m!^/dev/.+!) {
70 my ($storage, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
72 die "cannot format volume $volid with no storage" if !$storage;
74 my $path = PVE
::Storage
::path
($storage_cfg, $volid);
76 my ($vtype, undef, undef, undef, undef, $isBase, $format) =
77 PVE
::Storage
::parse_volname
($storage_cfg, $volid);
79 if ($format eq 'raw' || $format eq 'subvol') {
84 my $create_disks = sub {
85 my ($storecfg, $vmid, $settings, $conf) = @_;
90 PVE
::LXC
::foreach_mountpoint
($settings, sub {
91 my ($ms, $mountpoint) = @_;
93 my $volid = $mountpoint->{volume
};
94 my $mp = $mountpoint->{mp
};
96 my ($storage, $volname) = PVE
::Storage
::parse_volume_id
($volid, 1);
100 if ($volid =~ m/^([^:\s]+):(\d+(\.\d+)?)$/) {
101 my ($storeid, $size) = ($1, $2);
103 $size = int($size*1024) * 1024;
105 my $scfg = PVE
::Storage
::storage_config
($storecfg, $storage);
106 # fixme: use better naming ct-$vmid-disk-X.raw?
108 if ($scfg->{type
} eq 'dir' || $scfg->{type
} eq 'nfs') {
110 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw',
112 format_disk
($storecfg, $volid);
114 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'subvol',
117 } elsif ($scfg->{type
} eq 'zfspool') {
119 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'subvol',
121 } elsif ($scfg->{type
} eq 'drbd') {
123 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw', undef, $size);
124 format_disk
($storecfg, $volid);
126 } elsif ($scfg->{type
} eq 'rbd') {
128 die "krbd option must be enabled on storage type '$scfg->{type}'\n" if !$scfg->{krbd
};
129 $volid = PVE
::Storage
::vdisk_alloc
($storecfg, $storage, $vmid, 'raw', undef, $size);
130 format_disk
($storecfg, $volid);
132 die "unable to create containers on storage type '$scfg->{type}'\n";
134 push @$vollist, $volid;
135 $conf->{$ms} = PVE
::LXC
::print_ct_mountpoint
({volume
=> $volid, size
=> $size, mp
=> $mp });
137 # use specified/existing volid
141 # free allocated images on error
143 syslog
('err', "VM $vmid creating disks failed");
144 &$destroy_disks($storecfg, $vollist);
150 __PACKAGE__-
>register_method({
154 description
=> "LXC container index (per node).",
156 description
=> "Only list CTs where you have VM.Audit permissons on /vms/<vmid>.",
160 protected
=> 1, # /proc files are only readable by root
162 additionalProperties
=> 0,
164 node
=> get_standard_option
('pve-node'),
173 links
=> [ { rel
=> 'child', href
=> "{vmid}" } ],
178 my $rpcenv = PVE
::RPCEnvironment
::get
();
179 my $authuser = $rpcenv->get_user();
181 my $vmstatus = PVE
::LXC
::vmstatus
();
184 foreach my $vmid (keys %$vmstatus) {
185 next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Audit' ], 1);
187 my $data = $vmstatus->{$vmid};
188 $data->{vmid
} = $vmid;
196 __PACKAGE__-
>register_method({
200 description
=> "Create or restore a container.",
202 user
=> 'all', # check inside
203 description
=> "You need 'VM.Allocate' permissions on /vms/{vmid} or on the VM pool /pool/{pool}. " .
204 "For restore, it is enough if the user has 'VM.Backup' permission and the VM already exists. " .
205 "You also need 'Datastore.AllocateSpace' permissions on the storage.",
210 additionalProperties
=> 0,
211 properties
=> PVE
::LXC
::json_config_properties
({
212 node
=> get_standard_option
('pve-node'),
213 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::Cluster
::complete_next_vmid
}),
215 description
=> "The OS template or backup file.",
218 completion
=> \
&PVE
::LXC
::complete_os_templates
,
223 description
=> "Sets root password inside container.",
226 storage
=> get_standard_option
('pve-storage-id', {
227 description
=> "Default Storage.",
234 description
=> "Allow to overwrite existing container.",
239 description
=> "Mark this as restore task.",
243 type
=> 'string', format
=> 'pve-poolid',
244 description
=> "Add the VM to the specified pool.",
254 my $rpcenv = PVE
::RPCEnvironment
::get
();
256 my $authuser = $rpcenv->get_user();
258 my $node = extract_param
($param, 'node');
260 my $vmid = extract_param
($param, 'vmid');
262 my $basecfg_fn = PVE
::LXC
::config_file
($vmid);
264 my $same_container_exists = -f
$basecfg_fn;
266 my $restore = extract_param
($param, 'restore');
269 # fixme: limit allowed parameters
273 my $force = extract_param
($param, 'force');
275 if (!($same_container_exists && $restore && $force)) {
276 PVE
::Cluster
::check_vmid_unused
($vmid);
279 my $password = extract_param
($param, 'password');
281 my $storage = extract_param
($param, 'storage') // 'local';
283 my $storage_cfg = cfs_read_file
("storage.cfg");
285 my $scfg = PVE
::Storage
::storage_check_node
($storage_cfg, $storage, $node);
287 raise_param_exc
({ storage
=> "storage '$storage' does not support container root directories"})
288 if !($scfg->{content
}->{images
} || $scfg->{content
}->{rootdir
});
290 my $pool = extract_param
($param, 'pool');
292 if (defined($pool)) {
293 $rpcenv->check_pool_exist($pool);
294 $rpcenv->check_perm_modify($authuser, "/pool/$pool");
297 $rpcenv->check($authuser, "/storage/$storage", ['Datastore.AllocateSpace']);
299 if ($rpcenv->check($authuser, "/vms/$vmid", ['VM.Allocate'], 1)) {
301 } elsif ($pool && $rpcenv->check($authuser, "/pool/$pool", ['VM.Allocate'], 1)) {
303 } elsif ($restore && $force && $same_container_exists &&
304 $rpcenv->check($authuser, "/vms/$vmid", ['VM.Backup'], 1)) {
305 # OK: user has VM.Backup permissions, and want to restore an existing VM
310 PVE
::LXC
::check_ct_modify_config_perm
($rpcenv, $authuser, $vmid, $pool, [ keys %$param]);
312 PVE
::Storage
::activate_storage
($storage_cfg, $storage);
314 my $ostemplate = extract_param
($param, 'ostemplate');
318 if ($ostemplate eq '-') {
319 die "pipe requires cli environment\n"
320 if $rpcenv->{type
} ne 'cli';
321 die "pipe can only be used with restore tasks\n"
324 die "restore from pipe requires rootfs parameter\n" if !defined($param->{rootfs
});
326 $rpcenv->check_volume_access($authuser, $storage_cfg, $vmid, $ostemplate);
327 $archive = PVE
::Storage
::abs_filesystem_path
($storage_cfg, $ostemplate);
332 my $no_disk_param = {};
333 foreach my $opt (keys %$param) {
334 my $value = $param->{$opt};
335 if ($opt eq 'rootfs' || $opt =~ m/^mp\d+$/) {
336 # allow to use simple numbers (add default storage in that case)
337 $param->{$opt} = "$storage:$value" if $value =~ m/^\d+(\.\d+)?$/;
339 $no_disk_param->{$opt} = $value;
342 PVE
::LXC
::update_pct_config
($vmid, $conf, 0, $no_disk_param);
344 my $check_vmid_usage = sub {
346 die "can't overwrite running container\n"
347 if PVE
::LXC
::check_running
($vmid);
349 PVE
::Cluster
::check_vmid_unused
($vmid);
354 &$check_vmid_usage(); # final check after locking
356 PVE
::Cluster
::check_cfs_quorum
();
360 if (!defined($param->{rootfs
})) {
362 my (undef, $disksize) = PVE
::LXC
::Create
::recover_config
($archive);
363 $disksize /= 1024 * 1024; # create_disks expects GB as unit size
364 die "unable to detect disk size - please specify rootfs (size)\n"
366 $param->{rootfs
} = "$storage:$disksize";
368 $param->{rootfs
} = "$storage:4"; # defaults to 4GB
372 $vollist = &$create_disks($storage_cfg, $vmid, $param, $conf);
374 PVE
::LXC
::Create
::create_rootfs
($storage_cfg, $vmid, $conf, $archive, $password, $restore);
376 $conf->{hostname
} ||= "CT$vmid";
377 $conf->{memory
} ||= 512;
378 $conf->{swap
} //= 512;
379 PVE
::LXC
::create_config
($vmid, $conf);
382 &$destroy_disks($storage_cfg, $vollist);
383 PVE
::LXC
::destroy_config
($vmid);
386 PVE
::AccessControl
::add_vm_to_pool
($vmid, $pool) if $pool;
389 my $realcmd = sub { PVE
::LXC
::lock_container
($vmid, 1, $code); };
391 &$check_vmid_usage(); # first check before locking
393 return $rpcenv->fork_worker($restore ?
'vzrestore' : 'vzcreate',
394 $vmid, $authuser, $realcmd);
398 __PACKAGE__-
>register_method({
403 description
=> "Directory index",
408 additionalProperties
=> 0,
410 node
=> get_standard_option
('pve-node'),
411 vmid
=> get_standard_option
('pve-vmid'),
419 subdir
=> { type
=> 'string' },
422 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
428 my $conf = PVE
::LXC
::load_config
($param->{vmid
});
431 { subdir
=> 'config' },
432 { subdir
=> 'status' },
433 { subdir
=> 'vncproxy' },
434 { subdir
=> 'vncwebsocket' },
435 { subdir
=> 'spiceproxy' },
436 { subdir
=> 'migrate' },
437 # { subdir => 'initlog' },
439 { subdir
=> 'rrddata' },
440 { subdir
=> 'firewall' },
441 { subdir
=> 'snapshot' },
447 __PACKAGE__-
>register_method({
449 path
=> '{vmid}/rrd',
451 protected
=> 1, # fixme: can we avoid that?
453 check
=> ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
455 description
=> "Read VM RRD statistics (returns PNG)",
457 additionalProperties
=> 0,
459 node
=> get_standard_option
('pve-node'),
460 vmid
=> get_standard_option
('pve-vmid'),
462 description
=> "Specify the time frame you are interested in.",
464 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
467 description
=> "The list of datasources you want to display.",
468 type
=> 'string', format
=> 'pve-configid-list',
471 description
=> "The RRD consolidation function",
473 enum
=> [ 'AVERAGE', 'MAX' ],
481 filename
=> { type
=> 'string' },
487 return PVE
::Cluster
::create_rrd_graph
(
488 "pve2-vm/$param->{vmid}", $param->{timeframe
},
489 $param->{ds
}, $param->{cf
});
493 __PACKAGE__-
>register_method({
495 path
=> '{vmid}/rrddata',
497 protected
=> 1, # fixme: can we avoid that?
499 check
=> ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
501 description
=> "Read VM RRD statistics",
503 additionalProperties
=> 0,
505 node
=> get_standard_option
('pve-node'),
506 vmid
=> get_standard_option
('pve-vmid'),
508 description
=> "Specify the time frame you are interested in.",
510 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
513 description
=> "The RRD consolidation function",
515 enum
=> [ 'AVERAGE', 'MAX' ],
530 return PVE
::Cluster
::create_rrd_data
(
531 "pve2-vm/$param->{vmid}", $param->{timeframe
}, $param->{cf
});
534 __PACKAGE__-
>register_method({
535 name
=> 'destroy_vm',
540 description
=> "Destroy the container (also delete all uses files).",
542 check
=> [ 'perm', '/vms/{vmid}', ['VM.Allocate']],
545 additionalProperties
=> 0,
547 node
=> get_standard_option
('pve-node'),
548 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_stopped
}),
557 my $rpcenv = PVE
::RPCEnvironment
::get
();
559 my $authuser = $rpcenv->get_user();
561 my $vmid = $param->{vmid
};
563 # test if container exists
564 my $conf = PVE
::LXC
::load_config
($vmid);
566 my $storage_cfg = cfs_read_file
("storage.cfg");
568 die "unable to remove CT $vmid - used in HA resources\n"
569 if PVE
::HA
::Config
::vm_is_ha_managed
($vmid);
572 # reload config after lock
573 $conf = PVE
::LXC
::load_config
($vmid);
574 PVE
::LXC
::check_lock
($conf);
576 PVE
::LXC
::destroy_lxc_container
($storage_cfg, $vmid, $conf);
577 PVE
::AccessControl
::remove_vm_access
($vmid);
578 PVE
::Firewall
::remove_vmfw_conf
($vmid);
581 my $realcmd = sub { PVE
::LXC
::lock_container
($vmid, 1, $code); };
583 return $rpcenv->fork_worker('vzdestroy', $vmid, $authuser, $realcmd);
588 __PACKAGE__-
>register_method ({
590 path
=> '{vmid}/vncproxy',
594 check
=> ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
596 description
=> "Creates a TCP VNC proxy connections.",
598 additionalProperties
=> 0,
600 node
=> get_standard_option
('pve-node'),
601 vmid
=> get_standard_option
('pve-vmid'),
605 description
=> "use websocket instead of standard VNC.",
610 additionalProperties
=> 0,
612 user
=> { type
=> 'string' },
613 ticket
=> { type
=> 'string' },
614 cert
=> { type
=> 'string' },
615 port
=> { type
=> 'integer' },
616 upid
=> { type
=> 'string' },
622 my $rpcenv = PVE
::RPCEnvironment
::get
();
624 my $authuser = $rpcenv->get_user();
626 my $vmid = $param->{vmid
};
627 my $node = $param->{node
};
629 my $authpath = "/vms/$vmid";
631 my $ticket = PVE
::AccessControl
::assemble_vnc_ticket
($authuser, $authpath);
633 $sslcert = PVE
::Tools
::file_get_contents
("/etc/pve/pve-root-ca.pem", 8192)
636 my ($remip, $family);
638 if ($node ne PVE
::INotify
::nodename
()) {
639 ($remip, $family) = PVE
::Cluster
::remote_node_ip
($node);
641 $family = PVE
::Tools
::get_host_address_family
($node);
644 my $port = PVE
::Tools
::next_vnc_port
($family);
646 # NOTE: vncterm VNC traffic is already TLS encrypted,
647 # so we select the fastest chipher here (or 'none'?)
648 my $remcmd = $remip ?
649 ['/usr/bin/ssh', '-t', $remip] : [];
651 my $conf = PVE
::LXC
::load_config
($vmid, $node);
652 my $concmd = PVE
::LXC
::get_console_command
($vmid, $conf);
654 my $shcmd = [ '/usr/bin/dtach', '-A',
655 "/var/run/dtach/vzctlconsole$vmid",
656 '-r', 'winch', '-z', @$concmd];
661 syslog
('info', "starting lxc vnc proxy $upid\n");
665 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
666 '-timeout', $timeout, '-authpath', $authpath,
667 '-perm', 'VM.Console'];
669 if ($param->{websocket
}) {
670 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
671 push @$cmd, '-notls', '-listen', 'localhost';
674 push @$cmd, '-c', @$remcmd, @$shcmd;
681 my $upid = $rpcenv->fork_worker('vncproxy', $vmid, $authuser, $realcmd);
683 PVE
::Tools
::wait_for_vnc_port
($port);
694 __PACKAGE__-
>register_method({
695 name
=> 'vncwebsocket',
696 path
=> '{vmid}/vncwebsocket',
699 description
=> "You also need to pass a valid ticket (vncticket).",
700 check
=> ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
702 description
=> "Opens a weksocket for VNC traffic.",
704 additionalProperties
=> 0,
706 node
=> get_standard_option
('pve-node'),
707 vmid
=> get_standard_option
('pve-vmid'),
709 description
=> "Ticket from previous call to vncproxy.",
714 description
=> "Port number returned by previous vncproxy call.",
724 port
=> { type
=> 'string' },
730 my $rpcenv = PVE
::RPCEnvironment
::get
();
732 my $authuser = $rpcenv->get_user();
734 my $authpath = "/vms/$param->{vmid}";
736 PVE
::AccessControl
::verify_vnc_ticket
($param->{vncticket
}, $authuser, $authpath);
738 my $port = $param->{port
};
740 return { port
=> $port };
743 __PACKAGE__-
>register_method ({
744 name
=> 'spiceproxy',
745 path
=> '{vmid}/spiceproxy',
750 check
=> ['perm', '/vms/{vmid}', [ 'VM.Console' ]],
752 description
=> "Returns a SPICE configuration to connect to the CT.",
754 additionalProperties
=> 0,
756 node
=> get_standard_option
('pve-node'),
757 vmid
=> get_standard_option
('pve-vmid'),
758 proxy
=> get_standard_option
('spice-proxy', { optional
=> 1 }),
761 returns
=> get_standard_option
('remote-viewer-config'),
765 my $vmid = $param->{vmid
};
766 my $node = $param->{node
};
767 my $proxy = $param->{proxy
};
769 my $authpath = "/vms/$vmid";
770 my $permissions = 'VM.Console';
772 my $conf = PVE
::LXC
::load_config
($vmid);
774 die "CT $vmid not running\n" if !PVE
::LXC
::check_running
($vmid);
776 my $concmd = PVE
::LXC
::get_console_command
($vmid, $conf);
778 my $shcmd = ['/usr/bin/dtach', '-A',
779 "/var/run/dtach/vzctlconsole$vmid",
780 '-r', 'winch', '-z', @$concmd];
782 my $title = "CT $vmid";
784 return PVE
::API2Tools
::run_spiceterm
($authpath, $permissions, $vmid, $node, $proxy, $title, $shcmd);
788 __PACKAGE__-
>register_method({
789 name
=> 'migrate_vm',
790 path
=> '{vmid}/migrate',
794 description
=> "Migrate the container to another node. Creates a new migration task.",
796 check
=> ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]],
799 additionalProperties
=> 0,
801 node
=> get_standard_option
('pve-node'),
802 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid
}),
803 target
=> get_standard_option
('pve-node', {
804 description
=> "Target node.",
805 completion
=> \
&PVE
::LXC
::complete_migration_target
,
809 description
=> "Use online/live migration.",
816 description
=> "the task ID.",
821 my $rpcenv = PVE
::RPCEnvironment
::get
();
823 my $authuser = $rpcenv->get_user();
825 my $target = extract_param
($param, 'target');
827 my $localnode = PVE
::INotify
::nodename
();
828 raise_param_exc
({ target
=> "target is local node."}) if $target eq $localnode;
830 PVE
::Cluster
::check_cfs_quorum
();
832 PVE
::Cluster
::check_node_exists
($target);
834 my $targetip = PVE
::Cluster
::remote_node_ip
($target);
836 my $vmid = extract_param
($param, 'vmid');
839 PVE
::LXC
::load_config
($vmid);
841 # try to detect errors early
842 if (PVE
::LXC
::check_running
($vmid)) {
843 die "can't migrate running container without --online\n"
844 if !$param->{online
};
847 if (PVE
::HA
::Config
::vm_is_ha_managed
($vmid) && $rpcenv->{type
} ne 'ha') {
852 my $service = "ct:$vmid";
854 my $cmd = ['ha-manager', 'migrate', $service, $target];
856 print "Executing HA migrate for CT $vmid to node $target\n";
858 PVE
::Tools
::run_command
($cmd);
863 return $rpcenv->fork_worker('hamigrate', $vmid, $authuser, $hacmd);
870 PVE
::LXC
::Migrate-
>migrate($target, $targetip, $vmid, $param);
875 return $rpcenv->fork_worker('vzmigrate', $vmid, $authuser, $realcmd);
879 __PACKAGE__-
>register_method({
880 name
=> 'vm_feature',
881 path
=> '{vmid}/feature',
885 description
=> "Check if feature for virtual machine is available.",
887 check
=> ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
890 additionalProperties
=> 0,
892 node
=> get_standard_option
('pve-node'),
893 vmid
=> get_standard_option
('pve-vmid'),
895 description
=> "Feature to check.",
897 enum
=> [ 'snapshot' ],
899 snapname
=> get_standard_option
('pve-lxc-snapshot-name', {
907 hasFeature
=> { type
=> 'boolean' },
910 #items => { type => 'string' },
917 my $node = extract_param
($param, 'node');
919 my $vmid = extract_param
($param, 'vmid');
921 my $snapname = extract_param
($param, 'snapname');
923 my $feature = extract_param
($param, 'feature');
925 my $conf = PVE
::LXC
::load_config
($vmid);
928 my $snap = $conf->{snapshots
}->{$snapname};
929 die "snapshot '$snapname' does not exist\n" if !defined($snap);
932 my $storage_cfg = PVE
::Storage
::config
();
934 #my $nodelist = PVE::LXC::shared_nodes($conf, $storage_cfg);
935 my $hasFeature = PVE
::LXC
::has_feature
($feature, $conf, $storage_cfg, $snapname);
938 hasFeature
=> $hasFeature,
939 #nodes => [ keys %$nodelist ],
943 __PACKAGE__-
>register_method({
945 path
=> '{vmid}/template',
949 description
=> "Create a Template.",
951 description
=> "You need 'VM.Allocate' permissions on /vms/{vmid}",
952 check
=> [ 'perm', '/vms/{vmid}', ['VM.Allocate']],
955 additionalProperties
=> 0,
957 node
=> get_standard_option
('pve-node'),
958 vmid
=> get_standard_option
('pve-vmid', { completion
=> \
&PVE
::LXC
::complete_ctid_stopped
}),
961 returns
=> { type
=> 'null'},
965 my $rpcenv = PVE
::RPCEnvironment
::get
();
967 my $authuser = $rpcenv->get_user();
969 my $node = extract_param
($param, 'node');
971 my $vmid = extract_param
($param, 'vmid');
975 my $conf = PVE
::LXC
::load_config
($vmid);
976 PVE
::LXC
::check_lock
($conf);
978 die "unable to create template, because CT contains snapshots\n"
979 if $conf->{snapshots
} && scalar(keys %{$conf->{snapshots
}});
981 die "you can't convert a template to a template\n"
982 if PVE
::LXC
::is_template
($conf);
984 die "you can't convert a CT to template if the CT is running\n"
985 if PVE
::LXC
::check_running
($vmid);
988 PVE
::LXC
::template_create
($vmid, $conf);
991 $conf->{template
} = 1;
993 PVE
::LXC
::write_config
($vmid, $conf);
994 # and remove lxc config
995 PVE
::LXC
::update_lxc_config
(undef, $vmid, $conf);
997 return $rpcenv->fork_worker('vztemplate', $vmid, $authuser, $realcmd);
1000 PVE
::LXC
::lock_container
($vmid, undef, $updatefn);