Skip to content

Commit

Permalink
Merge pull request #2364 from GNS3/bugfix/3572
Browse files Browse the repository at this point in the history
Fix CPUs limitation for Docker containers does not allow fractional values
  • Loading branch information
grossmj committed Apr 3, 2024
2 parents 9b66d93 + 998898a commit e1d3ee1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions gns3server/compute/docker/docker_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ async def create(self):
result = await self.manager.query("POST", "containers/create", data=params)
self._cid = result["Id"]
log.info(f"Docker container '{self._name}' [{self._id}] created")
if self._cpus > 0:
log.info(f"CPU limit set to {self._cpus} CPUs")
if self._memory > 0:
log.info(f"Memory limit set to {self._memory} MB")
return True

def _format_env(self, variables, env):
Expand Down
4 changes: 2 additions & 2 deletions gns3server/db/models/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


from sqlalchemy import Boolean, Column, String, Integer, ForeignKey, PickleType
from sqlalchemy import Boolean, Column, String, Integer, Float, ForeignKey, PickleType
from sqlalchemy.orm import relationship

from .base import BaseTable, generate_uuid, GUID
Expand Down Expand Up @@ -77,7 +77,7 @@ class DockerTemplate(Template):
extra_hosts = Column(String)
extra_volumes = Column(PickleType)
memory = Column(Integer)
cpus = Column(Integer)
cpus = Column(Float)
custom_adapters = Column(PickleType)

__mapper_args__ = {"polymorphic_identity": "docker", "polymorphic_load": "selectin"}
Expand Down
2 changes: 1 addition & 1 deletion gns3server/schemas/compute/docker_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DockerBase(BaseModel):
extra_hosts: Optional[str] = Field(None, description="Docker extra hosts (added to /etc/hosts)")
extra_volumes: Optional[List[str]] = Field(None, description="Additional directories to make persistent")
memory: Optional[int] = Field(None, description="Maximum amount of memory the container can use in MB")
cpus: Optional[int] = Field(None, description="Maximum amount of CPU resources the container can use")
cpus: Optional[float] = Field(None, description="Maximum amount of CPU resources the container can use")
custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adapters")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DockerTemplate(TemplateBase):
extra_hosts: Optional[str] = Field("", description="Docker extra hosts (added to /etc/hosts)")
extra_volumes: Optional[List] = Field([], description="Additional directories to make persistent")
memory: Optional[int] = Field(0, description="Maximum amount of memory the container can use in MB")
cpus: Optional[int] = Field(0, description="Maximum amount of CPU resources the container can use")
cpus: Optional[float] = Field(0, description="Maximum amount of CPU resources the container can use")
custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")


Expand Down

0 comments on commit e1d3ee1

Please sign in to comment.