[pve-devel] [PATCH 2/5] generate cloudconfig configdrive

Alexandre Derumier aderumier at odiso.com
Wed Jun 10 17:10:10 CEST 2015


generate configdrive.iso if cloudconfig option=1

configdrive is generate in /tmp/cloudinit/vmid/configdrive
(we don't want to expose it iso folders, as it can have user pass/ssh keys)

setup it as ide3
and set it as pending removal

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 41 +++++++++++++++++++++++++++++++++++++++--
 control.in        |  2 +-
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 03c489b..66a60a9 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -740,6 +740,8 @@ sub get_iso_path {
 	return get_cdrom_path();
     } elsif ($cdrom eq 'none') {
 	return '';
+    } elsif ($cdrom eq 'cloudinit') {
+	return "/tmp/cloudinit/$vmid/configdrive.iso";
     } elsif ($cdrom =~ m|^/|) {
 	return $cdrom;
     } else {
@@ -751,7 +753,7 @@ sub get_iso_path {
 sub filename_to_volume_id {
     my ($vmid, $file, $media) = @_;
 
-    if (!($file eq 'none' || $file eq 'cdrom' ||
+     if (!($file eq 'none' || $file eq 'cdrom' || $file eq 'cloudinit' ||
 	  $file =~ m|^/dev/.+| || $file =~ m/^([^:]+):(.+)$/)) {
 
 	return undef if $file =~ m|/|;
@@ -4160,12 +4162,14 @@ sub vm_start {
 	check_lock($conf) if !$skiplock;
 
 	die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
-
+	
 	if (!$statefile && scalar(keys %{$conf->{pending}})) {
 	    vmconfig_apply_pending($vmid, $conf, $storecfg);
 	    $conf = load_config($vmid); # update/reload
 	}
 
+	generate_cloudinitconfig($conf, $vmid);
+
 	my $defaults = load_defaults();
 
 	# set environment variable useful inside network script
@@ -6268,4 +6272,37 @@ sub scsihw_infos {
     return ($maxdev, $controller, $controller_prefix);
 }
 
+sub generate_cloudinitconfig {
+    my ($conf, $vmid) = @_;
+
+    return if !$conf->{cloudinit};
+
+    my $path = "/tmp/cloudinit/$vmid";
+
+    mkdir "/tmp/cloudinit";
+    mkdir $path;
+    mkdir "$path/drive";
+    mkdir "$path/drive/openstack";
+    mkdir "$path/drive/openstack/latest";
+    mkdir "$path/drive/openstack/content";
+
+    my $cmd = [];
+    push @$cmd, 'genisoimage';
+    push @$cmd, '-R';
+    push @$cmd, '-V', 'config-2';
+    push @$cmd, '-o', "$path/configdrive.iso";
+    push @$cmd, "$path/drive";
+
+    run_command($cmd);
+    rmtree("$path/drive");
+    my $drive = PVE::QemuServer::parse_drive('ide3', 'cloudinit,media=cdrom');
+    $conf->{'ide3'} = PVE::QemuServer::print_drive($vmid, $drive);
+    update_config_nolock($vmid, $conf, 1);
+
+    vmconfig_delete_pending_option($conf, 'ide3');
+    vmconfig_delete_pending_option($conf, 'cloudinit');
+    update_config_nolock($vmid, $conf, 1);
+
+}
+
 1;
diff --git a/control.in b/control.in
index 84841ce..a6f6be1 100644
--- a/control.in
+++ b/control.in
@@ -3,7 +3,7 @@ Version: @@VERSION@@-@@PKGRELEASE@@
 Section: admin
 Priority: optional
 Architecture: @@ARCH@@
-Depends: libc6 (>= 2.7-18), perl (>= 5.10.0-19), libterm-readline-gnu-perl, pve-qemu-kvm (>= 2.2-1), netcat6, libpve-access-control, libpve-storage-perl, pve-cluster, libjson-perl, libjson-xs-perl, libio-multiplex-perl, libnet-ssleay-perl, socat, pve-firewall, libuuid-perl, pve-ha-manager
+Depends: libc6 (>= 2.7-18), perl (>= 5.10.0-19), libterm-readline-gnu-perl, pve-qemu-kvm (>= 2.2-1), netcat6, libpve-access-control, libpve-storage-perl, pve-cluster, libjson-perl, libjson-xs-perl, libio-multiplex-perl, libnet-ssleay-perl, socat, pve-firewall, libuuid-perl, pve-ha-manager, genisoimage
 Maintainer: Proxmox Support Team <support at proxmox.com>
 Description: Qemu Server Tools
  This package contains the Qemu Server tools used by Proxmox VE
-- 
2.1.4




More information about the pve-devel mailing list