From 087db8cc5b7c0fb04d9e5d3287fe146a14acdfa9 Mon Sep 17 00:00:00 2001 From: Jose Phillips Date: Wed, 24 Aug 2016 15:40:50 -0500 Subject: [PATCH] Set the desired hostname to a instance using murano instead of Murano Pattern Without this patch all the instances are deployed with the following hostname: Murano-RandomID-HOSTNAME-randomID With this Patch the new instances will be deployed just with the hostname. This is more benefit on Windows instances where the recommended length for the hostname is 15 characters. Change-Id: I8c9867481071b2ae09c3ea17cba4c535759aaf58 Closes-Bug: #1605786 --- .../Classes/resources/LinuxMuranoInstance.yaml | 8 +++++--- meta/io.murano/Resources/murano-init.conf | 2 ++ meta/io.murano/Resources/windows-init.ps1 | 14 ++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml b/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml index b061df0bd..ccd91749c 100644 --- a/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml +++ b/meta/io.murano/Classes/resources/LinuxMuranoInstance.yaml @@ -53,7 +53,9 @@ Methods: generateCloudConfig: Body: - $resources: new(sys:Resources) - - $muranoInitConf: $resources.yaml('murano-init.conf') + - $muranoInitConf: $resources.yaml('murano-init.conf').bind(dict( + instanceHostname => $.name + )) - Return: $muranoInitConf generateUserData: @@ -93,7 +95,7 @@ Methods: - $userData: $muranoScript.replace($muranoReplacements) + $initScript.replace($scriptReplacements) - Return: $userData - + releaseResources: Body: - $region: $.getRegion() @@ -104,4 +106,4 @@ Methods: - $template.resources: $template.resources.deleteAll($resourcesToDelete) - $region.stack.setTemplate($template) - - super($, $.releaseResources()) \ No newline at end of file + - super($, $.releaseResources()) diff --git a/meta/io.murano/Resources/murano-init.conf b/meta/io.murano/Resources/murano-init.conf index f7c516061..5e0bb3c27 100644 --- a/meta/io.murano/Resources/murano-init.conf +++ b/meta/io.murano/Resources/murano-init.conf @@ -16,3 +16,5 @@ - python-dev - python-setuptools - python-virtualenv + + hostname: $instanceHostname diff --git a/meta/io.murano/Resources/windows-init.ps1 b/meta/io.murano/Resources/windows-init.ps1 index 68a52428f..c12a0033f 100644 --- a/meta/io.murano/Resources/windows-init.ps1 +++ b/meta/io.murano/Resources/windows-init.ps1 @@ -17,6 +17,7 @@ $WindowsAgentConfigBase64 = '%AGENT_CONFIG_BASE64%' $WindowsAgentConfigFile = "C:\Murano\Agent\WindowsAgent.exe.config" $WindowsAgentLogFile = "C:\Murano\Agent\log.txt" +$CurrentComputerName = HOSTNAME $NewComputerName = '%INTERNAL_HOSTNAME%' $MuranoFileShare = '\\%MURANO_SERVER_ADDRESS%\share' @@ -63,13 +64,14 @@ Write-Log "Service has been updated." Write-Log "Adding environment variable 'MuranoFileShare' = '$MuranoFileShare' ..." [Environment]::SetEnvironmentVariable('MuranoFileShare', $MuranoFileShare, [EnvironmentVariableTarget]::Machine) Write-Log "Environment variable added." +# (jose-phillips) If the Master Image or CloudBase-Init is already set the hostname this procedure fail. +if ($CurrentComputerName -ne $NewComputerName){ + Write-Log "Renaming computer to '$NewComputerName' ..." + $null = Rename-Computer -NewName $NewComputerName -Force -Write-Log "Renaming computer to '$NewComputerName' ..." -$null = Rename-Computer -NewName $NewComputerName -Force - -Write-Log "New name assigned, restart required." -$RestartRequired = $true - + Write-Log "New name assigned, restart required." + $RestartRequired = $true +} Write-Log 'All done!' if ( $RestartRequired ) {