Skip to content

Commit

Permalink
Merge "feat: added endpoint for free vlans" into development
Browse files Browse the repository at this point in the history
  • Loading branch information
sadsfae authored and gerritforge-ltd committed Jan 10, 2025
2 parents 55fefe4 + 484d09c commit 6936315
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/quads-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ curl -X POST -u $USERNAME:$PASSWORD -H 'accept: application/json' 'http://localh
- `/api/v3/schedules` Retrieve a list of all schedules
- `/api/v3/available` List available hosts, usually used with `--schedule-start YYYY-MM-DD HH` and `--schedule-end YYYY-MM-DD HH`
- `/api/v3/interfaces` List interfaces of QUADS host(s)
- `/api/v3/vlans` Retrieve a list of all vlans
- `/api/v3/vlans/free` Retrieve a list of all available vlans
- `/api/v3/clouds/summary` Obtain a full summary of clouds, tickets, descriptions
- `/api/v3/moves` Obtain a list of hosts with their current and future clouds

Expand Down
10 changes: 10 additions & 0 deletions src/quads/server/blueprints/vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def get_vlan(vlan_id: int) -> Response:
@vlan_bp.route("/")
def get_vlans() -> Response:
_vlans = VlanDao.get_vlans()
if not _vlans:
return jsonify([])
return jsonify([_vlan.as_dict() for _vlan in _vlans])


@vlan_bp.route("/free")
def get_free_vlans() -> Response:
_vlans = VlanDao.get_free_vlans()
if not _vlans:
return jsonify([])
return jsonify([_vlan.as_dict() for _vlan in _vlans])


Expand Down
17 changes: 13 additions & 4 deletions src/quads/server/dao/vlan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from quads.server.dao.baseDao import BaseDao
from quads.server.models import Vlan, db
from quads.server.models import Assignment, Vlan, db


class VlanDao(BaseDao):
Expand All @@ -25,7 +25,16 @@ def get_vlan(vlan_id: int) -> Vlan:

@staticmethod
def get_vlans() -> List[Vlan]:
# TODO:Union with assignments table on assignments.vlan_id=Vlan.vlan_id where assignments.active=True
# to include a column with the assignment ID
vlans = db.session.query(Vlan).all()
vlans = db.session.query(Vlan).order_by(Vlan.vlan_id).all()
return vlans

@staticmethod
def get_free_vlans() -> List[Vlan]:
vlans = (
db.session.query(Vlan)
.outerjoin(Assignment, (Vlan.id == Assignment.vlan_id) & (Assignment.active == True))
.filter(Assignment.id == None) # noqa: E711
.order_by(Vlan.vlan_id)
.all()
)
return vlans
20 changes: 20 additions & 0 deletions src/quads/server/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,26 @@ paths:
security:
- BearerAuth: [ ]

/vlans/free/:
get:
summary: Returns a list with all the free vlans
tags:
- Vlans
responses:
'200':
description: OK
content:
application/json:
schema:
items:
$ref: '#/components/schemas/Vlan'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'

/vlans/{vlan_id}/:
get:
summary: Returns a detail of a specific vlan by id
Expand Down

0 comments on commit 6936315

Please sign in to comment.