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
This commit is contained in:
div8cn 2021-01-14 08:50:16 +08:00 committed by GitHub
parent b482da8c91
commit c9a1d300cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -84,7 +84,11 @@ public class LibvirtDomainXMLParser {
String authUserName = getAttrValue("auth", "username", disk);
String poolUuid = getAttrValue("secret", "uuid", disk);
String host = getAttrValue("host", "name", disk);
int port = Integer.parseInt(getAttrValue("host", "port", disk));
int port = 0;
String xmlPort = getAttrValue("host", "port", disk);
if (StringUtils.isNotBlank(xmlPort)) {
port = Integer.parseInt(xmlPort);
}
String diskLabel = getAttrValue("target", "dev", disk);
String bus = getAttrValue("target", "bus", disk);

View File

@ -23,6 +23,7 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -55,7 +56,11 @@ public class LibvirtStoragePoolXMLParser {
String format = getAttrValue("format", "type", source);
if (type.equalsIgnoreCase("rbd")) {
int port = Integer.parseInt(getAttrValue("host", "port", source));
int port = 0;
String xmlPort = getAttrValue("host", "port", source);
if (StringUtils.isNotBlank(xmlPort)) {
port = Integer.parseInt(xmlPort);
}
String pool = getTagValue("name", source);
Element auth = (Element)source.getElementsByTagName("auth").item(0);