summaryrefslogtreecommitdiff
path: root/ironic/common/network.py
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2017-06-01 15:24:44 +0100
committerJohn L. Villalovos <john.l.villalovos@intel.com>2017-06-15 15:03:10 -0700
commit039225610d220ddb3d9d1edf4a74c8cb2a0de4fd (patch)
treecf4926aa680fe57779dec96067bdbe755506cbb8 /ironic/common/network.py
parent6084277a51d4587dc961ae24500c42f4abb83588 (diff)
downloadironic-039225610d220ddb3d9d1edf4a74c8cb2a0de4fd.tar.gz
Validate portgroup physical network consistency
When creating or updating a port that is a member of a portgroup, we need to validate the consistency of the physical networks of the ports in the portgroup. There are 3 cases we are interested in: - Creating a port which is a member of a portgroup. - Updating the physical network of a port which is a member of a portgroup. - Updating the portgroup of a port. All ports in a portgroup should have the same value (which may be None) for their physical_network field. During creation or update of a port in a portgroup we apply the following validation criteria: - If the portgroup has existing ports with different physical networks, we raise PortgroupPhysnetInconsistent. This shouldn't ever happen. - If the port has a physical network that is inconsistent with other ports in the portgroup, we raise exception.Conflict. If a port's physical network is None, this indicates that ironic's VIF attachment mapping algorithm should operate in a legacy (physical network unaware) mode for this port or portgroup. This allows existing ironic nodes to continue to function after an upgrade to a release including physical network support. Change-Id: I6a6d248155f98109dd36dba5837494f6974846e6 Partial-Bug: #1666009
Diffstat (limited to 'ironic/common/network.py')
-rw-r--r--ironic/common/network.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/ironic/common/network.py b/ironic/common/network.py
index 17d753be5..895ff8741 100644
--- a/ironic/common/network.py
+++ b/ironic/common/network.py
@@ -42,3 +42,25 @@ def get_node_vif_ids(task):
port_vifs[port.uuid] = vif
vifs['ports'] = port_vifs
return vifs
+
+
+def get_portgroup_by_id(task, portgroup_id):
+ """Lookup a portgroup by ID on a task object.
+
+ :param task: a TaskManager instance
+ :param portgroup_id: ID of the portgroup.
+ :returns: A Portgroup object or None.
+ """
+ for portgroup in task.portgroups:
+ if portgroup.id == portgroup_id:
+ return portgroup
+
+
+def get_ports_by_portgroup_id(task, portgroup_id):
+ """Lookup ports by their portgroup ID on a task object.
+
+ :param task: a TaskManager instance
+ :param portgroup_id: ID of the portgroup.
+ :returns: A list of Port objects.
+ """
+ return [port for port in task.ports if port.portgroup_id == portgroup_id]