def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) # NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry # associated with the instance-id. This prevents us from handing it # out again immediately, as allocating it to a new instance before # a DHCP lease has timed-out is bad. Instead, the fixed-ip will # be disassociated with the instance-id by a call to one of two # methods inherited from FlatManager: # - if DHCP is in use, a lease expiring in dnsmasq triggers # a call to release_fixed_ip in the network manager. # - otherwise, _disassociate_stale_fixed_ips is called periodically # to disassociate all fixed ips that are unallocated # but still associated with an instance-id. for fixed_ip in fixed_ips: db.fixed_ip_update(admin_context, fixed_ip['address'], { 'allocated': False, 'virtual_interface_id': None }) if len(fixed_ips) == 0: LOG.error( _('No fixed IPs to deallocate for vif %s') % vif_ref['id'])
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) # NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry # associated with the instance-id. This prevents us from handing it # out again immediately, as allocating it to a new instance before # a DHCP lease has timed-out is bad. Instead, the fixed-ip will # be disassociated with the instance-id by a call to one of two # methods inherited from FlatManager: # - if DHCP is in use, a lease expiring in dnsmasq triggers # a call to release_fixed_ip in the network manager. # - otherwise, _disassociate_stale_fixed_ips is called periodically # to disassociate all fixed ips that are unallocated # but still associated with an instance-id. for fixed_ip in fixed_ips: db.fixed_ip_update(admin_context, fixed_ip['address'], {'allocated': False, 'virtual_interface_id': None}) if len(fixed_ips) == 0: LOG.error(_('No fixed IPs to deallocate for vif %s') % vif_ref['id'])
def _from_bm_node(instance_id, tenant_id): LOG.debug('_from_bm_node(instance_id=%s,tenant_id=%s)', instance_id, tenant_id) ctx = context.get_admin_context() info = [] for vif in db.virtual_interface_get_by_instance(ctx, instance_id): LOG.debug('vif=%s', vif.__dict__) mac = vif.address network_ref = None if vif['network_id']: network_ref = db.network_get(ctx, vif['network_id']) if not network_ref: LOG.warn('vif.network is None') continue LOG.debug('vif.network=%s', network_ref.__dict__) network_uuid = network_ref.uuid if not network_uuid: LOG.warn('network_uuid is None') continue vifinfo_uuid = _get_vifinfo_uuid(tenant_id, network_uuid, vif.uuid) LOG.debug('vifinfo_uuid=%s', vifinfo_uuid) if not vifinfo_uuid: continue fixed_ips = db.fixed_ips_by_virtual_interface(ctx, vif.id) if not fixed_ips: LOG.warn('fixed_ip is None') continue addrs = [fip.address for fip in fixed_ips] info.append((vifinfo_uuid, network_uuid, mac, addrs)) LOG.debug('_from_bm_node(instance_id=%s,tenant_id=%s) end: info=%s', instance_id, tenant_id, info) return info
def _from_bm_node(instance_id, tenant_id): LOG.debug('_from_bm_node(instance_id=%s,tenant_id=%s)', instance_id, tenant_id) ctx = context.get_admin_context() info = [] for vif in db.virtual_interface_get_by_instance(ctx, instance_id): LOG.debug('vif=%s', vif.__dict__) mac = vif.address network_ref = None if vif['network_id']: network_ref = db.network_get(ctx, vif['network_id']) if not network_ref: LOG.warn('vif.network is None') continue LOG.debug('vif.network=%s', network_ref.__dict__) network_uuid = network_ref.uuid if not network_uuid: LOG.warn('network_uuid is None') continue vifinfo_uuid = _get_vifinfo_uuid(tenant_id, network_uuid, vif.uuid) LOG.debug('vifinfo_uuid=%s', vifinfo_uuid) if not vifinfo_uuid: continue fixed_ips = db.fixed_ips_by_virtual_interface(ctx, vif.id) if not fixed_ips: LOG.warn('fixed_ip is None') continue addrs = [fip.address for fip in fixed_ips] info.append((vifinfo_uuid, network_uuid, mac, addrs)) LOG.debug('_from_bm_node(instance_id=%s,tenant_id=%s) end: info=%s', instance_id, tenant_id, info) return info
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec["id"]) return [fixed_ip["address"] for fixed_ip in fixed_ips]
def get_by_virtual_interface_id(cls, context, vif_id): expected_attrs = ['network', 'floating_ips'] db_fixedips = db.fixed_ips_by_virtual_interface(context, vif_id) return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips, expected_attrs=expected_attrs)
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ # TODO(tr3buchet): link fixed_ips to vif by uuid so only 1 db call vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref["id"]) for fixed_ip in fixed_ips: db.fixed_ip_update(admin_context, fixed_ip["address"], {"allocated": False, "virtual_interface_id": None}) if len(fixed_ips) == 0: LOG.error(_("No fixed IPs to deallocate for vif %s" % vif_ref["id"]))
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list of IPv4 address strings associated with the specified virtual interface, based on the fixed_ips table. """ # TODO(tr3buchet): link fixed_ips to vif by uuid so only 1 db call vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if not vif_rec or not vif_rec['id']: return [] fixed_ips = db.fixed_ips_by_virtual_interface(context, vif_rec['id']) return [fixed_ip['address'] for fixed_ip in fixed_ips]
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) for fixed_ip in fixed_ips: db.fixed_ip_update(admin_context, fixed_ip['address'], {'allocated': False, 'virtual_interface_id': None}) if len(fixed_ips) == 0: LOG.error(_('No fixed IPs to deallocate for vif %s'), vif_ref['id'])
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) for fixed_ip in fixed_ips: db.fixed_ip_update(admin_context, fixed_ip['address'], { 'allocated': False, 'virtual_interface_id': None }) if len(fixed_ips) == 0: LOG.error( _('No fixed IPs to deallocate for vif %s' % vif_ref['id']))
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) # NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry # associated with the instance-id. This prevents us from handing it # out again immediately, as allocating it to a new instance before # a DHCP lease has timed-out is bad. Instead, the fixed-ip will # be disassociated with the instance-id by a call to one of two # methods inherited from FlatManager: # - if DHCP is in use, a lease expiring in dnsmasq triggers # a call to release_fixed_ip in the network manager, or it will # be timed out periodically if the lease fails. # - otherwise, we release the ip immediately read_deleted_context = admin_context.elevated(read_deleted='yes') for fixed_ip in fixed_ips: fixed_id = fixed_ip['id'] floating_ips = self.net_manager.db.floating_ip_get_by_fixed_ip_id( admin_context, fixed_id) # disassociate floating ips related to fixed_ip for floating_ip in floating_ips: address = floating_ip['address'] manager.FloatingIP.disassociate_floating_ip( self.net_manager, read_deleted_context, address, affect_auto_assigned=True) # deallocate if auto_assigned if floating_ip['auto_assigned']: manager.FloatingIP.deallocate_floating_ip( read_deleted_context, address, affect_auto_assigned=True) db.fixed_ip_update(admin_context, fixed_ip['address'], {'allocated': False, 'virtual_interface_id': None}) if not self.net_manager.DHCP: db.fixed_ip_disassociate(admin_context, fixed_ip['address']) if len(fixed_ips) == 0: LOG.error(_('No fixed IPs to deallocate for vif %s'), vif_ref['id'])
def deallocate_ips_by_vif(self, context, tenant_id, net_id, vif_ref): """Deallocate all fixed IPs associated with the specified virtual interface. """ admin_context = context.elevated() fixed_ips = db.fixed_ips_by_virtual_interface(admin_context, vif_ref['id']) # NOTE(s0mik): Sets fixed-ip to deallocated, but leaves the entry # associated with the instance-id. This prevents us from handing it # out again immediately, as allocating it to a new instance before # a DHCP lease has timed-out is bad. Instead, the fixed-ip will # be disassociated with the instance-id by a call to one of two # methods inherited from FlatManager: # - if DHCP is in use, a lease expiring in dnsmasq triggers # a call to release_fixed_ip in the network manager, or it will # be timed out periodically if the lease fails. # - otherwise, we release the ip immediately read_deleted_context = admin_context.elevated(read_deleted='yes') for fixed_ip in fixed_ips: fixed_id = fixed_ip['id'] floating_ips = self.net_manager.db.floating_ip_get_by_fixed_ip_id( admin_context, fixed_id) # disassociate floating ips related to fixed_ip for floating_ip in floating_ips: address = floating_ip['address'] manager.FloatingIP.disassociate_floating_ip( self.net_manager, read_deleted_context, address, affect_auto_assigned=True) # deallocate if auto_assigned if floating_ip['auto_assigned']: manager.FloatingIP.deallocate_floating_ip( read_deleted_context, address, affect_auto_assigned=True) db.fixed_ip_update(admin_context, fixed_ip['address'], { 'allocated': False, 'virtual_interface_id': None }) if not self.net_manager.DHCP: db.fixed_ip_disassociate(admin_context, fixed_ip['address']) if len(fixed_ips) == 0: LOG.error(_('No fixed IPs to deallocate for vif %s'), vif_ref['id'])
def get_by_virtual_interface_id(cls, context, vif_id): db_fixedips = db.fixed_ips_by_virtual_interface(context, vif_id) return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips)
def get_by_virtual_interface_id(cls, context, vif_id): expected_attrs = ['network', 'floating_ips'] db_fixedips = db.fixed_ips_by_virtual_interface(context, vif_id) return obj_base.obj_make_list(context, cls(context), objects.FixedIP, db_fixedips, expected_attrs=expected_attrs)