From 64674bf0ed966c3e8f241d555b772f03e7407951 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Mon, 17 Jun 2019 17:14:18 -0700 Subject: Block port deletions where vif is present We must not allow users to be able to delete ports when a VIF record is present. If they are able to, then the user risks orphaning ports in neutron which could result in address depletion prevent the port from being able to be used again. Co-Authored-By: Madhuri Kumari Story: 2006710 Task: 37074 Change-Id: I9f8eaf94a375984ea2f567f0a87c2ed1ed5cb3b7 --- ironic/conductor/utils.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'ironic/conductor/utils.py') diff --git a/ironic/conductor/utils.py b/ironic/conductor/utils.py index e537219c6..75b90486a 100644 --- a/ironic/conductor/utils.py +++ b/ironic/conductor/utils.py @@ -1134,3 +1134,30 @@ def hash_password(password=''): :param value: Value to be hashed """ return crypt.crypt(password, make_salt()) + + +def get_attached_vif(port): + """Get any attached vif ID for the port + + :param port: The port object upon which to check for a vif + record. + :returns: Returns a tuple of the vif if found and the use of + the vif in the form of a string, 'tenant', 'cleaning' + 'provisioning', 'rescuing'. + :raises: InvalidState exception upon finding a port with a + transient state vif on the port. + """ + + tenant_vif = port.internal_info.get('tenant_vif_port_id') + if tenant_vif: + return (tenant_vif, 'tenant') + clean_vif = port.internal_info.get('cleaning_vif_port_id') + if clean_vif: + return (clean_vif, 'cleaning') + prov_vif = port.internal_info.get('provisioning_vif_port_id') + if prov_vif: + return (prov_vif, 'provisioning') + rescue_vif = port.internal_info.get('rescuing_vif_port_id') + if rescue_vif: + return (rescue_vif, 'rescuing') + return (None, None) -- cgit v1.2.1