Search in sources :

Example 6 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class LibvirtComputingResource method cleanupNetworkElementCommand.

protected ExecutionResult cleanupNetworkElementCommand(final IpAssocCommand cmd) {
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
    final String lastIp = cmd.getAccessDetail(NetworkElementCommand.NETWORK_PUB_LAST_IP);
    Connect conn;
    try {
        conn = LibvirtConnection.getConnectionByVmName(routerName);
        final List<InterfaceDef> nics = getInterfaces(conn, routerName);
        final Map<String, Integer> broadcastUriAllocatedToVM = new HashMap<String, Integer>();
        Integer nicPos = 0;
        for (final InterfaceDef nic : nics) {
            if (nic.getBrName().equalsIgnoreCase(_linkLocalBridgeName)) {
                broadcastUriAllocatedToVM.put("LinkLocal", nicPos);
            } else {
                if (nic.getBrName().equalsIgnoreCase(_publicBridgeName) || nic.getBrName().equalsIgnoreCase(_privBridgeName) || nic.getBrName().equalsIgnoreCase(_guestBridgeName)) {
                    broadcastUriAllocatedToVM.put(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED).toString(), nicPos);
                } else {
                    final String broadcastUri = getBroadcastUriFromBridge(nic.getBrName());
                    broadcastUriAllocatedToVM.put(broadcastUri, nicPos);
                }
            }
            nicPos++;
        }
        final IpAddressTO[] ips = cmd.getIpAddresses();
        final int numOfIps = ips.length;
        int nicNum = 0;
        for (final IpAddressTO ip : ips) {
            if (!broadcastUriAllocatedToVM.containsKey(ip.getBroadcastUri())) {
                /* plug a vif into router */
                VifHotPlug(conn, routerName, ip.getBroadcastUri(), ip.getVifMacAddress());
                broadcastUriAllocatedToVM.put(ip.getBroadcastUri(), nicPos++);
            }
            nicNum = broadcastUriAllocatedToVM.get(ip.getBroadcastUri());
            if (org.apache.commons.lang.StringUtils.equalsIgnoreCase(lastIp, "true") && !ip.isAdd()) {
                // in isolated network eth2 is the default public interface. We don't want to delete it.
                if (nicNum != 2) {
                    vifHotUnPlug(conn, routerName, ip.getVifMacAddress());
                    networkUsage(routerIp, "deleteVif", "eth" + nicNum);
                }
            }
        }
    } catch (final LibvirtException e) {
        s_logger.error("ipassoccmd failed", e);
        return new ExecutionResult(false, e.getMessage());
    } catch (final InternalErrorException e) {
        s_logger.error("ipassoccmd failed", e);
        return new ExecutionResult(false, e.getMessage());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) LibvirtException(org.libvirt.LibvirtException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) InterfaceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)

Example 7 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class LibvirtComputingResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
    Connect conn;
    final NicTO nic = cmd.getNic();
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        conn = LibvirtConnection.getConnectionByVmName(routerName);
        final List<InterfaceDef> pluggedNics = getInterfaces(conn, routerName);
        InterfaceDef routerNic = null;
        for (final InterfaceDef pluggedNic : pluggedNics) {
            if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
                routerNic = pluggedNic;
                break;
            }
        }
        if (routerNic == null) {
            return new ExecutionResult(false, "Can not find nic with mac " + nic.getMac() + " for VM " + routerName);
        }
        return new ExecutionResult(true, null);
    } catch (final LibvirtException e) {
        final String msg = "Creating guest network failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new ExecutionResult(false, msg);
    }
}
Also used : InterfaceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ExecutionResult(com.cloud.utils.ExecutionResult) NicTO(com.cloud.agent.api.to.NicTO)

Example 8 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class LibvirtComputingResource method executeInVR.

@Override
public ExecutionResult executeInVR(final String routerIp, final String script, final String args, final Duration timeout) {
    final Script command = new Script(_routerProxyPath, timeout, s_logger);
    final AllLinesParser parser = new AllLinesParser();
    command.add(script);
    command.add(routerIp);
    if (args != null) {
        command.add(args);
    }
    String details = command.execute(parser);
    if (details == null) {
        details = parser.getLines();
    }
    return new ExecutionResult(command.getExitValue() == 0, details);
}
Also used : Script(com.cloud.utils.script.Script) AllLinesParser(com.cloud.utils.script.OutputInterpreter.AllLinesParser) ExecutionResult(com.cloud.utils.ExecutionResult)

Example 9 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class Ovm3VirtualRoutingResource method executeInVR.

@Override
public ExecutionResult executeInVR(String routerIp, String script, String args, Duration timeout) {
    if (!script.contains(domRCloudPath)) {
        script = domRCloudPath + "/" + script;
    }
    String cmd = script + " " + args;
    logger.debug("executeInVR via " + agentName + " on " + routerIp + ": " + cmd);
    try {
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        CloudstackPlugin.ReturnCode result;
        result = cSp.domrExec(routerIp, cmd);
        return new ExecutionResult(result.getRc(), result.getStdOut());
    } catch (Exception e) {
        logger.error("executeInVR FAILED via " + agentName + " on " + routerIp + ":" + cmd + ", " + e.getMessage(), e);
    }
    return new ExecutionResult(false, "");
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 10 with ExecutionResult

use of com.cloud.utils.ExecutionResult in project cloudstack by apache.

the class Ovm3VirtualRoutingResource method prepNetBoth.

private ExecutionResult prepNetBoth(String routerName, IpAddressTO[] ips, String type) {
    Xen xen = new Xen(c);
    try {
        Xen.Vm vm = xen.getVmConfig(routerName);
        for (IpAddressTO ip : ips) {
            Integer devId = vm.getVifIdByMac(ip.getVifMacAddress());
            if (devId < 0 && "IpAssocVpcCommand".equals(type)) {
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress();
                logger.error(msg);
                return new ExecutionResult(false, msg);
            } else if (devId < 0 && "IpAssocCommand".equals(type)) {
                // vm.get
                String msg = "No valid Nic devId found for " + vm.getVmName() + " with " + ip.getVifMacAddress() + " " + " Ignoring for now (routervm)";
                logger.debug(msg);
                devId = 2;
            }
            ip.setNicDevId(devId);
        }
    } catch (Exception e) {
        String msg = type + " failure on applying one ip due to exception:  " + e;
        logger.error(msg);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult)

Aggregations

ExecutionResult (com.cloud.utils.ExecutionResult)50 InternalErrorException (com.cloud.exception.InternalErrorException)23 IOException (java.io.IOException)20 ConfigurationException (javax.naming.ConfigurationException)20 IpAddressTO (com.cloud.agent.api.to.IpAddressTO)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)16 URISyntaxException (java.net.URISyntaxException)13 NicTO (com.cloud.agent.api.to.NicTO)11 ConnectException (java.net.ConnectException)11 RemoteException (java.rmi.RemoteException)11 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)9 SAXException (org.xml.sax.SAXException)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)8 MalformedURLException (java.net.MalformedURLException)8 TimeoutException (java.util.concurrent.TimeoutException)8 XmlRpcException (org.apache.xmlrpc.XmlRpcException)8 CloudException (com.cloud.exception.CloudException)7 Connection (com.xensource.xenapi.Connection)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 URI (java.net.URI)7