@@ -1220,8 +1220,8 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1220
1220
cwd = os .getcwd ()
1221
1221
target = overrides .get ('target' )
1222
1222
if target is not None :
1223
+ tunnel , tunnelhost , tunnelport , tunneluser , vmport = False , None , 22 , 'root' , None
1223
1224
if isinstance (target , str ):
1224
- tunnel , tunnelhost , tunnelport , tunneluser , vmport = False , None , 22 , 'root' , None
1225
1225
user = None
1226
1226
if '@' in target :
1227
1227
if len (target ) != 2 :
@@ -1231,20 +1231,21 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1231
1231
user , target = target .split ('@' )
1232
1232
if '.' not in target and not valid_ip (target ):
1233
1233
credentials = common ._ssh_credentials (self .k , target )
1234
- hostname = credentials [1 ]
1235
1234
user = user or credentials [0 ]
1235
+ ip = credentials [1 ]
1236
+ hostname = ip
1236
1237
else :
1237
1238
hostname , ip = target , target
1238
1239
user = user or 'root'
1239
1240
elif isinstance (target , dict ):
1240
- hostname = target .get ('hostname ' )
1241
- user = target .get ('user ' )
1242
- ip = target .get ('ip' )
1241
+ user = target .get ('user' , 'root ' )
1242
+ hostname = target .get ('hostname' , 'localhost ' )
1243
+ ip = target .get ('ip' , 'localhost' )
1243
1244
vmport = target .get ('vmport' )
1244
- tunnel = self . tunnel
1245
- tunnelhost = self . tunnelhost
1246
- tunnelport = self . tunnelport
1247
- tunneluser = self . tunneluser
1245
+ tunnel = target . get ( ' tunnel' , False )
1246
+ tunnelhost = target . get ( ' tunnelhost' , None )
1247
+ tunnelport = target . get ( ' tunnelport' , 22 )
1248
+ tunneluser = target . get ( ' tunneluser' , 'root' )
1248
1249
requirefile = overrides .get ('requirefile' )
1249
1250
if requirefile is not None :
1250
1251
requirefile = os .path .expanduser (requirefile )
@@ -1261,8 +1262,7 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1261
1262
msg = "No scripts provided"
1262
1263
error (msg )
1263
1264
return {'result' : 'failure' , 'reason' : msg }
1264
- outputdir = os .path .realpath (outputdir or overrides .get ('destdir' ))
1265
- default_destdir = outputdir or '/root'
1265
+ outputdir = os .path .realpath (outputdir or overrides .get ('destdir' , '.' ))
1266
1266
directoryfiles = []
1267
1267
treatedfiles = []
1268
1268
directories = []
@@ -1273,7 +1273,7 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1273
1273
if 'path' in entry :
1274
1274
destdir = os .path .dirname (entry ['path' ])
1275
1275
else :
1276
- destdir = f"{ default_destdir } /{ os .path .dirname (entry ['origin' ])} "
1276
+ destdir = f"{ destdir } /{ os .path .dirname (entry ['origin' ])} "
1277
1277
if not os .path .exists (destdir ):
1278
1278
pprint (f"Creating directory { destdir } " )
1279
1279
os .makedirs (destdir )
@@ -1317,15 +1317,18 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1317
1317
entrydir = os .path .dirname (entry )
1318
1318
entryname = os .path .basename (entry )
1319
1319
rendered = self .process_inputfile (workflow , entry , overrides = overrides )
1320
- destfile = f"{ default_destdir } /{ entrydir } /{ entryname } "
1320
+ destfile = f"{ destdir } /{ entrydir } /{ entryname } "
1321
1321
with open (destfile , 'w' ) as f :
1322
1322
f .write (rendered )
1323
1323
os .chmod (destfile , stat .S_IMODE (os .stat (entry ).st_mode ))
1324
1324
finalscripts = []
1325
1325
tmpdir = None
1326
- if outputdir is None :
1326
+ if 'destdir' in overrides :
1327
+ outputdir = overrides ['destdir' ]
1328
+ elif outputdir is None :
1327
1329
tmpdir = TemporaryDirectory ()
1328
- destdir = outputdir or tmpdir .name
1330
+ outputdir = tmpdir .name
1331
+ outputdir = os .path .realpath (outputdir )
1329
1332
for entry in scripts :
1330
1333
origin = os .path .expanduser (entry )
1331
1334
if not os .path .exists (origin ):
@@ -1334,15 +1337,15 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1334
1337
return {'result' : 'failure' , 'reason' : msg }
1335
1338
elif os .path .isdir (origin ):
1336
1339
origin = entry .get ('origin' )
1337
- if not os .path .exists (f"{ destdir } /{ origin } " ):
1338
- os .makedirs (f"{ destdir } /{ origin } " )
1340
+ if not os .path .exists (f"{ outputdir } /{ origin } " ):
1341
+ os .makedirs (f"{ outputdir } /{ origin } " )
1339
1342
directories .append (origin )
1340
1343
for _fic in os .listdir (origin ):
1341
1344
directoryfiles .append (f'{ origin } /{ _fic } ' )
1342
1345
continue
1343
1346
scriptname = os .path .basename (origin )
1344
1347
rendered = self .process_inputfile (workflow , origin , overrides = overrides )
1345
- destfile = f"{ destdir } /{ scriptname } "
1348
+ destfile = f"{ outputdir } /{ scriptname } "
1346
1349
if 'path' in destfile :
1347
1350
destfile = entry .get ('path' )
1348
1351
if not os .path .exists (os .path .dirname (destfile )):
@@ -1353,16 +1356,16 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1353
1356
finalscripts .append (scriptname )
1354
1357
if cmds :
1355
1358
cmdscontent = '\n ' .join (cmds )
1356
- destfile = f"{ destdir } /cmds.sh"
1359
+ destfile = f"{ outputdir } /cmds.sh"
1357
1360
with open (destfile , 'w' ) as f :
1358
1361
f .write (cmdscontent )
1359
1362
finalscripts .append ('cmds.sh' )
1360
1363
if not run :
1361
1364
pprint ("Not running as dry mode was requested" )
1362
1365
return {'result' : 'success' }
1363
1366
if target is not None :
1364
- remotedir = f"/tmp/{ os .path .basename (destdir )} "
1365
- scpcmd = scp (hostname , ip = ip , user = user , source = destdir , destination = remotedir , download = False ,
1367
+ remotedir = f"/tmp/{ os .path .basename (outputdir )} "
1368
+ scpcmd = scp (hostname , ip = ip , user = user , source = outputdir , destination = remotedir , download = False ,
1366
1369
insecure = True , tunnel = tunnel , tunnelhost = tunnelhost , tunnelport = tunnelport ,
1367
1370
tunneluser = tunneluser , vmport = vmport )
1368
1371
os .system (scpcmd )
@@ -1376,7 +1379,7 @@ def create_workflow(self, workflow, overrides={}, outputdir=None, run=True):
1376
1379
tunnelport = tunnelport , tunneluser = tunneluser , vmport = vmport )
1377
1380
os .system (sshcommand )
1378
1381
else :
1379
- os .chdir (destdir )
1382
+ os .chdir (outputdir )
1380
1383
for script in finalscripts :
1381
1384
os .chmod (script , 0o700 )
1382
1385
pprint (f"Running script { script } locally" )
0 commit comments