提交 ea5805ed 编写于 作者: D Doug Goldstein

VMware: Convert driver type defines to enum

The VMware driver supports multiple backends for the VMware Player and
VMware Workstation, convert this logic into enum and use VIR_ENUM_IMPL()
to provide conversions to and from strings.
上级 5b36ab90
......@@ -35,6 +35,10 @@
#include "vmware_conf.h"
#include "virstring.h"
VIR_ENUM_IMPL(vmwareDriver, VMWARE_DRIVER_LAST,
"player",
"ws");
/* Free all memory associated with a vmware_driver structure */
void
vmwareFreeDriver(struct vmware_driver *driver)
......@@ -141,7 +145,7 @@ vmwareLoadDomains(struct vmware_driver *driver)
ctx.parseFileName = vmwareCopyVMXFileName;
cmd = virCommandNewArgList(VMRUN, "-T",
driver->type == TYPE_PLAYER ? "player" : "ws",
vmwareDriverTypeToString(driver->type),
"list", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0)
......@@ -221,8 +225,9 @@ vmwareExtractVersion(struct vmware_driver *driver)
int ret = -1;
virCommandPtr cmd;
char * outbuf = NULL;
const char * bin = (driver->type == TYPE_PLAYER) ? "vmplayer" : "vmware";
const char * pattern = (driver->type == TYPE_PLAYER) ?
const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ?
"vmplayer" : "vmware";
const char * pattern = (driver->type == VMWARE_DRIVER_PLAYER) ?
"VMware Player " : "VMware Workstation ";
cmd = virCommandNewArgList(bin, "-v", NULL);
......
/*---------------------------------------------------------------------------*/
/* Copyright 2010, diateam (www.diateam.net)
* Copyright (c) 2013, Doug Goldstein (cardoe@cardoe.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -30,8 +31,14 @@
# define VIR_FROM_THIS VIR_FROM_VMWARE
# define PROGRAM_SENTINEL ((char *)0x1)
# define TYPE_PLAYER 0
# define TYPE_WORKSTATION 1
enum vmwareDriverType {
VMWARE_DRIVER_PLAYER = 0, /* VMware Player */
VMWARE_DRIVER_WORKSTATION = 1, /* VMware Workstation */
VMWARE_DRIVER_LAST, /* required last item */
};
VIR_ENUM_DECL(vmwareDriver)
struct vmware_driver {
virMutex lock;
......
......@@ -35,8 +35,6 @@
#include "vmware_driver.h"
#include "virstring.h"
static const char *vmw_types[] = { "player", "ws" };
static void
vmwareDriverLock(struct vmware_driver *driver)
{
......@@ -133,7 +131,7 @@ vmwareConnectOpen(virConnectPtr conn,
goto cleanup;
driver->type = STRNEQ(conn->uri->scheme, "vmwareplayer") ?
TYPE_WORKSTATION : TYPE_PLAYER;
VMWARE_DRIVER_WORKSTATION : VMWARE_DRIVER_PLAYER;
if (!(driver->domains = virDomainObjListNew()))
goto cleanup;
......@@ -202,7 +200,8 @@ vmwareUpdateVMStatus(struct vmware_driver *driver, virDomainObjPtr vm)
int newState;
int ret = -1;
cmd = virCommandNewArgList(VMRUN, "-T", vmw_types[driver->type],
cmd = virCommandNewArgList(VMRUN, "-T",
vmwareDriverTypeToString(driver->type),
"list", NULL);
virCommandSetOutputBuffer(cmd, &outbuf);
if (virCommandRun(cmd, NULL) < 0)
......@@ -256,7 +255,7 @@ vmwareStopVM(struct vmware_driver *driver,
PROGRAM_SENTINEL, "soft", NULL
};
vmwareSetSentinal(cmd, vmw_types[driver->type]);
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
if (virRun(cmd, NULL) < 0) {
......@@ -284,7 +283,7 @@ vmwareStartVM(struct vmware_driver *driver, virDomainObjPtr vm)
return -1;
}
vmwareSetSentinal(cmd, vmw_types[driver->type]);
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, vmxPath);
if (!((vmwareDomainPtr) vm->privateData)->gui)
vmwareSetSentinal(cmd, NOGUI);
......@@ -451,7 +450,7 @@ vmwareDomainSuspend(virDomainPtr dom)
};
int ret = -1;
if (driver->type == TYPE_PLAYER) {
if (driver->type == VMWARE_DRIVER_PLAYER) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("vmplayer does not support libvirt suspend/resume"
" (vmware pause/unpause) operation "));
......@@ -468,7 +467,7 @@ vmwareDomainSuspend(virDomainPtr dom)
goto cleanup;
}
vmwareSetSentinal(cmd, vmw_types[driver->type]);
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -500,7 +499,7 @@ vmwareDomainResume(virDomainPtr dom)
};
int ret = -1;
if (driver->type == TYPE_PLAYER) {
if (driver->type == VMWARE_DRIVER_PLAYER) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("vmplayer does not support libvirt suspend/resume "
"(vmware pause/unpause) operation "));
......@@ -517,7 +516,7 @@ vmwareDomainResume(virDomainPtr dom)
goto cleanup;
}
vmwareSetSentinal(cmd, vmw_types[driver->type]);
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, ((vmwareDomainPtr) vm->privateData)->vmxPath);
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PAUSED) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -562,7 +561,7 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags)
}
vmxPath = ((vmwareDomainPtr) vm->privateData)->vmxPath;
vmwareSetSentinal(cmd, vmw_types[driver->type]);
vmwareSetSentinal(cmd, vmwareDriverTypeToString(driver->type));
vmwareSetSentinal(cmd, vmxPath);
if (vmwareUpdateVMStatus(driver, vm) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册