use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method setupLinkLocalNetwork.
public void setupLinkLocalNetwork(final Connection conn) {
try {
final Network.Record rec = new Network.Record();
final Set<Network> networks = Network.getByNameLabel(conn, _linkLocalPrivateNetworkName);
Network linkLocal = null;
if (networks.size() == 0) {
rec.nameDescription = "link local network used by system vms";
rec.nameLabel = _linkLocalPrivateNetworkName;
final Map<String, String> configs = new HashMap<String, String>();
configs.put("ip_begin", NetUtils.getLinkLocalGateway());
configs.put("ip_end", NetUtils.getLinkLocalIpEnd());
configs.put("netmask", NetUtils.getLinkLocalNetMask());
configs.put("vswitch-disable-in-band", "true");
rec.otherConfig = configs;
linkLocal = Network.create(conn, rec);
} else {
linkLocal = networks.iterator().next();
if (!linkLocal.getOtherConfig(conn).containsKey("vswitch-disable-in-band")) {
linkLocal.addToOtherConfig(conn, "vswitch-disable-in-band", "true");
}
}
/* Make sure there is a physical bridge on this network */
VIF dom0vif = null;
final Pair<VM, VM.Record> vm = getControlDomain(conn);
final VM dom0 = vm.first();
final Set<VIF> vifs = dom0.getVIFs(conn);
if (vifs.size() != 0) {
for (final VIF vif : vifs) {
final Map<String, String> otherConfig = vif.getOtherConfig(conn);
if (otherConfig != null) {
final String nameLabel = otherConfig.get("nameLabel");
if (nameLabel != null && nameLabel.equalsIgnoreCase("link_local_network_vif")) {
dom0vif = vif;
}
}
}
}
/* create temp VIF0 */
if (dom0vif == null) {
s_logger.debug("Can't find a vif on dom0 for link local, creating a new one");
final VIF.Record vifr = new VIF.Record();
vifr.VM = dom0;
vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
if (vifr.device == null) {
s_logger.debug("Failed to create link local network, no vif available");
return;
}
final Map<String, String> config = new HashMap<String, String>();
config.put("nameLabel", "link_local_network_vif");
vifr.otherConfig = config;
vifr.MAC = "FE:FF:FF:FF:FF:FF";
vifr.network = linkLocal;
vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT;
dom0vif = VIF.create(conn, vifr);
plugDom0Vif(conn, dom0vif);
} else {
s_logger.debug("already have a vif on dom0 for link local network");
if (!dom0vif.getCurrentlyAttached(conn)) {
plugDom0Vif(conn, dom0vif);
}
}
final String brName = linkLocal.getBridge(conn);
callHostPlugin(conn, "vmops", "setLinkLocalIP", "brName", brName);
_host.setLinkLocalNetwork(linkLocal.getUuid(conn));
} catch (final XenAPIException e) {
s_logger.warn("Unable to create local link network", e);
throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to create local link network", e);
throw new CloudRuntimeException("Unable to create local link network due to " + e.toString(), e);
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method skipOrRemoveSR.
protected void skipOrRemoveSR(Connection conn, SR sr) {
if (sr == null) {
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Removing SR"));
}
try {
Set<VDI> vdis = sr.getVDIs(conn);
for (VDI vdi : vdis) {
if (MapUtils.isEmpty(vdi.getCurrentOperations(conn))) {
continue;
}
return;
}
removeSR(conn, sr);
return;
} catch (XenAPIException | XmlRpcException e) {
s_logger.warn(logX(sr, "Unable to get current opertions " + e.toString()), e);
}
String msg = "Remove SR failed";
s_logger.warn(msg);
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class XenServerConnectionPool method join.
protected void join(Connection conn, String masterIp, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException, Types.JoiningHostCannotContainSharedSrs {
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
Pool.join(conn, masterIp, username, password.peek());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class Xenserver625StorageProcessor method createTemplateFromSnapshot2.
public Answer createTemplateFromSnapshot2(final CopyCommand cmd) {
final Connection conn = hypervisorResource.getConnection();
final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO();
final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO();
if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) {
return null;
}
NfsTO destStore = null;
PrimaryDataStoreTO srcStore = null;
URI destUri = null;
try {
srcStore = (PrimaryDataStoreTO) snapshotObjTO.getDataStore();
destStore = (NfsTO) templateObjTO.getDataStore();
destUri = new URI(destStore.getUrl());
} catch (final Exception ex) {
s_logger.debug("Invalid URI", ex);
return new CopyCmdAnswer("Invalid URI: " + ex.toString());
}
SR srcSr = null;
SR destSr = null;
final String destDir = templateObjTO.getPath();
VDI destVdi = null;
boolean result = false;
try {
final Map<String, String> srcDetails = cmd.getOptions();
final String iScsiName = srcDetails.get(DiskTO.IQN);
final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST);
final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
String srType = null;
srType = CitrixResourceBase.SRType.LVMOISCSI.toString();
srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false, srType, true);
final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
final String localDir = "/var/cloud_mount/" + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
mountNfs(conn, destNfsPath, localDir);
makeDirectory(conn, localDir + "/" + destDir);
destSr = createFileSR(conn, localDir + "/" + destDir);
// there should only be one VDI in this SR
final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
destVdi = srcVdi.copy(conn, destSr);
final String nameLabel = "cloud-" + UUID.randomUUID().toString();
destVdi.setNameLabel(conn, nameLabel);
// scan makes XenServer pick up VDI physicalSize
destSr.scan(conn);
final String templateUuid = destVdi.getUuid(conn);
final String templateFilename = templateUuid + ".vhd";
final long virtualSize = destVdi.getVirtualSize(conn);
final long physicalSize = destVdi.getPhysicalUtilisation(conn);
// create the template.properties file
String templatePath = destNfsPath + "/" + destDir;
templatePath = templatePath.replaceAll("//", "/");
result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId());
if (!result) {
throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
}
final TemplateObjectTO newTemplate = new TemplateObjectTO();
newTemplate.setPath(destDir + "/" + templateFilename);
newTemplate.setFormat(Storage.ImageFormat.VHD);
newTemplate.setHypervisorType(HypervisorType.XenServer);
newTemplate.setSize(virtualSize);
newTemplate.setPhysicalSize(physicalSize);
newTemplate.setName(templateUuid);
result = true;
return new CopyCmdAnswer(newTemplate);
// } catch (Exception ex) {
// s_logger.error("Failed to create a template from a snapshot",
// ex);
//
// return new
// CopyCmdAnswer("Failed to create a template from a snapshot: " +
// ex.toString());
} catch (final BadServerResponse e) {
s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} catch (final XenAPIException e) {
s_logger.error("Failed to create a template from a snapshot due to xenapi error", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} catch (final XmlRpcException e) {
s_logger.error("Failed to create a template from a snapshot due to rpc error", e);
return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
} finally {
if (!result) {
if (destVdi != null) {
try {
destVdi.destroy(conn);
} catch (final Exception e) {
s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e);
}
}
}
if (srcSr != null) {
hypervisorResource.removeSR(conn, srcSr);
}
if (destSr != null) {
hypervisorResource.removeSR(conn, destSr);
}
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class XenServer56FenceCommandWrapper method execute.
@Override
public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) {
final Connection conn = xenServer56.getConnection();
try {
final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid());
if (alive == null) {
s_logger.debug("Failed to check heartbeat, so unable to fence");
return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence");
}
if (alive) {
s_logger.debug("Heart beat is still going so unable to fence");
return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence");
}
final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName());
for (final VM vm : vms) {
s_logger.info("Fence command for VM " + command.getVmName());
vm.powerStateReset(conn);
vm.destroy(conn);
}
return new FenceAnswer(command);
} catch (final XmlRpcException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
} catch (final XenAPIException e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
} catch (final Exception e) {
s_logger.warn("Unable to fence", e);
return new FenceAnswer(command, false, e.getMessage());
}
}
Aggregations