Revision eaa4c57c
b/lib/bootstrap.py | ||
---|---|---|
603 | 603 |
nodegroups=nodegroups, |
604 | 604 |
nodes=nodes, |
605 | 605 |
instances={}, |
606 |
networks={}, |
|
606 | 607 |
serial_no=1, |
607 | 608 |
ctime=now, mtime=now) |
608 | 609 |
utils.WriteFile(cfg_file, |
b/lib/cmdlib.py | ||
---|---|---|
15301 | 15301 |
result = ial.out_text |
15302 | 15302 |
return result |
15303 | 15303 |
|
15304 |
# Network LUs |
|
15305 |
class LUNetworkAdd(LogicalUnit): |
|
15306 |
def BuildHooksNodes(self): |
|
15307 |
pass |
|
15308 |
|
|
15309 |
def BuildHooksEnv(self): |
|
15310 |
pass |
|
15311 |
|
|
15312 |
|
|
15313 |
class LUNetworkRemove(LogicalUnit): |
|
15314 |
def BuildHooksNodes(self): |
|
15315 |
pass |
|
15316 |
|
|
15317 |
def BuildHooksEnv(self): |
|
15318 |
pass |
|
15319 |
|
|
15320 |
|
|
15321 |
class LUNetworkSetParams(LogicalUnit): |
|
15322 |
def BuildHooksNodes(self): |
|
15323 |
pass |
|
15324 |
|
|
15325 |
def BuildHooksEnv(self): |
|
15326 |
pass |
|
15327 |
|
|
15328 |
|
|
15329 |
class _NetworkQuery(_QueryBase): |
|
15330 |
def ExpandNames(self, lu): |
|
15331 |
pass |
|
15332 |
|
|
15333 |
def DeclareLocks(self, lu, level): |
|
15334 |
pass |
|
15335 |
|
|
15336 |
def _GetQueryData(self, lu): |
|
15337 |
pass |
|
15338 |
|
|
15339 |
|
|
15340 |
class LUNetworkQuery(NoHooksLU): |
|
15341 |
pass |
|
15342 |
|
|
15343 |
|
|
15344 |
class LUNetworkConnect(LogicalUnit): |
|
15345 |
def BuildHooksNodes(self): |
|
15346 |
pass |
|
15347 |
|
|
15348 |
def BuildHooksEnv(self): |
|
15349 |
pass |
|
15350 |
|
|
15351 |
|
|
15352 |
class LUNetworkDisconnect(LogicalUnit): |
|
15353 |
def BuildHooksNodes(self): |
|
15354 |
pass |
|
15355 |
|
|
15356 |
def BuildHooksEnv(self): |
|
15357 |
pass |
|
15358 |
|
|
15304 | 15359 |
|
15305 | 15360 |
#: Query type implementations |
15306 | 15361 |
_QUERY_IMPL = { |
... | ... | |
15308 | 15363 |
constants.QR_INSTANCE: _InstanceQuery, |
15309 | 15364 |
constants.QR_NODE: _NodeQuery, |
15310 | 15365 |
constants.QR_GROUP: _GroupQuery, |
15366 |
constants.QR_NETWORK: _NetworkQuery, |
|
15311 | 15367 |
constants.QR_OS: _OsQuery, |
15312 | 15368 |
constants.QR_EXPORT: _ExportQuery, |
15313 | 15369 |
} |
b/lib/constants.py | ||
---|---|---|
302 | 302 |
HTYPE_NODE = "NODE" |
303 | 303 |
HTYPE_GROUP = "GROUP" |
304 | 304 |
HTYPE_INSTANCE = "INSTANCE" |
305 |
HTYPE_NETWORK = "NETWORK" |
|
305 | 306 |
|
306 | 307 |
HKR_SKIP = 0 |
307 | 308 |
HKR_FAIL = 1 |
... | ... | |
1065 | 1066 |
|
1066 | 1067 |
NIC_MODE_BRIDGED = "bridged" |
1067 | 1068 |
NIC_MODE_ROUTED = "routed" |
1069 |
NIC_IP_POOL = "pool" |
|
1068 | 1070 |
|
1069 | 1071 |
NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED]) |
1070 | 1072 |
|
1073 |
# An extra description of the network. |
|
1074 |
# Can be used by hooks/kvm-vif-bridge to apply different rules |
|
1075 |
NETWORK_TYPE_PRIVATE = "private" |
|
1076 |
NETWORK_TYPE_PUBLIC = "public" |
|
1077 |
|
|
1078 |
NETWORK_VALID_TYPES = frozenset([NETWORK_TYPE_PRIVATE, NETWORK_TYPE_PUBLIC]) |
|
1079 |
|
|
1071 | 1080 |
NICS_PARAMETER_TYPES = { |
1072 | 1081 |
NIC_MODE: VTYPE_STRING, |
1073 | 1082 |
NIC_LINK: VTYPE_STRING, |
... | ... | |
1095 | 1104 |
INIC_IP = "ip" |
1096 | 1105 |
INIC_MODE = "mode" |
1097 | 1106 |
INIC_LINK = "link" |
1107 |
INIC_NETWORK = "network" |
|
1098 | 1108 |
INIC_PARAMS_TYPES = { |
1099 | 1109 |
INIC_IP: VTYPE_MAYBE_STRING, |
1100 | 1110 |
INIC_LINK: VTYPE_STRING, |
1101 | 1111 |
INIC_MAC: VTYPE_STRING, |
1102 | 1112 |
INIC_MODE: VTYPE_STRING, |
1113 |
INIC_NETWORK: VTYPE_MAYBE_STRING, |
|
1103 | 1114 |
} |
1104 | 1115 |
INIC_PARAMS = frozenset(INIC_PARAMS_TYPES.keys()) |
1105 | 1116 |
|
... | ... | |
1603 | 1614 |
QR_OS = "os" |
1604 | 1615 |
QR_JOB = "job" |
1605 | 1616 |
QR_EXPORT = "export" |
1617 |
QR_NETWORK = "network" |
|
1606 | 1618 |
|
1607 | 1619 |
#: List of resources which can be queried using L{opcodes.OpQuery} |
1608 | 1620 |
QR_VIA_OP = frozenset([ |
... | ... | |
1612 | 1624 |
QR_GROUP, |
1613 | 1625 |
QR_OS, |
1614 | 1626 |
QR_EXPORT, |
1627 |
QR_NETWORK, |
|
1615 | 1628 |
]) |
1616 | 1629 |
|
1617 | 1630 |
#: List of resources which can be queried using Local UniX Interface |
... | ... | |
1703 | 1716 |
SS_MAINTAIN_NODE_HEALTH = "maintain_node_health" |
1704 | 1717 |
SS_UID_POOL = "uid_pool" |
1705 | 1718 |
SS_NODEGROUPS = "nodegroups" |
1719 |
SS_NETWORKS = "networks" |
|
1706 | 1720 |
|
1707 | 1721 |
SS_FILE_PERMS = 0444 |
1708 | 1722 |
|
b/lib/objects.py | ||
---|---|---|
51 | 51 |
|
52 | 52 |
|
53 | 53 |
__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance", |
54 |
"OS", "Node", "NodeGroup", "Cluster", "FillDict"] |
|
54 |
"OS", "Node", "NodeGroup", "Cluster", "FillDict", "Network"]
|
|
55 | 55 |
|
56 | 56 |
_TIMESTAMPS = ["ctime", "mtime"] |
57 | 57 |
_UUID = ["uuid"] |
... | ... | |
432 | 432 |
"nodes", |
433 | 433 |
"nodegroups", |
434 | 434 |
"instances", |
435 |
"networks", |
|
435 | 436 |
"serial_no", |
436 | 437 |
] + _TIMESTAMPS |
437 | 438 |
|
... | ... | |
444 | 445 |
""" |
445 | 446 |
mydict = super(ConfigData, self).ToDict() |
446 | 447 |
mydict["cluster"] = mydict["cluster"].ToDict() |
447 |
for key in "nodes", "instances", "nodegroups": |
|
448 |
for key in "nodes", "instances", "nodegroups", "networks":
|
|
448 | 449 |
mydict[key] = self._ContainerToDicts(mydict[key]) |
449 | 450 |
|
450 | 451 |
return mydict |
... | ... | |
459 | 460 |
obj.nodes = cls._ContainerFromDicts(obj.nodes, dict, Node) |
460 | 461 |
obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance) |
461 | 462 |
obj.nodegroups = cls._ContainerFromDicts(obj.nodegroups, dict, NodeGroup) |
463 |
obj.networks = cls._ContainerFromDicts(obj.networks, dict, Network) |
|
462 | 464 |
return obj |
463 | 465 |
|
464 | 466 |
def HasAnyDiskOfType(self, dev_type): |
... | ... | |
495 | 497 |
# gives a good approximation. |
496 | 498 |
if self.HasAnyDiskOfType(constants.LD_DRBD8): |
497 | 499 |
self.cluster.drbd_usermode_helper = constants.DEFAULT_DRBD_HELPER |
500 |
if self.networks is None: |
|
501 |
self.networks = {} |
|
498 | 502 |
|
499 | 503 |
|
500 | 504 |
class NIC(ConfigObject): |
501 | 505 |
"""Config object representing a network card.""" |
502 |
__slots__ = ["mac", "ip", "nicparams"] |
|
506 |
__slots__ = ["mac", "ip", "network", "nicparams"]
|
|
503 | 507 |
|
504 | 508 |
@classmethod |
505 | 509 |
def CheckParameterSyntax(cls, nicparams): |
... | ... | |
1359 | 1363 |
"hv_state_static", |
1360 | 1364 |
"disk_state_static", |
1361 | 1365 |
"alloc_policy", |
1366 |
"networks", |
|
1362 | 1367 |
] + _TIMESTAMPS + _UUID |
1363 | 1368 |
|
1364 | 1369 |
def ToDict(self): |
... | ... | |
1406 | 1411 |
if self.ipolicy is None: |
1407 | 1412 |
self.ipolicy = MakeEmptyIPolicy() |
1408 | 1413 |
|
1414 |
if self.networks is None: |
|
1415 |
self.networks = {} |
|
1416 |
|
|
1409 | 1417 |
def FillND(self, node): |
1410 | 1418 |
"""Return filled out ndparams for L{objects.Node} |
1411 | 1419 |
|
... | ... | |
1989 | 1997 |
return True |
1990 | 1998 |
|
1991 | 1999 |
|
2000 |
class Network(ConfigObject): |
|
2001 |
"""Object representing a network definition for ganeti. |
|
2002 |
|
|
2003 |
""" |
|
2004 |
__slots__ = [ |
|
2005 |
"name", |
|
2006 |
"serial_no", |
|
2007 |
"network_type", |
|
2008 |
"mac_prefix", |
|
2009 |
"family", |
|
2010 |
"network", |
|
2011 |
"network6", |
|
2012 |
"gateway", |
|
2013 |
"gateway6", |
|
2014 |
"size", |
|
2015 |
"reservations", |
|
2016 |
"ext_reservations", |
|
2017 |
] + _TIMESTAMPS + _UUID |
|
2018 |
|
|
2019 |
|
|
1992 | 2020 |
class SerializableConfigParser(ConfigParser.SafeConfigParser): |
1993 | 2021 |
"""Simple wrapper over ConfigParse that allows serialization. |
1994 | 2022 |
|
b/lib/opcodes.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
import logging |
37 | 37 |
import re |
38 |
import ipaddr |
|
38 | 39 |
|
39 | 40 |
from ganeti import constants |
40 | 41 |
from ganeti import errors |
... | ... | |
167 | 168 |
_PAllowRuntimeChgs = ("allow_runtime_changes", True, ht.TBool, |
168 | 169 |
"Allow runtime changes (eg. memory ballooning)") |
169 | 170 |
|
171 |
#: a required network name |
|
172 |
_PNetworkName = ("network_name", ht.NoDefault, ht.TNonEmptyString, |
|
173 |
"Set network name") |
|
170 | 174 |
|
171 | 175 |
#: OP_ID conversion regular expression |
172 | 176 |
_OPID_RE = re.compile("([a-z])([A-Z])") |
... | ... | |
343 | 347 |
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType, |
344 | 348 |
"Storage type") |
345 | 349 |
|
350 |
_CheckNetworkType = ht.TElemOf(constants.NETWORK_VALID_TYPES) |
|
351 |
|
|
352 |
#: Network type parameter |
|
353 |
_PNetworkType = ("network_type", None, ht.TOr(ht.TNone, _CheckNetworkType), |
|
354 |
"Network type") |
|
355 |
|
|
356 |
def _CheckCIDRNetNotation(value): |
|
357 |
"""Ensure a given cidr notation type is valid. |
|
358 |
|
|
359 |
""" |
|
360 |
try: |
|
361 |
ipaddr.IPv4Network(value) |
|
362 |
except ipaddr.AddressValueError: |
|
363 |
return False |
|
364 |
return True |
|
365 |
|
|
366 |
def _CheckCIDRAddrNotation(value): |
|
367 |
"""Ensure a given cidr notation type is valid. |
|
368 |
|
|
369 |
""" |
|
370 |
try: |
|
371 |
ipaddr.IPv4Address(value) |
|
372 |
except ipaddr.AddressValueError: |
|
373 |
return False |
|
374 |
return True |
|
375 |
|
|
376 |
def _CheckCIDR6AddrNotation(value): |
|
377 |
"""Ensure a given cidr notation type is valid. |
|
378 |
|
|
379 |
""" |
|
380 |
try: |
|
381 |
ipaddr.IPv6Address(value) |
|
382 |
except ipaddr.AddressValueError: |
|
383 |
return False |
|
384 |
return True |
|
385 |
|
|
386 |
def _CheckCIDR6NetNotation(value): |
|
387 |
"""Ensure a given cidr notation type is valid. |
|
388 |
|
|
389 |
""" |
|
390 |
try: |
|
391 |
ipaddr.IPv6Network(value) |
|
392 |
except ipaddr.AddressValueError: |
|
393 |
return False |
|
394 |
return True |
|
346 | 395 |
|
347 | 396 |
class _AutoOpParamSlots(objectutils.AutoSlots): |
348 | 397 |
"""Meta class for opcode definitions. |
... | ... | |
1201 | 1250 |
("identify_defaults", False, ht.TBool, |
1202 | 1251 |
"Reset instance parameters to default if equal"), |
1203 | 1252 |
("ip_check", True, ht.TBool, _PIpCheckDoc), |
1253 |
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"), |
|
1204 | 1254 |
("mode", ht.NoDefault, ht.TElemOf(constants.INSTANCE_CREATE_MODES), |
1205 | 1255 |
"Instance creation mode"), |
1206 | 1256 |
("nics", ht.NoDefault, ht.TListOf(_TestNicDef), |
... | ... | |
1594 | 1644 |
("wait_for_sync", True, ht.TBool, |
1595 | 1645 |
"Whether to wait for the disk to synchronize, when changing template"), |
1596 | 1646 |
("offline", None, ht.TMaybeBool, "Whether to mark instance as offline"), |
1647 |
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"), |
|
1597 | 1648 |
] |
1598 | 1649 |
OP_RESULT = _TSetParamsResult |
1599 | 1650 |
|
... | ... | |
1952 | 2003 |
WITH_LU = False |
1953 | 2004 |
|
1954 | 2005 |
|
2006 |
# Network opcodes |
|
2007 |
# Add a new network in the cluster |
|
2008 |
class OpNetworkAdd(OpCode): |
|
2009 |
"""Add an IP network to the cluster.""" |
|
2010 |
OP_DSC_FIELD = "network_name" |
|
2011 |
OP_PARAMS = [ |
|
2012 |
_PNetworkName, |
|
2013 |
_PNetworkType, |
|
2014 |
("network", None, ht.TAnd(ht.TString ,_CheckCIDRNetNotation), None), |
|
2015 |
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None), |
|
2016 |
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None), |
|
2017 |
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None), |
|
2018 |
("mac_prefix", None, ht.TMaybeString, None), |
|
2019 |
("add_reserved_ips", None, |
|
2020 |
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None), |
|
2021 |
] |
|
2022 |
|
|
2023 |
class OpNetworkRemove(OpCode): |
|
2024 |
"""Remove an existing network from the cluster. |
|
2025 |
Must not be connected to any nodegroup. |
|
2026 |
|
|
2027 |
""" |
|
2028 |
OP_DSC_FIELD = "network_name" |
|
2029 |
OP_PARAMS = [ |
|
2030 |
_PNetworkName, |
|
2031 |
_PForce, |
|
2032 |
] |
|
2033 |
|
|
2034 |
class OpNetworkSetParams(OpCode): |
|
2035 |
"""Modify Network's parameters except for IPv4 subnet""" |
|
2036 |
OP_DSC_FIELD = "network_name" |
|
2037 |
OP_PARAMS = [ |
|
2038 |
_PNetworkName, |
|
2039 |
_PNetworkType, |
|
2040 |
("gateway", None, ht.TOr(ht.TNone, _CheckCIDRAddrNotation), None), |
|
2041 |
("network6", None, ht.TOr(ht.TNone, _CheckCIDR6NetNotation), None), |
|
2042 |
("gateway6", None, ht.TOr(ht.TNone, _CheckCIDR6AddrNotation), None), |
|
2043 |
("mac_prefix", None, ht.TMaybeString, None), |
|
2044 |
("add_reserved_ips", None, |
|
2045 |
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None), |
|
2046 |
("remove_reserved_ips", None, |
|
2047 |
ht.TOr(ht.TNone, ht.TListOf(_CheckCIDRAddrNotation)), None), |
|
2048 |
] |
|
2049 |
|
|
2050 |
class OpNetworkConnect(OpCode): |
|
2051 |
"""Connect a Network to a specific Nodegroup with the defined netparams |
|
2052 |
(mode, link). Nics in this Network will inherit those params. |
|
2053 |
Produce errors if a NIC (that its not already assigned to a network) |
|
2054 |
has an IP that is contained in the Network this will produce error unless |
|
2055 |
--no-conflicts-check is passed. |
|
2056 |
|
|
2057 |
""" |
|
2058 |
OP_DSC_FIELD = "network_name" |
|
2059 |
OP_PARAMS = [ |
|
2060 |
_PGroupName, |
|
2061 |
_PNetworkName, |
|
2062 |
("network_mode", None, ht.TString, None), |
|
2063 |
("network_link", None, ht.TString, None), |
|
2064 |
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"), |
|
2065 |
] |
|
2066 |
|
|
2067 |
class OpNetworkDisconnect(OpCode): |
|
2068 |
"""Disconnect a Network from a Nodegroup. Produce errors if NICs are |
|
2069 |
present in the Network unless --no-conficts-check option is passed. |
|
2070 |
|
|
2071 |
""" |
|
2072 |
OP_DSC_FIELD = "network_name" |
|
2073 |
OP_PARAMS = [ |
|
2074 |
_PGroupName, |
|
2075 |
_PNetworkName, |
|
2076 |
("conflicts_check", True, ht.TBool, "Check for conflicting IPs"), |
|
2077 |
] |
|
2078 |
|
|
2079 |
class OpNetworkQuery(OpCode): |
|
2080 |
"""Compute the list of networks.""" |
|
2081 |
OP_PARAMS = [ |
|
2082 |
_POutputFields, |
|
2083 |
("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), |
|
2084 |
"Empty list to query all groups, group names otherwise"), |
|
2085 |
] |
|
2086 |
|
|
2087 |
|
|
1955 | 2088 |
def _GetOpList(): |
1956 | 2089 |
"""Returns list of all defined opcodes. |
1957 | 2090 |
|
Also available in: Unified diff