Add `State.limit` context manager to limit bits of a deploy to certain hosts.
from __future__ import division, unicode_literals
+from contextlib import contextmanager
from uuid import uuid4
import six
@@ -16,7 +17,7 @@ from pyinfra import __version__, logger
from .config import Config
from .exceptions import PyinfraError
from .pipelining import PipelineFacts
-from .util import sha1_hash
+from .util import ensure_hosts_list, sha1_hash
# Work out the max parallel we can achieve with the open files limit of the user/process,
# take 10 for opening Python files and /3 for ~3 files per host during op runs.
@@ -170,6 +171,14 @@ class State(object):
# Pipeline facts context manager attached to self
self.pipeline_facts = PipelineFacts(self)
+ @contextmanager
+ def limit(self, hosts):
+ hosts = ensure_hosts_list(hosts)
+
+ self.limit_hosts = hosts
+ yield
+ self.limit_hosts = None
+
def ready_host(self, host):
'''
Flag a host as ready, after which facts will not be gathered for it.
