Skip to content

Commit

Permalink
added constants.py, fixed a bug with the submission to the UniRZ, cha…
Browse files Browse the repository at this point in the history
…nged username/password to optional params
  • Loading branch information
pyrokar1993 committed Dec 12, 2022
1 parent 511f550 commit a1f9039
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 51 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ coverage
*.njsproj
*.sln
*.sw?

api/constants.py
31 changes: 14 additions & 17 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def upload_file(request: Request, datafiles: List[UploadFile] = File(...),


@app.post("/uploadFileJson")
async def upload_file(request: Request, datafiles: List[UploadFile] = File(...), docker: str = Form(...), username: str = Form(...), password: str = Form(...)):
async def upload_file(request: Request, datafiles: List[UploadFile] = File(...), docker: str = Form(...), username: str = Form(default=None), password: str = Form(default=None)):
filelist = []

for datafile in datafiles:
Expand Down Expand Up @@ -82,13 +82,11 @@ def run_simulation(request: Request, input=None, ftype=None, parentfolder="work"
while os.path.exists(os.path.join(workdir, name_job)):
name_job = generate_random_folder()

if ftype == "fileJson":
if ftype == "fileJson" or ftype == "Json":
name_configfile = "config.json"
elif ftype == "fileBin":
name_configfile = "config.bin"
elif ftype == "Json":
name_configfile = "config.json"


if container:
simulate_docker(parentfolder, name_configfile, name_job, ftype, datafile)
else:
Expand All @@ -100,21 +98,20 @@ def run_simulation(request: Request, input=None, ftype=None, parentfolder="work"
startscript += "bsub -q 'BatchXL' -J '" + name_job + "' batchscript.csh\n"
startscript += "cd ..\n"

client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect(FTP_SERVER, 22, "alubojanski", "%.30fpgM") #username, passwd)
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect(FTP_SERVER, 22, username, passwd)

folderlist.append(name_job)
with client.open_sftp() as sftp:
sftp.chdir("work")

if not container:
with client.open_sftp() as sftp:
sftp.chdir("work")
with sftp.open("startskript.csh", "at") as sftp_file:
sftp_file.write(startscript)
sftp_file.close()
sftp.chmod("startskript.csh", stat.S_IRWXU)
sftp.close()

with sftp.open("startskript.csh", "at") as sftp_file:
sftp_file.write(startscript)
sftp_file.close()
sftp.chmod("startskript.csh", stat.S_IRWXU)
sftp.close()
folderlist.append(name_job)

if not external:
return templates.TemplateResponse("submitted.html", {"request": request, "container_list": folderlist})
Expand Down
4 changes: 4 additions & 0 deletions api/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IMAGE_TAG = "inretensys:0.3-gurobi"
CONTAINER_NAME = "inret-ensys-testcontainer"

FTP_SERVER = "csdata.tu-ilmenau.de"
78 changes: 46 additions & 32 deletions api/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
</head>

<body>
<script type="text/javascript">
function toggle_login_form() {
let item = document.getElementById("loginform");

item.hidden = !item.hidden;
}
</script>

<div class="pagewrapper">
<div class="container">
<!-- header -->
Expand All @@ -25,55 +33,61 @@

<!-- content -->
<div class="accordion" id="accordionExample">
<br />
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
Binärdateien
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne"
aria-expanded="false" aria-controls="collapseOne">
JSON-Dateien
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<form action="/uploadFileBinary" enctype="multipart/form-data" method="post">
<div class="mb-3 row">
<h5>Logindaten Universitätsrechenzentrum</h5>
<div class="col">
<label for="username" class="form-label">Username</label>
<input type="username" class="form-control" name="username" id="username" placeholder="Nutzername">
</div>
<div class="col">
<label for="password" class="form-label">Email address</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
</div>
<form action="/uploadFileJson" enctype="multipart/form-data" method="post">
<h5>Daten des Energiesystems</h5>
<div class="mb-3">
<label for="datafile" class="form-label">Konfigurationsdatei</label>
<input class="form-control" name="datafiles" type="file" id="datafile" multiple="multiple"><br />
<h5>Ausführungsmethode</h5>
<div class="form-check">
<label class="form-check-label" for="docker">Run with Docker</label>
<input class="form-check-input" type="radio" name="docker" id="docker" value="docker">
</div>
<div class="form-check">
<label class="form-check-label" for="ssh">Run with SSH</label>
<input class="form-check-input" type="radio" name="docker" id="ssh" value="ssh" checked>
<div onchange=toggle_login_form()>
<h5>Ausführungsmethode</h5>
<div class="form-check">
<label class="form-check-label" for="docker">Run with Docker</label>
<input class="form-check-input" type="radio" name="docker" id="docker" value="docker" checked>
</div>
<div class="form-check">
<label class="form-check-label" for="ssh">Run with SSH</label>
<input class="form-check-input" type="radio" name="docker" id="ssh" value="ssh">
</div><br />
<div class="mb-3 row" id="loginform" hidden>
<h5>Logindaten Universitätsrechenzentrum</h5>
<div class="col">
<label for="username" class="form-label">Username</label>
<input type="username" class="form-control" name="username" id="username" placeholder="Nutzername">
</div>
<div class="col">
<label for="password" class="form-label">Email address</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
</div>
</div><br />
<button class="btn btn-outline-success form-control" type="submit">Run Simulation</button>
</div>
</form>
</form>
</div>
</div>
</div>
<div class="accordion-item">
<div class="accordion-item" hidden>
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
JSON-Dateien
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">
Binärdateien
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo"
data-bs-parent="#accordionExample">
<div class="accordion-body">
<form action="/uploadFileJson" enctype="multipart/form-data" method="post">

<form action="/uploadFileBinary" enctype="multipart/form-data" method="post">
<div class="mb-3 row">
<h5>Logindaten Universitätsrechenzentrum</h5>
<div class="col">
Expand All @@ -92,11 +106,11 @@ <h5>Daten des Energiesystems</h5>
<h5>Ausführungsmethode</h5>
<div class="form-check">
<label class="form-check-label" for="docker">Run with Docker</label>
<input class="form-check-input" type="radio" name="docker" id="docker" value="docker">
<input class="form-check-input" type="radio" name="docker" id="docker" value="docker" checked>
</div>
<div class="form-check">
<label class="form-check-label" for="ssh">Run with SSH</label>
<input class="form-check-input" type="radio" name="docker" id="ssh" value="ssh" checked>
<input class="form-check-input" type="radio" name="docker" id="ssh" value="ssh">
</div><br />
<button class="btn btn-outline-success form-control" type="submit">Run Simulation</button>
</div>
Expand Down

0 comments on commit a1f9039

Please sign in to comment.