Revision 34a51ae9 lib/config.py
b/lib/config.py | ||
---|---|---|
50 | 50 |
from ganeti import uidpool |
51 | 51 |
from ganeti import netutils |
52 | 52 |
from ganeti import runtime |
53 |
from ganeti import network |
|
53 | 54 |
|
54 | 55 |
|
55 | 56 |
_config_lock = locking.SharedLock("ConfigWriter") |
... | ... | |
2093 | 2094 |
nodegroups = ["%s %s" % (nodegroup.uuid, nodegroup.name) for nodegroup in |
2094 | 2095 |
self._config_data.nodegroups.values()] |
2095 | 2096 |
nodegroups_data = fn(utils.NiceSort(nodegroups)) |
2097 |
networks = ["%s %s" % (net.uuid, net.name) for net in |
|
2098 |
self._config_data.networks.values()] |
|
2099 |
networks_data = fn(utils.NiceSort(networks)) |
|
2096 | 2100 |
|
2097 | 2101 |
ssconf_values = { |
2098 | 2102 |
constants.SS_CLUSTER_NAME: cluster.cluster_name, |
... | ... | |
2117 | 2121 |
constants.SS_MAINTAIN_NODE_HEALTH: str(cluster.maintain_node_health), |
2118 | 2122 |
constants.SS_UID_POOL: uid_pool, |
2119 | 2123 |
constants.SS_NODEGROUPS: nodegroups_data, |
2124 |
constants.SS_NETWORKS: networks_data, |
|
2120 | 2125 |
} |
2121 | 2126 |
bad_values = [(k, v) for k, v in ssconf_values.items() |
2122 | 2127 |
if not isinstance(v, (str, basestring))] |
... | ... | |
2244 | 2249 |
""" |
2245 | 2250 |
for rm in self._all_rms: |
2246 | 2251 |
rm.DropECReservations(ec_id) |
2252 |
|
|
2253 |
@locking.ssynchronized(_config_lock) |
|
2254 |
def AddNetwork(self, net, ec_id): |
|
2255 |
"""Add a network to the configuration. |
|
2256 |
|
|
2257 |
@type net: L{objects.Network} |
|
2258 |
@param net: the Network object to add |
|
2259 |
@type ec_id: string |
|
2260 |
@param ec_id: unique id for the job to use when creating a missing UUID |
|
2261 |
|
|
2262 |
""" |
|
2263 |
self._UnlockedAddNetwork(net, ec_id) |
|
2264 |
self._WriteConfig() |
|
2265 |
|
|
2266 |
def _UnlockedAddNetwork(self, net, ec_id): |
|
2267 |
"""Add a network to the configuration. |
|
2268 |
|
|
2269 |
""" |
|
2270 |
logging.info("Adding network %s to configuration", net.name) |
|
2271 |
|
|
2272 |
self._EnsureUUID(net, ec_id) |
|
2273 |
|
|
2274 |
existing_uuid = self._UnlockedLookupNetwork(net.name) |
|
2275 |
if existing_uuid: |
|
2276 |
raise errors.OpPrereqError("Desired network name '%s' already" |
|
2277 |
" exists as a network (UUID: %s)" % |
|
2278 |
(net.name, existing_uuid), |
|
2279 |
errors.ECODE_EXISTS) |
|
2280 |
net.serial_no = 1 |
|
2281 |
self._config_data.networks[net.uuid] = net |
|
2282 |
self._config_data.cluster.serial_no += 1 |
|
2283 |
|
|
2284 |
def _UnlockedLookupNetwork(self, target): |
|
2285 |
"""Lookup a network's UUID. |
|
2286 |
|
|
2287 |
@type target: string |
|
2288 |
@param target: network name or UUID |
|
2289 |
@rtype: string |
|
2290 |
@return: network UUID |
|
2291 |
@raises errors.OpPrereqError: when the target network cannot be found |
|
2292 |
|
|
2293 |
""" |
|
2294 |
if target in self._config_data.networks: |
|
2295 |
return target |
|
2296 |
for net in self._config_data.networks.values(): |
|
2297 |
if net.name == target: |
|
2298 |
return net.uuid |
|
2299 |
return None |
|
2300 |
|
|
2301 |
@locking.ssynchronized(_config_lock, shared=1) |
|
2302 |
def LookupNetwork(self, target): |
|
2303 |
"""Lookup a network's UUID. |
|
2304 |
|
|
2305 |
This function is just a wrapper over L{_UnlockedLookupNetwork}. |
|
2306 |
|
|
2307 |
@type target: string |
|
2308 |
@param target: network name or UUID |
|
2309 |
@rtype: string |
|
2310 |
@return: network UUID |
|
2311 |
|
|
2312 |
""" |
|
2313 |
return self._UnlockedLookupNetwork(target) |
|
2314 |
|
|
2315 |
@locking.ssynchronized(_config_lock) |
|
2316 |
def RemoveNetwork(self, network_uuid): |
|
2317 |
"""Remove a network from the configuration. |
|
2318 |
|
|
2319 |
@type network_uuid: string |
|
2320 |
@param network_uuid: the UUID of the network to remove |
|
2321 |
|
|
2322 |
""" |
|
2323 |
logging.info("Removing network %s from configuration", network_uuid) |
|
2324 |
|
|
2325 |
if network_uuid not in self._config_data.networks: |
|
2326 |
raise errors.ConfigurationError("Unknown network '%s'" % network_uuid) |
|
2327 |
|
|
2328 |
del self._config_data.networks[network_uuid] |
|
2329 |
self._config_data.cluster.serial_no += 1 |
|
2330 |
self._WriteConfig() |
Also available in: Unified diff