|
 |
080a59 |
From b8b0d03e43bee40ad15fa4c3aa6ca8b07ca98e31 Mon Sep 17 00:00:00 2001
|
|
 |
080a59 |
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
|
|
 |
080a59 |
Date: Wed, 10 May 2017 15:48:09 -0300
|
|
 |
080a59 |
Subject: [PATCH] vm: Set values of OvirtVmDisplay using OvirtXmlElement struct
|
|
 |
080a59 |
|
|
 |
080a59 |
This required the addition of OVIRT_VM_DISPLAY_INVALID to the
|
|
 |
080a59 |
OvirtVmDisplayType enum as the default value.
|
|
 |
080a59 |
|
|
 |
080a59 |
The value of the 'type' property of OvirtVmDisplay is tested after the
|
|
 |
080a59 |
parsing is done, to ensure it is either vnc or spice.
|
|
 |
080a59 |
|
|
 |
080a59 |
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
|
|
 |
080a59 |
|
|
 |
080a59 |
govirt/ovirt-vm-display.c | 2 +-
|
|
 |
080a59 |
govirt/ovirt-vm-display.h | 3 +-
|
|
 |
080a59 |
govirt/ovirt-vm-xml.c | 118 ++++++++++++++
|
|
 |
080a59 |
3 files changed, 38 insertions(+), 85 deletions(-)
|
|
 |
080a59 |
|
|
 |
080a59 |
diff
|
|
 |
080a59 |
index 37e042a..b03c303 100644
|
|
 |
080a59 |
|
|
 |
080a59 |
|
|
 |
080a59 |
@@ -197,7 +197,7 @@ static void ovirt_vm_display_class_init(OvirtVmDisplayClass *klass)
|
|
 |
080a59 |
"Type",
|
|
 |
080a59 |
"Display Type",
|
|
 |
080a59 |
OVIRT_TYPE_VM_DISPLAY_TYPE,
|
|
 |
080a59 |
- OVIRT_VM_DISPLAY_SPICE,
|
|
 |
080a59 |
+ OVIRT_VM_DISPLAY_INVALID,
|
|
 |
080a59 |
G_PARAM_READWRITE |
|
|
 |
080a59 |
G_PARAM_STATIC_STRINGS));
|
|
 |
080a59 |
g_object_class_install_property(object_class,
|
|
 |
080a59 |
diff
|
|
 |
080a59 |
index f7eb310..38ef9b7 100644
|
|
 |
080a59 |
|
|
 |
080a59 |
|
|
 |
080a59 |
@@ -55,7 +55,8 @@ struct _OvirtVmDisplayClass
|
|
 |
080a59 |
|
|
 |
080a59 |
typedef enum {
|
|
 |
080a59 |
OVIRT_VM_DISPLAY_SPICE,
|
|
 |
080a59 |
- OVIRT_VM_DISPLAY_VNC
|
|
 |
080a59 |
+ OVIRT_VM_DISPLAY_VNC,
|
|
 |
080a59 |
+ OVIRT_VM_DISPLAY_INVALID,
|
|
 |
080a59 |
} OvirtVmDisplayType;
|
|
 |
080a59 |
|
|
 |
080a59 |
GType ovirt_vm_display_get_type(void);
|
|
 |
080a59 |
diff
|
|
 |
080a59 |
index 25f50f3..0603427 100644
|
|
 |
080a59 |
|
|
 |
080a59 |
|
|
 |
080a59 |
@@ -33,102 +33,54 @@
|
|
 |
080a59 |
static gboolean vm_set_display_from_xml(OvirtVm *vm,
|
|
 |
080a59 |
RestXmlNode *root)
|
|
 |
080a59 |
{
|
|
 |
080a59 |
- RestXmlNode *node;
|
|
 |
080a59 |
OvirtVmDisplay *display;
|
|
 |
080a59 |
- const char *display_key = g_intern_string("display");
|
|
 |
080a59 |
- const char *type_key = g_intern_string("type");
|
|
 |
080a59 |
- const char *address_key = g_intern_string("address");
|
|
 |
080a59 |
- const char *port_key = g_intern_string("port");
|
|
 |
080a59 |
- const char *secure_port_key = g_intern_string("secure_port");
|
|
 |
080a59 |
- const char *monitors_key = g_intern_string("monitors");
|
|
 |
080a59 |
- const char *certificate_key = g_intern_string("certificate");
|
|
 |
080a59 |
- const char *smartcard_key = g_intern_string("smartcard_enabled");
|
|
 |
080a59 |
- const char *allow_override_key = g_intern_string("allow_override");
|
|
 |
080a59 |
- const char *proxy_key = g_intern_string("proxy");
|
|
 |
080a59 |
+ OvirtVmDisplayType type;
|
|
 |
080a59 |
+ OvirtXmlElement display_elements[] = {
|
|
 |
080a59 |
+ { .prop_name = "type",
|
|
 |
080a59 |
+ .xml_path = "type",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "address",
|
|
 |
080a59 |
+ .xml_path = "address",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "port",
|
|
 |
080a59 |
+ .xml_path = "port",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "secure-port",
|
|
 |
080a59 |
+ .xml_path = "secure_port",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "monitor-count",
|
|
 |
080a59 |
+ .xml_path = "monitors",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "smartcard",
|
|
 |
080a59 |
+ .xml_path = "smartcard_enabled",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "allow-override",
|
|
 |
080a59 |
+ .xml_path = "allow_override",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "host-subject",
|
|
 |
080a59 |
+ .xml_path = "certificate/subject",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { .prop_name = "proxy-url",
|
|
 |
080a59 |
+ .xml_path = "proxy",
|
|
 |
080a59 |
+ },
|
|
 |
080a59 |
+ { NULL, },
|
|
 |
080a59 |
+ };
|
|
 |
080a59 |
|
|
 |
080a59 |
if (root == NULL) {
|
|
 |
080a59 |
return FALSE;
|
|
 |
080a59 |
}
|
|
 |
080a59 |
- root = g_hash_table_lookup(root->children, display_key);
|
|
 |
080a59 |
+ root = rest_xml_node_find(root, "display");
|
|
 |
080a59 |
if (root == NULL) {
|
|
 |
080a59 |
g_debug("Could not find 'display' node");
|
|
 |
080a59 |
return FALSE;
|
|
 |
080a59 |
}
|
|
 |
080a59 |
display = ovirt_vm_display_new();
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, type_key);
|
|
 |
080a59 |
- g_return_val_if_fail(node != NULL, FALSE);
|
|
 |
080a59 |
- if (g_strcmp0(node->content, "spice") == 0) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display), "type", OVIRT_VM_DISPLAY_SPICE, NULL);
|
|
 |
