Skip to content
Permalink
Browse files

send keys in parallel

  • Loading branch information
domenkozar committed Mar 26, 2020
1 parent f2804bc commit e40d3e33901369d6fe1f18f79ea8be1c7425d003
Showing with 26 additions and 2 deletions.
  1. +26 −2 nixops/backends/__init__.py
@@ -4,7 +4,9 @@
import re
import subprocess
from typing import Dict, Any, List, Optional, Union, Set
import types
import nixops.util
import nixops.parallel
import nixops.resources
import nixops.ssh_util
import xml.etree.ElementTree as ET
@@ -273,12 +275,20 @@ def send_keys(self) -> None:
return
if self.store_keys_on_machine:
return
for k, opts in self.get_keys().items():

def worker(task: nixops.parallel.Task) -> None:
k = task.key
opts = task.opts
self.log("uploading key ‘{0}’...".format(k))
tmp = self.depl.tempdir + "/key-" + self.name

if "destDir" not in opts:
raise Exception("Key '{}' has no 'destDir' specified.".format(k))

tmp = "{dir}/key-{name}-{key}".format(
dir=self.depl.tempdir,
name=self.name,
key=k,
)
destDir = opts["destDir"].rstrip("/")
self.run_command(
(
@@ -329,6 +339,20 @@ def send_keys(self) -> None:
)
self.run_command("mv " + tmp_outfile_esc + " " + outfile_esc)
os.remove(tmp)

def task(key: str, opts: Dict[str, Any]) -> nixops.parallel.Task:
task = types.SimpleNamespace()
task.name = self.name
task.key = key
task.opts = opts
return task

nixops.parallel.run_tasks(
# by default ssh allows 10 sessions per connection via MaxSessions setting
nr_workers=8,
tasks=[task(key, item) for (key, item) in self.get_keys().items()],
worker_fun=worker,
)
self.run_command(
"mkdir -m 0750 -p /run/keys && "
"chown root:keys /run/keys && "

0 comments on commit e40d3e3

Please sign in to comment.
You can’t perform that action at this time.