Tuesday, December 18, 2012

A better IsolatedHostsFilter

We have a cluster of 15 nodes, of which 2 are really beefy. We wanted to make our most resource intensive images (windows and oracle) run on these nodes only. The IsolatedHostsFilter allows isolation of hosts to run only a given set of images. However, it also limits the configured hosts to ONLY run the specified images. We want to isolate certain images to only run on given hosts, but still allow these hosts to run any image if there's capacity.

The following modification to isolated hosts filter does this (we also added isolated_hosts as a listopt in flags.py).


isolated_hosts_filter.py:


class IsolatedHostsFilter(filters.BaseHostFilter):
    """Returns host."""

    def host_passes_legacy(self, host_state, filter_properties):
        spec = filter_properties.get('request_spec', {})
        props = spec.get('instance_properties', {})
        image_ref = props.get('image_ref')
        image_isolated = image_ref in FLAGS.isolated_images
        host_isolated = host_state.host in FLAGS.isolated_hosts
        return image_isolated == host_isolated

    def host_passes(self, host_state, filter_properties):
        if not isinstance(FLAGS.isolated_images, list):
            LOG.debug('Falling back to legacy...')
            return self.host_passes_legacy(host_state, filter_properties)

# if current image not present in isolated_images return true
# if current image IS present in isolated_images && my host is listed for that image return true
# otherwise return false

        spec = filter_properties.get('request_spec', {})
        props = spec.get('instance_properties', {})
        image_ref = props.get('image_ref')

        #create dict
        d = {}
        for i in FLAGS.isolated_images:
                (img,hosts)=i.split('=')
                d[img]=hosts.split(',')

        if not image_ref in d:
                LOG.debug("didn't find image in dict!")
                return True
        if host_state.host in d[image_ref]:
                LOG.debug("found my host (%s) in d[%s]!" % (host_state.host, image_ref)) 
                return True
        return False


Nova.conf:

# Windows 2008
isolated_images=4adc0cb2-f65d-4c70-ae02-522e3cf245ef=prodnc15,prodnc16

# Windows 2003
isolated_images=d2e845f4-b011-4f0d-8438-b5e799d8dd66=prodnc15,prodnc16

# Oracle 11
isolated_images=7aeef3a1-4ca4-4cc3-aba0-38b5a35804c2=prodnc15,prodnc16

No comments:

Post a Comment