mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh-network: Introduce virshNetworkEventCallback to handle network events
Signed-off-by: Lin Ma <lma@suse.com>
This commit is contained in:
parent
ab8aa7ccc8
commit
96837ab140
@ -1156,6 +1156,7 @@ struct virshNetEventData {
|
|||||||
bool loop;
|
bool loop;
|
||||||
bool timestamp;
|
bool timestamp;
|
||||||
int count;
|
int count;
|
||||||
|
virshNetworkEventCallback *cb;
|
||||||
};
|
};
|
||||||
typedef struct virshNetEventData virshNetEventData;
|
typedef struct virshNetEventData virshNetEventData;
|
||||||
|
|
||||||
@ -1195,6 +1196,12 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
vshEventDone(data->ctl);
|
vshEventDone(data->ctl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virshNetworkEventCallback virshNetworkEventCallbacks[] = {
|
||||||
|
{ "lifecycle",
|
||||||
|
VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint), },
|
||||||
|
};
|
||||||
|
verify(VIR_NETWORK_EVENT_ID_LAST == ARRAY_CARDINALITY(virshNetworkEventCallbacks));
|
||||||
|
|
||||||
static const vshCmdInfo info_network_event[] = {
|
static const vshCmdInfo info_network_event[] = {
|
||||||
{.name = "help",
|
{.name = "help",
|
||||||
.data = N_("Network Events")
|
.data = N_("Network Events")
|
||||||
@ -1246,7 +1253,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
|
for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
|
||||||
vshPrint(ctl, "%s\n", virshNetworkEventIdTypeToString(i));
|
vshPrint(ctl, "%s\n", virshNetworkEventCallbacks[i].name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1256,7 +1263,10 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshError(ctl, "%s", _("either --list or --event <type> is required"));
|
vshError(ctl, "%s", _("either --list or --event <type> is required"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ((event = virshNetworkEventIdTypeFromString(eventName)) < 0) {
|
for (event = 0; event < VIR_NETWORK_EVENT_ID_LAST; event++)
|
||||||
|
if (STREQ(eventName, virshNetworkEventCallbacks[event].name))
|
||||||
|
break;
|
||||||
|
if (event == VIR_NETWORK_EVENT_ID_LAST) {
|
||||||
vshError(ctl, _("unknown event type %s"), eventName);
|
vshError(ctl, _("unknown event type %s"), eventName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1265,6 +1275,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
data.loop = vshCommandOptBool(cmd, "loop");
|
data.loop = vshCommandOptBool(cmd, "loop");
|
||||||
data.timestamp = vshCommandOptBool(cmd, "timestamp");
|
data.timestamp = vshCommandOptBool(cmd, "timestamp");
|
||||||
data.count = 0;
|
data.count = 0;
|
||||||
|
data.cb = &virshNetworkEventCallbacks[event];
|
||||||
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1274,7 +1285,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((eventId = virConnectNetworkEventRegisterAny(priv->conn, net, event,
|
if ((eventId = virConnectNetworkEventRegisterAny(priv->conn, net, event,
|
||||||
VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint),
|
data.cb->cb,
|
||||||
&data, NULL)) < 0)
|
&data, NULL)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
switch (vshEventWait(ctl)) {
|
switch (vshEventWait(ctl)) {
|
||||||
|
@ -32,6 +32,14 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
virshCommandOptNetworkBy(_ctl, _cmd, _name, \
|
virshCommandOptNetworkBy(_ctl, _cmd, _name, \
|
||||||
VIRSH_BYUUID | VIRSH_BYNAME)
|
VIRSH_BYUUID | VIRSH_BYNAME)
|
||||||
|
|
||||||
|
struct virshNetworkEventCallback {
|
||||||
|
const char *name;
|
||||||
|
virConnectNetworkEventGenericCallback cb;
|
||||||
|
};
|
||||||
|
typedef struct virshNetworkEventCallback virshNetworkEventCallback;
|
||||||
|
|
||||||
|
extern virshNetworkEventCallback virshNetworkEventCallbacks[];
|
||||||
|
|
||||||
extern const vshCmdDef networkCmds[];
|
extern const vshCmdDef networkCmds[];
|
||||||
|
|
||||||
#endif /* LIBVIRT_VIRSH_NETWORK_H */
|
#endif /* LIBVIRT_VIRSH_NETWORK_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user