Mercurial > repos > enis > gcp_batch_netcat
changeset 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 | cd36336ffaf6 |
files | Dockerfile gcp_batch_netcat.py gcp_batch_netcat.xml test-data/gcp_batch_netcat_out.txt |
diffstat | 4 files changed, 98 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Dockerfile Mon Jul 14 21:12:06 2025 +0000 @@ -0,0 +1,8 @@ +FROM google/cloud-sdk:latest + +RUN apt-get update && apt-get install -y python3 netcat-openbsd + +COPY gcp_batch_netcat.py /usr/bin/ +COPY gcp_batch_netcat.xml /usr/bin/ + +ENTRYPOINT ["python3", "/usr/bin/gcp_batch_netcat.py"]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gcp_batch_netcat.py Mon Jul 14 21:12:06 2025 +0000 @@ -0,0 +1,63 @@ + +import json +import subprocess +import argparse +import uuid + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--nfs_address', required=True) + parser.add_argument('--output', required=True) + parser.add_argument('--project', required=True) + parser.add_argument('--region', required=True) + parser.add_argument('--port', default='2049') + args = parser.parse_args() + + job_name = f'netcat-job-{uuid.uuid4()}' + + job_spec = { + "taskGroups": [ + { + "taskSpec": { + "runnables": [ + { + "script": { + "text": f"nc -z -v {args.nfs_address} {args.port}" + } + } + ] + }, + "taskCount": 1, + "parallelism": 1 + } + ], + "logsPolicy": { + "destination": "CLOUD_LOGGING" + } + } + + job_spec_file = 'job.json' + with open(job_spec_file, 'w') as f: + json.dump(job_spec, f) + + command = [ + 'gcloud', 'batch', 'jobs', 'submit', job_name, + '--location', args.region, + '--project', args.project, + '--config', job_spec_file, + '--format=text' + ] + + try: + result = subprocess.run(command, capture_output=True, text=True, check=True) + with open(args.output, 'w') as f: + f.write("Job output:\n") + f.write(result.stdout) + f.write(result.stderr) + except subprocess.CalledProcessError as e: + with open(args.output, 'w') as f: + f.write("Error submitting job:\n") + f.write(e.stderr) + +if __name__ == '__main__': + main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gcp_batch_netcat.xml Mon Jul 14 21:12:06 2025 +0000 @@ -0,0 +1,26 @@ +<tool id="gcp_batch_netcat" name="GCP Batch Netcat" version="0.1.1"> + <description>Submit a job to GCP Batch and connect to an NFS server.</description> + <requirements> + <requirement type="package" version="438.0.0">google-cloud-sdk</requirement> + <requirement type="package" version="0.7.1">netcat</requirement> + <container type="docker">afgane/gcp-batch-netcat:0.1.0</container> + </requirements> + <command><![CDATA[ +python3 '$__tool_directory__/gcp_batch_netcat.py' --nfs_address '$nfs_address' --output '$output' --project '$project' --region '$region' --port '$port' + ]]></command> +</invoke> + <inputs> + <param name="nfs_address" type="text" label="NFS Server Address" optional="false"/> + <param name="project" type="text" label="GCP Project ID" optional="false"/> + <param name="region" type="text" label="GCP Region" optional="false"/> + <param name="port" type="integer" value="2049" label="Port"/> + </inputs> + <outputs> + <data name="output" format="txt"/> + </outputs> + <help><![CDATA[ +**What it does** + +Submits a job to GCP Batch that connects to the specified NFS server using netcat. + ]]></help> +</tool>