[RFC 2/3] qemu-agent: add guest-network-delete-interface command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a corresponding command to guest-network-set-interface.

Signed-off-by: Chen Fan <chen.fan.fnst@xxxxxxxxxxxxxx>
---
 qga/commands-posix.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 qga/commands-win32.c |  6 ++++++
 qga/qapi-schema.json | 11 +++++++++++
 3 files changed, 68 insertions(+)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 5ee7949..058085f 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1971,6 +1971,51 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,
 
     return 0;
 }
+
+int64_t qmp_guest_network_delete_interface(const char *name, Error **errp)
+{
+    struct netcf_if *iface;
+    int ret = -1;
+    unsigned int flags = 0;
+
+    /* open netcf */
+    if (netcf == NULL) {
+        if (ncf_init(&netcf, NULL) != 0) {
+            error_setg(errp, "netcf init failed");
+            return ret;
+        }
+    }
+
+    iface = ncf_lookup_by_name(netcf, name);
+    if (!iface) {
+       error_setg(errp, "couldn't find interface named '%s'", name);
+       return ret;
+    }
+
+    if (ncf_if_status(iface, &flags) < 0) {
+        error_setg(errp, "netcf interface get status failed");
+        goto cleanup;
+    }
+
+    if (flags & NETCF_IFACE_ACTIVE) {
+        ret = ncf_if_down(iface);
+        if (ret < 0) {
+            error_setg(errp, "netcf interface stop failed");
+            goto cleanup;
+        }
+    }
+
+    ret = ncf_if_undefine(iface);
+    if (ret < 0) {
+        error_setg(errp, "netcf interface delete failed");
+        goto cleanup;
+    }
+
+    ret = 0;
+cleanup:
+    ncf_if_free(iface);
+    return ret;
+}
 #else
 int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,
                                         Error **errp)
@@ -1978,6 +2023,12 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,
     error_set(errp, QERR_UNSUPPORTED);
     return -1;
 }
+
+int64_t qmp_guest_network_delete_interface(const char *name, Error **errp)
+{
+    error_set(errp, QERR_UNSUPPORTED);
+    return -1;
+}
 #endif
 
 #define SYSCONF_EXACT(name, errp) sysconf_exact((name), #name, (errp))
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 4c14514..52f6e47 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -453,6 +453,12 @@ int64_t qmp_guest_network_set_interface(GuestNetworkInterface2 *interface,
     return -1;
 }
 
+int64_t qmp_guest_network_delete_interface(const char *name, Error **errp)
+{
+    error_set(errp, QERR_UNSUPPORTED);
+    return -1;
+}
+
 /* add unsupported commands to the blacklist */
 GList *ga_command_blacklist_init(GList *blacklist)
 {
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 77f499b..b886f97 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -642,6 +642,17 @@
   'returns': 'int' }
 
 ##
+# @guest-network-delete-interface:
+#
+# @name: interface name.
+#
+# Since: 2.3
+##
+{ 'command': 'guest-network-delete-interface',
+  'data'   : {'name': 'str' },
+  'returns': 'int' }
+
+##
 # @GuestLogicalProcessor:
 #
 # @logical-id: Arbitrary guest-specific unique identifier of the VCPU.
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]