mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
List all available VMware VMs.
This commit is contained in:
1 parent
57f5e7a7d9
commit
a260377f0e
4 files changed
+56
-14
No files matched your search
@@ -41,7 +41,7 @@ class VMware(BaseManager):
|
||||
|
||||
super().__init__()
|
||||
self._vmrun_path = None
|
||||
self._host_type = "player"
|
||||
self._default_vm_path = "/home/grossmj/vmware"
|
||||
|
||||
@property
|
||||
def vmrun_path(self):
|
||||
@@ -84,7 +84,10 @@ class VMware(BaseManager):
|
||||
if not vmrun_path:
|
||||
vmrun_path = self.find_vmrun()
|
||||
if host_type is None:
|
||||
host_type = self._host_type
|
||||
if sys.platform.startswith("darwin"):
|
||||
host_type = "fusion"
|
||||
else:
|
||||
host_type = self.config.get_section_config("VMware").get("host_type", "ws")
|
||||
command = [vmrun_path, "-T", host_type, subcommand]
|
||||
command.extend(args)
|
||||
log.debug("Executing vmrun with command: {}".format(command))
|
||||
@@ -104,3 +107,26 @@ class VMware(BaseManager):
|
||||
raise VMwareError("vmrun has returned an error: {}".format(vmrun_error))
|
||||
|
||||
return stdout_data.decode("utf-8", errors="ignore").splitlines()
|
||||
|
||||
def list_vms(self):
|
||||
"""
|
||||
Gets VMware VM list.
|
||||
"""
|
||||
|
||||
vms = []
|
||||
for path, _, filenames in os.walk(os.path.expanduser("~/vmware")):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1] == ".vmx":
|
||||
vmx_path = os.path.join(path, filename)
|
||||
try:
|
||||
with open(vmx_path, encoding="utf-8") as f:
|
||||
for line in f.read().splitlines():
|
||||
name, value = line.split('=', 1)
|
||||
if name.strip() == "displayName":
|
||||
vmname = value.strip('" ')
|
||||
vms.append({"vmname": vmname, "vmx_path": vmx_path})
|
||||
break
|
||||
except (OSError, ValueError) as e:
|
||||
log.warning("Could not read VMware vmx file {}: {}".format(vmx_path, e))
|
||||
continue
|
||||
return vms
|
||||
@@ -16,7 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Custom exceptions for the VirtualBox module.
|
||||
Custom exceptions for the VMware module.
|
||||
"""
|
||||
|
||||
from ..vm_error import VMError
|
||||
|
||||
@@ -99,8 +99,8 @@ class VMwareVM(BaseVM):
|
||||
Suspends this VMware VM.
|
||||
"""
|
||||
|
||||
yield from self._control_vm("suspend")
|
||||
log.info("VMware VM '{name}' [{id}] stopped".format(name=self.name, id=self.id))
|
||||
yield from self._control_vm("pause")
|
||||
log.info("VMware VM '{name}' [{id}] paused".format(name=self.name, id=self.id))
|
||||
|
||||
@asyncio.coroutine
|
||||
def resume(self):
|
||||
@@ -108,7 +108,7 @@ class VMwareVM(BaseVM):
|
||||
Resumes this VMware VM.
|
||||
"""
|
||||
|
||||
yield from self.start()
|
||||
yield from self._control_vm("unpause")
|
||||
log.info("VMware VM '{name}' [{id}] resumed".format(name=self.name, id=self.id))
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -141,7 +141,10 @@ class VMwareVM(BaseVM):
|
||||
# if nio and isinstance(nio, NIOUDP):
|
||||
# self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
|
||||
yield from self.stop()
|
||||
try:
|
||||
yield from self.stop()
|
||||
except VMwareError:
|
||||
pass
|
||||
|
||||
log.info("VirtualBox VM '{name}' [{id}] closed".format(name=self.name, id=self.id))
|
||||
self._closed = True
|
||||
|
||||
Reference in new issue
Block a user