DaanHoogland commented on code in PR #7712:
URL: https://github.com/apache/cloudstack/pull/7712#discussion_r1250766105


##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java:
##########
@@ -321,6 +327,55 @@ public boolean parseDomainXML(String domXML) {
                 watchDogDefs.add(def);
             }
 
+            NodeList cpuTunesList = 
rootElement.getElementsByTagName("cputune");
+            if (cpuTunesList.getLength() > 0) {
+                cpuTuneDef = new CpuTuneDef();
+                final Element cpuTuneDefElement = (Element) 
cpuTunesList.item(0);
+                final String cpuShares = 
cpuTuneDefElement.getAttribute("shares");
+                if (StringUtils.isNotBlank(cpuShares)) {
+                    cpuTuneDef.setShares((Integer.parseInt(cpuShares)));
+                }
+
+                final String quota = cpuTuneDefElement.getAttribute("quota");
+                if (StringUtils.isNotBlank(quota)) {
+                    cpuTuneDef.setQuota((Integer.parseInt(quota)));
+                }
+
+                final String period = cpuTuneDefElement.getAttribute("period");
+                if (StringUtils.isNotBlank(period)) {
+                    cpuTuneDef.setQuota((Integer.parseInt(period)));
+                }
+            }
+
+            NodeList cpuModeList = rootElement.getElementsByTagName("cpu");
+            if (cpuModeList.getLength() > 0){
+                cpuModeDef = new CpuModeDef();
+                final Element cpuModeDefElement = (Element) 
cpuModeList.item(0);
+                final String cpuModel = 
cpuModeDefElement.getAttribute("model");
+                if (StringUtils.isNotBlank(cpuModel)){
+                    cpuModeDef.setModel(cpuModel);
+                }
+                NodeList cpuFeatures = 
cpuModeDefElement.getElementsByTagName("features");
+                if (cpuFeatures.getLength() > 0) {
+                    final ArrayList<String> features = new 
ArrayList<>(cpuFeatures.getLength());
+                    for (int i = 0; i < cpuFeatures.getLength(); i++) {
+                        final Element feature = (Element)cpuFeatures.item(i);
+                        final String policy = feature.getAttribute("policy");
+                        String featureName = feature.getAttribute("name");
+                        if ("disable".equals(policy)) {
+                            featureName = "-" + featureName;
+                        }
+                        features.add(featureName);
+                    }
+                    cpuModeDef.setFeatures(features);
+                }
+                final String sockets = getAttrValue("topology", "sockets", 
cpuModeDefElement);
+                final String cores = getAttrValue("topology", "cores", 
cpuModeDefElement);
+                if (StringUtils.isNotBlank(sockets) && 
StringUtils.isNotBlank(cores)) {
+                    cpuModeDef.setTopology(Integer.parseInt(cores), 
Integer.parseInt(sockets));
+                }
+            }
+

Review Comment:
   @itsayushpandey can you extract these blocks to new methods to reduce 
complexity of this method and make the code more readible, please?



-- 
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