def instance_reservation_destroy(instance_reservation_id): session = get_session() with session.begin(): instance = instance_reservation_get(instance_reservation_id) if not instance: raise db_exc.BlazarDBNotFound(id=instance_reservation_id, model='InstanceReservations') session.delete(instance)
def host_destroy(host_id): session = get_session() with session.begin(): host = _host_get(session, host_id) if not host: # raise not found error raise db_exc.BlazarDBNotFound(id=host_id, model='Host') session.delete(host)
def event_destroy(event_id): session = get_session() with session.begin(): event = _event_get(session, event_id) if not event: # raise not found error raise db_exc.BlazarDBNotFound(id=event_id, model='Event') session.delete(event)
def lease_destroy(lease_id): session = get_session() with session.begin(): lease = _lease_get(session, lease_id) if not lease: # raise not found error raise db_exc.BlazarDBNotFound(id=lease_id, model='Lease') session.delete(lease)
def floatingip_destroy(floatingip_id): session = get_session() with session.begin(): floatingip = _floatingip_get(session, floatingip_id) if not floatingip: # raise not found error raise db_exc.BlazarDBNotFound(id=floatingip_id, model='FloatingIP') session.delete(floatingip)
def fip_allocation_destroy(allocation_id): session = get_session() with session.begin(): fip_allocation = _fip_allocation_get(session, allocation_id) if not fip_allocation: # raise not found error raise db_exc.BlazarDBNotFound(id=allocation_id, model='FloatingIPAllocation') session.delete(fip_allocation)
def required_fip_destroy(required_fip_id): session = get_session() with session.begin(): required_fip = _required_fip_get(session, required_fip_id) if not required_fip: # raise not found error raise db_exc.BlazarDBNotFound(id=required_fip_id, model='RequiredFloatingIP') session.delete(required_fip)
def host_allocation_destroy(host_allocation_id): session = get_session() with session.begin(): host_allocation = _host_allocation_get(session, host_allocation_id) if not host_allocation: # raise not found error raise db_exc.BlazarDBNotFound(id=host_allocation_id, model='ComputeHostAllocation') session.delete(host_allocation)
def reservation_destroy(reservation_id): session = get_session() with session.begin(): reservation = _reservation_get(session, reservation_id) if not reservation: # raise not found error raise db_exc.BlazarDBNotFound(id=reservation_id, model='Reservation') session.delete(reservation)
def host_extra_capability_destroy(host_extra_capability_id): session = get_session() with session.begin(): host_extra_capability = (_host_extra_capability_get( session, host_extra_capability_id)) if not host_extra_capability: # raise not found error raise db_exc.BlazarDBNotFound(id=host_extra_capability_id, model='ComputeHostExtraCapability') session.delete(host_extra_capability)
def instance_reservation_update(instance_reservation_id, values): session = get_session() with session.begin(): instance_reservation = instance_reservation_get( instance_reservation_id, session) if not instance_reservation: raise db_exc.BlazarDBNotFound(id=instance_reservation_id, model='InstanceReservations') instance_reservation.update(values) instance_reservation.save(session=session) return instance_reservation_get(instance_reservation_id)
def host_get_all_by_queries(queries): """Returns hosts filtered by an array of queries. :param queries: array of queries "key op value" where op can be http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html #sqlalchemy.sql.operators.ColumnOperators """ hosts_query = model_query(models.ComputeHost, get_session()) oper = { '<': ['lt', lambda a, b: a >= b], '>': ['gt', lambda a, b: a <= b], '<=': ['le', lambda a, b: a > b], '>=': ['ge', lambda a, b: a < b], '==': ['eq', lambda a, b: a != b], '!=': ['ne', lambda a, b: a == b], } hosts = [] for query in queries: try: key, op, value = query.split(' ', 2) except ValueError: raise db_exc.BlazarDBInvalidFilter(query_filter=query) column = getattr(models.ComputeHost, key, None) if column is not None: if op == 'in': filt = column.in_(value.split(',')) else: if op in oper: op = oper[op][0] try: attr = [ e for e in ['%s', '%s_', '__%s__'] if hasattr(column, e % op) ][0] % op except IndexError: raise db_exc.BlazarDBInvalidFilterOperator( filter_operator=op) if value == 'null': value = None filt = getattr(column, attr)(value) hosts_query = hosts_query.filter(filt) else: # looking for extra capabilities matches extra_filter = model_query( models.ComputeHostExtraCapability, get_session()).filter( models.ComputeHostExtraCapability.capability_name == key).all() if not extra_filter: raise db_exc.BlazarDBNotFound( id=key, model='ComputeHostExtraCapability') for host in extra_filter: if op in oper and oper[op][1](host.capability_value, value): hosts.append(host.computehost_id) elif op not in oper: msg = 'Operator %s for extra capabilities not implemented' raise NotImplementedError(msg % op) # We must also avoid selecting any host which doesn't have the # extra capability present. all_hosts = [h.id for h in hosts_query.all()] extra_filter_hosts = [h.computehost_id for h in extra_filter] hosts += [h for h in all_hosts if h not in extra_filter_hosts] return hosts_query.filter(~models.ComputeHost.id.in_(hosts)).all()