[libvirt] [libvirt-glib 1/2] Add python example for LibvirtGConfig

--- examples/config-test.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 96 insertions(+), 0 deletions(-) create mode 100644 examples/config-test.py diff --git a/examples/config-test.py b/examples/config-test.py new file mode 100644 index 0000000..92e8a89 --- /dev/null +++ b/examples/config-test.py @@ -0,0 +1,96 @@ +#!/usr/bin/python + +from gi.repository import LibvirtGConfig; + +domain = LibvirtGConfig.Domain.new() +domain.set_name("foo") +domain.set_memory(1024*1024*1024) +domain.set_vcpus(2) +domain.set_lifecycle(LibvirtGConfig.DomainLifecycleEvent.ON_POWEROFF, + LibvirtGConfig.DomainLifecycleAction.DESTROY) + +clock = LibvirtGConfig.DomainClock.new() +clock.set_offset(LibvirtGConfig.DomainClockOffset.UTC) +domain.set_clock(clock) + +os = LibvirtGConfig.DomainOs.new() +os.set_os_type(LibvirtGConfig.DomainOsType.HVM) +os.set_arch("x86_64") +devices = [ LibvirtGConfig.DomainOsBootDevice.CDROM, + LibvirtGConfig.DomainOsBootDevice.NETWORK ] +os.set_boot_devices(devices) +domain.set_os(os) + +disk = LibvirtGConfig.DomainDisk.new() +disk.set_type(LibvirtGConfig.DomainDiskType.FILE) +disk.set_guest_device_type(LibvirtGConfig.DomainDiskGuestDeviceType.DISK) +disk.set_source("/tmp/foo/bar") +disk.set_driver_name("qemu") +disk.set_driver_type("qcow2") +disk.set_target_bus(LibvirtGConfig.DomainDiskBus.IDE) +disk.set_target_dev("hda") +domain.add_device(disk) + +interface = LibvirtGConfig.DomainInterfaceNetwork.new() +interface.set_source("default") +domain.add_device(interface) + +interface = LibvirtGConfig.DomainInterfaceUser.new() +interface.set_ifname("eth0") +interface.set_link_state(LibvirtGConfig.DomainInterfaceLinkState.UP) +interface.set_mac("00:11:22:33:44:55") +interface.set_model("foo") +domain.add_device(interface) + +input = LibvirtGConfig.DomainInput.new() +input.set_device_type(LibvirtGConfig.DomainInputDeviceType.TABLET) +input.set_bus(LibvirtGConfig.DomainInputBus.USB) +domain.add_device(input) + +graphics = LibvirtGConfig.DomainGraphicsSpice.new() +graphics.set_port(1234) +domain.add_device(graphics) + +video = LibvirtGConfig.DomainVideo.new() +video.set_model(LibvirtGConfig.DomainVideoModel.QXL) +domain.add_device(video) + +console = LibvirtGConfig.DomainConsole.new() +pty = LibvirtGConfig.DomainChardevSourcePty.new() +console.set_source(pty) +domain.add_device(console) + +print domain.to_xml() + + +pool = LibvirtGConfig.StoragePool.new() +pool.set_pool_type(LibvirtGConfig.StoragePoolType.DIR) + +pool_source = LibvirtGConfig.StoragePoolSource.new() +pool_source.set_directory("/foo/bar") +pool.set_source(pool_source) + +perms = LibvirtGConfig.StoragePermissions.new() +perms.set_owner(1001) +perms.set_group(1005) +perms.set_mode(0744) +perms.set_label("virt_image_t") + +pool_target = LibvirtGConfig.StoragePoolTarget.new() +pool_target.set_path("/dev/disk/by-path") +pool_target.set_permissions(perms) +pool.set_target(pool_target) + +print pool.to_xml() + + +vol = LibvirtGConfig.StorageVol.new() +vol.set_name("my-vol") +vol.set_capacity(0xdeadbeef) + +vol_target = LibvirtGConfig.StorageVolTarget.new() +vol_target.set_format("qcow2") +vol_target.set_permissions(perms) +vol.set_target(vol_target) + +print vol.to_xml() -- 1.7.7.4

