use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method dettachVolume.
@Override
public Answer dettachVolume(final DettachCommand cmd) {
final DiskTO disk = cmd.getDisk();
final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore();
final String vmName = cmd.getVmName();
final String serial = this.resource.diskUuidToSerial(vol.getUuid());
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
final KvmPhysicalDisk phyDisk = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue(), disk.getDiskController(), disk.getDiskFormat(), serial, vol);
this.storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
return new DettachAnswer(disk);
} catch (final LibvirtException | InternalErrorException e) {
this.logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
return new DettachAnswer(e.toString());
}
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class KvmStorageProcessor method attachVolume.
@Override
public Answer attachVolume(final AttachCommand cmd) {
final DiskTO disk = cmd.getDisk();
final VolumeObjectTO vol = (VolumeObjectTO) disk.getData();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) vol.getDataStore();
final String vmName = cmd.getVmName();
final String serial = disk.getDiskSeq() + "-" + this.resource.diskUuidToSerial(vol.getUuid());
try {
final Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
this.storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath(), disk.getDetails());
final KvmPhysicalDisk phyDisk = this.storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue(), disk.getDiskController(), disk.getDiskFormat(), serial, vol);
return new AttachAnswer(disk);
} catch (final LibvirtException e) {
this.logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
this.storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath());
return new AttachAnswer(e.getMessage());
} catch (final InternalErrorException | CloudRuntimeException e) {
this.logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e);
return new AttachAnswer(e.getMessage());
}
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtStartCommandWrapper method execute.
@Override
public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VirtualMachineTO vmSpec = command.getVirtualMachine();
final String vmName = vmSpec.getName();
LibvirtVmDef vm = null;
DomainState state = DomainState.VIR_DOMAIN_SHUTOFF;
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
Connect conn = null;
try {
vm = libvirtComputingResource.createVmFromSpec(vmSpec);
conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType());
final Long remainingMem = getFreeMemory(conn, libvirtComputingResource);
if (remainingMem == null) {
return new StartAnswer(command, "Failed to get free memory");
} else if (remainingMem < vmSpec.getMinRam()) {
return new StartAnswer(command, "Not enough memory on the host, remaining: " + remainingMem + ", asking: " + vmSpec.getMinRam());
}
final NicTO[] nics = vmSpec.getNics();
libvirtComputingResource.createVbd(conn, vmSpec, vmName, vm);
if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)) {
return new StartAnswer(command, "Failed to connect physical disks to host");
}
libvirtComputingResource.createVifs(vmSpec, vm);
s_logger.debug("starting " + vmName + ": " + vm.toString());
libvirtComputingResource.startVm(conn, vmName, vm.toString());
// system vms
if (vmSpec.getType() != VirtualMachineType.User) {
// pass cmdline with config for the systemvm to configure itself
if (libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())) {
s_logger.debug("Passing cmdline succeeded");
} else {
final String errorMessage = "Passing cmdline failed, aborting.";
s_logger.debug(errorMessage);
return new StartAnswer(command, errorMessage);
}
String controlIp = null;
for (final NicTO nic : nics) {
if (nic.getType() == TrafficType.Control) {
controlIp = nic.getIp();
break;
}
}
// connect to the router by using its linklocal address (that should now be configured)
s_logger.debug("Starting ssh attempts to " + controlIp);
final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
if (!virtRouterResource.connect(controlIp, 30, 5000)) {
final String errorMessage = "Unable to login to router via linklocal address " + controlIp + " after 30 tries, aborting.";
s_logger.debug(errorMessage);
return new StartAnswer(command, errorMessage);
}
s_logger.debug("Successfully completed ssh attempts to " + controlIp);
}
state = DomainState.VIR_DOMAIN_RUNNING;
return new StartAnswer(command);
} catch (final LibvirtException | InternalErrorException | URISyntaxException e) {
s_logger.warn("Exception while starting VM: " + ExceptionUtils.getRootCauseMessage(e));
if (conn != null) {
libvirtComputingResource.handleVmStartFailure(vm);
}
return new StartAnswer(command, e.getMessage());
} finally {
if (state != DomainState.VIR_DOMAIN_RUNNING) {
storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vmSpec);
}
}
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class BridgeVifDriver method plug.
@Override
public LibvirtVmDef.InterfaceDef plug(final NicTO nic, final String guestOsType, final String nicAdapter) throws InternalErrorException, LibvirtException {
if (this.logger.isDebugEnabled()) {
this.logger.debug("nic=" + nic);
if (nicAdapter != null && !nicAdapter.isEmpty()) {
this.logger.debug("custom nic adapter=" + nicAdapter);
}
}
final LibvirtVmDef.InterfaceDef intf = new LibvirtVmDef.InterfaceDef();
String netId = null;
String protocol = null;
if (nic.getBroadcastType() == BroadcastDomainType.Vlan || nic.getBroadcastType() == BroadcastDomainType.Vxlan) {
netId = BroadcastDomainType.getValue(nic.getBroadcastUri());
protocol = BroadcastDomainType.getSchemeValue(nic.getBroadcastUri()).scheme();
} else if (nic.getBroadcastType() == BroadcastDomainType.Lswitch) {
throw new InternalErrorException("Nicira NVP Logicalswitches are not supported by the BridgeVifDriver");
}
final String trafficLabel = nic.getName();
Integer networkRateKBps = 0;
if (this.libvirtVersion > 10 * 1000 + 10) {
networkRateKBps = nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1 ? nic.getNetworkRateMbps().intValue() * 128 : 0;
}
if (nic.getType() == TrafficType.Guest) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && netId != null && protocol != null && !netId.equalsIgnoreCase("untagged") || nic.getBroadcastType() == BroadcastDomainType.Vxlan) {
if (trafficLabel != null && !trafficLabel.isEmpty()) {
this.logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel);
final String brName = createVnetBr(netId, trafficLabel, protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
} else {
final String brName = createVnetBr(netId, "private", protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else {
String brname = "";
if (trafficLabel != null && !trafficLabel.isEmpty()) {
brname = trafficLabel;
} else {
brname = this.bridges.get("guest");
}
intf.defBridgeNet(brname, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else if (nic.getType() == TrafficType.Control) {
/* Make sure the network is still there */
createControlNetwork();
intf.defBridgeNet(this.bridges.get("linklocal"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
} else if (nic.getType() == TrafficType.Public) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && netId != null && protocol != null && !netId.equalsIgnoreCase("untagged") || nic.getBroadcastType() == BroadcastDomainType.Vxlan) {
if (trafficLabel != null && !trafficLabel.isEmpty()) {
this.logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel);
final String brName = createVnetBr(netId, trafficLabel, protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
} else {
final String brName = createVnetBr(netId, "public", protocol);
intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else {
intf.defBridgeNet(this.bridges.get("public"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps);
}
} else if (nic.getType() == TrafficType.Management) {
intf.defBridgeNet(this.bridges.get("private"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
} else if (nic.getType() == TrafficType.Storage) {
final String storageBrName = nic.getName() == null ? this.bridges.get("private") : nic.getName();
intf.defBridgeNet(storageBrName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter));
}
return intf;
}
use of com.cloud.legacymodel.exceptions.InternalErrorException in project cosmic by MissionCriticalCloud.
the class ExtractIsoCmd method execute.
@Override
public void execute() {
try {
CallContext.current().setEventDetails(getEventDescription());
final String uploadUrl = _templateService.extract(this);
if (uploadUrl != null) {
final ExtractResponse response = _responseGenerator.createExtractResponse(id, zoneId, getEntityOwnerId(), mode, uploadUrl);
response.setResponseName(getCommandName());
response.setObjectName("iso");
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract ISO");
}
} catch (final InternalErrorException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
Aggregations