Figured this out, I hope it helps someone out… this PS Script creates a Host and then creates a deploy task to the Image specified when the host was created.
$vmname = "vmname"
$MacAddress = "00:00:00:00:00:00"
$ImageName = "ImageName"
#######################################################################################################################
# Configure the variables below for the Fog Server
#######################################################################################################################
#FogServer
$fogApiToken = 'your token'
$fogUserToken = 'your user token'
$fogServer = "fog server IP or dns name"
$Description = "Created by vCommander" # www.embotics.com
########################################################################################################################
# Nothing to configure below this line - Starting the main function of the script
########################################################################################################################
########################################################################################################################
# Setting Cert Policy - required for successful auth with the server if set to https
########################################################################################################################
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
########################################################################################################################
#Setup Auth headers and base url for FogServer
$headers = @{};
$headers.Add('fog-api-token', $fogApiToken);
$headers.Add('fog-user-token', $fogUserToken);
$baseUri = "http://$fogServer/fog"
#Get Image List From Fog Server
$ImageURL = $baseUri+"/image/"
$ImageResult = Invoke-RestMethod -Uri $ImageURL -Method GET -Headers $headers -ContentType "application/json"
$Image = $ImageResult.images | Select-object imageTypeID,id,name | Where-object {$_.name -eq $ImageName}
#GetHost List from fog Server
$HostURL = $baseUri +"/host/"
$HostResult = Invoke-RestMethod -Uri $HostURL -Method GET -Headers $headers -ContentType "application/json"
#Create Host entry from vCommander
$HostJson = @{
"name"= $vmname
"description"= $Description
"macs" = @($MacAddress)
"imageID"= $Image.id
"imagename" = $ImageName
}
$CreateHostJson = ConvertTo-Json($HostJson)
$createHostURL = $baseUri +"/host/create"
$createHostResult = Invoke-RestMethod -Uri $createHostURL -Method POST -body $CreateHostJson -Headers $headers -ContentType "application/json"
#Get Task types to confirm Structure
$TasktypesURL = $baseUri + "/tasktype"
$TasktypesResult = Invoke-RestMethod -Uri $TasksURL -Method GET -Headers $headers -ContentType "application/json"
$TasktypeID = ($TasktypesResult.tasktypes | Select-object name,id | Where-object {$_.name -eq "Deploy"}).id
#Create Task to Image Host
$ImageID = $image.id
$HostID = $createHostResult.id
$TaskURL = $baseUri + "/host/" + $HostID + "/task"
$TaskdataSet = @{
"hostname" = $createHostResult.name
"taskTypeID" = $TasktypeID
}
$taskdataToSend = ConvertTo-JSON($TaskdataSet)
$TaskResult = Invoke-RestMethod -Method Post -Uri $TaskURL -Headers $headers -Body $taskdataToSend -ContentType "application/json"