def on_end(self, resource_id): fip_reservation = db_api.fip_reservation_get(resource_id) allocations = db_api.fip_allocation_get_all_by_values( reservation_id=fip_reservation['reservation_id']) fip_pool = neutron.FloatingIPPool(fip_reservation['network_id']) for alloc in allocations: fip = db_api.floatingip_get(alloc['floatingip_id']) fip_pool.delete_reserved_floatingip(fip['floating_ip_address'])
def on_start(self, resource_id): fip_reservation = db_api.fip_reservation_get(resource_id) allocations = db_api.fip_allocation_get_all_by_values( reservation_id=fip_reservation['reservation_id']) ctx = context.current() fip_pool = neutron.FloatingIPPool(fip_reservation['network_id']) for alloc in allocations: fip = db_api.floatingip_get(alloc['floatingip_id']) fip_pool.create_reserved_floatingip( fip['subnet_id'], fip['floating_ip_address'], ctx.project_id, fip_reservation['reservation_id'])
def update_reservation(self, reservation_id, values): """Update reservation.""" reservation = db_api.reservation_get(reservation_id) lease = db_api.lease_get(reservation['lease_id']) dates_before = { 'start_date': lease['start_date'], 'end_date': lease['end_date'] } dates_after = { 'start_date': values['start_date'], 'end_date': values['end_date'] } fip_reservation = db_api.fip_reservation_get( reservation['resource_id']) if ('network_id' in values and values.get('network_id') != fip_reservation['network_id']): raise manager_ex.CantUpdateFloatingIPReservation( msg="Updating network_id is not supported") required_fips = fip_reservation['required_floatingips'] if ('required_floatingips' in values and values['required_floatingips'] != required_fips and values['required_floatingips'] != []): raise manager_ex.CantUpdateFloatingIPReservation( msg="Updating required_floatingips is not supported except " "with an empty list") self._update_allocations(dates_before, dates_after, reservation_id, reservation['status'], fip_reservation, values) updates = {} if 'amount' in values: updates['amount'] = values.get('amount') if updates: db_api.fip_reservation_update(fip_reservation['id'], updates) if ('required_floatingips' in values and values['required_floatingips'] != required_fips): db_api.required_fip_destroy_by_fip_reservation_id( fip_reservation['id']) for fip_address in values.get('required_floatingips'): fip_address_values = { 'address': fip_address, 'floatingip_reservation_id': fip_reservation['id'] } db_api.required_fip_create(fip_address_values)