use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class CitrixResourceBase method createLocalIsoSR.
public SR createLocalIsoSR(final Connection conn, final String srName) throws XenAPIException, XmlRpcException {
// if config drive sr already exists then return
SR sr = getSRByNameLabelandHost(conn, _configDriveSRName + _host.getIp());
if (sr != null) {
s_logger.debug("Config drive SR already exist, returing it");
return sr;
}
try {
final Map<String, String> deviceConfig = new HashMap<String, String>();
final com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_host.getIp(), 22);
try {
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(_username, _password.peek())) {
throw new CloudRuntimeException("Unable to authenticate");
}
final String cmd = "mkdir -p " + _configDriveIsopath;
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
throw new CloudRuntimeException("Cannot create directory configdrive_iso on XenServer hosts");
}
} catch (final IOException e) {
throw new CloudRuntimeException("Unable to create iso folder", e);
} finally {
sshConnection.close();
}
s_logger.debug("Created the config drive SR " + srName + " folder path " + _configDriveIsopath);
deviceConfig.put("location", _configDriveIsopath);
deviceConfig.put("legacy_mode", "true");
final Host host = Host.getByUuid(conn, _host.getUuid());
final String type = SRType.ISO.toString();
sr = SR.create(conn, host, deviceConfig, new Long(0), _configDriveIsopath, "iso", type, "iso", false, new HashMap<String, String>());
sr.setNameLabel(conn, srName);
sr.setNameDescription(conn, deviceConfig.get("location"));
sr.scan(conn);
s_logger.debug("Config drive ISO SR at the path " + _configDriveIsopath + " got created in host " + _host);
return sr;
} catch (final XenAPIException e) {
final String msg = "createLocalIsoSR failed! mountpoint " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
} catch (final Exception e) {
final String msg = "createLocalIsoSR failed! mountpoint: due to " + e.getMessage();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class CitrixResourceBase method ovsFullSyncStates.
private List<Pair<String, Long>> ovsFullSyncStates() {
final Connection conn = getConnection();
final String result = callHostPlugin(conn, "ovsgre", "ovs_get_vm_log", "host_uuid", _host.getUuid());
final String[] logs = result != null ? result.split(";") : new String[0];
final List<Pair<String, Long>> states = new ArrayList<Pair<String, Long>>();
for (final String log : logs) {
final String[] info = log.split(",");
if (info.length != 5) {
s_logger.warn("Wrong element number in ovs log(" + log + ")");
continue;
}
// ','.join([bridge, vmName, vmId, seqno, tag])
try {
states.add(new Pair<String, Long>(info[0], Long.parseLong(info[3])));
} catch (final NumberFormatException nfe) {
states.add(new Pair<String, Long>(info[0], -1L));
}
}
return states;
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final VM router = getVM(conn, routerName);
final VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress());
setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
}
} catch (final Exception e) {
s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e);
return new ExecutionResult(false, e.getMessage());
}
return new ExecutionResult(true, null);
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class CitrixResourceBase method initialize.
@Override
public StartupCommand[] initialize() throws IllegalArgumentException {
final Connection conn = getConnection();
if (!getHostInfo(conn)) {
s_logger.warn("Unable to get host information for " + _host.getIp());
return null;
}
final StartupRoutingCommand cmd = new StartupRoutingCommand();
fillHostInfo(conn, cmd);
cmd.setHypervisorType(HypervisorType.XenServer);
cmd.setCluster(_cluster);
cmd.setPoolSync(false);
try {
final Pool pool = Pool.getByUuid(conn, _host.getPool());
final Pool.Record poolr = pool.getRecord(conn);
poolr.master.getRecord(conn);
} catch (final Throwable e) {
s_logger.warn("Check for master failed, failing the FULL Cluster sync command");
}
final StartupStorageCommand sscmd = initializeLocalSR(conn);
if (sscmd != null) {
return new StartupCommand[] { cmd, sscmd };
}
return new StartupCommand[] { cmd };
}
use of com.xensource.xenapi.Connection in project cloudstack by apache.
the class CitrixResourceBase method prepareNetworkElementCommand.
protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
final Connection conn = getConnection();
final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
final IpAddressTO pubIp = cmd.getIpAddress();
try {
final VM router = getVM(conn, routerName);
final VIF correctVif = getCorrectVif(conn, router, pubIp);
pubIp.setNicDevId(Integer.valueOf(correctVif.getDevice(conn)));
} catch (final Exception e) {
final String msg = "Ip SNAT failure due to " + e.toString();
s_logger.error(msg, e);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}
Aggregations