-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddPlacementConstraintsIntoApplicationManifest.ps1
53 lines (38 loc) · 1.3 KB
/
AddPlacementConstraintsIntoApplicationManifest.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# AddPlacementConstraintsIntoApplicationManifest.ps1
#
Param
(
[string]$ApplicationManifestFilePath = [string]::Empty,
[string]$ServiceName = [string]::Empty,
[string]$PlacementConstraints = [string]::Empty,
[string]$ServiceType = "StatelessService"
)
$ApplicationManifestFilePath = Resolve-Path -Path $ApplicationManifestFilePath
if (!(Test-Path $ApplicationManifestFilePath -PathType Leaf)) {
throw "Could not locate the ApplicationMenifest file to update at the path '$ApplicationManifestFilePath'."
}
function Set-XmlNodesElementTextValue([xml]$xml, $node, $elementName, $textValue)
{
if ($null -eq $node.($elementName))
{
$element = $xml.CreateElement($elementName, $xml.DocumentElement.NamespaceURI)
$textNode = $xml.CreateTextNode($textValue)
$element.AppendChild($textNode) > $null
$node.AppendChild($element) > $null
}
else
{
$node.($elementName) = $textValue
}
}
[xml]$xml = Get-Content -Path $ApplicationManifestFilePath
$services = $xml.GetElementsByTagName('Service')
foreach ($service in $services) {
if ($service.Name -eq $ServiceName) {
$serviceInstance = $service.($ServiceType)
Set-XmlNodesElementTextValue -xml $xml -node $serviceInstance -elementName 'PlacementConstraints' -textValue "$PlacementConstraints"
break
}
}
$xml.Save($ApplicationManifestFilePath)