1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-30 20:28:08 +00:00

Fix CPU fractional values for Docker VMs.

This commit is contained in:
grossmj 2024-04-03 17:15:10 +07:00
parent 9b66d939d2
commit 998898a471
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD
4 changed files with 8 additions and 4 deletions

View File

@ -506,6 +506,10 @@ class DockerVM(BaseNode):
result = await self.manager.query("POST", "containers/create", data=params) result = await self.manager.query("POST", "containers/create", data=params)
self._cid = result["Id"] self._cid = result["Id"]
log.info(f"Docker container '{self._name}' [{self._id}] created") 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 return True
def _format_env(self, variables, env): def _format_env(self, variables, env):

View File

@ -16,7 +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/>.
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 sqlalchemy.orm import relationship
from .base import BaseTable, generate_uuid, GUID from .base import BaseTable, generate_uuid, GUID
@ -77,7 +77,7 @@ class DockerTemplate(Template):
extra_hosts = Column(String) extra_hosts = Column(String)
extra_volumes = Column(PickleType) extra_volumes = Column(PickleType)
memory = Column(Integer) memory = Column(Integer)
cpus = Column(Integer) cpus = Column(Float)
custom_adapters = Column(PickleType) custom_adapters = Column(PickleType)
__mapper_args__ = {"polymorphic_identity": "docker", "polymorphic_load": "selectin"} __mapper_args__ = {"polymorphic_identity": "docker", "polymorphic_load": "selectin"}

View File

@ -43,7 +43,7 @@ class DockerBase(BaseModel):
extra_hosts: Optional[str] = Field(None, description="Docker extra hosts (added to /etc/hosts)") 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") 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") 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") custom_adapters: Optional[List[CustomAdapter]] = Field(None, description="Custom adapters")

View File

@ -49,7 +49,7 @@ class DockerTemplate(TemplateBase):
extra_hosts: Optional[str] = Field("", description="Docker extra hosts (added to /etc/hosts)") extra_hosts: Optional[str] = Field("", description="Docker extra hosts (added to /etc/hosts)")
extra_volumes: Optional[List] = Field([], description="Additional directories to make persistent") 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") 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") custom_adapters: Optional[List[CustomAdapter]] = Field(default_factory=list, description="Custom adapters")