Guest User

Untitled

a guest
Dec 18th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # Windows 2008
  2. isolated_images=4adc0cb2-f65d-4c70-ae02-522e3cf245ef=prodnc15,prodnc16
  3.  
  4. # Windows 2003
  5. isolated_images=d2e845f4-b011-4f0d-8438-b5e799d8dd66=prodnc15,prodnc16
  6.  
  7. # Oracle 11
  8. isolated_images=7aeef3a1-4ca4-4cc3-aba0-38b5a35804c2=prodnc15,prodnc16
  9.  
  10.  
  11.  
  12.  
  13.  
  14. -------------
  15.  
  16.  
  17.  
  18. class IsolatedHostsFilter(filters.BaseHostFilter):
  19.     """Returns host."""
  20.  
  21.     def host_passes_legacy(self, host_state, filter_properties):
  22.         spec = filter_properties.get('request_spec', {})
  23.         props = spec.get('instance_properties', {})
  24.         image_ref = props.get('image_ref')
  25.         image_isolated = image_ref in FLAGS.isolated_images
  26.         host_isolated = host_state.host in FLAGS.isolated_hosts
  27.         return image_isolated == host_isolated
  28.  
  29.     def host_passes(self, host_state, filter_properties):
  30.         if not isinstance(FLAGS.isolated_images, list):
  31.             LOG.debug('Falling back to legacy...')
  32.             return self.host_passes_legacy(host_state, filter_properties)
  33.  
  34. # if current image not present in isolated_images return true
  35. # if current image IS present in isolated_images && my host is listed for that image return true
  36. # otherwise return false
  37.  
  38.         spec = filter_properties.get('request_spec', {})
  39.         props = spec.get('instance_properties', {})
  40.         image_ref = props.get('image_ref')
  41.  
  42.         #create dict
  43.         d = {}
  44.         for i in FLAGS.isolated_images:
  45.                 (img,hosts)=i.split('=')
  46.                 d[img]=hosts.split(',')
  47.  
  48.         if not image_ref in d:
  49.                 LOG.debug("didn't find image in dict!")
  50.                 return True
  51.         if host_state.host in d[image_ref]:
  52.                 LOG.debug("found my host (%s) in d[%s]!" % (host_state.host, image_ref))
  53.                 return True
  54.         return False
Advertisement
Add Comment
Please, Sign In to add comment