diff /usr/share/perl5/PVE/API2/OpenVZ.pm_ORIG /usr/share/perl5/PVE/API2/OpenVZ.pm 429a430,519 > > __PACKAGE__->register_method ({ > name => 'createtemplate', > path => '{vmid}/createtemplate', > method => 'POST', > description => "Create template from container.", > permissions => { > check => ['perm', '/storage/{storage}',['Datastore.AllocateTemplate']], > }, > protected => 1, > proxyto => 'node', > parameters => { > additionalProperties => 0, > properties => { > node => get_standard_option('pve-node'), > vmid => get_standard_option('pve-vmid'), > storage => get_standard_option('pve-storage-id'), > template => { type => 'string', maxLength => 255 }, > }, > }, > returns => { > type => 'string', > description => "the task ID.", > }, > code => sub { > my ($param) = @_; > > my $rpcenv = PVE::RPCEnvironment::get(); > > my $authuser = $rpcenv->get_user(); > > my $node = extract_param($param, 'node'); > > my $vmid = extract_param($param, 'vmid'); > > my $storage = extract_param($param, 'storage'); > > my $template = extract_param($param, 'template'); > > die "CT $vmid is running \n" > if PVE::OpenVZ::check_running($vmid); > > my $storage_cfg = cfs_read_file("storage.cfg"); > > my $scfg = PVE::Storage::storage_check_node($storage_cfg, $storage, $node); > > my $tmpldir = PVE::Storage::get_vztmpl_dir($storage_cfg, $storage); > > if ($template !~ /tar\.gz$/){ > $template .=".tar.gz"; > } > > my $target_template = $tmpldir . '/' . $template; > > die "$template already exists on storage $storage\n" > if -f $target_template; > > my $veconf = PVE::OpenVZ::load_config($vmid); > > die "CT $vmid has a network. Please remove the network and try again.\n" > if !$veconf->{netif}; > > my $private = PVE::OpenVZ::get_privatedir($veconf, $vmid); > > raise_param_exc({ storage => "storage '$storage' does not support openvz templates"}) > if !$scfg->{content}->{vztmpl}; > > raise_param_exc({ template => "template '$template' is not set"}) > if !defined($template); > > my $code = sub { > #run command > my $cmd = ['tar', '-czf', $target_template, '-C', $private , '.']; > > print "Creating template from CT $vmid\n"; > syslog('info', "Create template for CT $vmid\n"); > > PVE::Tools::run_command($cmd); > > print "Template $target_template created\n"; > }; > > my $realcmd = sub { > PVE::OpenVZ::lock_container($vmid, 1, $code); > }; > > return $rpcenv->fork_worker('vztemplate', $vmid, $authuser, $realcmd); > > }}); > 543a634 > { subdir => 'createtemplate' }, diff /usr/share/pve-manager/ext4/pvemanagerlib.js_ORIG /usr/share/pve-manager/ext4/pvemanagerlib.js 564a565 > vztemplate: [ 'CT', gettext('Create template') ], 2110a2112,2125 > > { > text: gettext('Create template'), > icon: '/pve2/images/forward.png', > handler: function() { > var win = Ext.create('PVE.window.Template', { > nodename: nodename, > vmid: vmid, > vmtype: 'openvz' > }); > win.show(); > } > }, > 6654a6670,6787 > Ext.define('PVE.window.Template', { > extend: 'Ext.window.Window', > > resizable: false, > > template : function(tmplstorage, templatename) { > var me = this; > PVE.Utils.API2Request({ > params: { storage: tmplstorage, template: templatename }, > url: '/nodes/' + me.nodename + '/' + me.vmtype + '/' + me.vmid + "/createtemplate", > waitMsgTarget: me, > method: 'POST', > failure: function(response, opts) { > Ext.Msg.alert(gettext('Error'), response.htmlStatus); > }, > success: function(response, options) { > var upid = response.result.data; > > var win = Ext.create('PVE.window.TaskViewer', { > upid: upid > }); > win.show(); > me.close(); > } > }); > }, > initComponent : function() { > var me = this; > > if (!me.nodename) { > throw "no node name specified"; > } > > if (!me.vmid) { > throw "no VM ID specified"; > } > > if (!me.vmtype) { > throw "no VM type specified"; > } > > var running = false; > var vmrec = PVE.data.ResourceStore.findRecord('vmid', me.vmid, > 0, false, false, true); > if (vmrec && vmrec.data && vmrec.data.running) { > Ext.Msg.alert(gettext('Error'), "VM " + me.vmid + "must be stopped to perform this action"); > throw "VM " + me.vmid + " must be stopped to perform this action"; > } > > if (me.vmtype !== 'openvz') { > throw "unsupported VM type '" + me.vmtype + "'"; > } > > me.formPanel = Ext.create('Ext.form.Panel', { > bodyPadding: 10, > border: false, > fieldDefaults: { > labelWidth: 120, > anchor: '100%' > }, > items: [ > { > xtype: 'PVE.form.StorageSelector', > name: 'tmplstorage', > nodename: me.nodename, > fieldLabel: gettext('Template storage'), > storageContent: 'vztmpl', > autoSelect: true, > allowBlank: false, > }, > { > xtype: 'pvetextfield', > name: 'templatename', > fieldLabel: gettext('Template name'), > blankText: gettext("Enter a template name"), > allowBlank: false, > listeners: { > change: function(f, value) { > submitBtn.setDisabled(!value); > } > } > } > ] > }); > > var form = me.formPanel.getForm(); > > var submitBtn = Ext.create('Ext.Button', { > text: gettext('Create'), > disabled: true, > handler: function() { > var values = form.getValues(); > me.template(values.tmplstorage, values.templatename); > } > }); > > Ext.apply(me, { > title: gettext('Create Template from ') + ' VM ' + me.vmid, > width: 400, > modal: true, > layout: 'auto', > border: false, > items: [ me.formPanel ], > buttons: [ submitBtn ] > }); > > me.callParent(); > } > > }); > > > > > > > > 17173c17306 < --- > 17221c17354 < --- >