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, "");
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations