Search in sources :

Example 26 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixResourceBase method getVncUrl.

public String getVncUrl(final Connection conn, final VM vm) {
    VM.Record record;
    Console c;
    try {
        record = vm.getRecord(conn);
        final Set<Console> consoles = record.consoles;
        if (consoles.isEmpty()) {
            s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
            return null;
        }
        final Iterator<Console> i = consoles.iterator();
        while (i.hasNext()) {
            c = i.next();
            if (c.getProtocol(conn) == Types.ConsoleProtocol.RFB) {
                return c.getLocation(conn);
            }
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to get console url due to " + e.toString();
        s_logger.warn(msg, e);
        return null;
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get console url due to " + e.getMessage();
        s_logger.warn(msg, e);
        return null;
    }
    return null;
}
Also used : VM(com.xensource.xenapi.VM) Console(com.xensource.xenapi.Console) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 27 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixResourceBase method removeSR.

public void removeSR(final Connection conn, final SR sr) {
    if (sr == null) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(logX(sr, "Removing SR"));
    }
    for (int i = 0; i < 2; i++) {
        try {
            final Set<VDI> vdis = sr.getVDIs(conn);
            for (final VDI vdi : vdis) {
                vdi.forget(conn);
            }
            Set<PBD> pbds = sr.getPBDs(conn);
            for (final PBD pbd : pbds) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(logX(pbd, "Unplugging pbd"));
                }
                // if (pbd.getCurrentlyAttached(conn)) {
                pbd.unplug(conn);
                // }
                pbd.destroy(conn);
            }
            pbds = sr.getPBDs(conn);
            if (pbds.size() == 0) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(logX(sr, "Forgetting"));
                }
                sr.forget(conn);
                return;
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(logX(sr, "There is still one or more PBDs attached."));
                if (s_logger.isTraceEnabled()) {
                    for (final PBD pbd : pbds) {
                        s_logger.trace(logX(pbd, " Still attached"));
                    }
                }
            }
        } catch (final XenAPIException e) {
            s_logger.debug(logX(sr, "Catch XenAPIException: " + e.toString()));
        } catch (final XmlRpcException e) {
            s_logger.debug(logX(sr, "Catch Exception: " + e.getMessage()));
        }
    }
    s_logger.warn(logX(sr, "Unable to remove SR"));
}
Also used : PBD(com.xensource.xenapi.PBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 28 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixPvlanSetupCommandWrapper method execute.

@Override
public Answer execute(final PvlanSetupCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final String primaryPvlan = command.getPrimary();
    final String isolatedPvlan = command.getIsolated();
    final String op = command.getOp();
    final String dhcpName = command.getDhcpName();
    final String dhcpMac = command.getDhcpMac();
    final String dhcpIp = command.getDhcpIp();
    final String vmMac = command.getVmMac();
    final String networkTag = command.getNetworkTag();
    String nwNameLabel = null;
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, networkTag);
        if (nw == null) {
            s_logger.error("Network is not configured on the backend for pvlan " + primaryPvlan);
            throw new CloudRuntimeException("Network for the backend is not configured correctly for pvlan primary: " + primaryPvlan);
        }
        nwNameLabel = nw.getNetwork().getNameLabel(conn);
    } catch (final XenAPIException e) {
        s_logger.warn("Fail to get network", e);
        return new Answer(command, false, e.toString());
    } catch (final XmlRpcException e) {
        s_logger.warn("Fail to get network", e);
        return new Answer(command, false, e.toString());
    }
    String result = null;
    if (command.getType() == PvlanSetupCommand.Type.DHCP) {
        result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-dhcp", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "dhcp-name", dhcpName, "dhcp-ip", dhcpIp, "dhcp-mac", dhcpMac);
        if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
            s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
            return new Answer(command, false, result);
        } else {
            s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
        }
    } else if (command.getType() == PvlanSetupCommand.Type.VM) {
        result = citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", nwNameLabel, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac);
        if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
            s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
            return new Answer(command, false, result);
        } else {
            s_logger.info("Programmed pvlan for vm with mac " + vmMac);
        }
    }
    return new Answer(command, true, result);
}
Also used : Answer(com.cloud.agent.api.Answer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 29 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixReadyCommandWrapper method execute.

@Override
public Answer execute(final ReadyCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final Long dcId = command.getDataCenterId();
    // Ignore the result of the callHostPlugin. Even if unmounting the
    // snapshots dir fails, let Ready command
    // succeed.
    citrixResourceBase.umountSnapshotDir(conn, dcId);
    citrixResourceBase.setupLinkLocalNetwork(conn);
    // try to destroy CD-ROM device for all system VMs on this host
    try {
        final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
        final Set<VM> vms = host.getResidentVMs(conn);
        for (final VM vm : vms) {
            citrixResourceBase.destroyPatchVbd(conn, vm.getNameLabel(conn));
        }
    } catch (final Exception e) {
    }
    try {
        final boolean result = citrixResourceBase.cleanupHaltedVms(conn);
        if (!result) {
            return new ReadyAnswer(command, "Unable to cleanup halted vms");
        }
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to cleanup halted vms", e);
        return new ReadyAnswer(command, "Unable to cleanup halted vms");
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to cleanup halted vms", e);
        return new ReadyAnswer(command, "Unable to cleanup halted vms");
    }
    return new ReadyAnswer(command);
}
Also used : VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 30 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class NotAValidCommand method testPvlanSetupCommandDhcpFailure.

@Test
public void testPvlanSetupCommandDhcpFailure() {
    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("false");
    final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(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

XmlRpcException (org.apache.xmlrpc.XmlRpcException)100 XenAPIException (com.xensource.xenapi.Types.XenAPIException)75 Connection (com.xensource.xenapi.Connection)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 Answer (com.cloud.agent.api.Answer)33 IOException (java.io.IOException)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 Network (com.xensource.xenapi.Network)25 Test (org.junit.Test)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Host (com.xensource.xenapi.Host)21 RebootAnswer (com.cloud.agent.api.RebootAnswer)20 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)20 HashMap (java.util.HashMap)20 VM (com.xensource.xenapi.VM)17 VDI (com.xensource.xenapi.VDI)16 ConfigurationException (javax.naming.ConfigurationException)16 SR (com.xensource.xenapi.SR)15 InternalErrorException (com.cloud.exception.InternalErrorException)13