+# Network opcodes
+# Add a new network in the cluster
+class OpNetworkAdd(OpCode):
+ """Add an IP network to the cluster."""
+ OP_DSC_FIELD = "network_name"
+ OP_PARAMS = [
+ _PNetworkName,
+ ("network_type", None, ht.TMaybe(_CheckNetworkType), "Network type"),
+ ("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, _TMaybeAddr4List,
+ "Which IP addresses to reserve"),
+ ("conflicts_check", True, ht.TBool,
+ "Whether to check for conflicting IP addresses"),
+ ("tags", ht.EmptyList, ht.TListOf(ht.TNonEmptyString), "Network tags"),
+ ]
+ OP_RESULT = ht.TNone
+
+
+class OpNetworkRemove(OpCode):
+ """Remove an existing network from the cluster.
+ Must not be connected to any nodegroup.
+
+ """
+ OP_DSC_FIELD = "network_name"
+ OP_PARAMS = [
+ _PNetworkName,
+ _PForce,
+ ]
+ OP_RESULT = ht.TNone
+
+
+class OpNetworkSetParams(OpCode):
+ """Modify Network's parameters except for IPv4 subnet"""
+ OP_DSC_FIELD = "network_name"
+ OP_PARAMS = [
+ _PNetworkName,
+ ("network_type", None, ht.TMaybeValueNone(_CheckNetworkType),
+ "Network type"),
+ ("gateway", None, ht.TMaybeValueNone(_TIpAddress4), "IPv4 gateway"),
+ ("network6", None, ht.TMaybeValueNone(_TIpNetwork6), "IPv6 subnet"),
+ ("gateway6", None, ht.TMaybeValueNone(_TIpAddress6), "IPv6 gateway"),
+ ("mac_prefix", None, ht.TMaybeValueNone(ht.TString),
+ "MAC address prefix that overrides cluster one"),
+ ("add_reserved_ips", None, _TMaybeAddr4List,
+ "Which external IP addresses to reserve"),
+ ("remove_reserved_ips", None, _TMaybeAddr4List,
+ "Which external IP addresses to release"),
+ ]
+ OP_RESULT = ht.TNone
+
+
+class OpNetworkConnect(OpCode):
+ """Connect a Network to a specific Nodegroup with the defined netparams
+ (mode, link). Nics in this Network will inherit those params.
+ Produce errors if a NIC (that its not already assigned to a network)
+ has an IP that is contained in the Network this will produce error unless
+ --no-conflicts-check is passed.
+
+ """
+ OP_DSC_FIELD = "network_name"
+ OP_PARAMS = [
+ _PGroupName,
+ _PNetworkName,
+ ("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
+
+
+class OpNetworkDisconnect(OpCode):
+ """Disconnect a Network from a Nodegroup. Produce errors if NICs are
+ present in the Network unless --no-conficts-check option is passed.
+
+ """
+ OP_DSC_FIELD = "network_name"
+ OP_PARAMS = [
+ _PGroupName,
+ _PNetworkName,
+ ("conflicts_check", True, ht.TBool, "Whether to check for conflicting IPs"),
+ ]
+ OP_RESULT = ht.TNone
+
+
+class OpNetworkQuery(OpCode):
+ """Compute the list of networks."""
+ OP_PARAMS = [
+ _POutputFields,
+ ("names", ht.EmptyList, ht.TListOf(ht.TNonEmptyString),
+ "Empty list to query all groups, group names otherwise"),
+ ]
+ OP_RESULT = _TOldQueryResult
+
+