Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf-8
- from collections import defaultdict
- import os_client_config
- neutron = os_client_config.make_client('network', cloud='envvars')
- ports = neutron.list_ports(device_owner='compute:kuryr')['ports']
- downed_ports = neutron.list_ports(device_owner='compute:kuryr', status='DOWN')['ports']
- trunks = neutron.list_trunks()['trunks']
- port_to_trunk = dict([(trunk['port_id'], trunk['id']) for trunk in trunks])
- down_in_trunks = defaultdict(list)
- for port in downed_ports:
- if 'parent_name' in port['binding:profile']:
- down_in_trunks[port_to_trunk[port['binding:profile']['parent_name']]].append(port['id'])
- for trunk, subports in down_in_trunks.items():
- print('Removing all Kuryr downed subports of trunk: %s' % trunk)
- neutron.trunk_remove_subports(trunk, {'sub_ports': [{'port_id': port} for port in subports]})
- for port in downed_ports:
- port_id = port['id']
- print('Deleting Neutron port: %s' % port_id)
- neutron.delete_port(port_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement