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

[libvirt] [libvirt-glib 2/2] Add GVirConfigDomainInterface setters



These attributes are valid for all types deriving from
GVirConfigDomainInterface so we add it to the base class.
---
 libvirt-gconfig/libvirt-gconfig-domain-interface.c |   62 ++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-interface.h |   14 +++++
 libvirt-gconfig/libvirt-gconfig.sym                |    5 ++
 libvirt-gconfig/tests/test-domain-create.c         |   18 +++++-
 4 files changed, 95 insertions(+), 4 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.c b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
index 5732ff1..6f64234 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-interface.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.c
@@ -19,11 +19,13 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  *
  * Author: Daniel P. Berrange <berrange redhat com>
+ *         Christophe Fergeau <cfergeau redhat com>
  */
 
 #include <config.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-object-private.h"
 
 #define GVIR_CONFIG_DOMAIN_INTERFACE_GET_PRIVATE(obj)                         \
         (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_INTERFACE, GVirConfigDomainInterfacePrivate))
@@ -48,3 +50,63 @@ static void gvir_config_domain_interface_init(GVirConfigDomainInterface *interfa
 
     interface->priv = GVIR_CONFIG_DOMAIN_INTERFACE_GET_PRIVATE(interface);
 }
+
+void gvir_config_domain_interface_set_ifname(GVirConfigDomainInterface *interface,
+                                             const char *ifname)
+{
+    GVirConfigObject *node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INTERFACE(interface));
+
+    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface),
+                                            "target");
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "device", ifname, NULL);
+    g_object_unref(G_OBJECT(node));
+}
+
+void gvir_config_domain_interface_set_link_state(GVirConfigDomainInterface *interface,
+                                                 GVirConfigDomainInterfaceLinkState state)
+{
+    GVirConfigObject *node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INTERFACE(interface));
+
+    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface),
+                                            "link");
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute_with_type(node,
+                                               "state",
+                                               GVIR_TYPE_CONFIG_DOMAIN_INTERFACE_LINK_STATE,
+                                               state,
+                                               NULL);
+    g_object_unref(G_OBJECT(node));
+}
+
+void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface *interface,
+                                          const char *mac_address)
+{
+    GVirConfigObject *node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INTERFACE(interface));
+
+    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface),
+                                            "mac");
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "address", mac_address, NULL);
+    g_object_unref(G_OBJECT(node));
+}
+
+void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface,
+                                            const char *model)
+{
+    GVirConfigObject *node;
+
+    g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INTERFACE(interface));
+
+    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(interface),
+                                            "model");
+    g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node));
+    gvir_config_object_set_attribute(node, "type", model, NULL);
+    g_object_unref(G_OBJECT(node));
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-interface.h b/libvirt-gconfig/libvirt-gconfig-domain-interface.h
index 7021ae4..28bbd41 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-interface.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-interface.h
@@ -56,9 +56,23 @@ struct _GVirConfigDomainInterfaceClass
     gpointer padding[20];
 };
 
+typedef enum {
+    GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DEFAULT,
+    GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_UP,
+    GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_DOWN
+} GVirConfigDomainInterfaceLinkState;
 
 GType gvir_config_domain_interface_get_type(void);
 
+void gvir_config_domain_interface_set_ifname(GVirConfigDomainInterface *interface,
+                                             const char *ifname);
+void gvir_config_domain_interface_set_link_state(GVirConfigDomainInterface *interface,
+                                                 GVirConfigDomainInterfaceLinkState state);
+void gvir_config_domain_interface_set_mac(GVirConfigDomainInterface *interface,
+                                          const char *mac_address);
+void gvir_config_domain_interface_set_model(GVirConfigDomainInterface *interface,
+                                            const char *model);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_DOMAIN_INTERFACE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index b06231c..6adc2c2 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -111,6 +111,11 @@ LIBVIRT_GCONFIG_0.0.1 {
 	gvir_config_domain_input_set_bus;
 
 	gvir_config_domain_interface_get_type;
+	gvir_config_domain_interface_link_state_get_type;
+	gvir_config_domain_interface_set_ifname;
+	gvir_config_domain_interface_set_link_state;
+	gvir_config_domain_interface_set_mac;
+	gvir_config_domain_interface_set_model;
 
 	gvir_config_domain_interface_network_get_type;
 	gvir_config_domain_interface_network_new;
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index bcaa29a..42aa09b 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -105,13 +105,23 @@ int main(void)
     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk));
 
 
-    /* network interface node */
-    GVirConfigDomainInterfaceNetwork *interface;
+    /* network interfaces node */
+    GVirConfigDomainInterface *interface;
 
-    interface = gvir_config_domain_interface_network_new();
-    gvir_config_domain_interface_network_set_source(interface, "default");
+    interface = GVIR_CONFIG_DOMAIN_INTERFACE(gvir_config_domain_interface_network_new());
+    gvir_config_domain_interface_network_set_source(GVIR_CONFIG_DOMAIN_INTERFACE_NETWORK(interface),
+                                                    "default");
     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(interface));
 
+    interface = GVIR_CONFIG_DOMAIN_INTERFACE(gvir_config_domain_interface_user_new());
+    gvir_config_domain_interface_set_ifname(interface, "eth0");
+    gvir_config_domain_interface_set_link_state(interface,
+                                                GVIR_CONFIG_DOMAIN_INTERFACE_LINK_STATE_UP);
+    gvir_config_domain_interface_set_mac(interface, "00:11:22:33:44:55");
+    gvir_config_domain_interface_set_model(interface, "foo");
+    devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(interface));
+
+
     /* input node */
     GVirConfigDomainInput *input;
 
-- 
1.7.7.3


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