Skip to content

Commit c9a1d30

Browse files
authored
kvm: Fix RBD primary storage host port null error (#4565)
Add RBD main storage through UI, it will fail when there is no host port parameter; Because when we created the pool, we did not add the port target in the xml
1 parent b482da8 commit c9a1d30

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public boolean parseDomainXML(String domXML) {
8484
String authUserName = getAttrValue("auth", "username", disk);
8585
String poolUuid = getAttrValue("secret", "uuid", disk);
8686
String host = getAttrValue("host", "name", disk);
87-
int port = Integer.parseInt(getAttrValue("host", "port", disk));
87+
int port = 0;
88+
String xmlPort = getAttrValue("host", "port", disk);
89+
if (StringUtils.isNotBlank(xmlPort)) {
90+
port = Integer.parseInt(xmlPort);
91+
}
8892
String diskLabel = getAttrValue("target", "dev", disk);
8993
String bus = getAttrValue("target", "bus", disk);
9094

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.xml.parsers.DocumentBuilderFactory;
2424
import javax.xml.parsers.ParserConfigurationException;
2525

26+
import org.apache.commons.lang.StringUtils;
2627
import org.apache.log4j.Logger;
2728
import org.w3c.dom.Document;
2829
import org.w3c.dom.Element;
@@ -55,7 +56,11 @@ public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
5556
String format = getAttrValue("format", "type", source);
5657

5758
if (type.equalsIgnoreCase("rbd")) {
58-
int port = Integer.parseInt(getAttrValue("host", "port", source));
59+
int port = 0;
60+
String xmlPort = getAttrValue("host", "port", source);
61+
if (StringUtils.isNotBlank(xmlPort)) {
62+
port = Integer.parseInt(xmlPort);
63+
}
5964
String pool = getTagValue("name", source);
6065

6166
Element auth = (Element)source.getElementsByTagName("auth").item(0);

0 commit comments

Comments
 (0)