none
Automatic availability of WKS nodes

    Question

  • Hello.

    We use HPC cluster on computer labs (Windows 7 Ent. x64, HPC Pack 2008 R2 SP4) and we want to set availability policy based on lab timetable. I can download lab timetable in XML file and I can parse it using PowerShell so I have information for example:

    Monday 8:00 9:30
    Monday 9:45 11:15
    etc.

    I want to use this information and create workstation node template in XML file and then import it to the cluster.

    In XML node template file is availability information saved in hex format starting on Sunday, so for example computer availability for computing on Monday 8:00 - 9:30 will seems like this 0000000000000000E.

    Is there comfortable option how can I convert my timetable to this format? Or how can I convert it?

    Thank you

    Sunday, March 31, 2013 3:36 PM

Answers

  • Solution of my problem is this PowerShell script:

    $url ="https://stagservices.upol.cz/ws/services/rest/rozvrhy/getRozvrhByMistnost?semestr=%25&budova=LP&mistnost=5003"
    $client = new-object System.Net.WebClient
    $client.DownloadFile( $url, ".\rozvrh.xml" )
    [System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
    $file = resolve-path("rozvrh.xml")
    $xd.load($file)
    $ns = New-Object Xml.XmlNamespaceManager $xd.NameTable
    $ns.AddNamespace( "ns1", "http://stag-ws.zcu.cz/" )
    $nodelist = $xd.selectnodes("/ns1:getRozvrhByMistnostResponse/rozvrh/rozvrhovaAkce", $ns)
    $temp = @()
    foreach ($rozvrhovaAkce in $nodelist) {
        $startTime = $rozvrhovaAkce.selectSingleNode("hodinaSkutOd").get_innerXml()
    	$start = [datetime]$startTime
    	$endTime = $rozvrhovaAkce.selectSingleNode("hodinaSkutDo").get_innerXml()
    	$end = [datetime]$endTime
    	$day = $rozvrhovaAkce.selectSingleNode("den").get_innerXml()
    	$type = $rozvrhovaAkce.selectSingleNode("typAkce").get_innerXml()
    	if (($type -eq "Cvičení") -or ($type -eq "Seminář")) {
    		switch ($day) {
    		"Pondělí" {$cons = 48}
    		"Úterý" {$cons = 96}
    		"Středa" {$cons = 144}
    		"Čtvrtek" {$cons = 192}
    		"Pátek" {$cons = 240}
    		}
    	$startHour = $start.Hour * 2
    	$startMinute = $start.Minute
    	$endHour = $end.Hour * 2
    	$endMinute = $end.Minute
    	if ($startMinute -gt 30) {$startHour++}
    	elseif (($endMinute -le 30) -and ($endMinute -gt 0)) {$endHour++}
    	elseif ($endMinute -gt 30) {$endHour += 2}
    	$startHour = $cons + $startHour
    	$endHour = $cons + $endHour
    	$temp += $startHour
    	$temp += $endHour
    	}
    }
    
    $availability = @(10..297)
    for ($i = 0; $i -lt $temp.Length; $i += 2) {
        for ($j = $temp[$i]; $j -le $temp[$i + 1]; $j++) {
            $availability[$j] = $true
            }
        }
    
    $hex_av = @()
    for ($i = 0; $i -lt $availability.Length; $i += 4) {
        if (($availability[$i] -eq $true ) -and ($availability[$i+1] -eq $true) -and ($availability[$i+2] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "0"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+1] -eq $true) -and ($availability[$i+2] -eq $true)) {
            $hex_av += "1"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+1] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "2"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+1] -eq $true)) {
            $hex_av += "3"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+2] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "4"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+2] -eq $true)) {
            $hex_av += "5"
        }
        elseif (($availability[$i] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "6"
        }
        elseif ($availability[$i] -eq $true) {
            $hex_av += "7"
        }
        elseif (($availability[$i+1] -eq $true) -and ($availability[$i+2] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "8"
        }
        elseif (($availability[$i+1] -eq $true) -and ($availability[$i+2] -eq $true)) {
            $hex_av += "9"
        }
        elseif (($availability[$i+1] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "A"
        }
        elseif ($availability[$i+1] -eq $true) {
            $hex_av += "B"
        }
        elseif (($availability[$i+2] -eq $true) -and ($availability[$i+3] -eq $true)) {
            $hex_av += "C"
        }
        elseif ($availability[$i+2] -eq $true) {
            $hex_av += "D"
        }
        elseif ($availability[$i+3] -eq $true) {
            $hex_av += "E"
        }
        else {
            $hex_av += "F"
        }
    }
    for ($i = 0; $i -lt 12; $i++) {
        $hex_av += "F"
    }
    
    $results = $hex_av -join ''
    
    [xml]$template = Get-Content 5003.xml
    $template.Template.Item.ChildNodes.Item(4).Value = $results
    $template.Save("5003.xml")

    • Marked as answer by Lukas Beran Saturday, April 6, 2013 1:16 PM
    Saturday, April 6, 2013 1:16 PM