-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Checkin of Pipeworks to GitHub (Finally)
- Loading branch information
0 parents
commit 522bc15
Showing
285 changed files
with
20,106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
function Add-AzureLocalResource | ||
{ | ||
<# | ||
.Synopsis | ||
Adds an Azure local storage resource to a service definition | ||
.Description | ||
Adds an Azure local storage resource to a service definition. | ||
Azure local storage can create well-known directories on the host machine | ||
.Example | ||
New-AzureServiceDefinition -ServiceName "foo" | | ||
Add-AzureLocalResource -ServiceDefinition | ||
.Link | ||
New-AzureServiceDefinition | ||
#> | ||
[OutputType([xml],[string])] | ||
param( | ||
# The ServiceDefinition XML. This should be created with New-AzureServiceDefinition or retreived with Import-AzureServiceDefinition | ||
[Parameter(Mandatory=$true, | ||
ValueFromPipeline=$true, | ||
ValueFromPipelineByPropertyName=$true)] | ||
[ValidateScript({ | ||
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition") | ||
if (-not $IsServiceDefinition) { | ||
throw "Input must be a ServiceDefinition XML" | ||
} | ||
return $true | ||
})] | ||
[Xml] | ||
$ServiceDefinition, | ||
|
||
# If set, the local resource will only apply to the role named ToRole. If ToRole is not found, or doesn't | ||
# exist, the last role will be used. | ||
[string] | ||
$ToRole, | ||
|
||
# The name of the local storage. This will be the path of the name storage element, relative to the root drive. | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$Name, | ||
|
||
# The size of the storage. Sizes will be rounded up to the nearest megabyte. | ||
[Long] | ||
$Size = 1mb, | ||
|
||
# If set, a role will not be cleaned on recycle | ||
[switch] | ||
$DoNotcleanOnRoleRecycle, | ||
|
||
# If set, will output results as string rather than XML | ||
[switch] | ||
$AsString | ||
) | ||
|
||
process { | ||
|
||
#region Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item. | ||
$roles = @($ServiceDefinition.ServiceDefinition.WebRole), @($ServiceDefinition.ServiceDefinition.WorkerRole) + @($ServiceDefinition.ServiceDefinition.VirtualMachineRole) | ||
$xmlNamespace = @{'ServiceDefinition'='http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'} | ||
$selectXmlParams = @{ | ||
XPath = '//ServiceDefinition:WebRole|//ServiceDefinition:WorkerRole|//ServiceDefinition:VirtualMachineRole' | ||
Namespace = $xmlNamespace | ||
} | ||
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams | | ||
Select-Object -ExpandProperty Node) | ||
if (-not $roles) { | ||
$ServiceDefinition = $ServiceDefinition | | ||
Add-AzureRole -RoleName "WebRole1" | ||
|
||
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams | | ||
Select-Object -ExpandProperty Node) | ||
} | ||
#endregion Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item. | ||
|
||
if ($roles.Count -gt 1) { | ||
if ($ToRole) { | ||
} else { | ||
$role = $roles[-1] | ||
} | ||
} else { | ||
if ($ToRole) { | ||
if ($roles[0].Name -eq $ToRole) { | ||
$role = $roles[0] | ||
} else { | ||
$role = $null | ||
} | ||
} else { | ||
$role = $roles[0] | ||
} | ||
} | ||
|
||
if (-not $role) { return } | ||
|
||
$realSize = [Math]::Ceiling($size / 1mb) | ||
|
||
if (-not $role.LocalResources) { | ||
$role.InnerXml += "<LocalResources/>" | ||
} | ||
|
||
$localResourcesNode = Select-Xml -Xml $role -Namespace $xmlNamespace -XPath '//ServiceDefinition:LocalResources' | | ||
Select-Object -ExpandProperty Node | ||
|
||
$localResourcesNode.InnerXml += "<LocalStorage name='$Name' sizeInMB='$realSize' cleanOnRoleRecycle='$($DoNotcleanOnRoleRecycle.ToString().ToLower())'/>" | ||
|
||
} | ||
|
||
end { | ||
if ($AsString) { | ||
$strWrite = New-Object IO.StringWriter | ||
$serviceDefinition.Save($strWrite) | ||
return "$strWrite" | ||
} else { | ||
$serviceDefinition | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
function Add-AzureRole | ||
{ | ||
<# | ||
.Synopsis | ||
Adds and azure role to a service definition | ||
.Description | ||
Adds an azure role to a service definition | ||
.Example | ||
New-AzureServiceDefinition -ServiceName AService | | ||
Add-AzureRole -RoleName MyWebRole -VMSize Large -RoleType Web -AsString | ||
.Link | ||
New-AzureServiceDefinition | ||
#> | ||
[OutputType([xml],[string])] | ||
param( | ||
# The Service Definition | ||
[Parameter(Mandatory=$true, | ||
ValueFromPipeline=$true, | ||
ValueFromPipelineByPropertyName=$true)] | ||
[ValidateScript({ | ||
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition") | ||
if (-not $IsServiceDefinition) { | ||
throw "Input must be a ServiceDefinition XML" | ||
} | ||
return $true | ||
})] | ||
[Xml] | ||
$ServiceDefinition, | ||
|
||
# The name of the role | ||
[Parameter(Mandatory=$true, | ||
ValueFromPipelineByPropertyName=$true)] | ||
[string] | ||
$RoleName, | ||
|
||
# The VMSize | ||
[ValidateSet('ExtraSmall','Small','Medium', 'Large', 'Extra-Large', 'XS', 'XL', 'S', 'M', 'L')] | ||
[string] | ||
$VMSize, | ||
|
||
# If set, will disable native code execution on the role. This will prevent PHP or other CGI from working | ||
[Switch] | ||
$DisableNativeCodeExecution, | ||
|
||
# If set, will output as a string | ||
[switch] | ||
$AsString, | ||
|
||
# The type of the role. | ||
[ValidateSet('Web','Worker','VirtualMachine', 'VM')] | ||
[string] | ||
$RoleType = 'Web' | ||
) | ||
|
||
process { | ||
#region Correct Parameters | ||
$enableNativeCodeExecution = (-not $DisableNativeCodeExecution).ToString().ToLower() | ||
$vmSize = if ('XS' -eq $VmSize) { | ||
"ExtraSmall" | ||
} elseif ('XL' -eq $VmSize) { | ||
"ExtraLarge" | ||
} elseif ('M' -eq $VmSize) { | ||
"Medium" | ||
} elseif ('S' -eq $VmSize) { | ||
"Small" | ||
} elseif ('L' -eq $VmSize) { | ||
"Large" | ||
} elseif ($vmSize) { | ||
$vmSize | ||
} else { | ||
$null | ||
} | ||
|
||
if ($vmSize) { | ||
# Force every instance of a subword into camel case | ||
foreach ($subWord in 'Extra','Small', 'Medium', 'Large') { | ||
$vmSize= $vmSize -ireplace $subWord, $subWord | ||
} | ||
} | ||
#endregion Correct Parameters | ||
|
||
$roleElement = if ($roleType -eq 'Web') { | ||
"WebRole" | ||
} elseif ($roleType -eq 'Worker') { | ||
"WorkerRole" | ||
} elseif ('VirtualMachine', 'VM' -contains $roleType) { | ||
"VirtualMachineRole" | ||
} | ||
|
||
if ($vmSize) { | ||
@($serviceDefinition.ChildNodes)[-1].InnerXml += "<$roleElement name='$RoleName' vmsize='$VMSize' enableNativeCodeExecution='$enableNativeCodeExecution' />" | ||
} else { | ||
@($serviceDefinition.ChildNodes)[-1].InnerXml += "<$roleElement name='$RoleName' enableNativeCodeExecution='$enableNativeCodeExecution' />" | ||
} | ||
|
||
|
||
} | ||
|
||
end { | ||
if ($AsString) { | ||
$strWrite = New-Object IO.StringWriter | ||
$serviceDefinition.Save($strWrite) | ||
return "$strWrite" | ||
} else { | ||
$serviceDefinition | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
function Add-AzureSetting | ||
{ | ||
<# | ||
.Synopsis | ||
Adds an Azure local storage resource to a service definition | ||
.Description | ||
Adds an Azure local storage resource to a service definition. | ||
Azure local storage can create well-known directories on the host machine | ||
.Link | ||
New-AzureServiceDefinition | ||
.Example | ||
New-AzureServiceDefinition -ServiceName MyService | | ||
Add-AzureSetting -Name MySetting -Value MyValue -AsString | ||
#> | ||
[CmdletBinding(DefaultParameterSetName='NameAndValue')] | ||
[OutputType([xml],[string])] | ||
param( | ||
# The ServiceDefinition XML. This should be created with New-AzureServiceDefinition or retreived with Import-AzureServiceDefinition | ||
[Parameter(Mandatory=$true, | ||
ValueFromPipeline=$true, | ||
ValueFromPipelineByPropertyName=$true)] | ||
[ValidateScript({ | ||
$isServiceDefinition = $_.NameTable.Get("http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition") | ||
if (-not $IsServiceDefinition) { | ||
throw "Input must be a ServiceDefinition XML" | ||
} | ||
return $true | ||
})] | ||
[Xml] | ||
$ServiceDefinition, | ||
|
||
# The name of the setting to configure | ||
[Parameter(Mandatory=$true, ParameterSetName='NameAndValue')] | ||
[string] | ||
$Name, | ||
|
||
# The value to us for the setting | ||
[Parameter(Mandatory=$true, ParameterSetName='NameAndValue')] | ||
[string] | ||
$Value, | ||
|
||
# A table of names and values for Azure settings | ||
[Parameter(Mandatory=$true, ParameterSetName='SettingTable')] | ||
[Hashtable] | ||
$Setting, | ||
|
||
# If set, will output results as string rather than XML | ||
[switch] | ||
$AsString | ||
) | ||
|
||
process { | ||
if ($psCmdlet.ParameterSetName -eq 'NameAndValue') { | ||
# Resolve the role if it set, create the role if it doesn't exist, and track it if they assume the last item. | ||
$roles = @($ServiceDefinition.ServiceDefinition.WebRole), | ||
@($ServiceDefinition.ServiceDefinition.WorkerRole) + | ||
@($ServiceDefinition.ServiceDefinition.VirtualMachineRole) | ||
$xmlNamespace = @{'ServiceDefinition'='http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'} | ||
$selectXmlParams = @{ | ||
XPath = '//ServiceDefinition:WebRole|//ServiceDefinition:WorkerRole|//ServiceDefinition:VirtualMachineRole' | ||
Namespace = $xmlNamespace | ||
} | ||
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams | | ||
Select-Object -ExpandProperty Node) | ||
if (-not $roles) { | ||
$ServiceDefinition = $ServiceDefinition | | ||
Add-AzureRole -RoleName "WebRole1" | ||
|
||
$roles = @(Select-Xml -Xml $ServiceDefinition @selectXmlParams | | ||
Select-Object -ExpandProperty Node) | ||
} | ||
|
||
if ($roles.Count -gt 1) { | ||
if ($ToRole) { | ||
} else { | ||
$role = $roles[-1] | ||
} | ||
} else { | ||
if ($ToRole) { | ||
if ($roles[0].Name -eq $ToRole) { | ||
$role = $roles[0] | ||
} else { | ||
$role = $null | ||
} | ||
} else { | ||
$role = $roles[0] | ||
} | ||
} | ||
|
||
if (-not $role) { return } | ||
|
||
if (-not $role.ConfigurationSettings) { | ||
$role.InnerXml += "<ConfigurationSettings/>" | ||
} | ||
$ConfigurationSettingsNode = | ||
$(Select-Xml -Xml $role -Namespace $xmlNamespace -XPath '//ServiceDefinition:ConfigurationSettings' | | ||
Select-Object -ExpandProperty Node -First 1) | ||
|
||
$ConfigurationSettingsNode.InnerXml += "<Setting name='$Name' value='$([Security.SecurityElement]::Escape($value))'/>" | ||
} elseif ($psCmdlet.ParameterSetName -eq 'SettingTable') { | ||
$null = $psboundParameters.Remove('asString') | ||
$null = $psboundParameters.Remove('setting') | ||
foreach ($kv in $setting.GetEnumerator()) { | ||
$psboundParameters.Name = $kv.Key | ||
$psboundParameters.Value = $kv.Value | ||
$psboundParameters.ServiceDefinition = $ServiceDefinition | ||
$ServiceDefinition = & $myInvocation.MyCommand @psBoundParameters | ||
} | ||
} | ||
} | ||
|
||
end { | ||
if ($AsString) { | ||
$strWrite = New-Object IO.StringWriter | ||
$serviceDefinition.Save($strWrite) | ||
return "$strWrite" | ||
} else { | ||
$serviceDefinition | ||
} | ||
} | ||
} |
Oops, something went wrong.