1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Set ram, ethernet adapters, serial adapters

This commit is contained in:
Julien Duponchelle 2015-02-12 21:02:52 +01:00
parent 05df7001a3
commit 8b61aa9ae7
4 changed files with 213 additions and 11 deletions

View File

@ -49,6 +49,10 @@ class IOUHandler:
request.match_info["project_id"],
request.json.get("vm_id"),
console=request.json.get("console"),
serial_adapters=request.json.get("serial_adapters"),
ethernet_adapters=request.json.get("ethernet_adapters"),
ram=request.json.get("ram"),
nvram=request.json.get("nvram")
)
vm.path = request.json.get("path", vm.path)
vm.iourc_path = request.json.get("iourc_path", vm.iourc_path)
@ -99,6 +103,11 @@ class IOUHandler:
vm.console = request.json.get("console", vm.console)
vm.path = request.json.get("path", vm.path)
vm.iourc_path = request.json.get("iourc_path", vm.iourc_path)
vm.ethernet_adapters = request.json.get("ethernet_adapters", vm.ethernet_adapters)
vm.serial_adapters = request.json.get("serial_adapters", vm.serial_adapters)
vm.ram = request.json.get("ram", vm.ram)
vm.nvram = request.json.get("nvram", vm.nvram)
response.json(vm)
@classmethod

View File

