Search in sources :

Example 6 with XsLocalNetwork

use of com.cloud.hypervisor.xenserver.resource.XsLocalNetwork in project cloudstack by apache.

the class CitrixOvsFetchInterfaceCommandWrapper method execute.

@Override
public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) {
    String label = command.getLabel();
    //FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host.
    if (citrixResourceBase.isXcp()) {
        label = citrixResourceBase.getLabel();
    }
    s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp());
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label);
        if (nw == null) {
            throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp());
        }
        s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn));
        final PIF pif = nw.getPif(conn);
        final PIF.Record pifRec = pif.getRecord(conn);
        s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")");
        return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC);
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    }
}
Also used : XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 7 with XsLocalNetwork

use of com.cloud.hypervisor.xenserver.resource.XsLocalNetwork in project cloudstack by apache.

the class XenServer610WrapperTest method testMigrateWithStorageReceiveCommand.

@Test
public void testMigrateWithStorageReceiveCommand() {
    final String vmName = "small";
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final Connection conn = Mockito.mock(Connection.class);
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
    final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
    final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
    final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
    final List<Pair<VolumeTO, String>> volumeToFiler = new ArrayList<>();
    volumeToFiler.add(new Pair<>(vol1, storage1.getPath()));
    volumeToFiler.add(new Pair<>(vol2, storage2.getPath()));
    final NicTO nicTO1 = Mockito.mock(NicTO.class);
    final NicTO nicTO2 = Mockito.mock(NicTO.class);
    final NicTO nicTO3 = Mockito.mock(NicTO.class);
    final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
    final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
    final Network network = Mockito.mock(Network.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final Network nw1 = Mockito.mock(Network.class);
    final Network nw2 = Mockito.mock(Network.class);
    final Network nw3 = Mockito.mock(Network.class);
    final SR sr1 = Mockito.mock(SR.class);
    final SR sr2 = Mockito.mock(SR.class);
    final MigrateWithStorageReceiveCommand migrateStorageCommand = new MigrateWithStorageReceiveCommand(vmSpec, volumeToFiler);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer610Resource.getConnection()).thenReturn(conn);
    when(vmSpec.getName()).thenReturn(vmName);
    when(vmSpec.getNics()).thenReturn(nicTOs);
    when(storage1.getUuid()).thenReturn(uuid);
    when(storage2.getUuid()).thenReturn(uuid);
    when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
    when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
    try {
        when(xenServer610Resource.getNetwork(conn, nicTO1)).thenReturn(nw1);
        when(xenServer610Resource.getNetwork(conn, nicTO2)).thenReturn(nw2);
        when(xenServer610Resource.getNetwork(conn, nicTO3)).thenReturn(nw3);
        when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
        when(nativeNetworkForTraffic.getNetwork()).thenReturn(network);
        when(xenServer610Resource.getHost()).thenReturn(xsHost);
        when(xsHost.getUuid()).thenReturn(uuid);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
    verify(xenServer610Resource, times(1)).getConnection();
    try {
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
        verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
        verify(nativeNetworkForTraffic, times(1)).getNetwork();
        verify(xenServer610Resource, times(1)).getHost();
        verify(xsHost, times(1)).getUuid();
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    assertFalse(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) MigrateWithStorageReceiveCommand(com.cloud.agent.api.MigrateWithStorageReceiveCommand) Answer(com.cloud.agent.api.Answer) VolumeTO(com.cloud.agent.api.to.VolumeTO) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Pair(com.cloud.utils.Pair) NicTO(com.cloud.agent.api.to.NicTO) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Example 8 with XsLocalNetwork

use of com.cloud.hypervisor.xenserver.resource.XsLocalNetwork in project cloudstack by apache.

the class XenServer610WrapperTest method testMigrateWithStorageCommand.

@Test
public void testMigrateWithStorageCommand() {
    final String vmName = "small";
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final String path = "/";
    final Connection conn = Mockito.mock(Connection.class);
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final VolumeTO vol1 = Mockito.mock(VolumeTO.class);
    final VolumeTO vol2 = Mockito.mock(VolumeTO.class);
    final StorageFilerTO storage1 = Mockito.mock(StorageFilerTO.class);
    final StorageFilerTO storage2 = Mockito.mock(StorageFilerTO.class);
    final Map<VolumeTO, StorageFilerTO> volumeToFiler = new HashMap<VolumeTO, StorageFilerTO>();
    volumeToFiler.put(vol1, storage1);
    volumeToFiler.put(vol2, storage2);
    final NicTO nicTO1 = Mockito.mock(NicTO.class);
    final NicTO nicTO2 = Mockito.mock(NicTO.class);
    final NicTO nicTO3 = Mockito.mock(NicTO.class);
    final NicTO[] nicTOs = { nicTO1, nicTO2, nicTO3 };
    final XsLocalNetwork nativeNetworkForTraffic = Mockito.mock(XsLocalNetwork.class);
    final Network networkForSm = Mockito.mock(Network.class);
    final XsHost xsHost = Mockito.mock(XsHost.class);
    final SR sr1 = Mockito.mock(SR.class);
    final SR sr2 = Mockito.mock(SR.class);
    final VDI vdi1 = Mockito.mock(VDI.class);
    final VDI vdi2 = Mockito.mock(VDI.class);
    final MigrateWithStorageCommand migrateStorageCommand = new MigrateWithStorageCommand(vmSpec, volumeToFiler);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer610Resource.getConnection()).thenReturn(conn);
    when(vmSpec.getName()).thenReturn(vmName);
    when(vmSpec.getNics()).thenReturn(nicTOs);
    when(storage1.getUuid()).thenReturn(uuid);
    when(storage2.getUuid()).thenReturn(uuid);
    when(vol1.getPath()).thenReturn(path);
    when(vol2.getPath()).thenReturn(path);
    when(xenServer610Resource.getStorageRepository(conn, storage1.getUuid())).thenReturn(sr1);
    when(xenServer610Resource.getStorageRepository(conn, storage2.getUuid())).thenReturn(sr2);
    when(xenServer610Resource.getVDIbyUuid(conn, storage1.getPath())).thenReturn(vdi1);
    when(xenServer610Resource.getVDIbyUuid(conn, storage2.getPath())).thenReturn(vdi2);
    try {
        when(xenServer610Resource.getNativeNetworkForTraffic(conn, TrafficType.Storage, null)).thenReturn(nativeNetworkForTraffic);
        when(nativeNetworkForTraffic.getNetwork()).thenReturn(networkForSm);
        when(xenServer610Resource.getHost()).thenReturn(xsHost);
        when(xsHost.getUuid()).thenReturn(uuid);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(migrateStorageCommand, xenServer610Resource);
    verify(xenServer610Resource, times(1)).getConnection();
    try {
        verify(xenServer610Resource, times(1)).prepareISO(conn, vmName, null, null);
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO1);
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO2);
        verify(xenServer610Resource, times(1)).getNetwork(conn, nicTO3);
        verify(xenServer610Resource, times(1)).getNativeNetworkForTraffic(conn, TrafficType.Storage, null);
        verify(nativeNetworkForTraffic, times(1)).getNetwork();
        verify(xenServer610Resource, times(1)).getHost();
        verify(xsHost, times(1)).getUuid();
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    assertFalse(answer.getResult());
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) Answer(com.cloud.agent.api.Answer) VolumeTO(com.cloud.agent.api.to.VolumeTO) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) NicTO(com.cloud.agent.api.to.NicTO) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Example 9 with XsLocalNetwork

use of com.cloud.hypervisor.xenserver.resource.XsLocalNetwork in project cloudstack by apache.

the class NotAValidCommand method testPvlanSetupCommandDhcpSuccess.

@Test
public void testPvlanSetupCommandDhcpSuccess() {
    final String label = "net";
    final Connection conn = Mockito.mock(Connection.class);
    final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
    final Network network2 = Mockito.mock(Network.class);
    final PvlanSetupCommand lanSetup = PvlanSetupCommand.createDhcpSetup("add", URI.create("http://127.0.0.1"), "tag", "dhcp", "0:0:0:0:0:0", "127.0.0.1");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String dhcpName = lanSetup.getDhcpName();
    final String dhcpMac = lanSetup.getDhcpMac();
    final String dhcpIp = lanSetup.getDhcpIp();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, "tag")).thenReturn(network);
        when(network.getNetwork()).thenReturn(network2);
        when(network2.getNameLabel(conn)).thenReturn(label);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac)).thenReturn("true");
    final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 10 with XsLocalNetwork

