Skip to content

Commit

Permalink
fix: define-cloud to mod assignments with future schedules
Browse files Browse the repository at this point in the history
closes: #546

Change-Id: I033ee39a984451fc247c0afe3c356bd6675ef816
  • Loading branch information
grafuls committed Nov 4, 2024
1 parent c3b80c0 commit f5f934d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 2 additions & 16 deletions src/quads/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,26 +936,12 @@ def action_cloudresource(self):
) as ex: # pragma: no cover
raise CliException(str(ex))
elif assignment:
try:
response = self.quads.update_assignment(assignment.id, data)
self.quads.update_cloud(
cloud.name,
{
"last_redefined": ":".join(
datetime.now().isoformat().split(":")[:-1]
)
},
)

except (APIServerException, APIBadRequest) as ex: # pragma: no cover
raise CliException(str(ex))
if response.status_code == 200:
self.logger.info("Assignment updated.")
raise CliException("Cloud already has an active assignment.")
else:
if self.cli_args.get("cloud") != conf.get("spare_pool_name"):
if not self.cli_args.get("cloudticket"):
self.logger.warning("No ticket provided.")
self.logger.warning("No assignment created or updated.")
self.logger.warning("No assignment created.")

except ConnectionError: # pragma: no cover
raise CliException(
Expand Down
9 changes: 8 additions & 1 deletion src/quads/server/dao/cloud.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import List, Optional, Type

from sqlalchemy import Boolean, or_
from sqlalchemy import Boolean, or_, select

from quads.config import Config
from quads.server.dao.baseDao import (
Expand Down Expand Up @@ -72,6 +72,12 @@ def get_clouds() -> List[Cloud]:

@staticmethod
def get_free_clouds() -> List[Cloud]:
future_schedule_subquery = (
select(Schedule.id)
.join(Assignment, Schedule.assignment_id == Assignment.id)
.filter(Assignment.cloud_id == Cloud.id, Schedule.start > datetime.now())
.exists()
)
free_clouds = (
db.session.query(Cloud)
.outerjoin(Assignment, Cloud.id == Assignment.cloud_id)
Expand All @@ -83,6 +89,7 @@ def get_free_clouds() -> List[Cloud]:
Assignment.id == None,
Schedule.id == None,
),
~future_schedule_subquery,
)
.order_by(Cloud.name.asc())
.distinct()
Expand Down

0 comments on commit f5f934d

Please sign in to comment.