From e1494c968926c5af237c0403ef4442b6440f517d Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 21 Nov 2012 18:03:13 +0100 Subject: [PATCH] Fix network opcode parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 32e3d8b1 (βopcodes: Network parameter improvements and fixesβ) changed a few parameters in the network add, connect and set params opcodes, but some of the changes are buggy. The patch changed the type to TMaybe(), whereas the default should have been changed from None to NoDefault - the network, mode and link are required. It also wrongly unified all types as _CheckCIDRNetNotation, whereas some are AddrNotation. The patch fixes these (correctly, I hope) and also add some new aliases for readability. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/opcodes.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/opcodes.py b/lib/opcodes.py index f1960fe85..6c31f5531 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -397,8 +397,11 @@ def _CheckCIDR6NetNotation(value): return True -_TIpAddress = ht.TOr(ht.TNone, ht.TAnd(ht.TString, _CheckCIDRNetNotation)) -_TIpAddress6 = ht.TOr(ht.TNone, ht.TAnd(ht.TString, _CheckCIDR6NetNotation)) +_TIpAddress4 = ht.TAnd(ht.TString, _CheckCIDRAddrNotation) +_TIpAddress6 = ht.TAnd(ht.TString, _CheckCIDR6AddrNotation) +_TIpNetwork4 = ht.TAnd(ht.TString, _CheckCIDRNetNotation) +_TIpNetwork6 = ht.TAnd(ht.TString, _CheckCIDR6NetNotation) +_TMaybeAddr4List = ht.TMaybe(ht.TListOf(_TIpAddress4)) class _AutoOpParamSlots(objectutils.AutoSlots): @@ -2018,14 +2021,13 @@ class OpNetworkAdd(OpCode): OP_PARAMS = [ _PNetworkName, _PNetworkType, - ("network", None, _TIpAddress, "IPv4 subnet"), - ("gateway", None, _TIpAddress, "IPv4 gateway"), - ("network6", None, _TIpAddress6, "IPv6 subnet"), - ("gateway6", None, _TIpAddress6, "IPv6 gateway"), + ("network", ht.NoDefault, _TIpNetwork4, "IPv4 subnet"), + ("gateway", None, ht.TMaybe(_TIpAddress4), "IPv4 gateway"), + ("network6", None, ht.TMaybe(_TIpNetwork6), "IPv6 subnet"), + ("gateway6", None, ht.TMaybe(_TIpAddress6), "IPv6 gateway"), ("mac_prefix", None, ht.TMaybeString, "MAC address prefix that overrides cluster one"), - ("add_reserved_ips", None, - ht.TMaybe(ht.TListOf(_CheckCIDRAddrNotation)), + ("add_reserved_ips", None, _TMaybeAddr4List, "Which IP addresses to reserve"), ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Network tags"), ] @@ -2051,16 +2053,14 @@ class OpNetworkSetParams(OpCode): OP_PARAMS = [ _PNetworkName, _PNetworkType, - ("gateway", None, _TIpAddress, "IPv4 gateway"), - ("network6", None, _TIpAddress6, "IPv6 subnet"), - ("gateway6", None, _TIpAddress6, "IPv6 gateway"), + ("gateway", None, ht.TMaybe(_TIpAddress4), "IPv4 gateway"), + ("network6", None, ht.TMaybe(_TIpNetwork6), "IPv6 subnet"), + ("gateway6", None, ht.TMaybe(_TIpAddress6), "IPv6 gateway"), ("mac_prefix", None, ht.TMaybeString, "MAC address prefix that overrides cluster one"), - ("add_reserved_ips", None, - ht.TMaybe(ht.TListOf(_CheckCIDRAddrNotation)), + ("add_reserved_ips", None, _TMaybeAddr4List, "Which external IP addresses to reserve"), - ("remove_reserved_ips", None, - ht.TMaybe(ht.TListOf(_CheckCIDRAddrNotation)), + ("remove_reserved_ips", None, _TMaybeAddr4List, "Which external IP addresses to release"), ] OP_RESULT = ht.TNone @@ -2078,8 +2078,8 @@ class OpNetworkConnect(OpCode): OP_PARAMS = [ _PGroupName, _PNetworkName, - ("network_mode", None, ht.TMaybeString, "Connectivity mode"), - ("network_link", None, ht.TMaybeString, "Connectivity link"), + ("network_mode", ht.NoDefault, ht.TString, "Connectivity mode"), + ("network_link", ht.NoDefault, ht.TString, "Connectivity link"), ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"), ] OP_RESULT = ht.TNone -- GitLab