use of com.cloud.hypervisor.xenserver.resource.XsLocalNetwork in project cloudstack by apache.

the class NotAValidCommand method testPvlanSetupCommandVmSuccess.

@Test
public void testPvlanSetupCommandVmSuccess() {
    final String label = "net";
    final Connection conn = Mockito.mock(Connection.class);
    final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
    final Network network2 = Mockito.mock(Network.class);
    final PvlanSetupCommand lanSetup = PvlanSetupCommand.createVmSetup("add", URI.create("http://127.0.0.1"), "tag", "0:0:0:0:0:0");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String vmMac = lanSetup.getVmMac();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, "tag")).thenReturn(network);
        when(network.getNetwork()).thenReturn(network2);
        when(network2.getNameLabel(conn)).thenReturn(label);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac)).thenReturn("true");
    final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Aggregations

XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)11 Connection (com.xensource.xenapi.Connection)11 Network (com.xensource.xenapi.Network)9 XenAPIException (com.xensource.xenapi.Types.XenAPIException)9 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 Answer (com.cloud.agent.api.Answer)8 Test (org.junit.Test)7 RebootAnswer (com.cloud.agent.api.RebootAnswer)5 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)5 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)5 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)4 NicTO (com.cloud.agent.api.to.NicTO)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 VolumeTO (com.cloud.agent.api.to.VolumeTO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 SR (com.xensource.xenapi.SR)4 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)3 Pair (com.cloud.utils.Pair)3 HashMap (java.util.HashMap)3