--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-domain-sound.c | 86 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-sound.h | 77 +++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 14 +++- libvirt-gconfig/tests/test-domain-create.c | 8 ++ 6 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-sound.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-sound.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 660d090..6342431 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -34,6 +34,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-os.h \ libvirt-gconfig-domain-seclabel.h \ libvirt-gconfig-domain-snapshot.h \ + libvirt-gconfig-domain-sound.h \ libvirt-gconfig-domain-timer.h \ libvirt-gconfig-domain-video.h \ libvirt-gconfig-helpers.h \ @@ -79,6 +80,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-os.c \ libvirt-gconfig-domain-seclabel.c \ libvirt-gconfig-domain-snapshot.c \ + libvirt-gconfig-domain-sound.c \ libvirt-gconfig-domain-timer.c \ libvirt-gconfig-domain-video.c \ libvirt-gconfig-helpers.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-sound.c b/libvirt-gconfig/libvirt-gconfig-domain-sound.c new file mode 100644 index 0000000..1fdbb43 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-sound.c @@ -0,0 +1,86 @@ +/* + * libvirt-gconfig-domain-sound.c: libvirt domain sound configuration + * + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@gmail.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-object-private.h" + +#define GVIR_CONFIG_DOMAIN_SOUND_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_SOUND, GVirConfigDomainSoundPrivate)) + +struct _GVirConfigDomainSoundPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainSound, gvir_config_domain_sound, GVIR_TYPE_CONFIG_DOMAIN_DEVICE); + + +static void gvir_config_domain_sound_class_init(GVirConfigDomainSoundClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainSoundPrivate)); +} + + +static void gvir_config_domain_sound_init(GVirConfigDomainSound *sound) +{ + g_debug("Init GVirConfigDomainSound=%p", sound); + + sound->priv = GVIR_CONFIG_DOMAIN_SOUND_GET_PRIVATE(sound); +} + + +GVirConfigDomainSound *gvir_config_domain_sound_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_SOUND, + "sound", NULL); + return GVIR_CONFIG_DOMAIN_SOUND(object); +} + +GVirConfigDomainSound *gvir_config_domain_sound_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_SOUND, + "sound", NULL, xml, error); + return GVIR_CONFIG_DOMAIN_SOUND(object); +} + +void gvir_config_domain_sound_set_model(GVirConfigDomainSound *sound, + GVirConfigDomainSoundModel model) +{ + GVirConfigObject *node; + + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_SOUND(sound)); + node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(sound), + "sound"); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(node)); + gvir_config_object_set_attribute_with_type(node, "model", + GVIR_TYPE_CONFIG_DOMAIN_SOUND_MODEL, + model, + NULL); + g_object_unref(G_OBJECT(node)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-sound.h b/libvirt-gconfig/libvirt-gconfig-domain-sound.h new file mode 100644 index 0000000..706b2b1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-sound.h @@ -0,0 +1,77 @@ +/* + * libvirt-gconfig-domain-sound.h: libvirt domain sound configuration + * + * Copyright (C) 2011 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@gmail.com> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_SOUND_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_SOUND_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_SOUND (gvir_config_domain_sound_get_type ()) +#define GVIR_CONFIG_DOMAIN_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_SOUND, GVirConfigDomainSound)) +#define GVIR_CONFIG_DOMAIN_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_SOUND, GVirConfigDomainSoundClass)) +#define GVIR_IS_CONFIG_DOMAIN_SOUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_SOUND)) +#define GVIR_IS_CONFIG_DOMAIN_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_SOUND)) +#define GVIR_CONFIG_DOMAIN_SOUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_SOUND, GVirConfigDomainSoundClass)) + +typedef struct _GVirConfigDomainSound GVirConfigDomainSound; +typedef struct _GVirConfigDomainSoundPrivate GVirConfigDomainSoundPrivate; +typedef struct _GVirConfigDomainSoundClass GVirConfigDomainSoundClass; + +struct _GVirConfigDomainSound +{ + GVirConfigDomainDevice parent; + + GVirConfigDomainSoundPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainSoundClass +{ + GVirConfigDomainDeviceClass parent_class; + + gpointer padding[20]; +}; + +typedef enum { + GVIR_CONFIG_DOMAIN_SOUND_MODEL_SB16, + GVIR_CONFIG_DOMAIN_SOUND_MODEL_ES1370, + GVIR_CONFIG_DOMAIN_SOUND_MODEL_PCSPK, + GVIR_CONFIG_DOMAIN_SOUND_MODEL_AC97, + GVIR_CONFIG_DOMAIN_SOUND_MODEL_ICH6 +} GVirConfigDomainSoundModel; + +GType gvir_config_domain_sound_get_type(void); + +GVirConfigDomainSound *gvir_config_domain_sound_new(void); +GVirConfigDomainSound *gvir_config_domain_sound_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_domain_sound_set_model(GVirConfigDomainSound *sound, + GVirConfigDomainSoundModel model); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_SOUND_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index f37ece0..7176400 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -51,6 +51,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-os.h> #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-sound.h> #include <libvirt-gconfig/libvirt-gconfig-domain-timer.h> #include <libvirt-gconfig/libvirt-gconfig-domain-video.h> #include <libvirt-gconfig/libvirt-gconfig-enum-types.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index fdcfecf..39f39d4 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -157,10 +157,6 @@ LIBVIRT_GCONFIG_0.0.3 { gvir_config_domain_os_set_arch; gvir_config_domain_os_type_get_type; - gvir_config_domain_snapshot_get_type; - gvir_config_domain_snapshot_new; - gvir_config_domain_snapshot_new_from_xml; - gvir_config_domain_seclabel_get_type; gvir_config_domain_seclabel_type_get_type; gvir_config_domain_seclabel_new; @@ -170,6 +166,16 @@ LIBVIRT_GCONFIG_0.0.3 { gvir_config_domain_seclabel_set_baselabel; gvir_config_domain_seclabel_set_label; + gvir_config_domain_snapshot_get_type; + gvir_config_domain_snapshot_new; + gvir_config_domain_snapshot_new_from_xml; + + gvir_config_domain_sound_get_type; + gvir_config_domain_sound_model_get_type; + gvir_config_domain_sound_new; + gvir_config_domain_sound_new_from_xml; + gvir_config_domain_sound_set_model; + gvir_config_domain_timer_get_type; gvir_config_domain_timer_new; gvir_config_domain_timer_new_from_xml; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index c5f0027..21c7664 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -146,6 +146,14 @@ int main(void) GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(video)); + /* sound node */ + GVirConfigDomainSound *sound; + + sound = gvir_config_domain_sound_new(); + gvir_config_domain_sound_set_model(sound, + GVIR_CONFIG_DOMAIN_SOUND_MODEL_ES1370); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(sound)); + /* console node */ GVirConfigDomainConsole *console; GVirConfigDomainChardevSourcePty *pty; -- 1.7.7.4

On Wed, Dec 21, 2011 at 10:59:11AM +0100, Christophe Fergeau wrote:
--- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-domain-sound.c | 86 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-sound.h | 77 +++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 14 +++- libvirt-gconfig/tests/test-domain-create.c | 8 ++ 6 files changed, 184 insertions(+), 4 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-sound.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-sound.h
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Dec 21, 2011 at 10:59:10AM +0100, Christophe Fergeau wrote:
--- examples/config-test.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 96 insertions(+), 0 deletions(-) create mode 100644 examples/config-test.py
ACK, but lets call it config-demo.py since this is an example script, not a test script. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Dec 21, 2011 at 02:44:14PM +0000, Daniel P. Berrange wrote:
On Wed, Dec 21, 2011 at 10:59:10AM +0100, Christophe Fergeau wrote:
--- examples/config-test.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 96 insertions(+), 0 deletions(-) create mode 100644 examples/config-test.py
ACK, but lets call it config-demo.py since this is an example script, not a test script.
Ok, I renamed it and added it to EXTRA_DIST Christophe
participants (2)
-
Christophe Fergeau
-
Daniel P. Berrange