leolleeooleo commented on code in PR #6404:
URL: https://github.com/apache/cloudstack/pull/6404#discussion_r878893247


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java:
##########
@@ -331,6 +339,38 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
         return new MigrateAnswer(command, result == null, result, null);
     }
 
+    protected String replaceVncPassword(String xmlDesc, String vncPassword) 
throws ParserConfigurationException, IOException, SAXException, 
TransformerException {
+        InputStream in = IOUtils.toInputStream(xmlDesc);
+        DocumentBuilderFactory docFactory = 
DocumentBuilderFactory.newInstance();
+        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+        Document doc = docBuilder.parse(in);
+        Node domainNode = doc.getFirstChild();
+        NodeList domainChildNodes = domainNode.getChildNodes();
+
+        for (int i = 0; i < domainChildNodes.getLength(); i++) {
+            Node domainChildNode = domainChildNodes.item(i);
+            if ("devices".equals(domainChildNode.getNodeName())) {
+                NodeList devicesChildNodes = domainChildNode.getChildNodes();
+                for (int x = 0; x < devicesChildNodes.getLength(); x++) {
+                    Node deviceChildNode = devicesChildNodes.item(x);
+                    if ("graphics".equals(deviceChildNode.getNodeName())) {
+                        NamedNodeMap graphicAttributes = 
deviceChildNode.getAttributes();
+                        Node passwdNode = 
graphicAttributes.getNamedItem("passwd");
+                        String vncPasswordValue = String.format("%s", 
vncPassword);

Review Comment:
   `String.format` doesn't change anything,
   Why not just direct use `vncPassword`
   ```
   passwd.setValue(vncPassword);
   ...
   passwdNode.setNodeValue(vncPassword);
   ```
   
   



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java:
##########
@@ -151,6 +152,13 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
             xmlDesc = dm.getXMLDesc(xmlFlag);
             xmlDesc = replaceIpForVNCInDescFile(xmlDesc, target);
 
+            // Limit the VNC password in case the length is greater than 8 
characters
+            // Since libvirt version 8 VNC passwords are limited to 8 
characters
+            if 
(org.apache.commons.lang3.StringUtils.isNotBlank(to.getVncPassword())) {

Review Comment:
   I suggest get password from `xmlDesc`
   ```
   String oldVncPassword = getVncPassword(xmlDesc);
   if (oldVncPassword != null && oldVncPassword.length() > 8) {
       String newVncPassword = 
org.apache.commons.lang3.StringUtils.truncate(oldVncPassword, 8);
       xmlDesc = replaceVncPassword(xmlDesc, newVncPassword);
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to