080a59 |
- } else if (g_strcmp0(node->content, "vnc") == 0) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display), "type", OVIRT_VM_DISPLAY_VNC, NULL);
|
|
 |
080a59 |
- } else {
|
|
 |
080a59 |
- g_warning("Unknown display type: %s", node->content);
|
|
 |
080a59 |
+ ovirt_rest_xml_node_parse(root, G_OBJECT(display), display_elements);
|
|
 |
080a59 |
+ g_object_get(G_OBJECT(display), "type", &type, NULL);
|
|
 |
080a59 |
+ if (type == OVIRT_VM_DISPLAY_INVALID) {
|
|
 |
080a59 |
return FALSE;
|
|
 |
080a59 |
}
|
|
 |
080a59 |
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, monitors_key);
|
|
 |
080a59 |
- g_return_val_if_fail(node != NULL, FALSE);
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "monitor-count", strtoul(node->content, NULL, 0),
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
-
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, address_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display), "address", node->content, NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, port_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "port", strtoul(node->content, NULL, 0),
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, secure_port_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "secure-port", strtoul(node->content, NULL, 0),
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, smartcard_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- gboolean smartcard;
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- smartcard = (g_strcmp0(node->content, "true") == 0);
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "smartcard", smartcard,
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, allow_override_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- gboolean allow_override;
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- allow_override = (g_strcmp0(node->content, "true") == 0);
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "allow-override", allow_override,
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, certificate_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- const char *subject_key = g_intern_string("subject");
|
|
 |
080a59 |
- node = g_hash_table_lookup(node->children, subject_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display),
|
|
 |
080a59 |
- "host-subject", node->content,
|
|
 |
080a59 |
- NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
- node = g_hash_table_lookup(root->children, proxy_key);
|
|
 |
080a59 |
- if (node != NULL) {
|
|
 |
080a59 |
- g_object_set(G_OBJECT(display), "proxy-url", node->content, NULL);
|
|
 |
080a59 |
- }
|
|
 |
080a59 |
-
|
|
 |
080a59 |
/* FIXME: this overrides the ticket/expiry which may
|
|
 |
080a59 |
* already be set
|
|
 |
080a59 |
*/
|
|
 |
080a59 |
--
|
|
 |
080a59 |
2.14.4
|
|
 |
080a59 |
|