|
|
|
@ -0,0 +1,156 @@
|
|
|
|
|
--- /usr/share/perl5/PVE/QemuServer/Cloudinit.pm.orig 2021-04-29 16:16:04.000000000 +0200
|
|
|
|
|
+++ /usr/share/perl5/PVE/QemuServer/Cloudinit.pm 2022-01-10 17:36:46.174949937 +0100
|
|
|
|
|
@@ -159,6 +159,12 @@
|
|
|
|
|
sub configdrive2_network {
|
|
|
|
|
my ($conf) = @_;
|
|
|
|
|
|
|
|
|
|
+ ## Support Windows
|
|
|
|
|
+ my $ostype = $conf->{"ostype"};
|
|
|
|
|
+ my $default_dns = '';
|
|
|
|
|
+ my $default_search = '';
|
|
|
|
|
+ ##
|
|
|
|
|
+
|
|
|
|
|
my $content = "auto lo\n";
|
|
|
|
|
$content .= "iface lo inet loopback\n\n";
|
|
|
|
|
|
|
|
|
|
@@ -166,12 +172,15 @@
|
|
|
|
|
if ($nameservers && @$nameservers) {
|
|
|
|
|
$nameservers = join(' ', @$nameservers);
|
|
|
|
|
$content .= " dns_nameservers $nameservers\n";
|
|
|
|
|
+ $default_dns = $nameservers; # Support windows
|
|
|
|
|
}
|
|
|
|
|
if ($searchdomains && @$searchdomains) {
|
|
|
|
|
$searchdomains = join(' ', @$searchdomains);
|
|
|
|
|
$content .= " dns_search $searchdomains\n";
|
|
|
|
|
+ $default_search = $searchdomains; # Support Windows
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ my $dnsinserted = 0;
|
|
|
|
|
my @ifaces = grep { /^net(\d+)$/ } keys %$conf;
|
|
|
|
|
foreach my $iface (sort @ifaces) {
|
|
|
|
|
(my $id = $iface) =~ s/^net//;
|
|
|
|
|
@@ -189,6 +198,14 @@
|
|
|
|
|
$content .= " address $addr\n";
|
|
|
|
|
$content .= " netmask $mask\n";
|
|
|
|
|
$content .= " gateway $net->{gw}\n" if $net->{gw};
|
|
|
|
|
+
|
|
|
|
|
+ ## Support windows
|
|
|
|
|
+ if(PVE::QemuServer::windows_version($ostype) && not($dnsinserted)) {
|
|
|
|
|
+ $content .= " dns-nameservers $default_dns\n";
|
|
|
|
|
+ $content .= " dns-search $default_search\n";
|
|
|
|
|
+ $dnsinserted++;
|
|
|
|
|
+ }
|
|
|
|
|
+ ##
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ($net->{ip6}) {
|
|
|
|
|
@@ -207,19 +224,95 @@
|
|
|
|
|
return $content;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+sub get_mac_addresses {
|
|
|
|
|
+ my ($conf) = @_;
|
|
|
|
|
+
|
|
|
|
|
+ my $dhcpstring = undef;
|
|
|
|
|
+ my @dhcpmacs = ();
|
|
|
|
|
+ my @ifaces = grep { /^net(\d+)$/ } keys %$conf;
|
|
|
|
|
+
|
|
|
|
|
+ foreach my $iface (sort @ifaces) {
|
|
|
|
|
+ (my $id = $iface) =~ s/^net//;
|
|
|
|
|
+ my $net = PVE::QemuServer::parse_net($conf->{$iface});
|
|
|
|
|
+ next if !$conf->{"ipconfig$id"};
|
|
|
|
|
+ my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
|
|
|
|
|
+
|
|
|
|
|
+ my $mac = lc $net->{macaddr};
|
|
|
|
|
+
|
|
|
|
|
+ if (($ipconfig->{ip}) and ($ipconfig->{ip} eq 'dhcp')){
|
|
|
|
|
+ push @dhcpmacs, $mac;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (@dhcpmacs){
|
|
|
|
|
+ $dhcpstring .= ",\n \"dhcp\":[";
|
|
|
|
|
+ foreach my $mac (@dhcpmacs){
|
|
|
|
|
+ if ($mac != @dhcpmacs[-1]){
|
|
|
|
|
+ $dhcpstring .= "\"$mac\",";
|
|
|
|
|
+ }
|
|
|
|
|
+ else{
|
|
|
|
|
+ $dhcpstring .= "\"$mac\"]";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ($dhcpstring);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
sub configdrive2_gen_metadata {
|
|
|
|
|
- my ($user, $network) = @_;
|
|
|
|
|
+ my ($conf, $vmid, $user, $network) = @_;
|
|
|
|
|
+
|
|
|
|
|
+ # Get DHCP nics by mac adresses
|
|
|
|
|
+ my $dhcpmacs = undef;
|
|
|
|
|
+ $dhcpmacs = get_mac_addresses($conf);
|
|
|
|
|
|
|
|
|
|
+ # Get UUID
|
|
|
|
|
my $uuid_str = Digest::SHA::sha1_hex($user.$network);
|
|
|
|
|
- return configdrive2_metadata($uuid_str);
|
|
|
|
|
+
|
|
|
|
|
+ # Get hostname
|
|
|
|
|
+ my ($hostname, $fqdn) = get_hostname_fqdn($conf, $vmid);
|
|
|
|
|
+
|
|
|
|
|
+ # Get username, default to Administrator if none
|
|
|
|
|
+ my $username = "Administrator";
|
|
|
|
|
+ if (defined($conf->{ciuser})){
|
|
|
|
|
+ $username = $conf->{ciuser};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # Get user password
|
|
|
|
|
+ my $password = $conf->{cipassword};
|
|
|
|
|
+
|
|
|
|
|
+ # Get ssh keys and make a list out of it in json format
|
|
|
|
|
+ my $keystring = undef;
|
|
|
|
|
+ if (defined(my $pubkeys = $conf->{sshkeys})) {
|
|
|
|
|
+ $pubkeys = URI::Escape::uri_unescape($pubkeys);
|
|
|
|
|
+ my @pubkeysarray = split "\n", $pubkeys;
|
|
|
|
|
+ my $arraylength = @pubkeysarray;
|
|
|
|
|
+ my $incrementer = 1;
|
|
|
|
|
+ $keystring =",\n \"public_keys\": {\n";
|
|
|
|
|
+ for my $key (@pubkeysarray){
|
|
|
|
|
+ $keystring .= " \"SSH${incrementer}\" : \"${key}\"";
|
|
|
|
|
+ if ($arraylength != $incrementer){
|
|
|
|
|
+ $keystring .= ",\n";
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $keystring .= "\n }";
|
|
|
|
|
+ }
|
|
|
|
|
+ $incrementer++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return configdrive2_metadata($password, $uuid_str, $hostname, $username, $keystring, $network, $dhcpmacs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub configdrive2_metadata {
|
|
|
|
|
- my ($uuid) = @_;
|
|
|
|
|
+ my ($password, $uuid, $hostname, $username, $pubkeys, $network, $dhcpmacs) = @_;
|
|
|
|
|
return <<"EOF";
|
|
|
|
|
{
|
|
|
|
|
- "uuid": "$uuid",
|
|
|
|
|
- "network_config": { "content_path": "/content/0000" }
|
|
|
|
|
+ "meta":{
|
|
|
|
|
+ "admin_username": "$username",
|
|
|
|
|
+ "admin_pass": "$password",
|
|
|
|
|
+ "uuid":"$uuid",
|
|
|
|
|
+ "hostname":"$hostname"
|
|
|
|
|
+ },
|
|
|
|
|
+ "network_config":{"content_path":"/content/0000"}$pubkeys$dhcpmacs
|
|
|
|
|
}
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
@@ -232,7 +325,7 @@
|
|
|
|
|
$network_data = configdrive2_network($conf) if !defined($network_data);
|
|
|
|
|
|
|
|
|
|
if (!defined($meta_data)) {
|
|
|
|
|
- $meta_data = configdrive2_gen_metadata($user_data, $network_data);
|
|
|
|
|
+ $meta_data = configdrive2_gen_metadata($conf, $vmid, $user_data, $network_data);
|
|
|
|
|
}
|
|
|
|
|
my $files = {
|
|
|
|
|
'/openstack/latest/user_data' => $user_data,
|