diff --git a/bin/heat-engine b/bin/heat-engine index a0c3183b2..314b35199 100755 --- a/bin/heat-engine +++ b/bin/heat-engine @@ -46,12 +46,31 @@ gettextutils.install('heat', lazy=True) LOG = logging.getLogger('heat.engine') + +def discover_networking_service(): + from heat.common import heat_keystoneclient as hkc + + # create empty context + ctxt = hkc.context.RequestContext() + # create admin client + admin_client = hkc.KeystoneClient(ctxt).admin_client + services = admin_client.services.list() + + if 'network' in [s.type for s in services]: + cfg.CONF.set_override('networking_service', 'neutron') + else: + cfg.CONF.set_override('networking_service', 'nova') + + if __name__ == '__main__': cfg.CONF(project='heat', prog='heat-engine') logging.setup('heat') messaging.setup() + if not cfg.CONF.networking_service: + discover_networking_service() + from heat.engine import service as engine srv = engine.EngineService(cfg.CONF.host, rpc_api.ENGINE_TOPIC) diff --git a/etc/heat/heat.conf.sample b/etc/heat/heat.conf.sample index 451836d79..d3fc5808e 100644 --- a/etc/heat/heat.conf.sample +++ b/etc/heat/heat.conf.sample @@ -73,6 +73,10 @@ # Deprecated. (string value) #onready= +# Select OpenStack component responsible for networking - nova +# or neutron. (string value) +#networking_service= + # # Options defined in heat.common.config diff --git a/heat/common/config.py b/heat/common/config.py index 79bc66fa8..51a8c45ef 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -138,7 +138,11 @@ engine_opts = [ help=_('RPC timeout for the engine liveness check that is used' ' for stack locking.')), cfg.StrOpt('onready', - help=_('Deprecated.'))] + help=_('Deprecated.')), + cfg.StrOpt('networking_service', + choices=['nova', 'neutron'], + help=_('Select OpenStack component ' + 'responsible for networking - nova or neutron.'))] rpc_opts = [ cfg.StrOpt('host', diff --git a/heat/engine/resource.py b/heat/engine/resource.py index f93966572..8f89a798e 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -1086,3 +1086,7 @@ class Resource(object): # force fetch all resource data from the database again self._data = None return True + + @staticmethod + def is_using_neutron(): + return cfg.CONF.networking_service == 'neutron' diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index e465799f6..c18deca1f 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -995,6 +995,15 @@ class ResourceTest(HeatTestCase): TestResource.resource_to_template( 'Test::Resource::resource')) + def test_is_using_neutron(self): + snippet = rsrc_defn.ResourceDefinition('aresource', + 'GenericResourceType') + res = resource.Resource('aresource', snippet, self.stack) + cfg.CONF.set_override('networking_service', 'neutron') + self.assertTrue(res.is_using_neutron()) + cfg.CONF.set_override('networking_service', 'nova') + self.assertFalse(res.is_using_neutron()) + class ResourceAdoptTest(HeatTestCase): def setUp(self):