comparison gcp_batch_netcat.py @ 0:7852c0efafd7 draft

planemo upload for repository https://github.com/afgane/gcp_batch_netcat
author enis
date Mon, 14 Jul 2025 21:12:06 +0000
parents
children 79160beab2a4
comparison
equal deleted inserted replaced
-1:000000000000 0:7852c0efafd7
1
2 import json
3 import subprocess
4 import argparse
5 import uuid
6
7 def main():
8 parser = argparse.ArgumentParser()
9 parser.add_argument('--nfs_address', required=True)
10 parser.add_argument('--output', required=True)
11 parser.add_argument('--project', required=True)
12 parser.add_argument('--region', required=True)
13 parser.add_argument('--port', default='2049')
14 args = parser.parse_args()
15
16 job_name = f'netcat-job-{uuid.uuid4()}'
17
18 job_spec = {
19 "taskGroups": [
20 {
21 "taskSpec": {
22 "runnables": [
23 {
24 "script": {
25 "text": f"nc -z -v {args.nfs_address} {args.port}"
26 }
27 }
28 ]
29 },
30 "taskCount": 1,
31 "parallelism": 1
32 }
33 ],
34 "logsPolicy": {
35 "destination": "CLOUD_LOGGING"
36 }
37 }
38
39 job_spec_file = 'job.json'
40 with open(job_spec_file, 'w') as f:
41 json.dump(job_spec, f)
42
43 command = [
44 'gcloud', 'batch', 'jobs', 'submit', job_name,
45 '--location', args.region,
46 '--project', args.project,
47 '--config', job_spec_file,
48 '--format=text'
49 ]
50
51 try:
52 result = subprocess.run(command, capture_output=True, text=True, check=True)
53 with open(args.output, 'w') as f:
54 f.write("Job output:\n")
55 f.write(result.stdout)
56 f.write(result.stderr)
57 except subprocess.CalledProcessError as e:
58 with open(args.output, 'w') as f:
59 f.write("Error submitting job:\n")
60 f.write(e.stderr)
61
62 if __name__ == '__main__':
63 main()