Search in sources :

Example 6 with PlugNicAnswer

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

the class ManagementServerMock method createVM.

public UserVm createVM(String name, Network network) {
    VMTemplateVO tmpl = getVMTemplate();
    assertNotNull(tmpl);
    ServiceOffering small = getServiceByName("Small Instance");
    assertNotNull(small);
    Answer<?> callback = new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            Commands cmds = (Commands) args[1];
            if (cmds == null) {
                return null;
            }
            PlugNicAnswer reply = new PlugNicAnswer(null, true, "PlugNic");
            com.cloud.agent.api.Answer[] answers = { reply };
            cmds.setAnswers(answers);
            return null;
        }
    };
    try {
        Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback);
    } catch (AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long id = _userVmDao.getNextInSequence(Long.class, "id");
    UserVmVO vm = new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM, 1, small.getId(), null, name, null);
    vm.setState(com.cloud.vm.VirtualMachine.State.Running);
    vm.setHostId(_hostId);
    vm.setDataCenterId(network.getDataCenterId());
    _userVmDao.persist(vm);
    NicProfile profile = new NicProfile();
    try {
        _vmMgr.addVmToNetwork(vm, network, profile);
    } catch (Exception ex) {
    // TODO Auto-generated catch block
    //ex.printStackTrace();
    }
    return vm;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UserVmVO(com.cloud.vm.UserVmVO) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) NicProfile(com.cloud.vm.NicProfile) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) Answer(org.mockito.stubbing.Answer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer)

Aggregations

PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)6 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)4 NicTO (com.cloud.agent.api.to.NicTO)4 InternalErrorException (com.cloud.exception.InternalErrorException)3 Commands (com.cloud.agent.manager.Commands)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 RemoteException (java.rmi.RemoteException)2 ConfigurationException (javax.naming.ConfigurationException)2 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)1 UnPlugNicCommand (com.cloud.agent.api.UnPlugNicCommand)1 CloudException (com.cloud.exception.CloudException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)1 VifDriver (com.cloud.hypervisor.kvm.resource.VifDriver)1 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)1 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)1