提交 b8fa5fd0 编写于 作者: M Matthias Bolte

esx: Implement network driver

An ESX server has one or more PhysicalNics that represent the actual
hardware NICs. Those can be listed via the interface driver.

A libvirt virtual network is mapped to a HostVirtualSwitch. On the
physical side a HostVirtualSwitch can be connected to PhysicalNics.
On the virtual side a HostVirtualSwitch has HostPortGroups that are
mapped to libvirt virtual network's portgroups. Typically there is
HostPortGroups named 'VM Network' that is used to connect virtual
machines to a HostVirtualSwitch. A second HostPortGroup typically
named 'Management Network' is used to connect the hypervisor itself
to the HostVirtualSwitch. This one is not mapped to a libvirt virtual
network's portgroup. There can be more HostPortGroups than those
typical two on a HostVirtualSwitch.

         +---------------+-------------------+
   ...---|               |                   |   +-------------+
         | HostPortGroup |                   |---| PhysicalNic |
         |   VM Network  |                   |   |    vmnic0   |
   ...---|               |                   |   +-------------+
         +---------------+ HostVirtualSwitch |
                         |     vSwitch0      |
         +---------------+                   |
         | HostPortGroup |                   |
   ...---|   Management  |                   |
         |    Network    |                   |
         +---------------+-------------------+

The virtual counterparts of the PhysicalNic is the HostVirtualNic for
the hypervisor and the VirtualEthernetCard for the virtual machines
that are grouped into HostPortGroups.

   +---------------------+   +---------------+---...
   | VirtualEthernetCard |---|               |
   +---------------------+   | HostPortGroup |
   +---------------------+   |   VM Network  |
   | VirtualEthernetCard |---|               |
   +---------------------+   +---------------+
                                             |
                             +---------------+
   +---------------------+   | HostPortGroup |
   |    HostVirtualNic   |---|   Management  |
   +---------------------+   |    Network    |
                             +---------------+---...

