mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00:00
Move code for exposing VM ip to the VM itself. And display VM starting status
Fix #1621
This commit is contained in:
parent
fd911542f7
commit
620de3ff25
@ -84,13 +84,10 @@ class Compute:
|
||||
self._id = compute_id
|
||||
|
||||
self.protocol = protocol
|
||||
self._console_host = console_host
|
||||
self.host = host
|
||||
self.port = port
|
||||
self._user = None
|
||||
if console_host is None:
|
||||
self._console_host = host
|
||||
else:
|
||||
self._console_host = console_host
|
||||
self._password = None
|
||||
self._connected = False
|
||||
self._closed = False # Close mean we are destroying the compute node
|
||||
@ -217,6 +214,8 @@ class Compute:
|
||||
@host.setter
|
||||
def host(self, host):
|
||||
self._host = host
|
||||
if self._console_host is None:
|
||||
self._console_host = host
|
||||
|
||||
@property
|
||||
def console_host(self):
|
||||
|
@ -263,15 +263,22 @@ class GNS3VM:
|
||||
engine.vmname = self._settings["vmname"]
|
||||
engine.ram = self._settings["ram"]
|
||||
engine.vpcus = self._settings["vcpus"]
|
||||
yield from engine.start()
|
||||
yield from self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM ({})".format(engine.vmname),
|
||||
protocol=self.protocol,
|
||||
host=self.ip_address,
|
||||
port=self.port,
|
||||
user=self.user,
|
||||
password=self.password,
|
||||
force=True)
|
||||
compute = yield from self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
host=None,
|
||||
force=True)
|
||||
|
||||
try:
|
||||
yield from engine.start()
|
||||
except Exception as e:
|
||||
yield from self._controller.delete_compute("vm")
|
||||
raise e
|
||||
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname),
|
||||
protocol=self.protocol,
|
||||
host=self.ip_address,
|
||||
port=self.port,
|
||||
user=self.user,
|
||||
password=self.password)
|
||||
|
||||
@locked_coroutine
|
||||
def _suspend(self):
|
||||
|
@ -29,7 +29,6 @@ import argparse
|
||||
import shutil
|
||||
import psutil
|
||||
import asyncio
|
||||
import subprocess
|
||||
|
||||
|
||||
from gns3server.web.web_server import WebServer
|
||||
@ -201,29 +200,6 @@ def kill_ghosts():
|
||||
pass
|
||||
|
||||
|
||||
def set_vmware_gns3vm_ip():
|
||||
"""
|
||||
For the GNS3 VM on VMware we need to get the ip of eth0.
|
||||
vmrun getGuestIPAddress is not reliable because it's return a
|
||||
random ip from one of the available interfaces.
|
||||
|
||||
We need to set a VMware variable with the value and this
|
||||
will allow the VM host machine to retrieve it
|
||||
"""
|
||||
vmtoolsd = shutil.which("vmtoolsd")
|
||||
if not vmtoolsd:
|
||||
return
|
||||
ip = None
|
||||
try:
|
||||
for a in psutil.net_if_addrs()["eth0"]:
|
||||
if ":" not in a.address:
|
||||
ip = a.address
|
||||
except (KeyError, IndexError):
|
||||
return
|
||||
if ip:
|
||||
subprocess.call(["vmtoolsd", "--cmd", "info-set guestinfo.gns3.eth0 {}".format(ip)])
|
||||
|
||||
|
||||
def run():
|
||||
args = parse_arguments(sys.argv[1:])
|
||||
|
||||
@ -247,8 +223,6 @@ def run():
|
||||
for config_file in Config.instance().get_config_files():
|
||||
user_log.info("Config file {} loaded".format(config_file))
|
||||
|
||||
set_vmware_gns3vm_ip()
|
||||
|
||||
set_config(args)
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user