:directory: network-add
:env. vars: NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
- NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
+ NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: master node
:post-execution: master node
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
- NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
+ NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
:post-execution: nodegroup nodes
:env. vars: GROUP_NAME, NETWORK_NAME,
GROUP_NETWORK_MODE, GROUP_NETWORK_LINK,
NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
- NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
+ NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: nodegroup nodes
:post-execution: nodegroup nodes
:directory: network-modify
:env. vars: NETWORK_NAME, NETWORK_SUBNET, NETWORK_GATEWAY, NETWORK_SUBNET6,
- NETWORK_GATEWAY6, NETWORK_TYPE, NETWORK_MAC_PREFIX, NETWORK_TAGS
+ NETWORK_GATEWAY6, NETWORK_MAC_PREFIX, NETWORK_TAGS
:pre-execution: master node
:post-execution: master node
INSTANCE_NICn_NETWORK_UUID, INSTANCE_NICn_NETWORK_SUBNET,
INSTANCE_NICn_NETWORK_GATEWAY, INSTANCE_NICn_NETWORK_SUBNET6,
INSTANCE_NICn_NETWORK_GATEWAY6, INSTANCE_NICn_NETWORK_MAC_PREFIX,
-INSTANCE_NICn_NETWORK_TYPE, INSTANCE_DISK_COUNT, INSTANCE_DISKn_SIZE,
-INSTANCE_DISKn_MODE.
+INSTANCE_DISK_COUNT, INSTANCE_DISKn_SIZE, INSTANCE_DISKn_MODE.
The INSTANCE_NICn_* and INSTANCE_DISKn_* variables represent the
properties of the *n* -th NIC and disk, and are zero-indexed.
'name': 'nat',
'network': '10.0.0.0/28',
'network6': None,
- 'network_type': 'private',
'reserved_count': 3,
'tags': ['nfdhcpd'],
…
"NET_OPT",
"NETWORK_OPT",
"NETWORK6_OPT",
- "NETWORK_TYPE_OPT",
"NEW_CLUSTER_CERT_OPT",
"NEW_CLUSTER_DOMAIN_SECRET_OPT",
"NEW_CONFD_HMAC_KEY_OPT",
help="Comma-delimited list of"
" reserved IPs to remove")
-NETWORK_TYPE_OPT = cli_option("--network-type",
- action="store", default=None, dest="network_type",
- help="Network type: private, public, None")
-
NETWORK6_OPT = cli_option("--network6",
action="store", default=None, dest="network6",
help="IP network in CIDR notation")
#: default list of fields for L{ListNetworks}
_LIST_DEF_FIELDS = ["name", "network", "gateway",
- "network_type", "mac_prefix", "group_list", "tags"]
+ "mac_prefix", "group_list", "tags"]
def _HandleReservedIPs(ips):
gateway6=opts.gateway6,
network6=opts.network6,
mac_prefix=opts.mac_prefix,
- network_type=opts.network_type,
add_reserved_ips=reserved_ips,
conflicts_check=opts.conflicts_check,
tags=tags)
cl = GetClient()
result = cl.QueryNetworks(fields=["name", "network", "gateway",
"network6", "gateway6",
- "mac_prefix", "network_type",
+ "mac_prefix",
"free_count", "reserved_count",
"map", "group_list", "inst_list",
"external_reservations",
names=args, use_locking=False)
for (name, network, gateway, network6, gateway6,
- mac_prefix, network_type, free_count, reserved_count,
+ mac_prefix, free_count, reserved_count,
mapping, group_list, instances, ext_res, serial, uuid) in result:
size = free_count + reserved_count
ToStdout("Network name: %s", name)
ToStdout(" IPv6 Subnet: %s", network6)
ToStdout(" IPv6 Gateway: %s", gateway6)
ToStdout(" Mac Prefix: %s", mac_prefix)
- ToStdout(" Type: %s", network_type)
ToStdout(" Size: %d", size)
ToStdout(" Free: %d (%.2f%%)", free_count,
100 * float(free_count) / float(size))
"add_reserved_ips": _HandleReservedIPs(opts.add_reserved_ips),
"remove_reserved_ips": _HandleReservedIPs(opts.remove_reserved_ips),
"mac_prefix": opts.mac_prefix,
- "network_type": opts.network_type,
"gateway6": opts.gateway6,
"network6": opts.network6,
}
"add": (
AddNetwork, ARGS_ONE_NETWORK,
[DRY_RUN_OPT, NETWORK_OPT, GATEWAY_OPT, ADD_RESERVED_IPS_OPT,
- MAC_PREFIX_OPT, NETWORK_TYPE_OPT, NETWORK6_OPT, GATEWAY6_OPT,
+ MAC_PREFIX_OPT, NETWORK6_OPT, GATEWAY6_OPT,
NOCONFLICTSCHECK_OPT, TAG_ADD_OPT, PRIORITY_OPT, SUBMIT_OPT],
"<network_name>", "Add a new IP network to the cluster"),
"list": (
"modify": (
SetNetworkParams, ARGS_ONE_NETWORK,
[DRY_RUN_OPT, SUBMIT_OPT, ADD_RESERVED_IPS_OPT, REMOVE_RESERVED_IPS_OPT,
- GATEWAY_OPT, MAC_PREFIX_OPT, NETWORK_TYPE_OPT, NETWORK6_OPT, GATEWAY6_OPT,
+ GATEWAY_OPT, MAC_PREFIX_OPT, NETWORK6_OPT, GATEWAY6_OPT,
PRIORITY_OPT],
"<network_name>", "Alters the parameters of a network"),
"connect": (
def _BuildNetworkHookEnv(name, subnet, gateway, network6, gateway6,
- network_type, mac_prefix, tags):
+ mac_prefix, tags):
"""Builds network related env variables for hooks
This builds the hook environment from individual variables.
@param network6: the ipv6 subnet
@type gateway6: string
@param gateway6: the ipv6 gateway
- @type network_type: string
- @param network_type: the type of the network
@type mac_prefix: string
@param mac_prefix: the mac_prefix
@type tags: list
env["NETWORK_GATEWAY6"] = gateway6
if mac_prefix:
env["NETWORK_MAC_PREFIX"] = mac_prefix
- if network_type:
- env["NETWORK_TYPE"] = network_type
if tags:
env["NETWORK_TAGS"] = " ".join(tags)
"network6": self.op.network6,
"gateway6": self.op.gateway6,
"mac_prefix": self.op.mac_prefix,
- "network_type": self.op.network_type,
"tags": self.op.tags,
}
return _BuildNetworkHookEnv(**args) # pylint: disable=W0142
network6=self.op.network6,
gateway6=self.op.gateway6,
mac_prefix=self.op.mac_prefix,
- network_type=self.op.network_type,
uuid=self.network_uuid,
family=constants.IP4_VERSION)
# Initialize the associated address pool
"""
self.network = self.cfg.GetNetwork(self.network_uuid)
self.gateway = self.network.gateway
- self.network_type = self.network.network_type
self.mac_prefix = self.network.mac_prefix
self.network6 = self.network.network6
self.gateway6 = self.network.gateway6
" reserved" % self.gateway,
errors.ECODE_STATE)
- if self.op.network_type:
- if self.op.network_type == constants.VALUE_NONE:
- self.network_type = None
- else:
- self.network_type = self.op.network_type
-
if self.op.mac_prefix:
if self.op.mac_prefix == constants.VALUE_NONE:
self.mac_prefix = None
"network6": self.network6,
"gateway6": self.gateway6,
"mac_prefix": self.mac_prefix,
- "network_type": self.network_type,
"tags": self.tags,
}
return _BuildNetworkHookEnv(**args) # pylint: disable=W0142
if self.op.gateway6:
self.network.gateway6 = self.gateway6
- if self.op.network_type:
- self.network.network_type = self.network_type
-
self.pool.Validate()
self.cfg.Update(self.network, feedback_fn)
RESERVE_ACTION = "reserve"
RELEASE_ACTION = "release"
-# An extra description of the network.
-# Can be used by hooks/kvm-vif-bridge to apply different rules
-NETWORK_TYPE_PRIVATE = "private"
-NETWORK_TYPE_PUBLIC = "public"
-
-NETWORK_VALID_TYPES = compat.UniqueFrozenset([
- NETWORK_TYPE_PRIVATE,
- NETWORK_TYPE_PUBLIC,
- ])
-
NICS_PARAMETER_TYPES = {
NIC_MODE: VTYPE_STRING,
NIC_LINK: VTYPE_STRING,
def _BuildNetworkEnv(name, network, gateway, network6, gateway6,
- network_type, mac_prefix, tags, env):
+ mac_prefix, tags, env):
"""Build environment variables concerning a Network.
"""
env["NETWORK_GATEWAY6"] = gateway6
if mac_prefix:
env["NETWORK_MAC_PREFIX"] = mac_prefix
- if network_type:
- env["NETWORK_TYPE"] = network_type
if tags:
env["NETWORK_TAGS"] = " ".join(tags)
if nic.network:
n = objects.Network.FromDict(nic.netinfo)
_BuildNetworkEnv(nic.network, n.network, n.gateway,
- n.network6, n.gateway6, n.network_type,
+ n.network6, n.gateway6,
n.mac_prefix, n.tags, env)
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
__slots__ = [
"name",
"serial_no",
- "network_type",
"mac_prefix",
"family",
"network",
result["%sNETWORK_GATEWAY6" % prefix] = self.gateway6
if self.mac_prefix:
result["%sNETWORK_MAC_PREFIX" % prefix] = self.mac_prefix
- if self.network_type:
- result["%sNETWORK_TYPE" % prefix] = self.network_type
return result
+ @classmethod
+ def FromDict(cls, val):
+ """Custom function for networks.
+
+ Remove deprecated network_type. Still this info can be passed via tags.
+
+ """
+ if "network_type" in val:
+ del val["network_type"]
+ obj = super(Network, cls).FromDict(val)
+ return obj
+
class SerializableConfigParser(ConfigParser.SafeConfigParser):
"""Simple wrapper over ConfigParse that allows serialization.
_PStorageType = ("storage_type", ht.NoDefault, _CheckStorageType,
"Storage type")
-_CheckNetworkType = ht.TElemOf(constants.NETWORK_VALID_TYPES)
-
@ht.WithDesc("IPv4 network")
def _CheckCIDRNetNotation(value):
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"),
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"),
"network6": ("IPv6Subnet", QFT_OTHER, 0, "IPv6 subnet"),
"gateway6": ("IPv6Gateway", QFT_OTHER, 0, "IPv6 gateway"),
"mac_prefix": ("MacPrefix", QFT_OTHER, 0, "MAC address prefix"),
- "network_type": ("NetworkType", QFT_OTHER, 0, "Network type"),
"serial_no": ("SerialNo", QFT_NUMBER, 0, _SERIAL_NO_DOC % "Network"),
"uuid": ("UUID", QFT_TEXT, 0, "Network UUID"),
}
None, None)
def CreateNetwork(self, network_name, network, gateway=None, network6=None,
- gateway6=None, mac_prefix=None, network_type=None,
+ gateway6=None, mac_prefix=None,
add_reserved_ips=None, tags=None, dry_run=False):
"""Creates a new network.
"gateway6": gateway6,
"network6": network6,
"mac_prefix": mac_prefix,
- "network_type": network_type,
"add_reserved_ips": add_reserved_ips,
"tags": tags,
}
NET_FIELDS = ["name", "network", "gateway",
"network6", "gateway6",
- "mac_prefix", "network_type",
+ "mac_prefix",
"free_count", "reserved_count",
"map", "group_list", "inst_list",
"external_reservations", "tags",
NIC_%d_NETWORK_MAC_PREFIX
(Optional) If a NIC network is specified, the network's mac prefix.
-NIC_%d_NETWORK_TYPE
- (Optional) If a NIC network is specified, the network's type.
-
NIC_%d_NETWORK_TAGS
(Optional) If a NIC network is specified, the network's tags, space
separated.
| [--network6=*NETWORK6*]
| [--gateway6=*GATEWAY6*]
| [--mac-prefix=*MACPREFIX*]
-| [--network-type=*NETWORKTYPE*]
| [--submit]
| {*network*}
The ``--gateway`` option allows you to specify the default gateway for
this network.
-The ``--network-type`` can be none, private or public.
-
IPv6 semantics can be assigned to the network via the ``--network6`` and
``--gateway6`` options. IP pool is meaningless for IPV6 so those two
values can be used for EUI64 generation from a NIC's MAC address.
| [--network6=*NETWORK6*]
| [--gateway6=*GATEWAY6*]
| [--mac-prefix=*MACPREFIX*]
-| [--network-type=*NETWORKTYPE*]
| [--submit]
| {*network*}
$(buildObject "Network" "network" $
[ simpleField "name" [t| NonEmptyString |]
, optionalField $
- simpleField "network_type" [t| NetworkType |]
- , optionalField $
simpleField "mac_prefix" [t| String |]
, optionalField $
simpleField "family" [t| Int |]
])
, ("OpNetworkAdd",
[ pNetworkName
- , pNetworkType
, pNetworkAddress4
, pNetworkGateway4
, pNetworkAddress6
])
, ("OpNetworkSetParams",
[ pNetworkName
- , pNetworkType
, pNetworkGateway4
, pNetworkAddress6
, pNetworkGateway6
, pTestDummyFail
, pTestDummySubmitJobs
, pNetworkName
- , pNetworkType
, pNetworkAddress4
, pNetworkGateway4
, pNetworkAddress6
pNetworkName :: Field
pNetworkName = simpleField "network_name" [t| NonEmptyString |]
--- | Network type field.
-pNetworkType :: Field
-pNetworkType = optionalField $ simpleField "network_type" [t| NetworkType |]
-
-- | Network address (IPv4 subnet). FIXME: no real type for this.
pNetworkAddress4 :: Field
pNetworkAddress4 =
, IAllocatorTestDir(..)
, IAllocatorMode(..)
, iAllocatorModeToRaw
- , NetworkType(..)
- , networkTypeToRaw
, NICMode(..)
, nICModeToRaw
, JobStatus(..)
])
$(THH.makeJSONInstance ''IAllocatorMode)
--- | Network type.
-$(THH.declareSADT "NetworkType"
- [ ("PrivateNetwork", 'C.networkTypePrivate)
- , ("PublicNetwork", 'C.networkTypePublic)
- ])
-$(THH.makeJSONInstance ''NetworkType)
-
-- | Netork mode.
$(THH.declareSADT "NICMode"
[ ("NMBridged", 'C.nicModeBridged)
module Test.Ganeti.Network
( testNetwork
, genBitStringMaxLen
- , genNetworkType
) where
import Test.QuickCheck
import Test.Ganeti.Objects
( genBitStringMaxLen
- , genNetworkType
, genValidNetwork )
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
, Node(..)
, genEmptyCluster
, genValidNetwork
- , genNetworkType
, genBitStringMaxLen
) where
import qualified Data.Set as Set
import qualified Text.JSON as J
-import Test.Ganeti.Query.Language (genJSValue)
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import Test.Ganeti.Types ()
-- generate netmask for the IPv4 network
netmask <- choose (24::Int, 30)
name <- genName >>= mkNonEmpty
- network_type <- genMaybe genNetworkType
mac_prefix <- genMaybe genName
- net_family <- arbitrary
net <- genIp4NetWithNetmask netmask
net6 <- genMaybe genIp6Net
gateway <- genMaybe genIp4AddrStr
gateway6 <- genMaybe genIp6Addr
- size <- genMaybe genJSValue
res <- liftM Just (genBitString $ netmask2NumHosts netmask)
ext_res <- liftM Just (genBitString $ netmask2NumHosts netmask)
- let n = Network name network_type mac_prefix net_family net net6 gateway
- gateway6 size res ext_res 0 Set.empty
+ let n = Network name mac_prefix net net6 gateway
+ gateway6 res ext_res 0 Set.empty
return n
--- | Generates an arbitrary network type.
-genNetworkType :: Gen NetworkType
-genNetworkType = elements [ PrivateNetwork, PublicNetwork ]
-
-- | Generate an arbitrary string consisting of '0' and '1' of the given length.
genBitString :: Int -> Gen String
genBitString len = vectorOf len (elements "01")
OpCodes.OpTestDummy <$> pure J.JSNull <*> pure J.JSNull <*>
pure J.JSNull <*> pure J.JSNull
"OP_NETWORK_ADD" ->
- OpCodes.OpNetworkAdd <$> genNameNE <*> arbitrary <*> genIp4Net <*>
+ OpCodes.OpNetworkAdd <$> genNameNE <*> genIp4Net <*>
genMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
genMaybe genMacPrefix <*> genMaybe (listOf genIp4Addr) <*>
arbitrary <*> (genTags >>= mapM mkNonEmpty)
"OP_NETWORK_REMOVE" ->
OpCodes.OpNetworkRemove <$> genNameNE <*> arbitrary
"OP_NETWORK_SET_PARAMS" ->
- OpCodes.OpNetworkSetParams <$> genNameNE <*> arbitrary <*>
+ OpCodes.OpNetworkSetParams <$> genNameNE <*>
genMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
genMaybe genMacPrefix <*> genMaybe (listOf genIp4Addr) <*>
genMaybe (listOf genIp4Addr)
$(genArbitrary ''IAllocatorMode)
-$(genArbitrary ''NetworkType)
-
$(genArbitrary ''NICMode)
$(genArbitrary ''JobStatus)
all_hs_codes = sort $ map Types.iAllocatorModeToRaw [minBound..maxBound]
assertEqual "for IAllocatorMode equivalence" all_py_codes all_hs_codes
--- | Test 'NetworkType' serialisation.
-prop_NetworkType_serialisation :: NetworkType -> Property
-prop_NetworkType_serialisation = testSerialisation
-
--- | Tests equivalence with Python, based on Constants.hs code.
-case_NetworkType_pyequiv :: Assertion
-case_NetworkType_pyequiv = do
- let all_py_codes = sort C.networkValidTypes
- all_hs_codes = sort $ map Types.networkTypeToRaw [minBound..maxBound]
- assertEqual "for NetworkType equivalence" all_py_codes all_hs_codes
-
-- | Test 'NICMode' serialisation.
prop_NICMode_serialisation :: NICMode -> Property
prop_NICMode_serialisation = testSerialisation
, 'prop_IAllocatorTestDir_serialisation
, 'prop_IAllocatorMode_serialisation
, 'case_IAllocatorMode_pyequiv
- , 'prop_NetworkType_serialisation
- , 'case_NetworkType_pyequiv
, 'prop_NICMode_serialisation
, 'prop_OpStatus_serialization
, 'prop_JobStatus_serialization