Skip to content

Commit 522bc15

Browse files
Initial Checkin of Pipeworks to GitHub (Finally)
0 parents  commit 522bc15

File tree

285 files changed

+20106
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+20106
-0
lines changed

Diff for: Add-AzureLocalResource.ps1

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
function Add-AzureLocalResource
2+
{
3+
<#
4+
.Synopsis
5+
Adds an Azure local storage resource to a service definition
6+
.Description
7+
Adds an Azure local storage resource to a service definition.
8+
9+
Azure local storage can create well-known directories on the host machine
10+
.Example
11+
New-AzureServiceDefinition -ServiceName "foo" |
12+
Add-AzureLocalResource -ServiceDefinition
13+
.Link
14+
New-AzureServiceDefinition
15+
#>
16+
[OutputType([xml],[string])]
17+
param(
18+
# The ServiceDefinition XML. This should be created with New-AzureServiceDefinition or retreived with Import-AzureServiceDefinition
19+
[Parameter(Mandatory=$true,
20+
ValueFromPipeline=$true,
21+
ValueFromPipelineByPropertyName=$true)]
22+
[ValidateScript({
23+
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition")
24+
if (-not $IsServiceDefinition) {
25+
throw "Input must be a ServiceDefinition XML"
26+
}
27+
return $true
28+
})]
29+
[Xml]
30+
$ServiceDefinition,
31+
32+
# If set, the local resource will only apply to the role named ToRole. If ToRole is not found, or doesn't
33+
# exist, the last role will be used.
34+
[string]
35+
$ToRole,
36+
37+
# The name of the local storage. This will be the path of the name storage element, relative to the root drive.
38+
[Parameter(Mandatory=$true)]
39+
[string]
40+
$Name,
41+
42+
# The size of the storage. Sizes will be rounded up to the nearest megabyte.
43+
[Long]
44+
$Size = 1mb,
45+
46+
# If set, a role will not be cleaned on recycle
47+
[switch]
48+
$DoNotcleanOnRoleRecycle,
49+
50+
# If set, will output results as string rather than XML
51+
[switch]
52+
$AsString
53+
)
54+
55+
process {
56+
57+
#region Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item.
58+
$roles = @($ServiceDefinition.ServiceDefinition.WebRole), @($ServiceDefinition.ServiceDefinition.WorkerRole) + @($ServiceDefinition.ServiceDefinition.VirtualMachineRole)
59+
$xmlNamespace = @{'ServiceDefinition'='http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'}
60+
$selectXmlParams = @{
61+
XPath = '//ServiceDefinition:WebRole|//ServiceDefinition:WorkerRole|//ServiceDefinition:VirtualMachineRole'
62+
Namespace = $xmlNamespace
63+
}
64+
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams |
65+
Select-Object -ExpandProperty Node)
66+
if (-not $roles) {
67+
$ServiceDefinition = $ServiceDefinition |
68+
Add-AzureRole -RoleName "WebRole1"
69+
70+
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams |
71+
Select-Object -ExpandProperty Node)
72+
}
73+
#endregion Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item.
74+
75+
if ($roles.Count -gt 1) {
76+
if ($ToRole) {
77+
} else {
78+
$role = $roles[-1]
79+
}
80+
} else {
81+
if ($ToRole) {
82+
if ($roles[0].Name -eq $ToRole) {
83+
$role = $roles[0]
84+
} else {
85+
$role = $null
86+
}
87+
} else {
88+
$role = $roles[0]
89+
}
90+
}
91+
92+
if (-not $role) { return }
93+
94+
$realSize = [Math]::Ceiling($size / 1mb)
95+
96+
if (-not $role.LocalResources) {
97+
$role.InnerXml += "<LocalResources/>"
98+
}
99+
100+
$localResourcesNode = Select-Xml -Xml $role -Namespace $xmlNamespace -XPath '//ServiceDefinition:LocalResources' |
101+
Select-Object -ExpandProperty Node
102+
103+
$localResourcesNode.InnerXml += "<LocalStorage name='$Name' sizeInMB='$realSize' cleanOnRoleRecycle='$($DoNotcleanOnRoleRecycle.ToString().ToLower())'/>"
104+
105+
}
106+
107+
end {
108+
if ($AsString) {
109+
$strWrite = New-Object IO.StringWriter
110+
$serviceDefinition.Save($strWrite)
111+
return "$strWrite"
112+
} else {
113+
$serviceDefinition
114+
}
115+
}
116+
}

