Revision 2bff1928
b/lib/backend.py | ||
---|---|---|
1112 | 1112 |
_Fail("Missing bridges %s", utils.CommaJoin(missing)) |
1113 | 1113 |
|
1114 | 1114 |
|
1115 |
def GetInstanceListForHypervisor(hname, hvparams=None, |
|
1116 |
get_hv_fn=hypervisor.GetHypervisor): |
|
1117 |
"""Provides a list of instances of the given hypervisor. |
|
1118 |
|
|
1119 |
@type hname: string |
|
1120 |
@param hname: name of the hypervisor |
|
1121 |
@type hvparams: dict of strings |
|
1122 |
@param hvparams: hypervisor parameters for the given hypervisor |
|
1123 |
@type get_hv_fn: function |
|
1124 |
@param get_hv_fn: function that returns a hypervisor for the given hypervisor |
|
1125 |
name; optional parameter to increase testability |
|
1126 |
|
|
1127 |
@rtype: list |
|
1128 |
@return: a list of all running instances on the current node |
|
1129 |
- instance1.example.com |
|
1130 |
- instance2.example.com |
|
1131 |
|
|
1132 |
""" |
|
1133 |
results = [] |
|
1134 |
try: |
|
1135 |
hv = get_hv_fn(hname) |
|
1136 |
names = hv.ListInstances(hvparams) |
|
1137 |
results.extend(names) |
|
1138 |
except errors.HypervisorError, err: |
|
1139 |
_Fail("Error enumerating instances (hypervisor %s): %s", |
|
1140 |
hname, err, exc=True) |
|
1141 |
return results |
|
1142 |
|
|
1143 |
|
|
1115 | 1144 |
def GetInstanceList(hypervisor_list, all_hvparams=None, |
1116 | 1145 |
get_hv_fn=hypervisor.GetHypervisor): |
1117 | 1146 |
"""Provides a list of instances. |
... | ... | |
1133 | 1162 |
""" |
1134 | 1163 |
results = [] |
1135 | 1164 |
for hname in hypervisor_list: |
1136 |
try: |
|
1137 |
hvparams = None |
|
1138 |
if all_hvparams is not None: |
|
1139 |
hvparams = all_hvparams[hname] |
|
1140 |
hv = get_hv_fn(hname) |
|
1141 |
names = hv.ListInstances(hvparams) |
|
1142 |
results.extend(names) |
|
1143 |
except errors.HypervisorError, err: |
|
1144 |
_Fail("Error enumerating instances (hypervisor %s): %s", |
|
1145 |
hname, err, exc=True) |
|
1146 |
|
|
1165 |
hvparams = None |
|
1166 |
if all_hvparams is not None: |
|
1167 |
hvparams = all_hvparams[hname] |
|
1168 |
results.extend(GetInstanceListForHypervisor(hname, hvparams, |
|
1169 |
get_hv_fn=get_hv_fn)) |
|
1147 | 1170 |
return results |
1148 | 1171 |
|
1149 | 1172 |
|
Also available in: Unified diff