from heat.engine import clients
from heat.engine import resource
+from heat.openstack.common import excutils
from heat.openstack.common import log as logging
logger = logging.getLogger(__name__)
def handle_create(self):
"""Allocate a floating IP for the current tenant."""
- ips = self.nova().floating_ips.create()
- logger.info('ElasticIp create %s' % str(ips))
- self.ipaddress = ips.ip
- self.resource_id_set(ips.id)
+ try:
+ ips = self.nova().floating_ips.create()
+ except clients.novaclient.exceptions.NotFound:
+ with excutils.save_and_reraise_exception():
+ msg = ("No default floating IP pool configured."
+ "Set 'default_floating_pool' in nova.conf.")
+ logger.error(msg)
+
+ if ips:
+ logger.info('ElasticIp create %s' % str(ips))
+ self.ipaddress = ips.ip
+ self.resource_id_set(ips.id)
if self.properties['InstanceId']:
server = self.nova().servers.get(self.properties['InstanceId'])
from heat.common import exception
from heat.common import template_format
from heat.engine.resources import eip
+from heat.engine import clients
from heat.engine import resource
from heat.engine import scheduler
from heat.tests.common import HeatTestCase
self.m.VerifyAll()
+ def test_eip_with_exception(self):
+ self.m.StubOutWithMock(self.fc.floating_ips, 'create')
+ eip.ElasticIp.nova().MultipleTimes().AndReturn(self.fc)
+ self.fc.floating_ips.create().AndRaise(
+ clients.novaclient.exceptions.NotFound('fake_falure'))
+ self.m.ReplayAll()
+
+ t = template_format.parse(eip_template)
+ stack = utils.parse_stack(t)
+ resource_name = 'IPAddress'
+ rsrc = eip.ElasticIp(resource_name,
+ t['Resources'][resource_name],
+ stack)
+
+ self.assertRaises(clients.novaclient.exceptions.NotFound,
+ rsrc.handle_create)
+ self.m.VerifyAll()
+
def test_association(self):
eip.ElasticIp.nova().AndReturn(self.fc)
eip.ElasticIpAssociation.nova().AndReturn(self.fc)