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

pull/370/head
grossmj 9 years ago
parent b53f0e89ce
commit 57bbd63085

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

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

Loading…
Cancel
Save