66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
import paramiko
|
|
|
|
manifest = """
|
|
apiVersion: longhorn.io/v1beta2
|
|
kind: RecurringJob
|
|
metadata:
|
|
name: snapshot-4h
|
|
namespace: longhorn-system
|
|
spec:
|
|
name: snapshot-4h
|
|
task: snapshot
|
|
cron: "0 */4 * * *"
|
|
retain: 6
|
|
concurrency: 2
|
|
groups:
|
|
- default
|
|
---
|
|
apiVersion: longhorn.io/v1beta2
|
|
kind: RecurringJob
|
|
metadata:
|
|
name: snapshot-daily
|
|
namespace: longhorn-system
|
|
spec:
|
|
name: snapshot-daily
|
|
task: snapshot
|
|
cron: "0 2 * * *"
|
|
retain: 7
|
|
concurrency: 2
|
|
groups:
|
|
- default
|
|
---
|
|
apiVersion: longhorn.io/v1beta2
|
|
kind: RecurringJob
|
|
metadata:
|
|
name: backup-daily-nas
|
|
namespace: longhorn-system
|
|
spec:
|
|
name: backup-daily-nas
|
|
task: backup
|
|
cron: "0 3 * * *"
|
|
retain: 14
|
|
concurrency: 2
|
|
groups:
|
|
- default
|
|
"""
|
|
|
|
clusters = [
|
|
("aerodrome", "140.44.4.11"),
|
|
("spaceport", "140.44.4.41")
|
|
]
|
|
|
|
for name, host in clusters:
|
|
print(f"=== Applying RecurringJobs on {name} ({host}) ===")
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(host, username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
stdin, stdout, stderr = ssh.exec_command('cat << \'EOF\' | kubectl apply -f -\n' + manifest + '\nEOF')
|
|
print("APPLY STDOUT:", stdout.read().decode())
|
|
print("APPLY STDERR:", stderr.read().decode())
|
|
|
|
stdin, stdout, stderr = ssh.exec_command('kubectl get recurringjobs.longhorn.io -n longhorn-system')
|
|
print("CURRENT JOBS:\n", stdout.read().decode())
|
|
ssh.close()
|
|
|