1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Support for NAT connection with cloud for VMware VMs. Fixes #322.

This commit is contained in:
grossmj 2015-10-12 17:07:39 -06:00
parent b53f0e89ce
commit 57bbd63085
2 changed files with 20 additions and 14 deletions

View File

@ -271,7 +271,7 @@ class VMwareHandler:
vmware_manager = VMware.instance()
vm = vmware_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
nio_type = request.json["type"]
if nio_type not in ("nio_udp", "nio_vmnet"):
if nio_type not in ("nio_udp", "nio_vmnet", "nio_nat"):
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
nio = vmware_manager.create_nio(None, request.json)
yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)

View File

@ -31,6 +31,7 @@ from gns3server.utils.asyncio import wait_for_file_creation
from collections import OrderedDict
from .vmware_error import VMwareError
from ..nios.nio_udp import NIOUDP
from ..nios.nio_nat import NIONAT
from .nio_vmnet import NIOVMNET
from ..adapters.ethernet_adapter import EthernetAdapter
from ..base_vm import BaseVM
@ -269,7 +270,7 @@ class VMwareVM(BaseVM):
vnet = "ethernet{}.vnet".format(adapter_number)
if vnet in self._vmx_pairs:
vmnet = os.path.basename(self._vmx_pairs[vnet])
if self.manager.is_managed_vmnet(vmnet):
if self.manager.is_managed_vmnet(vmnet) or vmnet == "vmnet0":
# vmnet already managed, try to allocate a new one
allocate_vmnet = True
else:
@ -799,9 +800,14 @@ class VMwareVM(BaseVM):
adapter_number=adapter_number))
self._read_vmx_file()
# check if trying to connect to a nat, bridged or host-only adapter
if self._ethernet_adapters[adapter_number].get_nio(0) and not self._use_any_adapter:
if self._get_vmx_setting("ethernet{}.present".format(adapter_number), "TRUE"):
if isinstance(nio, NIONAT):
if self._started:
raise VMwareError("Sorry, adding a link to NAT for a started VMware VM is not supported")
self._vmx_pairs["ethernet{}.connectiontype".format(adapter_number)] = "nat"
self._write_vmx_file()
else:
# check if trying to connect to a nat, bridged or host-only adapter
if not self._use_any_adapter and self._get_vmx_setting("ethernet{}.present".format(adapter_number), "TRUE"):
# check for the connection type
connection_type = "ethernet{}.connectiontype".format(adapter_number)
if connection_type in self._vmx_pairs and self._vmx_pairs[connection_type] in ("nat", "bridged", "hostonly"):
@ -809,15 +815,15 @@ class VMwareVM(BaseVM):
"Please remove it or allow GNS3 to use any adapter.".format(self._vmx_pairs[connection_type],
adapter_number))
if isinstance(nio, NIOVMNET):
if self._started:
raise VMwareError("Sorry, adding a link to a started VMware VM is not supported without uBridge enabled")
self._vmx_pairs["ethernet{}.vnet".format(adapter_number)] = nio.vmnet
self._write_vmx_file()
self._vmnets.append(nio.vmnet)
adapter.add_nio(0, nio)
if self._started and self._use_ubridge:
yield from self._add_ubridge_connection(nio, adapter_number)
if isinstance(nio, NIOVMNET):
if self._started:
raise VMwareError("Sorry, adding a link to a started VMware VM is not supported without uBridge enabled")
self._vmx_pairs["ethernet{}.vnet".format(adapter_number)] = nio.vmnet
self._write_vmx_file()
self._vmnets.append(nio.vmnet)
adapter.add_nio(0, nio)
if self._started and self._use_ubridge:
yield from self._add_ubridge_connection(nio, adapter_number)
log.info("VMware VM '{name}' [{id}]: {nio} added to adapter {adapter_number}".format(name=self.name,
id=self.id,