Diff for: Add-AzureRole.ps1

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
function Add-AzureRole
2+
{
3+
<#
4+
.Synopsis
5+
Adds and azure role to a service definition
6+
.Description
7+
Adds an azure role to a service definition
8+
.Example
9+
New-AzureServiceDefinition -ServiceName AService |
10+
Add-AzureRole -RoleName MyWebRole -VMSize Large -RoleType Web -AsString
11+
.Link
12+
New-AzureServiceDefinition
13+
#>
14+
[OutputType([xml],[string])]
15+
param(
16+
# The Service Definition
17+
[Parameter(Mandatory=$true,
18+
ValueFromPipeline=$true,
19+
ValueFromPipelineByPropertyName=$true)]
20+
[ValidateScript({
21+
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition")
22+
if (-not $IsServiceDefinition) {
23+
throw "Input must be a ServiceDefinition XML"
24+
}
25+
return $true
26+
})]
27+
[Xml]
28+
$ServiceDefinition,
29+
30+
# The name of the role
31+
[Parameter(Mandatory=$true,
32+
ValueFromPipelineByPropertyName=$true)]
33+
[string]
34+
$RoleName,
35+
36+
# The VMSize
37+
[ValidateSet('ExtraSmall','Small','Medium', 'Large', 'Extra-Large', 'XS', 'XL', 'S', 'M', 'L')]
38+
[string]
39+
$VMSize,
40+
41+
# If set, will disable native code execution on the role. This will prevent PHP or other CGI from working
42+
[Switch]
43+
$DisableNativeCodeExecution,
44+
45+
# If set, will output as a string
46+
[switch]
47+
$AsString,
48+
49+
# The type of the role.
50+
[ValidateSet('Web','Worker','VirtualMachine', 'VM')]
51+
[string]
52+
$RoleType = 'Web'
53+
)
54+
55+
process {
56+
#region Correct Parameters
57+
$enableNativeCodeExecution = (-not $DisableNativeCodeExecution).ToString().ToLower()
58+
$vmSize = if ('XS' -eq $VmSize) {
59+
"ExtraSmall"
60+
} elseif ('XL' -eq $VmSize) {
61+
"ExtraLarge"
62+
} elseif ('M' -eq $VmSize) {
63+
"Medium"
64+
} elseif ('S' -eq $VmSize) {
65+
"Small"
66+
} elseif ('L' -eq $VmSize) {
67+
"Large"
68+
} elseif ($vmSize) {
69+
$vmSize
70+
} else {
71+
$null
72+
}
73+
74+
if ($vmSize) {
75+
# Force every instance of a subword into camel case
76+
foreach ($subWord in 'Extra','Small', 'Medium', 'Large') {
77+
$vmSize= $vmSize -ireplace $subWord, $subWord
78+
}
79+
}
80+
#endregion Correct Parameters
81+
82+
$roleElement = if ($roleType -eq 'Web') {
83+
"WebRole"
84+
} elseif ($roleType -eq 'Worker') {
85+
"WorkerRole"
86+
} elseif ('VirtualMachine', 'VM' -contains $roleType) {
87+
"VirtualMachineRole"
88+
}
89+
90+
if ($vmSize) {
91+
@($serviceDefinition.ChildNodes)[-1].InnerXml += "<$roleElement name='$RoleName' vmsize='$VMSize' enableNativeCodeExecution='$enableNativeCodeExecution' />"
92+
} else {
93+
@($serviceDefinition.ChildNodes)[-1].InnerXml += "<$roleElement name='$RoleName' enableNativeCodeExecution='$enableNativeCodeExecution' />"
94+
}
95+
96+
97+
}
98+
99+
end {
100+
if ($AsString) {
101+
$strWrite = New-Object IO.StringWriter
102+
$serviceDefinition.Save($strWrite)
103+
return "$strWrite"
104+
} else {
105+
$serviceDefinition
106+
}
107+
}
108+
}

