[pve-devel] [PATCH 3/5] generate_cloudinit_userdata
Alexandre Derumier
aderumier at odiso.com
Wed Jun 10 17:10:11 CEST 2015
improve me: generate yaml from perl hash
sample yaml config:
fqdn: test2.odiso.net
manage_etc_hosts: true
users:
- name: root
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7BX393CdwvBp9DTZ9hSFxkjeJ+SsvKCRAxob62eiJJtnXcHIpyPX5FdNDHZHRjqGzhMnyHuHjnux+aXwuTzRLkY7Kw4BS0cB1Rn2K1Rx1CNonzNj6XetlmVOq773DO92NiVRHrpgQYzy/U377eab2EDkAoNSWAWT1YzWaBSxoFY5j8ohcblPHo5RA5WZlAXAC09mb9xw9yDKmHn6+C5Fp88E7vvKTysAgocQB4JPMpXg7y6XJxpEm8mnt8X7Sz/AuSjb2a8R3LlluGcVanH5HMhj9CZZBK5d+Stl6SKL6T5jKESm0qj/kKuXJkqwngo/BLxVwSfXxfNJu/kACxJkb aderumier at odiso.com
bootcmd:
- ifdown -a
- ifup -a
package_upgrade: true
power_state:
mode: poweroff
message: Bye Bye
timeout: 30
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 66a60a9..82fc887 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6285,6 +6285,7 @@ sub generate_cloudinitconfig {
mkdir "$path/drive/openstack";
mkdir "$path/drive/openstack/latest";
mkdir "$path/drive/openstack/content";
+ generate_cloudinit_userdata($conf, $path);
my $cmd = [];
push @$cmd, 'genisoimage';
@@ -6305,4 +6306,30 @@ sub generate_cloudinitconfig {
}
+sub generate_cloudinit_userdata {
+ my ($conf, $path) = @_;
+
+ my $content = "#cloud-config\n";
+ if ($conf->{hostname}) {
+ $content .= "fqdn: $conf->{hostname}\n";
+ $content .= "manage_etc_hosts: true\n";
+ }
+ if ($conf->{sshkey}) {
+ $content .= "users:\n";
+ $content .= " - name: root\n";
+ $content .= " ssh-authorized-keys:\n";
+ $content .= " - $conf->{sshkey}\n";
+ }
+
+ $content .= "package_upgrade: true\n";
+ $content .= "power_state:\n";
+ $content .= " mode: poweroff\n";
+ $content .= " message: Cloudinit config finished - Halting System\n";
+ $content .= " timeout: 30\n";
+
+ my $fn = "$path/drive/openstack/latest/user_data";
+
+ return file_write($fn, $content);
+
+}
1;
--
2.1.4
More information about the pve-devel
mailing list