Revision eaa4c57c lib/opcodes.py
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