Search in sources :

Example 6 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method configure.

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    this._name = name;
    try {
        this._dcId = Long.parseLong((String) params.get("zone"));
    } catch (final NumberFormatException e) {
        throw new ConfigurationException("Unable to get the zone " + params.get("zone"));
    }
    this._host.setUuid((String) params.get("guid"));
    this._name = this._host.getUuid();
    this._host.setIp((String) params.get("ipaddress"));
    this._username = (String) params.get("username");
    this._password.add((String) params.get("password"));
    this._pod = (String) params.get("pod");
    this._cluster = (String) params.get("cluster");
    this._privateNetworkName = (String) params.get("private.network.device");
    this._publicNetworkName = (String) params.get("public.network.device");
    this._guestNetworkName = (String) params.get("guest.network.device");
    this._instance = (String) params.get("instance.name");
    this._linkLocalPrivateNetworkName = (String) params.get("private.linkLocal.device");
    if (this._linkLocalPrivateNetworkName == null) {
        this._linkLocalPrivateNetworkName = "cloud_link_local_network";
    }
    this._storageNetworkName1 = (String) params.get("storage.network.device1");
    this._storageNetworkName2 = (String) params.get("storage.network.device2");
    this._heartbeatTimeout = NumbersUtil.parseInt((String) params.get("xenserver.heartbeat.timeout"), 120);
    this._heartbeatInterval = NumbersUtil.parseInt((String) params.get("xenserver.heartbeat.interval"), 60);
    String value = (String) params.get("wait");
    this._wait = NumbersUtil.parseInt(value, 600);
    value = (String) params.get("migratewait");
    this._migratewait = NumbersUtil.parseInt(value, 3600);
    this._maxNics = NumbersUtil.parseInt((String) params.get("xenserver.nics.max"), 7);
    if (this._pod == null) {
        throw new ConfigurationException("Unable to get the pod");
    }
    if (this._host.getIp() == null) {
        throw new ConfigurationException("Unable to get the host address");
    }
    if (this._username == null) {
        throw new ConfigurationException("Unable to get the username");
    }
    if (this._password.peek() == null) {
        throw new ConfigurationException("Unable to get the password");
    }
    if (this._host.getUuid() == null) {
        throw new ConfigurationException("Unable to get the uuid");
    }
    CheckXenHostInfo();
    this.storageHandler = buildStorageHandler();
    this._vrResource = new VirtualRoutingResource(this);
    if (!this._vrResource.configure(params)) {
        throw new ConfigurationException("Unable to configure VirtualRoutingResource");
    }
    return true;
}
Also used : ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource)

Example 7 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

the class LibvirtCheckSshCommandWrapper method execute.

@Override
public Answer execute(final CheckSshCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String vmName = command.getName();
    final String privateIp = command.getIp();
    final int cmdPort = command.getPort();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort);
    }
    final VirtualRoutingResource virtRouterResource = libvirtComputingResource.getVirtRouterResource();
    if (!virtRouterResource.connect(privateIp, cmdPort)) {
        return new CheckSshAnswer(command, "Can not ping System vm " + vmName + " because of a connection failure");
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Ping command port succeeded for vm " + vmName);
    }
    return new CheckSshAnswer(command);
}
Also used : CheckSshAnswer(com.cloud.legacymodel.communication.answer.CheckSshAnswer) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource)

Example 8 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testStartCommandIsolationEc2.

@Test
public void testStartCommandIsolationEc2() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final Host host = Mockito.mock(Host.class);
    final boolean executeInSequence = false;
    final StartCommand command = new StartCommand(vmSpec, host, executeInSequence);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtVmDef vmDef = Mockito.mock(LibvirtVmDef.class);
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    final NicTO nic = Mockito.mock(NicTO.class);
    final NicTO[] nics = new NicTO[] { nic };
    final int[] vms = new int[0];
    final String vmName = "Test";
    final String controlIp = "127.0.0.1";
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachineType.DomainRouter);
    when(vmSpec.getName()).thenReturn(vmName);
    when(this.libvirtComputingResource.createVmFromSpec(vmSpec)).thenReturn(vmDef);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
        when(conn.listDomains()).thenReturn(vms);
        doNothing().when(this.libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final URISyntaxException e) {
        fail(e.getMessage());
    }
    when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
    try {
        doNothing().when(this.libvirtComputingResource).createVifs(vmSpec, vmDef);
        when(this.libvirtComputingResource.startVm(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
        when(nic.getIsolationUri()).thenReturn(new URI("ec2://test"));
        when(vmSpec.getBootArgs()).thenReturn("ls -lart");
        when(this.libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
        when(nic.getIp()).thenReturn(controlIp);
        when(nic.getType()).thenReturn(TrafficType.Control);
        when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
        when(virtRouterResource.connect(controlIp, 30, 5000)).thenReturn(true);
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final URISyntaxException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.legacymodel.communication.command.StartCommand) Connect(org.libvirt.Connect) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) Host(com.cloud.legacymodel.dc.Host) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 9 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testRebootRouterCommand.

@Test
public void testRebootRouterCommand() {
    final VirtualRoutingResource routingResource = Mockito.mock(VirtualRoutingResource.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
    when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootRouterCommand(com.cloud.legacymodel.communication.command.RebootRouterCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 10 with VirtualRoutingResource

use of com.cloud.common.virtualnetwork.VirtualRoutingResource in project cosmic by MissionCriticalCloud.

the class LibvirtRebootRouterCommandWrapper method execute.

@Override
public Answer execute(final RebootRouterCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    final RebootCommand rebootCommand = new RebootCommand(command.getVmName(), true);
    final Answer answer = wrapper.execute(rebootCommand, libvirtComputingResource);
    final VirtualRoutingResource virtualRouterResource = libvirtComputingResource.getVirtRouterResource();
    if (virtualRouterResource.connect(command.getPrivateIpAddress())) {
        libvirtComputingResource.networkUsage(command.getPrivateIpAddress(), "create", null);
        return answer;
    } else {
        return new Answer(command, false, "Failed to connect to virtual router " + command.getVmName());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource)

Aggregations

VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)11 Answer (com.cloud.legacymodel.communication.answer.Answer)8 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)7 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)7 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)7 Test (org.junit.Test)7 Connect (org.libvirt.Connect)5 LibvirtException (org.libvirt.LibvirtException)5 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)3 LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)3 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)3 NicTO (com.cloud.legacymodel.to.NicTO)3 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)3 URISyntaxException (java.net.URISyntaxException)3 CheckSshCommand (com.cloud.legacymodel.communication.command.CheckSshCommand)2 RebootRouterCommand (com.cloud.legacymodel.communication.command.RebootRouterCommand)2 StartCommand (com.cloud.legacymodel.communication.command.StartCommand)2 Host (com.cloud.legacymodel.dc.Host)2 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)1