Skip to content

Commit

Permalink
[#90, #91] quotas, journey-tracker endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mjstealey committed Dec 23, 2024
1 parent c2d000f commit 4476688
Show file tree
Hide file tree
Showing 27 changed files with 2,788 additions and 12 deletions.
3 changes: 3 additions & 0 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export PROJECTS_RENEWAL_PERIOD_IN_DAYS=365
### Ansible
export ANSIBLE_AUTHORIZATION_TOKEN='xxxx-xxxx-xxxx-xxxx'

### Read Only Auth
export READONLY_AUTHORIZATION_TOKEN='xxxx-xxxx-xxxx-xxxx'

### Services Auth
export SERVICES_AUTHORIZATION_TOKEN='xxxx-xxxx-xxxx-xxxx'

Expand Down
2 changes: 1 addition & 1 deletion server/.swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.56
3.0.64
1 change: 1 addition & 0 deletions server/swagger_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from swagger_server.database.models.storage import FabricStorage, StorageSites
from swagger_server.database.models.tasktracker import TaskTimeoutTracker
from swagger_server.database.models.core_api_metrics import CoreApiMetrics
from swagger_server.database.models.quotas import FabricQuotas
"""
-------------------------------------------------------------------------------
END: Imports needed for alembic and flask using multiple model definition files
Expand Down
26 changes: 26 additions & 0 deletions server/swagger_server/controllers/journey_tracker_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import connexion
import six

from swagger_server.models.journey_tracker_people import JourneyTrackerPeople # noqa: E501
from swagger_server.models.status400_bad_request import Status400BadRequest # noqa: E501
from swagger_server.models.status401_unauthorized import Status401Unauthorized # noqa: E501
from swagger_server.models.status403_forbidden import Status403Forbidden # noqa: E501
from swagger_server.models.status404_not_found import Status404NotFound # noqa: E501
from swagger_server.models.status500_internal_server_error import Status500InternalServerError # noqa: E501
from swagger_server import util
from swagger_server.response_code import journey_tracker_controller as rc


def journey_tracker_people_get(since_date, until_date=None): # noqa: E501
"""Get people information for Journey Tracker
Get people information for Journey Tracker # noqa: E501
:param since_date: starting date to search from
:type since_date: str
:param until_date: ending date to search to
:type until_date: str
:rtype: JourneyTrackerPeople
"""
return rc.journey_tracker_people_get(since_date, until_date)
90 changes: 90 additions & 0 deletions server/swagger_server/controllers/quotas_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import connexion
import six

from swagger_server.models.quotas import Quotas # noqa: E501
from swagger_server.models.quotas_details import QuotasDetails # noqa: E501
from swagger_server.models.quotas_post import QuotasPost # noqa: E501
from swagger_server.models.quotas_put import QuotasPut # noqa: E501
from swagger_server.models.status200_ok_no_content import Status200OkNoContent # noqa: E501
from swagger_server.models.status400_bad_request import Status400BadRequest # noqa: E501
from swagger_server.models.status401_unauthorized import Status401Unauthorized # noqa: E501
from swagger_server.models.status403_forbidden import Status403Forbidden # noqa: E501
from swagger_server.models.status404_not_found import Status404NotFound # noqa: E501
from swagger_server.models.status500_internal_server_error import Status500InternalServerError # noqa: E501
from swagger_server import util
from swagger_server.response_code import quotas_controller as rc


def quotas_get(project_uuid=None, offset=None, limit=None): # noqa: E501
"""Get list of Resource Quotas
Get list of Resource Quotas # noqa: E501
:param project_uuid: project uuid
:type project_uuid: str
:param offset: number of items to skip before starting to collect the result set
:type offset: int
:param limit: maximum number of results to return per page (1 or more)
:type limit: int
:rtype: Quotas
"""
return rc.quotas_get(project_uuid, offset, limit)


def quotas_post(body=None): # noqa: E501
"""Create new Resource Quota
Create new Resource Quota # noqa: E501
:param body: Create a new Resource Quota
:type body: dict | bytes
:rtype: Quotas
"""
if connexion.request.is_json:
body = QuotasPost.from_dict(connexion.request.get_json()) # noqa: E501
return rc.quotas_post(body)


def quotas_uuid_delete(uuid): # noqa: E501
"""Delete single Resource Quota by UUID
Delete single Resource Quota by UUID # noqa: E501
:param uuid: universally unique identifier
:type uuid: str
:rtype: Status200OkNoContent
"""
return rc.quotas_uuid_delete(uuid)


def quotas_uuid_get(uuid): # noqa: E501
"""Get single Resource Quota by UUID
Get single Resource Quota by UUID # noqa: E501
:param uuid: universally unique identifier
:type uuid: str
:rtype: QuotasDetails
"""
return rc.quotas_uuid_get(uuid)


def quotas_uuid_put(uuid, body=None): # noqa: E501
"""Update single Resource Quota by UUID
Update single Resource Quota by UUID # noqa: E501
:param uuid: universally unique identifier
:type uuid: str
:param body: Update a Resource Quota
:type body: dict | bytes
:rtype: Status200OkNoContent
"""
if connexion.request.is_json:
body = QuotasPut.from_dict(connexion.request.get_json()) # noqa: E501
return rc.quotas_uuid_put(uuid, body)
54 changes: 54 additions & 0 deletions server/swagger_server/database/models/quotas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import enum

from sqlalchemy import UniqueConstraint

from swagger_server.database.db import db


# Enum for Resource Types
class EnumResourceTypes(enum.Enum):
core = "Core"
disk = "Disk"
fpga = "FPGA"
gpu = "GPU"
nvme = "NVME"
p4 = "P4"
ram = "RAM"
sharednic = "SharedNIC"
smartnic = "SmartNIC"
storage = "Storage"


# Enum for Resource Units
class EnumResourceUnits(enum.Enum):
hours = "Hours"


class FabricQuotas(db.Model):
"""
Quotas - Control Framework quotas for projects
- created_at = UTC datetime
- id - primary key
- project_uuid = UUID as string
- quota_limit = Float
- quota_used = Float
- resource_type = in [p4, core, ram, disk, gpu, smartnic, sharednic, fpga, nvme, storage] as string
- resource_unit = in [hours, ...] as string
- updated_at = UTC datetime
- uuid = UUID as string
"""
query: db.Query
__tablename__ = 'quotas'
__table_args__ = (
UniqueConstraint('project_uuid', 'resource_type', 'resource_unit', name='project_resource_type_unit'),)
__allow_unmapped__ = True

created_at = db.Column(db.DateTime(timezone=True), nullable=False)
id = db.Column(db.Integer, nullable=False, primary_key=True)
project_uuid = db.Column(db.String(), nullable=False)
quota_limit = db.Column(db.Float, nullable=False)
quota_used = db.Column(db.Float, nullable=False)
resource_type = db.Column(db.Enum(EnumResourceTypes), default=EnumResourceTypes.core, nullable=False)
resource_unit = db.Column(db.Enum(EnumResourceUnits), default=EnumResourceUnits.hours, nullable=False)
updated_at = db.Column(db.DateTime(timezone=True), nullable=False)
uuid = db.Column(db.String(), primary_key=False, nullable=False)
7 changes: 7 additions & 0 deletions server/swagger_server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from swagger_server.models.check_cookie import CheckCookie
from swagger_server.models.check_cookie_results import CheckCookieResults
from swagger_server.models.core_api_metrics import CoreApiMetrics
from swagger_server.models.journey_tracker_people import JourneyTrackerPeople
from swagger_server.models.journey_tracker_people_one import JourneyTrackerPeopleOne
from swagger_server.models.people import People
from swagger_server.models.people_details import PeopleDetails
from swagger_server.models.people_one import PeopleOne
Expand Down Expand Up @@ -48,6 +50,11 @@
from swagger_server.models.projects_tags_patch import ProjectsTagsPatch
from swagger_server.models.projects_token_holders_patch import ProjectsTokenHoldersPatch
from swagger_server.models.projects_topics_patch import ProjectsTopicsPatch
from swagger_server.models.quotas import Quotas
from swagger_server.models.quotas_details import QuotasDetails
from swagger_server.models.quotas_one import QuotasOne
from swagger_server.models.quotas_post import QuotasPost
from swagger_server.models.quotas_put import QuotasPut
from swagger_server.models.reference import Reference
from swagger_server.models.service_auth_details import ServiceAuthDetails
from swagger_server.models.service_auth_one import ServiceAuthOne
Expand Down
142 changes: 142 additions & 0 deletions server/swagger_server/models/journey_tracker_people.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from swagger_server.models.base_model_ import Model
from swagger_server.models.journey_tracker_people_one import JourneyTrackerPeopleOne # noqa: F401,E501
from swagger_server.models.status200_ok_single import Status200OkSingle # noqa: F401,E501
from swagger_server import util


class JourneyTrackerPeople(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, results: List[JourneyTrackerPeopleOne]=None, size: int=1, status: int=200, type: str=None): # noqa: E501
"""JourneyTrackerPeople - a model defined in Swagger
:param results: The results of this JourneyTrackerPeople. # noqa: E501
:type results: List[JourneyTrackerPeopleOne]
:param size: The size of this JourneyTrackerPeople. # noqa: E501
:type size: int
:param status: The status of this JourneyTrackerPeople. # noqa: E501
:type status: int
:param type: The type of this JourneyTrackerPeople. # noqa: E501
:type type: str
"""
self.swagger_types = {
'results': List[JourneyTrackerPeopleOne],
'size': int,
'status': int,
'type': str
}

self.attribute_map = {
'results': 'results',
'size': 'size',
'status': 'status',
'type': 'type'
}
self._results = results
self._size = size
self._status = status
self._type = type

@classmethod
def from_dict(cls, dikt) -> 'JourneyTrackerPeople':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The journey_tracker_people of this JourneyTrackerPeople. # noqa: E501
:rtype: JourneyTrackerPeople
"""
return util.deserialize_model(dikt, cls)

@property
def results(self) -> List[JourneyTrackerPeopleOne]:
"""Gets the results of this JourneyTrackerPeople.
:return: The results of this JourneyTrackerPeople.
:rtype: List[JourneyTrackerPeopleOne]
"""
return self._results

@results.setter
def results(self, results: List[JourneyTrackerPeopleOne]):
"""Sets the results of this JourneyTrackerPeople.
:param results: The results of this JourneyTrackerPeople.
:type results: List[JourneyTrackerPeopleOne]
"""

self._results = results

@property
def size(self) -> int:
"""Gets the size of this JourneyTrackerPeople.
:return: The size of this JourneyTrackerPeople.
:rtype: int
"""
return self._size

@size.setter
def size(self, size: int):
"""Sets the size of this JourneyTrackerPeople.
:param size: The size of this JourneyTrackerPeople.
:type size: int
"""

self._size = size

@property
def status(self) -> int:
"""Gets the status of this JourneyTrackerPeople.
:return: The status of this JourneyTrackerPeople.
:rtype: int
"""
return self._status

@status.setter
def status(self, status: int):
"""Sets the status of this JourneyTrackerPeople.
:param status: The status of this JourneyTrackerPeople.
:type status: int
"""

self._status = status

@property
def type(self) -> str:
"""Gets the type of this JourneyTrackerPeople.
:return: The type of this JourneyTrackerPeople.
:rtype: str
"""
return self._type

@type.setter
def type(self, type: str):
"""Sets the type of this JourneyTrackerPeople.
:param type: The type of this JourneyTrackerPeople.
:type type: str
"""

self._type = type
Loading

0 comments on commit 4476688

Please sign in to comment.