@ -55,11 +55,19 @@ class IOUVM(BaseVM):
:param manager: parent VM Manager
:param console: TCP console port
:params console_host: TCP console host IP
:params ethernet_adapters: Number of ethernet adapters
:params serial_adapters: Number of serial adapters
:params ram: Ram MB
:params nvram: Nvram KB
"""
def __init__(self, name, vm_id, project, manager,
console=None,
console_host="0.0.0.0"):
console_host="0.0.0.0",
ram=None,
nvram=None,
ethernet_adapters=None,
serial_adapters=None):
super().__init__(name, vm_id, project, manager)
@ -75,13 +83,14 @@ class IOUVM(BaseVM):
self._console_host = console_host
# IOU settings
self._ethernet_adapters = [EthernetAdapter(), EthernetAdapter()] # one adapter = 4 interfaces
self._serial_adapters = [SerialAdapter(), SerialAdapter()] # one adapter = 4 interfaces
self._slots = self._ethernet_adapters + self._serial_adapters
self._ethernet_adapters = []
self._serial_adapters = []
self.ethernet_adapters = 2 if ethernet_adapters is None else ethernet_adapters # one adapter = 4 interfaces
self.serial_adapters = 2 if serial_adapters is None else serial_adapters # one adapter = 4 interfaces
self._use_default_iou_values = True # for RAM & NVRAM values
self._nvram = 128 # Kilobytes
self._nvram = 128 if nvram is None else nvram # Kilobytes
self._initial_config = ""
self._ram = 256 # Megabytes
self._ram = 256 if ram is None else ram # Megabytes
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
if self._console is not None:
@ -193,7 +202,11 @@ class IOUVM(BaseVM):
"vm_id": self.id,
"console": self._console,
"project_id": self.project.id,
"path": self.path
"path": self.path,
"ethernet_adapters": len(self._ethernet_adapters),
"serial_adapters": len(self._serial_adapters),
"ram": self._ram,
"nvram": self._nvram
}
@property
@ -233,6 +246,57 @@ class IOUVM(BaseVM):
self._manager.port_manager.release_console_port(self._console)
self._console = self._manager.port_manager.reserve_console_port(console)
@property
def ram(self):
"""
Returns the amount of RAM allocated to this IOU instance.
:returns: amount of RAM in Mbytes (integer)
"""
return self._ram
@ram.setter
def ram(self, ram):
"""
Sets amount of RAM allocated to this IOU instance.
:param ram: amount of RAM in Mbytes (integer)
"""
if self._ram == ram:
return
log.info("IOU {name} [id={id}]: RAM updated from {old_ram}MB to {new_ram}MB".format(name=self._name,
id=self._id,
old_ram=self._ram,
new_ram=ram))
self._ram = ram
@property
def nvram(self):
"""
Returns the mount of NVRAM allocated to this IOU instance.
:returns: amount of NVRAM in Kbytes (integer)
"""
return self._nvram
@nvram.setter
def nvram(self, nvram):
"""
Sets amount of NVRAM allocated to this IOU instance.
:param nvram: amount of NVRAM in Kbytes (integer)
"""
if self._nvram == nvram:
return
log.info("IOU {name} [id={id}]: NVRAM updated from {old_nvram}KB to {new_nvram}KB".format(name=self._name,
id=self._id,
old_nvram=self._nvram,
new_nvram=nvram))
self._nvram = nvram
@property
def application_id(self):
return self._manager.get_application_id(self.id)
@ -571,3 +635,55 @@ class IOUVM(BaseVM):
self._ioucon_thread_stop_event = threading.Event()
self._ioucon_thread = threading.Thread(target=start_ioucon, args=(args, self._ioucon_thread_stop_event))
self._ioucon_thread.start()
@property
def ethernet_adapters(self):
"""
Returns the number of Ethernet adapters for this IOU instance.
:returns: number of adapters
"""
return len(self._ethernet_adapters)
@ethernet_adapters.setter
def ethernet_adapters(self, ethernet_adapters):
"""
Sets the number of Ethernet adapters for this IOU instance.
:param ethernet_adapters: number of adapters
"""
self._ethernet_adapters.clear()
for _ in range(0, ethernet_adapters):
self._ethernet_adapters.append(EthernetAdapter())
log.info("IOU {name} [id={id}]: number of Ethernet adapters changed to {adapters}".format(name=self._name,
id=self._id,
adapters=len(self._ethernet_adapters)))
self._slots = self._ethernet_adapters + self._serial_adapters
@property
def serial_adapters(self):
"""
Returns the number of Serial adapters for this IOU instance.
:returns: number of adapters
"""
return len(self._serial_adapters)
@serial_adapters.setter
def serial_adapters(self, serial_adapters):
"""
Sets the number of Serial adapters for this IOU instance.
:param serial_adapters: number of adapters
"""
self._serial_adapters.clear()
for _ in range(0, serial_adapters):
self._serial_adapters.append(SerialAdapter())
log.info("IOU {name} [id={id}]: number of Serial adapters changed to {adapters}".format(name=self._name,
id=self._id,
adapters=len(self._serial_adapters)))
self._slots = self._ethernet_adapters + self._serial_adapters

View File

@ -50,6 +50,22 @@ IOU_CREATE_SCHEMA = {
"description": "Path of iourc",
"type": "string"
},
"serial_adapters": {
"description": "How many serial adapters are connected to the IOU",
"type": "integer"
},
"ethernet_adapters": {
"description": "How many ethernet adapters are connected to the IOU",
"type": "integer"
},
"ram": {
"description": "Allocated RAM MB",
"type": ["integer", "null"]
},
"nvram": {
"description": "Allocated NVRAM KB",
"type": ["integer", "null"]
}
},
"additionalProperties": False,
"required": ["name", "path"]
@ -90,6 +106,14 @@ IOU_UPDATE_SCHEMA = {
"ethernet_adapters": {
"description": "How many ethernet adapters are connected to the IOU",
"type": ["integer", "null"]
},
"ram": {
"description": "Allocated RAM MB",
"type": ["integer", "null"]
},
"nvram": {
"description": "Allocated NVRAM KB",
"type": ["integer", "null"]
}
},
"additionalProperties": False,
@ -129,7 +153,23 @@ IOU_OBJECT_SCHEMA = {
"description": "Path of iou binary",
"type": "string"
},
"serial_adapters": {
"description": "How many serial adapters are connected to the IOU",
"type": "integer"
},
"ethernet_adapters": {
"description": "How many ethernet adapters are connected to the IOU",
"type": "integer"
},
"ram": {
"description": "Allocated RAM MB",
"type": "integer"
},
"nvram": {
"description": "Allocated NVRAM KB",
"type": "integer"
}
},
"additionalProperties": False,
"required": ["name", "vm_id", "console", "project_id", "path"]
"required": ["name", "vm_id", "console", "project_id", "path", "serial_adapters", "ethernet_adapters", "ram", "nvram"]
}

View File

@ -47,11 +47,33 @@ def vm(server, project, base_params):
def test_iou_create(server, project, base_params):
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), base_params, example=True)
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), base_params)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["serial_adapters"] == 2
assert response.json["ethernet_adapters"] == 2
assert response.json["ram"] == 256
assert response.json["nvram"] == 128
def test_iou_create_with_params(server, project, base_params):
params = base_params
params["ram"] = 1024
params["nvram"] = 512
params["serial_adapters"] = 4
params["ethernet_adapters"] = 0
response = server.post("/projects/{project_id}/iou/vms".format(project_id=project.id), params, example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/vms"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["serial_adapters"] == 4
assert response.json["ethernet_adapters"] == 0
assert response.json["ram"] == 1024
assert response.json["nvram"] == 512
def test_iou_get(server, project, vm):
@ -60,6 +82,10 @@ def test_iou_get(server, project, vm):
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["serial_adapters"] == 2
assert response.json["ethernet_adapters"] == 2
assert response.json["ram"] == 256
assert response.json["nvram"] == 128
def test_iou_start(server, vm):
@ -91,8 +117,19 @@ def test_iou_delete(server, vm):
def test_iou_update(server, vm, tmpdir, free_console_port):
response = server.put("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), {"name": "test",
"console": free_console_port})
params = {
"name": "test",
"console": free_console_port,
"ram": 512,
"nvram": 2048,
"ethernet_adapters": 4,
"serial_adapters": 0
}
response = server.put("/projects/{project_id}/iou/vms/{vm_id}".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), params)
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["console"] == free_console_port
assert response.json["ethernet_adapters"] == 4
assert response.json["serial_adapters"] == 0
assert response.json["ram"] == 512
assert response.json["nvram"] == 2048