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