Diff for: Add-AzureSetting.ps1

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
function Add-AzureSetting
2+
{
3+
<#
4+
.Synopsis
5+
Adds an Azure local storage resource to a service definition
6+
.Description
7+
Adds an Azure local storage resource to a service definition.
8+
9+
Azure local storage can create well-known directories on the host machine
10+
.Link
11+
New-AzureServiceDefinition
12+
.Example
13+
New-AzureServiceDefinition -ServiceName MyService |
14+
Add-AzureSetting -Name MySetting -Value MyValue -AsString
15+
#>
16+
[CmdletBinding(DefaultParameterSetName='NameAndValue')]
17+
[OutputType([xml],[string])]
18+
param(
19+
# The ServiceDefinition XML. This should be created with New-AzureServiceDefinition or retreived with Import-AzureServiceDefinition
20+
[Parameter(Mandatory=$true,
21+
ValueFromPipeline=$true,
22+
ValueFromPipelineByPropertyName=$true)]
23+
[ValidateScript({
24+
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition")
25+
if (-not $IsServiceDefinition) {
26+
throw "Input must be a ServiceDefinition XML"
27+
}
28+
return $true
29+
})]
30+
[Xml]
31+
$ServiceDefinition,
32+
33+
# The name of the setting to configure
34+
[Parameter(Mandatory=$true, ParameterSetName='NameAndValue')]
35+
[string]
36+
$Name,
37+
38+
# The value to us for the setting
39+
[Parameter(Mandatory=$true, ParameterSetName='NameAndValue')]
40+
[string]
41+
$Value,
42+
43+
# A table of names and values for Azure settings
44+
[Parameter(Mandatory=$true, ParameterSetName='SettingTable')]
45+
[Hashtable]
46+
$Setting,
47+
48+
# If set, will output results as string rather than XML
49+
[switch]
50+
$AsString
51+
)
52+
53+
process {
54+
if ($psCmdlet.ParameterSetName -eq 'NameAndValue') {
55+
# Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item.
56+
$roles = @($ServiceDefinition.ServiceDefinition.WebRole),
57+
@($ServiceDefinition.ServiceDefinition.WorkerRole) +
58+
@($ServiceDefinition.ServiceDefinition.VirtualMachineRole)
59+
$xmlNamespace = @{'ServiceDefinition'='http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'}
60+
$selectXmlParams = @{
61+
XPath = '//ServiceDefinition:WebRole|//ServiceDefinition:WorkerRole|//ServiceDefinition:VirtualMachineRole'
62+
Namespace = $xmlNamespace
63+
}
64+
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams |
65+
Select-Object -ExpandProperty Node)
66+
if (-not $roles) {
67+
$ServiceDefinition = $ServiceDefinition |
68+
Add-AzureRole -RoleName "WebRole1"
69+
70+
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams |
71+
Select-Object -ExpandProperty Node)
72+
}
73+
74+
if ($roles.Count -gt 1) {
75+
if ($ToRole) {
76+
} else {
77+
$role = $roles[-1]
78+
}
79+
} else {
80+
if ($ToRole) {
81+
if ($roles[0].Name -eq $ToRole) {
82+
$role = $roles[0]
83+
} else {
84+
$role = $null
85+
}
86+
} else {
87+
$role = $roles[0]
88+
}
89+
}
90+
91+
if (-not $role) { return }
92+
93+
if (-not $role.ConfigurationSettings) {
94+
$role.InnerXml += "<ConfigurationSettings/>"
95+
}
96+
$ConfigurationSettingsNode =
97+
$(Select-Xml -Xml $role -Namespace $xmlNamespace -XPath '//ServiceDefinition:ConfigurationSettings' |
98+
Select-Object -ExpandProperty Node -First 1)
99+
100+
$ConfigurationSettingsNode.InnerXml += "<Setting name='$Name' value='$([Security.SecurityElement]::Escape($value))'/>"
101+
} elseif ($psCmdlet.ParameterSetName -eq 'SettingTable') {
102+
$null = $psboundParameters.Remove('asString')
103+
$null = $psboundParameters.Remove('setting')
104+
foreach ($kv in $setting.GetEnumerator()) {
105+
$psboundParameters.Name = $kv.Key
106+
$psboundParameters.Value = $kv.Value
107+
$psboundParameters.ServiceDefinition = $ServiceDefinition
108+
$ServiceDefinition = & $myInvocation.MyCommand @psBoundParameters
109+
}
110+
}
111+
}
112+
113+
end {
114+
if ($AsString) {
115+
$strWrite = New-Object IO.StringWriter
116+
$serviceDefinition.Save($strWrite)
117+
return "$strWrite"
118+
} else {
119+
$serviceDefinition
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)