use of com.cloud.exception.InternalErrorException in project cloudstack by apache.
the class HypervDirectConnectResource method execute.
private PlugNicAnswer execute(final PlugNicCommand cmd) {
if (s_logger.isInfoEnabled()) {
s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd));
}
try {
final String vmName = cmd.getVmName();
final NicTO nic = cmd.getNic();
final URI broadcastUri = nic.getBroadcastUri();
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + nic.getBroadcastUri());
}
final String vlanId = BroadcastDomainType.getValue(broadcastUri);
int publicNicInfo = -1;
publicNicInfo = getVmFreeNicIndex(vmName);
if (publicNicInfo > 0) {
modifyNicVlan(vmName, vlanId, publicNicInfo, true, cmd.getNic().getName());
return new PlugNicAnswer(cmd, true, "success");
}
final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added";
s_logger.warn(msg);
return new PlugNicAnswer(cmd, false, msg);
} catch (final Exception e) {
s_logger.error("Unexpected exception: ", e);
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
}
}
use of com.cloud.exception.InternalErrorException in project cloudstack by apache.
the class IvsVifDriver method createVnet.
private void createVnet(String vnetId, String pif, String brName, String protocol) throws InternalErrorException {
synchronized (_vnetBridgeMonitor) {
String script = _modifyVlanPath;
if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) {
script = _modifyVxlanPath;
}
final Script command = new Script(script, _timeout, s_logger);
command.add("-v", vnetId);
command.add("-p", pif);
command.add("-b", brName);
command.add("-o", "add");
final String result = command.execute();
if (result != null) {
throw new InternalErrorException("Failed to create vnet " + vnetId + ": " + result);
}
}
}
use of com.cloud.exception.InternalErrorException in project cloudstack by apache.
the class LibvirtStartCommandWrapper method execute.
@Override
public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VirtualMachineTO vmSpec = command.getVirtualMachine();
vmSpec.setVncAddr(command.getHostIp());
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());
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();
for (final NicTO nic : nics) {
if (vmSpec.getType() != VirtualMachine.Type.User) {
nic.setPxeDisable(true);
}
}
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());
for (final NicTO nic : nics) {
if (nic.isSecurityGroupEnabled() || nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
if (vmSpec.getType() != VirtualMachine.Type.User) {
libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, vmName);
break;
} else {
final List<String> nicSecIps = nic.getNicSecIps();
String secIpsStr;
final StringBuilder sb = new StringBuilder();
if (nicSecIps != null) {
for (final String ip : nicSecIps) {
sb.append(ip).append(":");
}
secIpsStr = sb.toString();
} else {
secIpsStr = "0:";
}
libvirtComputingResource.defaultNetworkRules(conn, vmName, nic, vmSpec.getId(), secIpsStr);
}
}
}
// pass cmdline info to system vms
if (vmSpec.getType() != VirtualMachine.Type.User) {
//wait and try passCmdLine for 5 minutes at most for CLOUDSTACK-2823
String controlIp = null;
for (final NicTO nic : nics) {
if (nic.getType() == TrafficType.Control) {
controlIp = nic.getIp();
break;
}
}
for (int count = 0; count < 30; count++) {
libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs());
//check router is up?
final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
final boolean result = virtRouterResource.connect(controlIp, 1, 5000);
if (result) {
break;
}
}
}
state = DomainState.VIR_DOMAIN_RUNNING;
return new StartAnswer(command);
} catch (final LibvirtException e) {
s_logger.warn("LibvirtException ", e);
if (conn != null) {
libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
}
return new StartAnswer(command, e.getMessage());
} catch (final InternalErrorException e) {
s_logger.warn("InternalErrorException ", e);
if (conn != null) {
libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
}
return new StartAnswer(command, e.getMessage());
} catch (final URISyntaxException e) {
s_logger.warn("URISyntaxException ", e);
if (conn != null) {
libvirtComputingResource.handleVmStartFailure(conn, vmName, vm);
}
return new StartAnswer(command, e.getMessage());
} finally {
if (state != DomainState.VIR_DOMAIN_RUNNING) {
storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vmSpec);
}
}
}
use of com.cloud.exception.InternalErrorException in project cloudstack by apache.
the class LibvirtPrepareForMigrationCommandWrapper method execute.
@Override
public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VirtualMachineTO vm = command.getVirtualMachine();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Preparing host for migrating " + vm);
}
final NicTO[] nics = vm.getNics();
boolean skipDisconnect = false;
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
try {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vm.getName());
for (final NicTO nic : nics) {
libvirtComputingResource.getVifDriver(nic.getType()).plug(nic, null, "");
}
/* setup disks, e.g for iso */
final DiskTO[] volumes = vm.getDisks();
for (final DiskTO volume : volumes) {
if (volume.getType() == Volume.Type.ISO) {
libvirtComputingResource.getVolumePath(conn, volume);
}
}
skipDisconnect = true;
if (!storagePoolMgr.connectPhysicalDisksViaVmSpec(vm)) {
return new PrepareForMigrationAnswer(command, "failed to connect physical disks to host");
}
return new PrepareForMigrationAnswer(command);
} catch (final LibvirtException e) {
return new PrepareForMigrationAnswer(command, e.toString());
} catch (final InternalErrorException e) {
return new PrepareForMigrationAnswer(command, e.toString());
} catch (final URISyntaxException e) {
return new PrepareForMigrationAnswer(command, e.toString());
} finally {
if (!skipDisconnect) {
storagePoolMgr.disconnectPhysicalDisksViaVmSpec(vm);
}
}
}
use of com.cloud.exception.InternalErrorException in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final VM router = getVM(conn, routerName);
final NicTO nic = new NicTO();
nic.setMac(ip.getVifMacAddress());
nic.setType(ip.getTrafficType());
if (ip.getBroadcastUri() == null) {
nic.setBroadcastType(BroadcastDomainType.Native);
} else {
final URI uri = BroadcastDomainType.fromString(ip.getBroadcastUri());
nic.setBroadcastType(BroadcastDomainType.getSchemeValue(uri));
nic.setBroadcastUri(uri);
}
nic.setDeviceId(0);
nic.setNetworkRateMbps(ip.getNetworkRate());
nic.setName(ip.getNetworkName());
final Network network = getNetwork(conn, nic);
// Determine the correct VIF on DomR to associate/disassociate
// the
// IP address with
VIF correctVif = getCorrectVif(conn, router, network);
// If we are associating an IP address and DomR doesn't have a
// VIF
// for the specified vlan ID, we need to add a VIF
// If we are disassociating the last IP address in the VLAN, we
// need
// to remove a VIF
boolean addVif = false;
if (ip.isAdd() && correctVif == null) {
addVif = true;
}
if (addVif) {
// Add a new VIF to DomR
final String vifDeviceNum = getLowestAvailableVIFDeviceNum(conn, router);
if (vifDeviceNum == null) {
throw new InternalErrorException("There were no more available slots for a new VIF on router: " + router.getNameLabel(conn));
}
nic.setDeviceId(Integer.parseInt(vifDeviceNum));
correctVif = createVif(conn, routerName, router, null, nic);
correctVif.plug(conn);
// Add iptables rule for network usage
networkUsage(conn, routerIp, "addVif", "eth" + correctVif.getDevice(conn));
}
if (ip.isAdd() && correctVif == null) {
throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
}
if (correctVif != null) {
ip.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
ip.setNewNic(addVif);
}
}
} catch (final InternalErrorException e) {
s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
} catch (final Exception e) {
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(true, null);
}
Aggregations