[PATCH 0 of 4] Support for VNC password and sdl type graphics devices

Add support for persisting whether a guest as a VNC password in the infostore.

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1247095850 25200 # Node ID f609e31b0c17ea550f27426dd8e329c362f4db3e # Parent 0fb4613252c19abb6bf5496a8b7031793ba7f298 Add Password attribute to GraphicsRASD Also add necessary changes to the graphics struct and generating XML with the passwd attribute. The passwd won't show up in the XML we get back from libvirt, so pulling the passwd from the guest XML isn't included in parse_graphics_device(). Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 0fb4613252c1 -r f609e31b0c17 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Tue Jun 30 14:33:31 2009 -0700 +++ b/libxkutil/device_parsing.c Wed Jul 08 16:30:50 2009 -0700 @@ -81,6 +81,7 @@ free(dev->port); free(dev->host); free(dev->keymap); + free(dev->passwd); } static void cleanup_input_device(struct input_device *dev) diff -r 0fb4613252c1 -r f609e31b0c17 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Tue Jun 30 14:33:31 2009 -0700 +++ b/libxkutil/device_parsing.h Wed Jul 08 16:30:50 2009 -0700 @@ -70,6 +70,7 @@ char *port; char *host; char *keymap; + char *passwd; }; struct input_device { diff -r 0fb4613252c1 -r f609e31b0c17 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Tue Jun 30 14:33:31 2009 -0700 +++ b/libxkutil/xmlgen.c Wed Jul 08 16:30:50 2009 -0700 @@ -338,11 +338,21 @@ return XML_ERROR; xmlNewProp(tmp, BAD_CAST "type", BAD_CAST dev->type); + + if (STREQC(dev->type, "sdl")) + goto out; + xmlNewProp(tmp, BAD_CAST "port", BAD_CAST dev->port); xmlNewProp(tmp, BAD_CAST "listen", BAD_CAST dev->host); xmlNewProp(tmp, BAD_CAST "keymap", BAD_CAST dev->keymap); + + if (dev->passwd != NULL) + xmlNewProp(tmp, + BAD_CAST "passwd", + BAD_CAST dev->passwd); } + out: return NULL; } diff -r 0fb4613252c1 -r f609e31b0c17 schema/ResourceAllocationSettingData.mof --- a/schema/ResourceAllocationSettingData.mof Tue Jun 30 14:33:31 2009 -0700 +++ b/schema/ResourceAllocationSettingData.mof Wed Jul 08 16:30:50 2009 -0700 @@ -132,6 +132,9 @@ { [Description ("Keyboard keymapping")] string KeyMap; + + [Description ("VNC password")] + string Password; }; [Description ("KVM virtual graphics device"), @@ -141,6 +144,9 @@ { [Description ("Keyboard keymapping")] string KeyMap; + + [Description ("VNC password")] + string Password; }; [Description ("LXC virtual graphics device"), @@ -150,6 +156,9 @@ { [Description ("Keyboard keymapping")] string KeyMap; + + [Description ("VNC password")] + string Password; }; [Description ("Xen virtual input device"),

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1247095850 25200 # Node ID f915b6e4d1a3748fe8541cf2a3030a4613675945 # Parent f609e31b0c17ea550f27426dd8e329c362f4db3e Add methods for setting/getting boolean values from the infostore This will be used for determining whether a guest has a VNC password set since we cannot determine this info from the guest's XML alone. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r f609e31b0c17 -r f915b6e4d1a3 libxkutil/infostore.c --- a/libxkutil/infostore.c Wed Jul 08 16:30:50 2009 -0700 +++ b/libxkutil/infostore.c Wed Jul 08 16:30:50 2009 -0700 @@ -419,6 +419,36 @@ return xpath_set_string(ctx, key, val); } +bool infostore_get_bool(struct infostore_ctx *ctx, const char *key) +{ + char *sval = NULL; + bool val = false; + + sval = xpath_query_string(ctx, key); + if (sval == NULL) + goto out; + + if (STREQC(sval, "true")) + return true; + + out: + free(sval); + + return val; +} + +bool infostore_set_bool(struct infostore_ctx *ctx, const char *key, bool val) +{ + bool ret; + + if (val) + ret = xpath_set_string(ctx, key, "true"); + else + ret = xpath_set_string(ctx, key, "false"); + + return ret; +} + /* * Local Variables: * mode: C diff -r f609e31b0c17 -r f915b6e4d1a3 libxkutil/infostore.h --- a/libxkutil/infostore.h Wed Jul 08 16:30:50 2009 -0700 +++ b/libxkutil/infostore.h Wed Jul 08 16:30:50 2009 -0700 @@ -40,6 +40,9 @@ bool infostore_set_str(struct infostore_ctx *ctx, const char *key, const char * val); +bool infostore_get_bool(struct infostore_ctx *ctx, const char *key); +bool infostore_set_bool(struct infostore_ctx *ctx, + const char *key, bool val); #endif

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1247095850 25200 # Node ID 7b8eeb3b3fcbe2f9b6cb5eabe10569545244472e # Parent f915b6e4d1a3748fe8541cf2a3030a4613675945 (#2) Add support for specifying a password for VNC connections to VSMS Also support sdl type graphics devices. Be sure to write to the infostore whether the guest has a VNC password set. Updates: -Add support for updating the infostore with info as to whether the guest has a VNC password set Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r f915b6e4d1a3 -r 7b8eeb3b3fcb src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Wed Jul 08 16:30:50 2009 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Wed Jul 08 16:30:50 2009 -0700 @@ -771,7 +771,11 @@ const char *keymap; int ret; - dev->dev.graphics.type = strdup("vnc"); + if (cu_get_str_prop(inst, "ResourceSubType", &val) != CMPI_RC_OK) { + msg = "GraphicsRASD ResourceSubType field not valid"; + goto out; + } + dev->dev.graphics.type = strdup(val); /* FIXME: Add logic to prevent address:port collisions */ if (cu_get_str_prop(inst, "Address", &val) != CMPI_RC_OK) { @@ -792,8 +796,13 @@ dev->dev.graphics.keymap = strdup(keymap); + if (cu_get_str_prop(inst, "Password", &val) != CMPI_RC_OK) { + dev->dev.graphics.passwd = NULL; + } else { + dev->dev.graphics.passwd = strdup(val); + } + out: - return msg; } @@ -893,7 +902,7 @@ dev->type = (int)type; if (domain->type == DOMAIN_LXC) - msg = _container_rasd_to_vdev(inst, dev, type, ns); + msg = _container_rasd_to_vdev(inst, dev, type, ns); else msg = _sysvirt_rasd_to_vdev(inst, dev, type, ns); out: @@ -1137,6 +1146,13 @@ infostore_set_u64(ctx, "weight", dev->dev.vcpu.weight); infostore_set_u64(ctx, "limit", dev->dev.vcpu.limit); + + dev = dominfo->dev_graphics; + if (dev->dev.graphics.passwd != NULL) + infostore_set_bool(ctx, "has_vnc_passwd", true); + else + infostore_set_bool(ctx, "has_vnc_passwd", false); + out: infostore_close(ctx);

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1247095850 25200 # Node ID 580c1f5bf6cdb8ca70150bf2014dce8422515928 # Parent 7b8eeb3b3fcbe2f9b6cb5eabe10569545244472e (#2) Generate template RASDs for both types... Also return a value for the Password attribute in the case that the guest has a VNC password set. Updates: -Add support for setting the Password attribute in Virt_RASD.c Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 7b8eeb3b3fcb -r 580c1f5bf6cd src/Virt_RASD.c --- a/src/Virt_RASD.c Wed Jul 08 16:30:50 2009 -0700 +++ b/src/Virt_RASD.c Wed Jul 08 16:30:50 2009 -0700 @@ -276,11 +276,17 @@ } static CMPIStatus set_graphics_rasd_params(const struct virt_device *dev, - CMPIInstance *inst) + CMPIInstance *inst, + const char *name, + const char *classname) { int rc; char *addr_str = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + struct infostore_ctx *infostore = NULL; + bool has_passwd = false; CMSetProperty(inst, "ResourceSubType", (CMPIValue *)dev->dev.graphics.type, CMPI_chars); @@ -300,8 +306,33 @@ (CMPIValue *)dev->dev.graphics.keymap, CMPI_chars); } + conn = connect_by_classname(_BROKER, classname, &s); + if (conn == NULL) + goto out; + + dom = virDomainLookupByName(conn, name); + if (dom == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Domain %s not found", + name); + goto out; + } + + infostore = infostore_open(dom); + if (infostore != NULL) + has_passwd = infostore_get_bool(infostore, "has_vnc_passwd"); + + if (has_passwd) + CMSetProperty(inst, "Password", + (CMPIValue *)"********", CMPI_chars); + + infostore_close(infostore); + out: free(addr_str); + virDomainFree(dom); + virConnectClose(conn); return s; } @@ -423,7 +454,7 @@ } else if (dev->type == CIM_RES_TYPE_PROC) { set_proc_rasd_params(broker, ref, dev, host, inst); } else if (dev->type == CIM_RES_TYPE_GRAPHICS) { - s = set_graphics_rasd_params(dev, inst); + s = set_graphics_rasd_params(dev, inst, host, CLASSNAME(ref)); } else if (dev->type == CIM_RES_TYPE_INPUT) { s = set_input_rasd_params(dev, inst); } diff -r 7b8eeb3b3fcb -r 580c1f5bf6cd src/Virt_SettingsDefineCapabilities.c --- a/src/Virt_SettingsDefineCapabilities.c Wed Jul 08 16:30:50 2009 -0700 +++ b/src/Virt_SettingsDefineCapabilities.c Wed Jul 08 16:30:50 2009 -0700 @@ -1429,14 +1429,42 @@ return s; } +static CMPIStatus set_graphics_props(const CMPIObjectPath *ref, + const char *id, + const char *type, + struct inst_list *list) +{ + CMPIInstance *inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_GRAPHICS, DEVICE_RASD); + + CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); + + if (STREQC(type, "vnc")) { + const char *addr = "127.0.0.1:-1"; + + CMSetProperty(inst, "Address", (CMPIValue *)addr, CMPI_chars); + + CMSetProperty(inst, "KeyMap", (CMPIValue *)"en-us", CMPI_chars); + } + + CMSetProperty(inst, "ResourceSubType", (CMPIValue *)type, CMPI_chars); + + inst_list_add(list, inst); + + return s; +} + static CMPIStatus graphics_template(const CMPIObjectPath *ref, int template_type, struct inst_list *list) { const char *id; - const char *addr; - CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *type[] = {"vnc", "sdl"}; + int type_ct = 2; + int i; switch(template_type) { case SDC_RASD_MIN: @@ -1458,17 +1486,11 @@ goto out; } - inst = sdc_rasd_inst(&s, ref, CIM_RES_TYPE_GRAPHICS, DEVICE_RASD); - - CMSetProperty(inst, "InstanceID", (CMPIValue *)id, CMPI_chars); - - addr = "127.0.0.1:-1"; - CMSetProperty(inst, "Address", (CMPIValue *)addr, CMPI_chars); - - CMSetProperty(inst, "KeyMap", (CMPIValue *)"en-us", CMPI_chars); - CMSetProperty(inst, "ResourceSubType", (CMPIValue *)"vnc", CMPI_chars); - - inst_list_add(list, inst); + for (i = 0; i < type_ct; i++) { + s = set_graphics_props(ref, id, type[i], list); + if (s.rc != CMPI_RC_OK) + goto out; + } out: return s;

+1 Kaitlin Rupert wrote:
Add support for persisting whether a guest as a VNC password in the infostore.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
-- Richard Maciel, MSc IBM Linux Technology Center rmaciel@linux.vnet.ibm.com
participants (2)
-
Kaitlin Rupert
-
Richard Maciel