Search in sources :

Example 66 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixNetworkRulesVmSecondaryIpCommandWrapper method execute.

@Override
public Answer execute(final NetworkRulesVmSecondaryIpCommand command, final CitrixResourceBase citrixResourceBase) {
    boolean success = true;
    final Connection conn = citrixResourceBase.getConnection();
    final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "network_rules_vmSecondaryIp", "vmName", command.getVmName(), "vmMac", command.getVmMac(), "vmSecIp", command.getVmSecIp(), "action", command.getAction());
    if (result == null || result.isEmpty() || !Boolean.parseBoolean(result)) {
        success = false;
    }
    return new Answer(command, success, "");
}
Also used : Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection)

Example 67 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixOvsCreateGreTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsCreateGreTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    String bridge = "unkonwn";
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_create_gre", "bridge", bridge, "remoteIP", command.getRemoteIp(), "greKey", command.getKey(), "from", Long.toString(command.getFrom()), "to", Long.toString(command.getTo()));
        final String[] res = result.split(":");
        if (res.length != 2 || res.length == 2 && res[1].equalsIgnoreCase("[]")) {
            return new OvsCreateGreTunnelAnswer(command, false, result, citrixResourceBase.getHost().getIp(), bridge);
        } else {
            return new OvsCreateGreTunnelAnswer(command, true, result, citrixResourceBase.getHost().getIp(), bridge, Integer.parseInt(res[1]));
        }
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    }
    return new OvsCreateGreTunnelAnswer(command, false, "EXCEPTION", citrixResourceBase.getHost().getIp(), bridge);
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsCreateGreTunnelAnswer(com.cloud.agent.api.OvsCreateGreTunnelAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 68 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixCleanupNetworkRulesCmdWrapper method execute.

@Override
public Answer execute(final CleanupNetworkRulesCmd command, final CitrixResourceBase citrixResourceBase) {
    if (!citrixResourceBase.canBridgeFirewall()) {
        return new Answer(command, true, null);
    }
    final Connection conn = citrixResourceBase.getConnection();
    final String result = citrixResourceBase.callHostPlugin(conn, "vmops", "cleanup_rules", "instance", citrixResourceBase.getVMInstanceName());
    final int numCleaned = Integer.parseInt(result);
    if (result == null || result.isEmpty() || numCleaned < 0) {
        s_logger.warn("Failed to cleanup rules for host " + citrixResourceBase.getHost().getIp());
        return new Answer(command, false, result);
    }
    if (numCleaned > 0) {
        s_logger.info("Cleaned up rules for " + result + " vms on host " + citrixResourceBase.getHost().getIp());
    }
    return new Answer(command, true, result);
}
Also used : Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection)

Example 69 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    VDI vdi = null;
    try {
        final SR poolSr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
        if (command.getTemplateUrl() != null) {
            VDI tmpltvdi = null;
            tmpltvdi = citrixResourceBase.getVDIbyUuid(conn, command.getTemplateUrl());
            vdi = tmpltvdi.createClone(conn, new HashMap<String, String>());
            vdi.setNameLabel(conn, dskch.getName());
        } else {
            final VDI.Record vdir = new VDI.Record();
            vdir.nameLabel = dskch.getName();
            vdir.SR = poolSr;
            vdir.type = Types.VdiType.USER;
            vdir.virtualSize = dskch.getSize();
            vdi = VDI.create(conn, vdir);
        }
        VDI.Record vdir;
        vdir = vdi.getRecord(conn);
        s_logger.debug("Succesfully created VDI for " + command + ".  Uuid = " + vdir.uuid);
        final VolumeTO vol = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
        return new CreateAnswer(command, vol);
    } catch (final Exception e) {
        s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile) SR(com.xensource.xenapi.SR)

Example 70 with Connection

use of com.xensource.xenapi.Connection in project cloudstack by apache.

the class CitrixDeleteStoragePoolCommandWrapper method execute.

@Override
public Answer execute(final DeleteStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final StorageFilerTO poolTO = command.getPool();
    try {
        final SR sr;
        // instead of pulling it out using getUuid of the StorageFilerTO instance.
        if (command.getRemoveDatastore()) {
            Map<String, String> details = command.getDetails();
            String srNameLabel = details.get(DeleteStoragePoolCommand.DATASTORE_NAME);
            sr = citrixResourceBase.getStorageRepository(conn, srNameLabel);
        } else {
            sr = citrixResourceBase.getStorageRepository(conn, poolTO.getUuid());
        }
        citrixResourceBase.removeSR(conn, sr);
        final Answer answer = new Answer(command, true, "success");
        return answer;
    } catch (final Exception e) {
        final String msg = "DeleteStoragePoolCommand XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + poolTO.getHost() + poolTO.getPath();
        s_logger.error(msg, e);
        return new Answer(command, false, msg);
    }
}
Also used : Answer(com.cloud.agent.api.Answer) Connection(com.xensource.xenapi.Connection) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) SR(com.xensource.xenapi.SR)

Aggregations

Connection (com.xensource.xenapi.Connection)165 XenAPIException (com.xensource.xenapi.Types.XenAPIException)88 XmlRpcException (org.apache.xmlrpc.XmlRpcException)86 Answer (com.cloud.agent.api.Answer)79 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)58 Test (org.junit.Test)53 VDI (com.xensource.xenapi.VDI)47 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)46 SR (com.xensource.xenapi.SR)42 InternalErrorException (com.cloud.exception.InternalErrorException)39 RebootAnswer (com.cloud.agent.api.RebootAnswer)38 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)38 Network (com.xensource.xenapi.Network)35 VM (com.xensource.xenapi.VM)32 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)23 HashMap (java.util.HashMap)23 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)23 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)20 Host (com.xensource.xenapi.Host)19 URI (java.net.URI)19