mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-26 13:50:25 +03:00
Merge branch '3.1' into fix/mcp-initialization-ready-check
This commit is contained in:
commit
0a97e85a21
@ -16,6 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
|
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
from typing import List, Union, Optional
|
from typing import List, Union, Optional
|
||||||
@ -29,6 +30,8 @@ from .base import BaseRepository
|
|||||||
import gns3server.db.models as models
|
import gns3server.db.models as models
|
||||||
from gns3server import schemas
|
from gns3server import schemas
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
TEMPLATE_TYPE_TO_MODEL = {
|
TEMPLATE_TYPE_TO_MODEL = {
|
||||||
"cloud": models.CloudTemplate,
|
"cloud": models.CloudTemplate,
|
||||||
"docker": models.DockerTemplate,
|
"docker": models.DockerTemplate,
|
||||||
@ -123,8 +126,16 @@ class TemplatesRepository(BaseRepository):
|
|||||||
where(models.Image.filename == image_name, models.Image.path.endswith(image_path))
|
where(models.Image.filename == image_name, models.Image.path.endswith(image_path))
|
||||||
else:
|
else:
|
||||||
query = select(models.Image).where(models.Image.filename == image_name)
|
query = select(models.Image).where(models.Image.filename == image_name)
|
||||||
|
query = query.order_by(models.Image.image_id)
|
||||||
result = await self._db_session.execute(query)
|
result = await self._db_session.execute(query)
|
||||||
return result.scalars().one_or_none()
|
images = result.scalars().all()
|
||||||
|
if len(images) > 1:
|
||||||
|
log.warning(
|
||||||
|
f"Multiple DB entries found for image '{image_path}' "
|
||||||
|
f"({len(images)} rows). This indicates a data integrity issue. "
|
||||||
|
f"Using the entry with the lowest image_id ({images[0].image_id})."
|
||||||
|
)
|
||||||
|
return images[0] if images else None
|
||||||
|
|
||||||
async def add_image_to_template(
|
async def add_image_to_template(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@ -267,9 +267,13 @@ class TemplatesService:
|
|||||||
raise ControllerNotFoundError(f"Template '{template_id}' not found")
|
raise ControllerNotFoundError(f"Template '{template_id}' not found")
|
||||||
return template
|
return template
|
||||||
|
|
||||||
async def _remove_image(self, template_id: UUID, image_path:str) -> None:
|
async def _remove_image(self, template_id: UUID, image_path: str) -> None:
|
||||||
|
|
||||||
|
if not image_path:
|
||||||
|
return
|
||||||
image = await self._templates_repo.get_image(image_path)
|
image = await self._templates_repo.get_image(image_path)
|
||||||
|
if image is None:
|
||||||
|
return
|
||||||
await self._templates_repo.remove_image_from_template(template_id, image)
|
await self._templates_repo.remove_image_from_template(template_id, image)
|
||||||
|
|
||||||
async def update_template(self, template_id: UUID, template_update: schemas.TemplateUpdate) -> dict:
|
async def update_template(self, template_id: UUID, template_update: schemas.TemplateUpdate) -> dict:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user