Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from collections import defaultdict
  4.  
  5. import os_client_config
  6.  
  7.  
  8. neutron = os_client_config.make_client('network', cloud='envvars')
  9.  
  10. ports = neutron.list_ports(device_owner='compute:kuryr')['ports']
  11. downed_ports = neutron.list_ports(device_owner='compute:kuryr', status='DOWN')['ports']
  12. trunks = neutron.list_trunks()['trunks']
  13. port_to_trunk = dict([(trunk['port_id'], trunk['id']) for trunk in trunks])
  14.  
  15. down_in_trunks = defaultdict(list)
  16. for port in downed_ports:
  17. if 'parent_name' in port['binding:profile']:
  18. down_in_trunks[port_to_trunk[port['binding:profile']['parent_name']]].append(port['id'])
  19.  
  20. for trunk, subports in down_in_trunks.items():
  21. print('Removing all Kuryr downed subports of trunk: %s' % trunk)
  22. neutron.trunk_remove_subports(trunk, {'sub_ports': [{'port_id': port} for port in subports]})
  23.  
  24. for port in downed_ports:
  25. port_id = port['id']
  26. print('Deleting Neutron port: %s' % port_id)
  27. neutron.delete_port(port_id)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement