Skip to content

Commit 5859a7a

Browse files
authored
Merge pull request #12 from ComputationalScienceLab/rest-python3-client
Port Python REST client to Python 3
2 parents a631c7e + 75981da commit 5859a7a

File tree

2 files changed

+444
-0
lines changed

2 files changed

+444
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# ---------------------------------- #
2+
# Windows HPC Pack 2016 - Submit Job #
3+
# ---------------------------------- #
4+
5+
# by:
6+
# Thomas Hilbig, FH-Bielefeld, thomas.hilbig@fh-bielefeld.de
7+
# Simon Bekemeier, FH-Bielefeld, simon.bekemeier@fh-bielefeld.de
8+
9+
# works with
10+
# - Microsoft HPC Pack 2016 RTM / Update 1 / Update 2 / Update 3 and Microsoft HPC Pack 2019 Preview
11+
# - Python 3.7 and above
12+
13+
import time
14+
import sys
15+
import base64
16+
import ssl
17+
import winhpclib_3x
18+
import getpass
19+
20+
# ------------------------------------------------- #
21+
# put in your HPC Job settings in the fields below: #
22+
# ------------------------------------------------- #
23+
24+
# HPC cluster FQDN
25+
MyHeadNodeName = 'myheadnode'
26+
27+
# Job Details (for more properties see HPC Web Service API at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/hh560265(v=vs.85)#remarks)
28+
# -----------
29+
# Job Name:
30+
JobName = "[MyHPC Job]"
31+
# JobTemplate: Default
32+
JobTemplate = "Default"
33+
# Project:
34+
Project = "[MyHPC Project]"
35+
# Priority: Lowest, BelowNormal, Normal
36+
Priority = "Normal"
37+
# Send email notifications to:
38+
EmailAddress = "[name@domain.com]"
39+
## Job resources
40+
# Select the type of resource to request for this job: Core, Node, Socket, GPU
41+
UnitType = "Core"
42+
43+
# Specify tasks for this job:
44+
# ---------------------------
45+
# Tasks (for more properties see HPC Web Service API at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/hh560262(v=vs.85)#remarks)
46+
# Task name:
47+
TaskName = "[MyHPC Task]"
48+
# Command line: ex. "mpiexec MyProgram.exe <param1> <param2>"
49+
CommandLine = "[YourCommandLine]"
50+
# Working directory:
51+
WorkingDirectory = "\\\myheadnode\\[HPC-Share]\\[username / subfolder / etc.]"
52+
# Standard output (relative path to working directory):
53+
StdOutFile = "%CCP_JOBID%_%CCP_TASKID%_out.txt"
54+
# Standard error (relative path to working directory):
55+
StdErrFile = "%CCP_JOBID%_%CCP_TASKID%_err.txt"
56+
# Specify the minimum and maximum number of resources to use for this task.
57+
# Minimum:
58+
MinCores = 1
59+
# Maximum:
60+
MaxCores = 1
61+
62+
# -------------------- #
63+
# end HPC Job settings #
64+
# -------------------- #
65+
66+
# input interactive username & password
67+
print ('input your username and password interactively ...')
68+
username = input('User: ')
69+
password = getpass.getpass('Password:')
70+
71+
try:
72+
# Configure server connection information
73+
server = winhpclib_3x.Server(MyHeadNodeName, username, password)
74+
75+
# Create job
76+
job = winhpclib_3x.Job(server)
77+
78+
# Job Details (for more properties see HPC Web Service API at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/hh560265(v=vs.85)#remarks)
79+
# -----------
80+
# Job Name:
81+
job.properties["Name"] = JobName
82+
# JobTemplate:
83+
job.properties["JobTemplate"] = JobTemplate
84+
# Project:
85+
job.properties["Project"] = Project
86+
# Priority:
87+
job.properties["Priority"] = Priority
88+
# Send email notifications to:
89+
job.properties["EmailAddress"] = EmailAddress
90+
91+
## Job resources
92+
# Select the type of resource to request for this job:
93+
job.properties["UnitType"] = UnitType
94+
# Enter the minimum and/or maximum of the selected resource type that this job is allowed to use:
95+
# Minimum:
96+
#job.properties[""] = ""
97+
# Maximum:
98+
#job.properties[""] = ""
99+
100+
# Instantiate job on the server
101+
print ('Creating job on the server...')
102+
job.create()
103+
104+
# Create task
105+
task = job.create_task()
106+
107+
# Specify tasks for this job:
108+
# ---------------------------
109+
# Tasks (for more properties see HPC Web Service API at https://docs.microsoft.com/en-us/previous-versions/windows/desktop/hh560262(v=vs.85)#remarks)
110+
# Task name:
111+
task.properties["Name"] = TaskName
112+
# Command line:
113+
task.properties["Commandline"] = CommandLine
114+
# Working directory:
115+
task.properties["WorkDirectory"] = WorkingDirectory
116+
# Standard output (relative path to working directory):
117+
task.properties["StdOutFilePath"] = StdOutFile
118+
# Standard error (relative path to working directory):
119+
task.properties["StdErrFilePath"] = StdErrFile
120+
# Specify the minimum and maximum number of resources to use for this task.
121+
# Minimum:
122+
task.properties["MinCores"] = MinCores
123+
# Maximum:
124+
task.properties["MaxCores"] = MaxCores
125+
126+
# Instantiate task on the server
127+
print ('Creating task within the job on the server...')
128+
task.create()
129+
130+
# Submit job
131+
print ('Submitting job...')
132+
job.submit(username, password)
133+
134+
# Catch exception
135+
except winhpclib_3x.Error as error:
136+
print ('Server returned an error:', error)

0 commit comments

Comments
 (0)