Ejemplo n.º 1
0
static int
esxListNetworks(virConnectPtr conn, char **const names, int maxnames)
{
    bool success = false;
    esxPrivate *priv = conn->networkPrivateData;
    esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
    esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
    int count = 0;
    int i;

    if (maxnames == 0) {
        return 0;
    }

    if (esxVI_EnsureSession(priv->primary) < 0 ||
        esxVI_LookupHostVirtualSwitchList(priv->primary,
                                          &hostVirtualSwitchList) < 0) {
        return -1;
    }

    for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
         hostVirtualSwitch = hostVirtualSwitch->_next) {
        names[count] = strdup(hostVirtualSwitch->name);

        if (names[count] == NULL) {
            virReportOOMError();
            goto cleanup;
        }

        ++count;
    }

    success = true;

  cleanup:
    if (! success) {
        for (i = 0; i < count; ++i) {
            VIR_FREE(names[i]);
        }

        count = -1;
    }

    esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);

    return count;
}
Ejemplo n.º 2
0
static int
esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
{
    bool success = false;
    esxPrivate *priv = conn->privateData;
    esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
    esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
    int count = 0;
    size_t i;

    if (maxnames == 0)
        return 0;

    if (esxVI_EnsureSession(priv->primary) < 0 ||
        esxVI_LookupHostVirtualSwitchList(priv->primary,
                                          &hostVirtualSwitchList) < 0) {
        return -1;
    }

    for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch;
         hostVirtualSwitch = hostVirtualSwitch->_next) {
        if (VIR_STRDUP(names[count], hostVirtualSwitch->name) < 0)
            goto cleanup;

        ++count;
    }

    success = true;

 cleanup:
    if (! success) {
        for (i = 0; i < count; ++i)
            VIR_FREE(names[i]);

        count = -1;
    }

    esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);

    return count;
}
Ejemplo n.º 3
0
static int
esxNumberOfNetworks(virConnectPtr conn)
{
    esxPrivate *priv = conn->networkPrivateData;
    esxVI_HostVirtualSwitch *hostVirtualSwitchList = NULL;
    esxVI_HostVirtualSwitch *hostVirtualSwitch = NULL;
    int count = 0;

    if (esxVI_EnsureSession(priv->primary) < 0 ||
        esxVI_LookupHostVirtualSwitchList(priv->primary,
                                          &hostVirtualSwitchList) < 0) {
        return -1;
    }

    for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL;
         hostVirtualSwitch = hostVirtualSwitch->_next) {
        ++count;
    }

    esxVI_HostVirtualSwitch_Free(&hostVirtualSwitchList);

    return count;
}