|
8 | 8 | import time
|
9 | 9 |
|
10 | 10 | from fabric import state
|
11 |
| -from fabric.api import (abort, env, get, hide, local, puts, run, runs_once, |
12 |
| - serial, settings, sudo, task, warn) |
| 11 | +from fabric.api import (abort, env, get, hide, hosts, local, puts, run, |
| 12 | + runs_once, serial, settings, sudo, task, warn) |
13 | 13 | from fabric.task_utils import crawl
|
14 | 14 |
|
15 | 15 | # Our command submodules
|
@@ -103,6 +103,15 @@ def fetch(self):
|
103 | 103 |
|
104 | 104 | self.fetched = True
|
105 | 105 |
|
| 106 | + def fetch_puppet_class(self, name): |
| 107 | + # These cannot be prefetched because there's too many variations. |
| 108 | + # But we only need to fetch once for each. |
| 109 | + if self.roledefs['puppet_class-%s' % name]: |
| 110 | + return |
| 111 | + |
| 112 | + hosts = _fetch_hosts('-C %s' % name) |
| 113 | + self.roledefs['puppet_class-%s' % name] = hosts |
| 114 | + |
106 | 115 | def __contains__(self, key):
|
107 | 116 | return True
|
108 | 117 |
|
@@ -235,12 +244,11 @@ def klass(class_name):
|
235 | 244 | env.hosts.extend(env.roledefs['class-%s' % class_name]())
|
236 | 245 |
|
237 | 246 | @task
|
| 247 | +@hosts('localhost') |
238 | 248 | def puppet_class(class_name):
|
239 | 249 | """Select all machines which include a given puppet class"""
|
240 |
| - hosts = _fetch_hosts('-C %s' % class_name) |
241 |
| - if (hosts == []): |
242 |
| - abort("Didn't find any hosts with class %s" % class_name) |
243 |
| - env.hosts.extend(sorted(hosts)) |
| 250 | + env.roledefs.fetch_puppet_class(class_name) |
| 251 | + env.hosts.extend(env.roledefs['puppet_class-%s' % class_name]()) |
244 | 252 |
|
245 | 253 | @task
|
246 | 254 | def vdc(vdc_name):
|
|
0 commit comments