Revision 81c60832 kamaki/clients/cyclades/__init__.py
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
72 | 72 |
name, flavor_id, image_id, |
73 | 73 |
metadata=metadata, personality=personality) |
74 | 74 |
|
75 |
def _async_run(self, method, kwarg_list): |
|
76 |
"""Fire threads of operations |
|
77 |
|
|
78 |
:param method: the method to run in each thread |
|
79 |
|
|
80 |
:param kwarg_list: (list of dicts) the arguments to pass in each method |
|
81 |
call |
|
82 |
""" |
|
83 |
flying = [] |
|
84 |
self._init_thread_limit() |
|
85 |
for kwargs in kwarg_list: |
|
86 |
self._watch_thread_limit(flying) |
|
87 |
flying.append(SilentEvent(method=method, **kwargs)) |
|
88 |
flying[-1].start() |
|
89 |
unfinished = [] |
|
90 |
for thread in flying: |
|
91 |
if thread.isAlive(): |
|
92 |
unfinished.append(thread) |
|
93 |
elif thread.exception: |
|
94 |
raise thread.exception |
|
95 |
flying = unfinished |
|
96 |
sendlog.info('- - - wait for threads to finish') |
|
97 |
for thread in flying: |
|
98 |
if thread.isAlive(): |
|
99 |
thread.join() |
|
100 |
elif thread.exception: |
|
101 |
raise thread.exception |
|
102 |
|
|
103 |
def create_cluster(self, servers): |
|
104 |
"""Create multiple servers asynchronously |
|
105 |
:param servers: (list of dicts) [ |
|
106 |
{name, flavor_id, image_id, metadata, personality}, ...] |
|
107 |
""" |
|
108 |
# Perform async server creations |
|
109 |
return self._async_run(self.create_server, servers) |
|
110 |
|
|
111 |
def delete_cluster(self, server_ids): |
|
112 |
""" |
|
113 |
:param server_ids: (list) ids of servers to delete |
|
114 |
""" |
|
115 |
self._async_run( |
|
116 |
self.delete_server, [dict(server_id=sid) for sid in server_ids]) |
|
117 |
|
|
118 | 75 |
def start_server(self, server_id): |
119 | 76 |
"""Submit a startup request |
120 | 77 |
|
Also available in: Unified diff