def init_host_floating_ips(self): """Configures floating ips owned by host.""" admin_context = context.get_admin_context() try: floating_ips = floating_ip_obj.FloatingIPList.get_by_host( admin_context, self.host) except exception.NotFound: return for floating_ip in floating_ips: if floating_ip.fixed_ip_id: try: fixed_ip = floating_ip.fixed_ip except exception.FixedIpNotFound: msg = _('Fixed ip %s not found') % floating_ip.fixed_ip_id LOG.debug(msg) continue interface = CONF.public_interface or floating_ip.interface try: self.l3driver.add_floating_ip(floating_ip.address, fixed_ip.address, interface, fixed_ip.network) except processutils.ProcessExecutionError: LOG.debug(_('Interface %s not found'), interface) raise exception.NoFloatingIpInterface(interface=interface)
def init_host_floating_ips(self): """Configures floating ips owned by host.""" admin_context = context.get_admin_context() try: floating_ips = self.db.floating_ip_get_all_by_host( admin_context, self.host) except exception.NotFound: return for floating_ip in floating_ips: fixed_ip_id = floating_ip.get('fixed_ip_id') if fixed_ip_id: try: fixed_ip = self.db.fixed_ip_get(admin_context, fixed_ip_id, get_network=True) except exception.FixedIpNotFound: msg = _('Fixed ip %(fixed_ip_id)s not found') % locals() LOG.debug(msg) continue interface = CONF.public_interface or floating_ip['interface'] try: self.l3driver.add_floating_ip(floating_ip['address'], fixed_ip['address'], interface, fixed_ip['network']) except processutils.ProcessExecutionError: LOG.debug(_('Interface %(interface)s not found'), locals()) raise exception.NoFloatingIpInterface(interface=interface)
def do_associate(): # associate floating ip floating = floating_ip_obj.FloatingIP.associate( context, floating_address, fixed_address, self.host) fixed = floating.fixed_ip if not fixed: # NOTE(vish): ip was already associated return try: # gogo driver time self.l3driver.add_floating_ip(floating_address, fixed_address, interface, fixed['network']) except processutils.ProcessExecutionError as e: with excutils.save_and_reraise_exception() as exc_ctxt: try: floating_ip_obj.FloatingIP.disassociate( context, floating_address) except Exception: LOG.warn( _('Failed to disassociated floating ' 'address: %s'), floating_address) pass if "Cannot find device" in str(e): try: LOG.error(_('Interface %s not found'), interface) except Exception: pass raise exception.NoFloatingIpInterface( interface=interface) payload = dict(project_id=context.project_id, instance_id=instance_uuid, floating_ip=floating_address) self.notifier.info(context, 'network.floating_ip.associate', payload)
def do_associate(): # associate floating ip fixed = self.db.floating_ip_fixed_ip_associate( context, floating_address, fixed_address, self.host) if not fixed: # NOTE(vish): ip was already associated return try: # gogo driver time self.l3driver.add_floating_ip(floating_address, fixed_address, interface, fixed['network']) except processutils.ProcessExecutionError as e: self.db.floating_ip_disassociate(context, floating_address) if "Cannot find device" in str(e): LOG.error(_('Interface %(interface)s not found'), locals()) raise exception.NoFloatingIpInterface(interface=interface) raise payload = dict(project_id=context.project_id, instance_id=instance_uuid, floating_ip=floating_address) notifier.notify(context, notifier.publisher_id("network"), 'network.floating_ip.associate', notifier.INFO, payload=payload)