2,187
edits
(Added "Move to a new Datastore") |
(Added "SOAP API") |
||
Line 72: | Line 72: | ||
# Redeploy the original workspace | # Redeploy the original workspace | ||
# Assuming the original workspace spins up OK, the new temporary workspace can be deleted | # Assuming the original workspace spins up OK, the new temporary workspace can be deleted | ||
== SOAP API == | |||
As of 2010, there is no [[Power_Shell|PowerShell]] or [[PowerCLI]] interface into Lab Manager. There is an underlying SOAP interface (on which a PowerCLI interface would be built), which provides limited interaction. This can be utilised via PowerShell scripts. | |||
The functions below were taken from http://poshcode.org/753, note that whilst you can connect to the Lab manager web service without explicitly supplying a user/pass (assuming the logged in user has access), you do need credentials in order to be able to create the Authentication Header that's required for all API calls. I tend to store a local copy of my user/pass (see [[Power_Shell#Store_Password_Securely|Store Password Securely]]) to make this less of a chore. | |||
<source lang="powershell"> | |||
function Ignore-SslErrors { | |||
# Create a compilation environment | |||
$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider | |||
$Compiler=$Provider.CreateCompiler() | |||
$Params=New-Object System.CodeDom.Compiler.CompilerParameters | |||
$Params.GenerateExecutable=$False | |||
$Params.GenerateInMemory=$True | |||
$Params.IncludeDebugInformation=$False | |||
$Params.ReferencedAssemblies.Add("System.DLL") > $null | |||
$TASource=@' | |||
namespace Local.ToolkitExtensions.Net.CertificatePolicy { | |||
public class TrustAll : System.Net.ICertificatePolicy { | |||
public TrustAll() { | |||
} | |||
public bool CheckValidationResult(System.Net.ServicePoint sp, | |||
System.Security.Cryptography.X509Certificates.X509Certificate cert, | |||
System.Net.WebRequest req, int problem) { | |||
return true; | |||
} | |||
} | |||
} | |||
'@ | |||
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource) | |||
$TAAssembly=$TAResults.CompiledAssembly | |||
## We now create an instance of the TrustAll and attach it to the ServicePointManager | |||
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll") | |||
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll | |||
} | |||
function New-ObjectFromProxy { | |||
param($proxy, $proxyAttributeName, $typeName) | |||
# Locate the assembly for $proxy | |||
$attribute = $proxy | gm | where { $_.Name -eq $proxyAttributeName } | |||
$str = "`$assembly = [" + $attribute.TypeName + "].assembly" | |||
invoke-expression $str | |||
# Instantiate an AuthenticationHeaderValue object. | |||
$type = $assembly.getTypes() | where { $_.Name -eq $typeName } | |||
return $assembly.CreateInstance($type) | |||
} | |||
function Connect-LabManager { | |||
param($server, $credential) | |||
# Log in to Lab Manager's web service. | |||
$server = "https://" + $server + "/" | |||
$endpoint = $server + "LabManager/SOAP/LabManager.asmx" | |||
$proxy = new-webserviceproxy -uri $endpoint -cred $credential | |||
# Before continuing we need to add an Authentication Header to $proxy. | |||
$authHeader = New-ObjectFromProxy -proxy $proxy -proxyAttributeName "AuthenticationHeaderValue" -typeName "AuthenticationHeader" | |||
$authHeader.username = $credential.GetNetworkCredential().UserName | |||
$authHeader.password = $credential.GetNetworkCredential().Password | |||
$proxy.AuthenticationHeaderValue = $authHeader | |||
return $proxy | |||
} | |||
</source> | |||