Search in sources :

Example 91 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class NotAValidCommand method testOvsDestroyTunnelCommandSuccess.

@Test
public void testOvsDestroyTunnelCommandSuccess() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyTunnelCommand destroyTunnel = new OvsDestroyTunnelCommand(1l, "net01", "port11");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyTunnel.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", destroyTunnel.getInPortName())).thenReturn("SUCCESS");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(destroyTunnel, 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) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) OvsDestroyTunnelCommand(com.cloud.agent.api.OvsDestroyTunnelCommand) Test(org.junit.Test)

Example 92 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class NotAValidCommand method testOvsCreateTunnelCommandSuccess.

@Test
public void testOvsCreateTunnelCommandSuccess() {
    final String bridge = "tunnel";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsCreateTunnelCommand createTunnel = new OvsCreateTunnelCommand("127.0.0.1", 1, 1l, 2l, 1l, "127.0.1.1", "net01", "cd84c713-f448-48c9-ba25-e6740d4a9003");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, createTunnel.getNetworkName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "create_tunnel", "bridge", bridge, "remote_ip", createTunnel.getRemoteIp(), "key", createTunnel.getKey().toString(), "from", createTunnel.getFrom().toString(), "to", createTunnel.getTo().toString(), "cloudstack-network-id", createTunnel.getNetworkUuid())).thenReturn("SUCCESS:0");
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    final Answer answer = wrapper.execute(createTunnel, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    verify(citrixResourceBase, times(1)).configureTunnelNetwork(conn, createTunnel.getNetworkId(), createTunnel.getFrom(), createTunnel.getNetworkName());
    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) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 93 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method setupvSwitchNetwork.

public synchronized Network setupvSwitchNetwork(final Connection conn) {
    try {
        if (_host.getVswitchNetwork() == null) {
            Network vswitchNw = null;
            final Network.Record rec = new Network.Record();
            final String nwName = Networks.BroadcastScheme.VSwitch.toString();
            final Set<Network> networks = Network.getByNameLabel(conn, nwName);
            if (networks.size() == 0) {
                rec.nameDescription = "vswitch network for " + nwName;
                rec.nameLabel = nwName;
                vswitchNw = Network.create(conn, rec);
            } else {
                vswitchNw = networks.iterator().next();
            }
            _host.setVswitchNetwork(vswitchNw);
        }
        return _host.getVswitchNetwork();
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to setup vswitch network", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to setup vswitch network", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to setup vswitch network", e);
    }
    return null;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 94 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method getHostVmStateReport.

protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
    // TODO : new VM sync model does not require a cluster-scope report, we
    // need to optimize
    // the report accordingly
    final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
    Map<VM, VM.Record> vm_map = null;
    for (int i = 0; i < 2; i++) {
        try {
            // USE THIS TO GET ALL VMS FROM
            vm_map = VM.getAllRecords(conn);
            // A CLUSTER
            break;
        } catch (final Throwable e) {
            s_logger.warn("Unable to get vms", e);
        }
        try {
            Thread.sleep(1000);
        } catch (final InterruptedException ex) {
        }
    }
    if (vm_map == null) {
        return vmStates;
    }
    for (final VM.Record record : vm_map.values()) {
        if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
            // Skip DOM0
            continue;
        }
        final VmPowerState ps = record.powerState;
        final Host host = record.residentOn;
        String host_uuid = null;
        if (!isRefNull(host)) {
            try {
                host_uuid = host.getUuid(conn);
            } catch (final BadServerResponse e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            } catch (final XenAPIException e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            } catch (final XmlRpcException e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            }
            if (host_uuid.equalsIgnoreCase(_host.getUuid())) {
                vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
            }
        }
    }
    return vmStates;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VM(com.xensource.xenapi.VM) VmPowerState(com.xensource.xenapi.Types.VmPowerState) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 95 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method attachConfigDriveIsoToVm.

public boolean attachConfigDriveIsoToVm(final Connection conn, final VM vm) throws XenAPIException, XmlRpcException {
    final String vmName = vm.getNameLabel(conn);
    final String isoURL = _configDriveIsopath + vmName + ".iso";
    VDI srVdi;
    try {
        final Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
        if (vdis.isEmpty()) {
            throw new CloudRuntimeException("Could not find ISO with URL: " + isoURL);
        }
        srVdi = vdis.iterator().next();
    } catch (final XenAPIException e) {
        s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
        return false;
    } catch (final Exception e) {
        s_logger.debug("Unable to get config drive iso: " + isoURL + " due to " + e.toString());
        return false;
    }
    VBD isoVBD = null;
    // Find the VM's CD-ROM VBD
    final Set<VBD> vbds = vm.getVBDs(conn);
    for (final VBD vbd : vbds) {
        final Types.VbdType type = vbd.getType(conn);
        final VBD.Record vbdr = vbd.getRecord(conn);
        // if the device exists then attach it
        if (!vbdr.userdevice.equals(_attachIsoDeviceNum) && type == Types.VbdType.CD) {
            isoVBD = vbd;
            break;
        }
    }
    if (isoVBD == null) {
        //create vbd
        final VBD.Record cfgDriveVbdr = new VBD.Record();
        cfgDriveVbdr.VM = vm;
        cfgDriveVbdr.empty = true;
        cfgDriveVbdr.bootable = false;
        cfgDriveVbdr.userdevice = "autodetect";
        cfgDriveVbdr.mode = Types.VbdMode.RO;
        cfgDriveVbdr.type = Types.VbdType.CD;
        final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
        isoVBD = cfgDriveVBD;
        s_logger.debug("Created CD-ROM VBD for VM: " + vm);
    }
    if (isoVBD != null) {
        // If an ISO is already inserted, eject it
        if (isoVBD.getEmpty(conn) == false) {
            isoVBD.eject(conn);
        }
        try {
            // Insert the new ISO
            isoVBD.insert(conn, srVdi);
            s_logger.debug("Attached config drive iso to vm " + vmName);
        } catch (final XmlRpcException ex) {
            s_logger.debug("Failed to attach config drive iso to vm " + vmName);
            return false;
        }
    }
    return true;
}
Also used : Types(com.xensource.xenapi.Types) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XenAPIException (com.xensource.xenapi.Types.XenAPIException)101 XmlRpcException (org.apache.xmlrpc.XmlRpcException)93 Connection (com.xensource.xenapi.Connection)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)53 Answer (com.cloud.agent.api.Answer)33 InternalErrorException (com.cloud.exception.InternalErrorException)31 SR (com.xensource.xenapi.SR)30 Host (com.xensource.xenapi.Host)29 Network (com.xensource.xenapi.Network)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 VDI (com.xensource.xenapi.VDI)25 IOException (java.io.IOException)25 HashMap (java.util.HashMap)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)25 Test (org.junit.Test)25 ConfigurationException (javax.naming.ConfigurationException)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 MalformedURLException (java.net.MalformedURLException)21 URISyntaxException (java.net.URISyntaxException)21 TimeoutException (java.util.concurrent.TimeoutException)21