mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00: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 timestamp;
|
||||
int count;
|
||||
virshNetworkEventCallback *cb;
|
||||
};
|
||||
typedef struct virshNetEventData virshNetEventData;
|
||||
|
||||
@ -1195,6 +1196,12 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
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[] = {
|
||||
{.name = "help",
|
||||
.data = N_("Network Events")
|
||||
@ -1246,7 +1253,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
size_t 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;
|
||||
}
|
||||
|
||||
@ -1256,7 +1263,10 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
vshError(ctl, "%s", _("either --list or --event <type> is required"));
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
@ -1265,6 +1275,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
data.loop = vshCommandOptBool(cmd, "loop");
|
||||
data.timestamp = vshCommandOptBool(cmd, "timestamp");
|
||||
data.count = 0;
|
||||
data.cb = &virshNetworkEventCallbacks[event];
|
||||
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
|
||||
return false;
|
||||
|
||||
@ -1274,7 +1285,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
|
||||
if ((eventId = virConnectNetworkEventRegisterAny(priv->conn, net, event,
|
||||
VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint),
|
||||
data.cb->cb,
|
||||
&data, NULL)) < 0)
|
||||
goto cleanup;
|
||||
switch (vshEventWait(ctl)) {
|
||||
|
@ -32,6 +32,14 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
|
||||
virshCommandOptNetworkBy(_ctl, _cmd, _name, \
|
||||
VIRSH_BYUUID | VIRSH_BYNAME)
|
||||
|
||||
struct virshNetworkEventCallback {
|
||||
const char *name;
|
||||
virConnectNetworkEventGenericCallback cb;
|
||||
};
|
||||
typedef struct virshNetworkEventCallback virshNetworkEventCallback;
|
||||
|
||||
extern virshNetworkEventCallback virshNetworkEventCallbacks[];
|
||||
|
||||
extern const vshCmdDef networkCmds[];
|
||||
|
||||
#endif /* LIBVIRT_VIRSH_NETWORK_H */
|
||||
|
Loading…
Reference in New Issue
Block a user