diff --git a/lib/cmdlib/cluster.py b/lib/cmdlib/cluster.py index 33433cc9bb1438386fb83906061a64fac3d0655f..67f32b5a68ac57d85379e879aa701e7ac8095bec 100644 --- a/lib/cmdlib/cluster.py +++ b/lib/cmdlib/cluster.py @@ -56,7 +56,8 @@ from ganeti.cmdlib.common import ShareAll, RunPostHook, \ CheckOSParams, CheckHVParams, AdjustCandidatePool, CheckNodePVs, \ ComputeIPolicyInstanceViolation, AnnotateDiskParams, SupportsOob, \ CheckIpolicyVsDiskTemplates, CheckDiskAccessModeValidity, \ - CheckDiskAccessModeConsistency, CreateNewClientCert + CheckDiskAccessModeConsistency, CreateNewClientCert, \ + OpAddInstanceCommunicationNetwork, OpConnectInstanceCommunicationNetwork import ganeti.masterd.instance @@ -1391,17 +1392,7 @@ class LUClusterSetParams(LogicalUnit): network_exists = False if not network_exists: - op = opcodes.OpNetworkAdd( - network_name=network_name, - gateway=None, - network=constants.INSTANCE_COMMUNICATION_NETWORK4, - gateway6=None, - network6=constants.INSTANCE_COMMUNICATION_NETWORK6, - mac_prefix=constants.INSTANCE_COMMUNICATION_MAC_PREFIX, - add_reserved_ips=None, - conflicts_check=True, - tags=[]) - jobs.append(op) + jobs.append(OpAddInstanceCommunicationNetwork(network_name)) for group_uuid in cfg.GetNodeGroupList(): group = cfg.GetNodeGroup(group_uuid) @@ -1416,12 +1407,7 @@ class LUClusterSetParams(LogicalUnit): network_connected = False if not network_connected: - op = opcodes.OpNetworkConnect( - group_name=group_uuid, - network_name=network_name, - network_mode=constants.NIC_MODE_ROUTED, - network_link=constants.INSTANCE_COMMUNICATION_NETWORK_LINK, - conflicts_check=True) + op = OpConnectInstanceCommunicationNetwork(group_uuid, network_name) jobs.append(op) if jobs: diff --git a/lib/cmdlib/common.py b/lib/cmdlib/common.py index 8d448ba1444aa7b87902a676cf6fd131cf2664f8..6e6f7698454b565abd6c0285898deeb5b8c131b1 100644 --- a/lib/cmdlib/common.py +++ b/lib/cmdlib/common.py @@ -1285,3 +1285,55 @@ def CreateNewClientCert(lu, node_uuid, filename=None): ((crypto_type, new_digest), ) = result.payload assert crypto_type == constants.CRYPTO_TYPE_SSL_DIGEST return new_digest + + +def OpAddInstanceCommunicationNetwork(network): + """Create OpCode that adds the instance communication network. + + This OpCode contains the configuration necessary for the instance + communication network. + + @type network: string + @param network: name or UUID of the instance communication network + + @rtype: L{ganeti.opcodes.OpCode} + @return: OpCode that creates the instance communication network + + """ + return opcodes.OpNetworkAdd( + network_name=network, + gateway=None, + network=constants.INSTANCE_COMMUNICATION_NETWORK4, + gateway6=None, + network6=constants.INSTANCE_COMMUNICATION_NETWORK6, + mac_prefix=constants.INSTANCE_COMMUNICATION_MAC_PREFIX, + add_reserved_ips=None, + conflicts_check=True, + tags=[]) + + +def OpConnectInstanceCommunicationNetwork(group_uuid, network): + """Create OpCode that connects a group to the instance communication + network. + + This OpCode contains the configuration necessary for the instance + communication network. + + @type group_uuid: string + @param group_uuid: UUID of the group to connect + + @type network: string + @param network: name or UUID of the network to connect to, i.e., the + instance communication network + + @rtype: L{ganeti.opcodes.OpCode} + @return: OpCode that connects the group to the instance + communication network + + """ + return opcodes.OpNetworkConnect( + group_name=group_uuid, + network_name=network, + network_mode=constants.NIC_MODE_ROUTED, + network_link=constants.INSTANCE_COMMUNICATION_NETWORK_LINK, + conflicts_check=True) diff --git a/lib/cmdlib/group.py b/lib/cmdlib/group.py index 86404c31ca58f198590d925642e535ed2c1f365b..6a55d85d79d8a41acc0be71dc90864ef5fb28177 100644 --- a/lib/cmdlib/group.py +++ b/lib/cmdlib/group.py @@ -28,7 +28,6 @@ from ganeti import constants from ganeti import errors from ganeti import locking from ganeti import objects -from ganeti import opcodes from ganeti import utils from ganeti.masterd import iallocator from ganeti.cmdlib.base import LogicalUnit, NoHooksLU, ResultWithJobs @@ -38,7 +37,7 @@ from ganeti.cmdlib.common import MergeAndVerifyHvState, \ ComputeNewInstanceViolations, GetDefaultIAllocator, ShareAll, \ CheckInstancesNodeGroups, LoadNodeEvacResult, MapInstanceLvsToNodes, \ CheckIpolicyVsDiskTemplates, CheckDiskAccessModeValidity, \ - CheckDiskAccessModeConsistency + CheckDiskAccessModeConsistency, OpConnectInstanceCommunicationNetwork import ganeti.masterd.instance @@ -157,8 +156,6 @@ class LUGroupAdd(LogicalUnit): L{None} """ - jobs = [] - try: cfg.LookupNetwork(network_name) network_exists = True @@ -166,16 +163,8 @@ class LUGroupAdd(LogicalUnit): network_exists = False if network_exists: - op = opcodes.OpNetworkConnect( - group_name=group_uuid, - network_name=network_name, - network_mode=constants.NIC_MODE_ROUTED, - network_link=constants.INSTANCE_COMMUNICATION_NETWORK_LINK, - conflicts_check=True) - jobs.append(op) - - if jobs: - return ResultWithJobs([jobs]) + op = OpConnectInstanceCommunicationNetwork(group_uuid, network_name) + return ResultWithJobs([[op]]) else: return None