The currently implemented network driver can list, define and undefine
HostVirtualSwitches including HostPortGroups for virtual machines.
Existing HostVirtualSwitches cannot be edited yet. This will be added
in a followup patch.
上级 ba86e5cd
......@@ -27,6 +27,7 @@ src/cpu/cpu_x86.c
src/datatypes.c
src/driver.c
src/esx/esx_driver.c
src/esx/esx_network_driver.c
src/esx/esx_storage_driver.c
src/esx/esx_util.c
src/esx/esx_vi.c
......
......@@ -47,8 +47,6 @@
#define MAX_BRIDGE_ID 256
#define VIR_FROM_THIS VIR_FROM_NETWORK
VIR_ENUM_DECL(virNetworkForward)
VIR_ENUM_IMPL(virNetworkForward,
VIR_NETWORK_FORWARD_LAST,
"none", "nat", "route", "bridge", "private", "vepa", "passthrough" )
......@@ -967,6 +965,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
}
VIR_FREE(tmp);
def->uuid_specified = true;
}
/* Parse network domain information */
......
......@@ -148,6 +148,7 @@ typedef struct _virNetworkDef virNetworkDef;
typedef virNetworkDef *virNetworkDefPtr;
struct _virNetworkDef {
unsigned char uuid[VIR_UUID_BUFLEN];
bool uuid_specified;
char *name;
char *bridge; /* Name of bridge device */
......@@ -289,4 +290,6 @@ int virNetworkObjIsDuplicate(virNetworkObjListPtr doms,
void virNetworkObjLock(virNetworkObjPtr obj);
void virNetworkObjUnlock(virNetworkObjPtr obj);
VIR_ENUM_DECL(virNetworkForward)
#endif /* __NETWORK_CONF_H__ */
此差异已折叠。
......@@ -783,6 +783,7 @@ ESX_VI__TEMPLATE__FREE(Context,
esxVI_SelectionSpec_Free(&item->selectSet_hostSystemToDatastore);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToHost);
esxVI_SelectionSpec_Free(&item->selectSet_computeResourceToParentToParent);
esxVI_SelectionSpec_Free(&item->selectSet_datacenterToNetwork);
})
int
......@@ -1927,6 +1928,13 @@ esxVI_BuildSelectSetCollection(esxVI_Context *ctx)
return -1;
}
/* Datacenter -> network (Network) */
if (esxVI_BuildSelectSet(&ctx->selectSet_datacenterToNetwork,
"datacenterToNetwork",
"Datacenter", "network", NULL) < 0) {
return -1;
}
return 0;
}
......@@ -2094,6 +2102,15 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
type, root->type);
goto cleanup;
}
} else if (STREQ(root->type, "Datacenter")) {
if (STREQ(type, "Network")) {
objectSpec->selectSet = ctx->selectSet_datacenterToNetwork;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid lookup of '%s' from '%s'"),
type, root->type);
goto cleanup;
}
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid lookup from '%s'"), root->type);
......@@ -4090,6 +4107,160 @@ esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
int
esxVI_LookupHostVirtualSwitchList(esxVI_Context *ctx,
esxVI_HostVirtualSwitch **hostVirtualSwitchList)
{
int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
if (hostVirtualSwitchList == NULL || *hostVirtualSwitchList != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
"config.network.vswitch") < 0 ||
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
&hostSystem) < 0) {
goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "config.network.vswitch")) {
if (esxVI_HostVirtualSwitch_CastListFromAnyType
(dynamicProperty->val, hostVirtualSwitchList) < 0) {
goto cleanup;
}
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
}
}
result = 0;
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return result;
}
int
esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
esxVI_HostVirtualSwitch **hostVirtualSwitch,
esxVI_Occurrence occurrence)
{
int result = -1;
esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
esxVI_HostVirtualSwitch *candidate = NULL;
if (hostVirtualSwitch == NULL || *hostVirtualSwitch != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
if (esxVI_LookupHostVirtualSwitchList(ctx, &hostVirtualSwitchList) < 0) {
goto cleanup;
}
/* Search for a matching HostVirtualSwitch */
for (candidate = hostVirtualSwitchList; candidate != NULL;
candidate = candidate->_next) {
if (STREQ(candidate->name, name)) {
if (esxVI_HostVirtualSwitch_DeepCopy(hostVirtualSwitch,
candidate) < 0) {
goto cleanup;
}
/* Found HostVirtualSwitch with matching name */
result = 0;
goto cleanup;
}
}
if (*hostVirtualSwitch == NULL &&
occurrence != esxVI_Occurrence_OptionalItem) {
virReportError(VIR_ERR_NO_NETWORK,
_("Could not find HostVirtualSwitch with name '%s'"),
name);
goto cleanup;
}
result = 0;
cleanup:
esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);
return result;
}
int
esxVI_LookupHostPortGroupList(esxVI_Context *ctx,
esxVI_HostPortGroup **hostPortGroupList)
{
int result = -1;
esxVI_String *propertyNameList = NULL;
esxVI_ObjectContent *hostSystem = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL;
if (hostPortGroupList == NULL || *hostPortGroupList != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
return -1;
}
if (esxVI_String_AppendValueToList(&propertyNameList,
"config.network.portgroup") < 0 ||
esxVI_LookupHostSystemProperties(ctx, propertyNameList,
&hostSystem) < 0) {
goto cleanup;
}
for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "config.network.portgroup")) {
if (esxVI_HostPortGroup_CastListFromAnyType
(dynamicProperty->val, hostPortGroupList) < 0) {
goto cleanup;
}
break;
} else {
VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
}
}
result = 0;
cleanup:
esxVI_String_Free(&propertyNameList);
esxVI_ObjectContent_Free(&hostSystem);
return result;
}
int
esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
esxVI_ObjectContent **networkList)
{
return esxVI_LookupObjectContentByType(ctx, ctx->datacenter->_reference,
"Network", propertyNameList,
networkList,
esxVI_Occurrence_OptionalList);
}
int
esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
......
......@@ -227,6 +227,7 @@ struct _esxVI_Context {
esxVI_SelectionSpec *selectSet_hostSystemToDatastore;
esxVI_SelectionSpec *selectSet_computeResourceToHost;
esxVI_SelectionSpec *selectSet_computeResourceToParentToParent;
esxVI_SelectionSpec *selectSet_datacenterToNetwork;
bool hasQueryVirtualDiskUuid;
bool hasSessionIsActive;
};
......@@ -492,6 +493,19 @@ int esxVI_LookupPhysicalNicByMACAddress(esxVI_Context *ctx, const char *mac,
esxVI_PhysicalNic **physicalNic,
esxVI_Occurrence occurrence);
int esxVI_LookupHostVirtualSwitchList
(esxVI_Context *ctx, esxVI_HostVirtualSwitch **hostVirtualSwitchList);
int esxVI_LookupHostVirtualSwitchByName(esxVI_Context *ctx, const char *name,
esxVI_HostVirtualSwitch **hostVirtualSwitch,
esxVI_Occurrence occurrence);
int esxVI_LookupHostPortGroupList(esxVI_Context *ctx,
esxVI_HostPortGroup **hostPortGroupList);
int esxVI_LookupNetworkList(esxVI_Context *ctx, esxVI_String *propertyNameList,
esxVI_ObjectContent **networkList);
int esxVI_HandleVirtualMachineQuestion
(esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
esxVI_VirtualMachineQuestionInfo *questionInfo, bool autoAnswer,
......
......@@ -338,12 +338,138 @@ object HostNasVolume extends HostFileSystemVolume
end
object HostNetOffloadCapabilities
Boolean csumOffload o
Boolean tcpSegmentation o
Boolean zeroCopyXmit o
end
object HostNetworkPolicy
HostNetworkSecurityPolicy security o
HostNicTeamingPolicy nicTeaming o
HostNetOffloadCapabilities offloadPolicy o
HostNetworkTrafficShapingPolicy shapingPolicy o
end
object HostNetworkSecurityPolicy
Boolean allowPromiscuous o
Boolean macChanges o
Boolean forgedTransmits o
end
object HostNetworkTrafficShapingPolicy
Boolean enabled o
Long averageBandwidth o
Long peakBandwidth o
Long burstSize o
end
object HostNicFailureCriteria
String checkSpeed o
Int speed o
Boolean checkDuplex o
Boolean fullDuplex o
Boolean checkErrorPercent o
Int percentage o
Boolean checkBeacon o
end
object HostNicOrderPolicy
String activeNic ol
String standbyNic ol
end
object HostNicTeamingPolicy
String policy o
Boolean reversePolicy o
Boolean notifySwitches o
Boolean rollingOrder o
HostNicFailureCriteria failureCriteria o
HostNicOrderPolicy nicOrder o
end
object HostPortGroup
String key o
HostPortGroupPort port ol
String vswitch o
HostNetworkPolicy computedPolicy r
HostPortGroupSpec spec r
end
object HostPortGroupPort
String key o
String mac ol
String type r
end
object HostPortGroupSpec
String name r
Int vlanId r
String vswitchName r
HostNetworkPolicy policy r
end
object HostScsiDiskPartition
String diskName r
Int partition r
end
object HostVirtualSwitch
String name r
String key r
Int numPorts r
Int numPortsAvailable r
Int mtu o
String portgroup ol
String pnic ol
HostVirtualSwitchSpec spec r
end
object HostVirtualSwitchAutoBridge extends HostVirtualSwitchBridge
String excludedNicDevice ol
end
object HostVirtualSwitchBeaconConfig
Int interval r
end
object HostVirtualSwitchBondBridge extends HostVirtualSwitchBridge
String nicDevice rl
HostVirtualSwitchBeaconConfig beacon o
end
object HostVirtualSwitchBridge
end
object HostVirtualSwitchSimpleBridge extends HostVirtualSwitchBridge
String nicDevice r
end
object HostVirtualSwitchSpec
Int numPorts r
HostVirtualSwitchBridge bridge o
HostNetworkPolicy policy o
Int mtu o
end
object HostVmfsVolume extends HostFileSystemVolume
Int blockSizeMb r
Int maxBlocks r
......@@ -805,6 +931,19 @@ end
# Methods
#
method AddPortGroup
ManagedObjectReference _this r
HostPortGroupSpec portgrp r
end
method AddVirtualSwitch
ManagedObjectReference _this r
String vswitchName r
HostVirtualSwitchSpec spec o
end
method AnswerVM
ManagedObjectReference _this r
String questionId r
......@@ -981,12 +1120,24 @@ method RegisterVM_Task returns ManagedObjectReference r
end
method RemovePortGroup
ManagedObjectReference _this r
String pgName r
end
method RemoveSnapshot_Task returns ManagedObjectReference r
ManagedObjectReference _this r
Boolean removeChildren r
end
method RemoveVirtualSwitch
ManagedObjectReference _this r
String vswitchName r
end
method RetrieveProperties returns ObjectContent ol
ManagedObjectReference _this:propertyCollector r
PropertyFilterSpec specSet rl
......
......@@ -1520,6 +1520,11 @@ additional_object_features = { "AutoStartDefaults" : Object.FEATURE__AN
Object.FEATURE__ANY_TYPE,
"HostDatastoreBrowserSearchResults" : Object.FEATURE__LIST |
Object.FEATURE__ANY_TYPE,
"HostPortGroup" : Object.FEATURE__LIST |
Object.FEATURE__ANY_TYPE,
"HostVirtualSwitch" : Object.FEATURE__DEEP_COPY |
Object.FEATURE__LIST |
Object.FEATURE__ANY_TYPE,
"ManagedObjectReference" : Object.FEATURE__ANY_TYPE,
"ObjectContent" : Object.FEATURE__DEEP_COPY,
"PhysicalNic" : Object.FEATURE__DEEP_COPY |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册