Search in sources :

Example 26 with ExecutionResult

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

the class VmwareResource method networkUsage.

protected String networkUsage(final String privateIpAddress, final String option, final String ethName) {
    String args = null;
    if (option.equals("get")) {
        args = "-g";
    } else if (option.equals("create")) {
        args = "-c";
    } else if (option.equals("reset")) {
        args = "-r";
    } else if (option.equals("addVif")) {
        args = "-a";
        args += ethName;
    } else if (option.equals("deleteVif")) {
        args = "-d";
        args += ethName;
    }
    ExecutionResult result = executeInVR(privateIpAddress, "netusage.sh", args);
    if (!result.isSuccess()) {
        return null;
    }
    return result.getDetails();
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult)

Example 27 with ExecutionResult

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

the class VmwareResource method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(SetSourceNatCommand cmd) {
    String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    String routerIp = getRouterSshControlIp(cmd);
    IpAddressTO pubIp = cmd.getIpAddress();
    try {
        int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress());
        pubIp.setNicDevId(ethDeviceNum);
    } catch (Exception e) {
        String msg = "Prepare Ip SNAT failure due to " + e.toString();
        s_logger.error(msg, e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 28 with ExecutionResult

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

the class VmwareResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) {
    VmwareContext context = getServiceContext();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        IpAddressTO[] ips = cmd.getIpAddresses();
        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
        String controlIp = VmwareResource.getRouterSshControlIp(cmd);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(routerName);
        // the check and will try to find it within cluster
        if (vmMo == null) {
            if (hyperHost instanceof HostMO) {
                ClusterMO clusterMo = new ClusterMO(hyperHost.getContext(), ((HostMO) hyperHost).getParentMor());
                vmMo = clusterMo.findVmOnHyperHost(routerName);
            }
        }
        if (vmMo == null) {
            String msg = "Router " + routerName + " no longer exists to execute IPAssoc command";
            s_logger.error(msg);
            throw new Exception(msg);
        }
        for (IpAddressTO ip : ips) {
            /**
                 * TODO support other networks
                 */
            URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
            if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + ip.getBroadcastUri());
            }
            String vlanId = BroadcastDomainType.getValue(broadcastUri);
            String publicNeworkName = HypervisorHostHelper.getPublicNetworkNamePrefix(vlanId);
            Pair<Integer, VirtualDevice> publicNicInfo = vmMo.getNicDeviceIndex(publicNeworkName);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Find public NIC index, public network name: " + publicNeworkName + ", index: " + publicNicInfo.first());
            }
            boolean addVif = false;
            if (ip.isAdd() && publicNicInfo.first().intValue() == -1) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp());
                }
                addVif = true;
            }
            if (addVif) {
                plugPublicNic(vmMo, vlanId, ip.getVifMacAddress());
                publicNicInfo = vmMo.getNicDeviceIndex(publicNeworkName);
                if (publicNicInfo.first().intValue() >= 0) {
                    networkUsage(controlIp, "addVif", "eth" + publicNicInfo.first());
                }
            }
            if (publicNicInfo.first().intValue() < 0) {
                String msg = "Failed to find DomR VIF to associate/disassociate IP with.";
                s_logger.error(msg);
                throw new InternalErrorException(msg);
            }
            ip.setNicDevId(publicNicInfo.first().intValue());
            ip.setNewNic(addVif);
        }
    } catch (Throwable e) {
        s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VirtualDevice(com.vmware.vim25.VirtualDevice) ExecutionResult(com.cloud.utils.ExecutionResult) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) InternalErrorException(com.cloud.exception.InternalErrorException) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) URI(java.net.URI) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext)

Example 29 with ExecutionResult

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

the class VmwareResource method prepareNetworkElementCommand.

private ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) {
    String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    String routerIp = getRouterSshControlIp(cmd);
    try {
        IpAddressTO[] ips = cmd.getIpAddresses();
        for (IpAddressTO ip : ips) {
            int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, ip.getVifMacAddress());
            if (ethDeviceNum < 0) {
                if (ip.isAdd()) {
                    throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
                } else {
                    s_logger.debug("VIF to deassociate IP with does not exist, return success");
                    continue;
                }
            }
            ip.setNicDevId(ethDeviceNum);
        }
    } catch (Exception e) {
        s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception:  ", e);
        return new ExecutionResult(false, e.toString());
    }
    return new ExecutionResult(true, null);
}
Also used : IpAddressTO(com.cloud.agent.api.to.IpAddressTO) ExecutionResult(com.cloud.utils.ExecutionResult) InternalErrorException(com.cloud.exception.InternalErrorException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 30 with ExecutionResult

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

the class VmwareResource method prepareNetworkElementCommand.

protected ExecutionResult prepareNetworkElementCommand(SetupGuestNetworkCommand cmd) {
    NicTO nic = cmd.getNic();
    String routerIp = getRouterSshControlIp(cmd);
    String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    try {
        int ethDeviceNum = findRouterEthDeviceIndex(domrName, routerIp, nic.getMac());
        nic.setDeviceId(ethDeviceNum);
    } catch (Exception e) {
        String msg = "Prepare SetupGuestNetwork failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new ExecutionResult(false, msg);
    }
    return new ExecutionResult(true, null);
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO)

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