[pve-devel] [PATCH 4/5] generate_cloudinit_metadata
Alexandre Derumier
aderumier at odiso.com
Wed Jun 10 17:10:12 CEST 2015
improve me : generate json from perl hashref
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 82fc887..790aa7e 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -18,6 +18,7 @@ use Cwd 'abs_path';
use IPC::Open3;
use JSON;
use Fcntl;
+use UUID;
use PVE::SafeSyslog;
use Storable qw(dclone);
use PVE::Exception qw(raise raise_param_exc);
@@ -6286,6 +6287,7 @@ sub generate_cloudinitconfig {
mkdir "$path/drive/openstack/latest";
mkdir "$path/drive/openstack/content";
generate_cloudinit_userdata($conf, $path);
+ generate_cloudinit_metadata($conf, $path);
my $cmd = [];
push @$cmd, 'genisoimage';
@@ -6332,4 +6334,30 @@ sub generate_cloudinit_userdata {
return file_write($fn, $content);
}
+
+sub generate_cloudinit_metadata {
+ my ($conf, $path) = @_;
+
+ my $uuid_str = undef;
+ if ($conf->{smbios1}) {
+ my $smbios = parse_smbios1($conf->{smbios1});
+ $uuid_str = $smbios->{uuid} if $smbios->{uuid};
+ }
+ if(!$uuid_str){
+ my ($uuid, $uuid_str);
+ UUID::generate($uuid);
+ UUID::unparse($uuid, $uuid_str);
+ }
+
+ my $content = "{\n";
+ $content .= " \"uuid\": \"$uuid_str\"\n";
+ $content .= "}\n";
+
+ my $fn = "$path/drive/openstack/latest/meta_data.json";
+
+ return file_write($fn, $content);
+
+
+}
+
1;
--
2.1.4
More information about the pve-devel
mailing list