[virt-tools-list] [virt-viewer] ovirt: Add support for an 'admin' key in vv file
Fabiano Fidêncio
fabiano at fidencio.org
Tue Apr 7 13:35:39 UTC 2015
On Tue, Apr 7, 2015 at 1:14 PM, Christophe Fergeau <cfergeau at redhat.com> wrote:
> When using a user with administrator rights, the VMs this user can
> access from the user portal and the admin portal are different, and
> REST API users must indicate which set of VMs they want through a
> specific header. libgovirt already has support for that in its API, but
> virt-viewer was not making use of that API.
> This commit adds support for an 'admin' field in the [ovirt] section of
> .vv files so oVirt can indicate remote-viewer whether this header should
> be set or not.
> ---
> src/ovirt-foreign-menu.c | 3 +++
> src/virt-viewer-file.c | 26 ++++++++++++++++++++++++++
> src/virt-viewer-file.h | 2 ++
> 3 files changed, 31 insertions(+)
>
> diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
> index 7c95e4c..9b6d3b8 100644
> --- a/src/ovirt-foreign-menu.c
> +++ b/src/ovirt-foreign-menu.c
> @@ -826,6 +826,7 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
> {
> OvirtProxy *proxy = NULL;
> OvirtForeignMenu *menu = NULL;
> + gboolean admin;
> char *ca_str = NULL;
> char *jsessionid = NULL;
> char *url = NULL;
> @@ -836,6 +837,7 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
> vm_guid = virt_viewer_file_get_ovirt_vm_guid(file);
> jsessionid = virt_viewer_file_get_ovirt_jsessionid(file);
> ca_str = virt_viewer_file_get_ovirt_ca(file);
> + admin = virt_viewer_file_get_ovirt_admin(file);
>
> if ((url == NULL) || (vm_guid == NULL))
> goto end;
> @@ -850,6 +852,7 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
> }
>
> g_object_set(G_OBJECT(proxy),
> + "admin", admin,
> "session-id", jsessionid,
> "ca-cert", ca,
> NULL);
> diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
> index c8f04e8..69b6531 100644
> --- a/src/virt-viewer-file.c
> +++ b/src/virt-viewer-file.c
> @@ -76,6 +76,8 @@
> * - jsessionid: string containing an authentication cookie to be used to
> * connect to the oVirt engine without being asked for credentials
> * - ca: string PEM data (use \n to separate the lines)
> + * - admin: boolean (0 or 1) indicating whether the VM is visible in the user or
> + * admin portal
> *
> * (the file can be extended with extra groups or keys, which should
> * be prefixed with x- to avoid later conflicts)
> @@ -119,6 +121,7 @@ enum {
> PROP_SECURE_CHANNELS,
> PROP_DELETE_THIS_FILE,
> PROP_SECURE_ATTENTION,
> + PROP_OVIRT_ADMIN,
> PROP_OVIRT_HOST,
> PROP_OVIRT_VM_GUID,
> PROP_OVIRT_JSESSIONID,
> @@ -677,6 +680,19 @@ virt_viewer_file_set_ovirt_ca(VirtViewerFile* self, const gchar* value)
> g_object_notify(G_OBJECT(self), "ovirt-ca");
> }
>
> +gint
> +virt_viewer_file_get_ovirt_admin(VirtViewerFile* self)
> +{
> + return virt_viewer_file_get_int(self, OVIRT_GROUP, "admin");
> +}
> +
> +void
> +virt_viewer_file_set_ovirt_admin(VirtViewerFile* self, gint value)
> +{
> + virt_viewer_file_set_int(self, OVIRT_GROUP, "admin", value);
> + g_object_notify(G_OBJECT(self), "ovirt-admin");
> +}
> +
> static void
> spice_hotkey_set_accel(const gchar *accel_path, const gchar *key)
> {
> @@ -840,6 +856,9 @@ virt_viewer_file_set_property(GObject* object, guint property_id,
> case PROP_DELETE_THIS_FILE:
> virt_viewer_file_set_delete_this_file(self, g_value_get_int(value));
> break;
> + case PROP_OVIRT_ADMIN:
> + virt_viewer_file_set_ovirt_admin(self, g_value_get_int(value));
> + break;
> case PROP_OVIRT_HOST:
> virt_viewer_file_set_ovirt_host(self, g_value_get_string(value));
> break;
> @@ -940,6 +959,9 @@ virt_viewer_file_get_property(GObject* object, guint property_id,
> case PROP_DELETE_THIS_FILE:
> g_value_set_int(value, virt_viewer_file_get_delete_this_file(self));
> break;
> + case PROP_OVIRT_ADMIN:
> + g_value_set_int(value, virt_viewer_file_get_ovirt_admin(self));
> + break;
> case PROP_OVIRT_HOST:
> g_value_take_string(value, virt_viewer_file_get_ovirt_host(self));
> break;
> @@ -1087,6 +1109,10 @@ virt_viewer_file_class_init(VirtViewerFileClass* klass)
> g_param_spec_int("delete-this-file", "delete-this-file", "delete-this-file", 0, 1, 0,
> G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
>
> + g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_OVIRT_ADMIN,
> + g_param_spec_int("ovirt-admin", "ovirt-admin", "ovirt-admin", 0, 1, 0,
> + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
> +
> g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_OVIRT_HOST,
> g_param_spec_string("ovirt-host", "ovirt-host", "ovirt-host", NULL,
> G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
> diff --git a/src/virt-viewer-file.h b/src/virt-viewer-file.h
> index f4b030c..e84988a 100644
> --- a/src/virt-viewer-file.h
> +++ b/src/virt-viewer-file.h
> @@ -108,6 +108,8 @@ gint virt_viewer_file_get_delete_this_file(VirtViewerFile* self);
> void virt_viewer_file_set_delete_this_file(VirtViewerFile* self, gint value);
> gchar* virt_viewer_file_get_secure_attention(VirtViewerFile* self);
> void virt_viewer_file_set_secure_attention(VirtViewerFile* self, const gchar* value);
> +gint virt_viewer_file_get_ovirt_admin(VirtViewerFile* self);
> +void virt_viewer_file_set_ovirt_admin(VirtViewerFile* self, gint value);
> gchar* virt_viewer_file_get_ovirt_host(VirtViewerFile* self);
> void virt_viewer_file_set_ovirt_host(VirtViewerFile* self, const gchar* value);
> gchar* virt_viewer_file_get_ovirt_vm_guid(VirtViewerFile* self);
> --
> 2.3.4
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
Not tested but looks good. ACK!
--
Fabiano Fidêncio
More information about the virt-tools-list
mailing list