Search in sources :

Example 66 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class VmwareResource method sortNicsByDeviceId.

private static NicTO[] sortNicsByDeviceId(NicTO[] nics) {
    List<NicTO> listForSort = new ArrayList<NicTO>();
    for (NicTO nic : nics) {
        listForSort.add(nic);
    }
    Collections.sort(listForSort, new Comparator<NicTO>() {

        @Override
        public int compare(NicTO arg0, NicTO arg1) {
            if (arg0.getDeviceId() < arg1.getDeviceId()) {
                return -1;
            } else if (arg0.getDeviceId() == arg1.getDeviceId()) {
                return 0;
            }
            return 1;
        }
    });
    return listForSort.toArray(new NicTO[0]);
}
Also used : ArrayList(java.util.ArrayList) NicTO(com.cloud.agent.api.to.NicTO)

Example 67 with NicTO

use of com.cloud.agent.api.to.NicTO 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());
    }
}
Also used : InternalErrorException(com.cloud.exception.InternalErrorException) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) URI(java.net.URI) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ClientProtocolException(org.apache.http.client.ClientProtocolException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) NicTO(com.cloud.agent.api.to.NicTO)

Example 68 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class HypervGuru method sortNicsByDeviceId.

private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
    List<NicTO> listForSort = new ArrayList<NicTO>();
    for (NicTO nic : nics) {
        listForSort.add(nic);
    }
    Collections.sort(listForSort, new Comparator<NicTO>() {

        @Override
        public int compare(NicTO arg0, NicTO arg1) {
            if (arg0.getDeviceId() < arg1.getDeviceId()) {
                return -1;
            } else if (arg0.getDeviceId() == arg1.getDeviceId()) {
                return 0;
            }
            return 1;
        }
    });
    return listForSort.toArray(new NicTO[0]);
}
Also used : ArrayList(java.util.ArrayList) NicTO(com.cloud.agent.api.to.NicTO)

Example 69 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class Ovm3VmSupportTest method PlugNicBreakTest.

@Test
public void PlugNicBreakTest() throws ConfigurationException, URISyntaxException {
    hypervisor = support.prepare(configTest.getParams());
    NicTO nic = prepNic(xen.getVmNicMac(), 240, TrafficType.Guest);
    PlugNicCommand plug = new PlugNicCommand(nic, xen.getVmName(), VirtualMachine.Type.User);
    Answer ra = hypervisor.executeRequest(plug);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : Answer(com.cloud.agent.api.Answer) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) NicTO(com.cloud.agent.api.to.NicTO) Test(org.junit.Test) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) CloudStackPluginTest(com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3HypervisorResourceTest(com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResourceTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)

Example 70 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class Ovm3VmSupportTest method unPlugNicBreakTest.

@Test
public void unPlugNicBreakTest() throws ConfigurationException, URISyntaxException {
    hypervisor = support.prepare(configTest.getParams());
    NicTO nic = prepNic(xen.getVmNicMac(), 240, TrafficType.Guest);
    UnPlugNicCommand plug = new UnPlugNicCommand(nic, xen.getVmName());
    Answer ra = hypervisor.executeRequest(plug);
    results.basicBooleanTest(ra.getResult(), false);
}
Also used : Answer(com.cloud.agent.api.Answer) NicTO(com.cloud.agent.api.to.NicTO) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) Test(org.junit.Test) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) CloudStackPluginTest(com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3HypervisorResourceTest(com.cloud.hypervisor.ovm3.resources.Ovm3HypervisorResourceTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)

Aggregations

NicTO (com.cloud.agent.api.to.NicTO)99 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)42 Answer (com.cloud.agent.api.Answer)31 Test (org.junit.Test)30 InternalErrorException (com.cloud.exception.InternalErrorException)28 LibvirtException (org.libvirt.LibvirtException)27 ArrayList (java.util.ArrayList)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 ConfigurationException (javax.naming.ConfigurationException)23 Connect (org.libvirt.Connect)23 URISyntaxException (java.net.URISyntaxException)22 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)21 IOException (java.io.IOException)20 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)19 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)19 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)19 Connection (com.xensource.xenapi.Connection)18 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 UnPlugNicCommand (com.cloud.agent.api.UnPlugNicCommand)13 URI (java.net.URI)12