Merge "Extend project cleanup"
This commit is contained in:
commit
2fbefe6481
|
@ -33,6 +33,7 @@ from openstack.cloud import exc
|
|||
from openstack.cloud import meta
|
||||
import openstack.config
|
||||
from openstack.config import cloud_region as cloud_region_mod
|
||||
from openstack import exceptions
|
||||
from openstack import proxy
|
||||
from openstack import utils
|
||||
|
||||
|
@ -782,16 +783,24 @@ class _OpenStackCloudMixin:
|
|||
if not status_queue:
|
||||
status_queue = queue.Queue()
|
||||
for service in self.config.get_enabled_services():
|
||||
if hasattr(self, service):
|
||||
proxy = getattr(self, service)
|
||||
if (
|
||||
proxy
|
||||
and hasattr(proxy, get_dep_fn_name)
|
||||
and hasattr(proxy, cleanup_fn_name)
|
||||
):
|
||||
deps = getattr(proxy, get_dep_fn_name)()
|
||||
if deps:
|
||||
dependencies.update(deps)
|
||||
try:
|
||||
if hasattr(self, service):
|
||||
proxy = getattr(self, service)
|
||||
if (
|
||||
proxy
|
||||
and hasattr(proxy, get_dep_fn_name)
|
||||
and hasattr(proxy, cleanup_fn_name)
|
||||
):
|
||||
deps = getattr(proxy, get_dep_fn_name)()
|
||||
if deps:
|
||||
dependencies.update(deps)
|
||||
except (
|
||||
exceptions.NotSupported,
|
||||
exceptions.ServiceDisabledException
|
||||
):
|
||||
# Cloud may include endpoint in catalog but not
|
||||
# implement the service or disable it
|
||||
pass
|
||||
dep_graph = utils.TinyDAG()
|
||||
for k, v in dependencies.items():
|
||||
dep_graph.add_node(k)
|
||||
|
@ -805,18 +814,22 @@ class _OpenStackCloudMixin:
|
|||
|
||||
for service in dep_graph.walk(timeout=wait_timeout):
|
||||
fn = None
|
||||
if hasattr(self, service):
|
||||
proxy = getattr(self, service)
|
||||
cleanup_fn = getattr(proxy, cleanup_fn_name, None)
|
||||
if cleanup_fn:
|
||||
fn = functools.partial(
|
||||
cleanup_fn,
|
||||
dry_run=dry_run,
|
||||
client_status_queue=status_queue,
|
||||
identified_resources=cleanup_resources,
|
||||
filters=filters,
|
||||
resource_evaluation_fn=resource_evaluation_fn
|
||||
)
|
||||
try:
|
||||
if hasattr(self, service):
|
||||
proxy = getattr(self, service)
|
||||
cleanup_fn = getattr(proxy, cleanup_fn_name, None)
|
||||
if cleanup_fn:
|
||||
fn = functools.partial(
|
||||
cleanup_fn,
|
||||
dry_run=dry_run,
|
||||
client_status_queue=status_queue,
|
||||
identified_resources=cleanup_resources,
|
||||
filters=filters,
|
||||
resource_evaluation_fn=resource_evaluation_fn
|
||||
)
|
||||
except exceptions.ServiceDisabledException:
|
||||
# same reason as above
|
||||
pass
|
||||
if fn:
|
||||
self._pool_executor.submit(
|
||||
cleanup_task, dep_graph, service, fn
|
||||
|
|
|
@ -5122,12 +5122,16 @@ class Proxy(proxy.Proxy):
|
|||
self.log.debug('Looking at port %s' % port)
|
||||
if port.device_owner in [
|
||||
'network:router_interface',
|
||||
'network:router_interface_distributed'
|
||||
'network:router_interface_distributed',
|
||||
'network:ha_router_replicated_interface'
|
||||
]:
|
||||
router_if.append(port)
|
||||
elif port.device_owner == 'network:dhcp':
|
||||
# we don't treat DHCP as a real port
|
||||
continue
|
||||
elif port.device_owner is None or port.device_owner == '':
|
||||
# Nobody owns the port - go with it
|
||||
continue
|
||||
elif (
|
||||
identified_resources
|
||||
and port.device_id not in identified_resources
|
||||
|
@ -5172,6 +5176,21 @@ class Proxy(proxy.Proxy):
|
|||
identified_resources=identified_resources,
|
||||
filters=None,
|
||||
resource_evaluation_fn=None)
|
||||
# Drop ports not belonging to anybody
|
||||
for port in self.ports(
|
||||
project_id=project_id,
|
||||
network_id=net.id
|
||||
):
|
||||
if port.device_owner is None or port.device_owner == '':
|
||||
self._service_cleanup_del_res(
|
||||
self.delete_port,
|
||||
port,
|
||||
dry_run=dry_run,
|
||||
client_status_queue=client_status_queue,
|
||||
identified_resources=identified_resources,
|
||||
filters=None,
|
||||
resource_evaluation_fn=None)
|
||||
|
||||
# Drop all subnets in the net (no further conditions)
|
||||
for obj in self.subnets(
|
||||
project_id=project_id,
|
||||
|
|
Loading…
Reference in New Issue