Search in sources :

Example 31 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse 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 32 with BadServerResponse

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

the class CitrixResourceBase method getHostVmStateReport.

protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
    final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
    Map<VM, VM.Record> vm_map = null;
    for (int i = 0; i < 2; i++) {
        try {
            vm_map = VM.getAllRecords(conn);
            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 33 with BadServerResponse

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

the class CitrixResourceBase method attachConfigDriveToMigratedVm.

public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, String ipAddr) {
    try {
        s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
        Set<VM> vms = VM.getByNameLabel(conn, vmName);
        SR sr = getSRByNameLabel(conn, vmName + VM_NAME_ISO_SUFFIX);
        // Here you will find only two vdis with the <vmname>.iso.
        // one is from source host and second from dest host
        Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX);
        if (vdis.isEmpty()) {
            s_logger.debug("Could not find config drive ISO: " + vmName);
            return false;
        }
        VDI configdriveVdi = null;
        for (VDI vdi : vdis) {
            SR vdiSr = vdi.getSR(conn);
            if (vdiSr.getUuid(conn).equals(sr.getUuid(conn))) {
                // get this vdi to attach to vbd
                configdriveVdi = vdi;
                s_logger.debug("VDI for the config drive ISO  " + vdi);
            } else {
                // delete the vdi in source host so that the <vmname>.iso file is get removed
                s_logger.debug("Removing the source host VDI for the config drive ISO  " + vdi);
                vdi.destroy(conn);
            }
        }
        if (configdriveVdi == null) {
            s_logger.debug("Config drive ISO VDI is not found ");
            return false;
        }
        for (VM vm : vms) {
            // create vbd
            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;
            VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
            s_logger.debug("Inserting vbd " + configdriveVdi);
            cfgDriveVBD.insert(conn, configdriveVdi);
            break;
        }
        return true;
    } catch (BadServerResponse e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a bad server response.", e);
        return false;
    } catch (XenAPIException e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a xapi problem.", e);
        return false;
    } catch (XmlRpcException e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e);
        return false;
    }
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 34 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse 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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with BadServerResponse

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

the class NotAValidCommand method testOvsVpcPhysicalTopologyConfigCommand.

@Test
public void testOvsVpcPhysicalTopologyConfigCommand() {
    final String bridge = "gre";
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsVpcPhysicalTopologyConfigCommand.Host[] hosts = new OvsVpcPhysicalTopologyConfigCommand.Host[0];
    final OvsVpcPhysicalTopologyConfigCommand.Tier[] tiers = new OvsVpcPhysicalTopologyConfigCommand.Tier[0];
    final OvsVpcPhysicalTopologyConfigCommand.Vm[] vms = new OvsVpcPhysicalTopologyConfigCommand.Vm[0];
    final OvsVpcPhysicalTopologyConfigCommand physicalTopology = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, "10.0.0.1/24");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.findOrCreateTunnelNetwork(conn, physicalTopology.getBridgeName())).thenReturn(network);
        when(network.getBridge(conn)).thenReturn(bridge);
        when(citrixResourceBase.callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridge, "config", physicalTopology.getVpcConfigInJson(), "host-id", ((Long) physicalTopology.getHostId()).toString(), "seq-no", Long.toString(1))).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(physicalTopology, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) 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) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)36 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 XmlRpcException (org.apache.xmlrpc.XmlRpcException)36 Connection (com.xensource.xenapi.Connection)25 Answer (com.cloud.agent.api.Answer)20 Network (com.xensource.xenapi.Network)14 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)14 Test (org.junit.Test)13 VDI (com.xensource.xenapi.VDI)12 RebootAnswer (com.cloud.agent.api.RebootAnswer)11 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SR (com.xensource.xenapi.SR)8 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)6