use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder in project ovirt-engine by oVirt.
the class CreateBrickCommand method runAnsibleCreateBrickPlaybook.
private void runAnsibleCreateBrickPlaybook() throws IOException, InterruptedException {
List<String> disks = new ArrayList<>();
Double totalSize = 0.0;
for (StorageDevice device : getParameters().getDisks()) {
disks.add(device.getDevPath());
// size is returned in MiB
totalSize += device.getSize();
}
if (totalSize < MIN_VG_SIZE) {
totalSize = totalSize - MIN_METADATA_PERCENT * totalSize;
} else {
totalSize = totalSize - DEFAULT_METADATA_SIZE_MB;
}
Pair<SizeUnit, Double> convertedSize = SizeConverter.autoConvert(totalSize.longValue(), SizeUnit.MiB);
String deviceSize = convertedSize.getSecond() + convertedSize.getFirst().toString();
String ssdDevice = "";
if (getParameters().getCacheDevice() != null) {
ssdDevice = getParameters().getCacheDevice().getDevPath();
}
int diskCount = getParameters().getNoOfPhysicalDisksInRaidVolume() == null ? 1 : getParameters().getNoOfPhysicalDisksInRaidVolume();
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("ssd", ssdDevice), new Pair<>("disks", JsonHelper.objectToJson(disks, false)), new Pair<>("vgname", "RHGS_vg_" + getParameters().getLvName()), new Pair<>("size", deviceSize), new Pair<>("diskcount", diskCount), new Pair<>("stripesize", getParameters().getStripeSize()), new Pair<>("wipefs", "yes"), new Pair<>("disktype", getParameters().getRaidType().toString()), new Pair<>("lvname", getParameters().getLvName() + "_lv"), new Pair<>("cache_lvname", getParameters().getLvName() + "_cache_lv"), new Pair<>("cache_lvsize", getParameters().getCacheSize() + "GiB"), new Pair<>("cachemode", getParameters().getCacheMode()), new Pair<>("fstype", GlusterConstants.FS_TYPE_XFS), new Pair<>("mntpath", getParameters().getMountPoint())).logFileDirectory(CreateBrickCommand.CREATE_BRICK_LOG_DIRECTORY).logFilePrefix("ovirt-gluster-brick-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.CREATE_BRICK_PLAYBOOK);
AnsibleReturnValue ansibleReturnValue = ansibleExecutor.runCommand(command);
if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
log.error("Failed to execute Ansible create brick role. Please check logs for more details: {}", command.logFile());
throw new EngineException(EngineError.GeneralException, String.format("Failed to execute Ansible create brick role. Please check logs for more details: %1$s", command.logFile()));
}
}
use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder in project ovirt-engine by oVirt.
the class CreateOvaCommand method runAnsiblePackOvaPlaybook.
private boolean runAnsiblePackOvaPlaybook(String vmName, String ovf, Collection<DiskImage> disks, Map<Guid, String> diskIdToPath) {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("target_directory", getParameters().getDirectory()), new Pair<>("ova_name", getParameters().getName()), new Pair<>("ovirt_ova_pack_ovf", genOvfParameter(ovf)), new Pair<>("ovirt_ova_pack_disks", genDiskParameters(disks, diskIdToPath))).logFileDirectory(CREATE_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-export-ova-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.EXPORT_OVA_PLAYBOOK);
boolean succeeded = false;
try {
succeeded = ansibleExecutor.runCommand(command).getAnsibleReturnCode() == AnsibleReturnCode.OK;
} catch (IOException | InterruptedException e) {
log.debug("Failed to create OVA", e);
}
if (!succeeded) {
log.error("Failed to create OVA. Please check logs for more details: {}", command.logFile());
}
return succeeded;
}
use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder in project ovirt-engine by oVirt.
the class HostUpgradeManager method checkForUpdates.
@Override
public HostUpgradeManagerResult checkForUpdates(final VDS host) {
AnsibleReturnValue ansibleReturnValue = null;
try {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(host.getHostName()).checkMode(true).enableLogging(false).verboseLevel(AnsibleVerbosity.LEVEL0).stdoutCallback(AnsibleConstants.HOST_UPGRADE_CALLBACK_PLUGIN).playbook(AnsibleConstants.HOST_UPGRADE_PLAYBOOK);
ansibleReturnValue = ansibleExecutor.runCommand(command);
if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
String error = String.format("Failed to run check-update of host '%1$s'.", host.getHostName());
log.error(error);
throw new RuntimeException(error);
}
List<String> availablePackages = JsonHelper.jsonToList(ansibleReturnValue.getStdout());
boolean updatesAvailable = !availablePackages.isEmpty();
HostUpgradeManagerResult hostUpgradeManagerResult = new HostUpgradeManagerResult();
hostUpgradeManagerResult.setUpdatesAvailable(updatesAvailable);
if (updatesAvailable) {
hostUpgradeManagerResult.setAvailablePackages(availablePackages);
log.info("There are available package updates ({}) for host '{}'", StringUtils.join(availablePackages, ", "), host.getHostName());
AuditLogable auditLog = new AuditLogableImpl();
auditLog.setVdsId(host.getId());
auditLog.setVdsName(host.getName());
if (availablePackages.isEmpty()) {
auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE);
} else {
if (availablePackages.size() > MAX_NUM_OF_DISPLAYED_UPDATES) {
auditLog.addCustomValue("Packages", String.format("%1$s and %2$s others. To see all packages check engine.log.", StringUtils.join(availablePackages.subList(0, MAX_NUM_OF_DISPLAYED_UPDATES), ", "), availablePackages.size() - MAX_NUM_OF_DISPLAYED_UPDATES));
} else {
auditLog.addCustomValue("Packages", StringUtils.join(availablePackages, ", "));
}
auditLogDirector.log(auditLog, AuditLogType.HOST_UPDATES_ARE_AVAILABLE_WITH_PACKAGES);
}
}
return hostUpgradeManagerResult;
} catch (final IOException e) {
log.error("Failed to read host packages: {}", e.getMessage());
if (ansibleReturnValue != null) {
log.debug("Ansible packages output: {}", ansibleReturnValue.getStdout());
}
throw new RuntimeException(e.getMessage(), e);
} catch (final Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder in project ovirt-engine by oVirt.
the class ExportOvaCommand method validateTargetFolder.
private ValidationResult validateTargetFolder() {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("target_directory", getParameters().getDirectory()), new Pair<>("validate_only", "True")).logFileDirectory(CreateOvaCommand.CREATE_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-export-ova-validate-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.EXPORT_OVA_PLAYBOOK);
boolean succeeded = false;
try {
succeeded = ansibleExecutor.runCommand(command).getAnsibleReturnCode() == AnsibleReturnCode.OK;
} catch (IOException | InterruptedException e) {
log.error("Invalid target for OVA (directory={}, host={}): {}", getParameters().getDirectory(), getVdsName(), e.getMessage());
log.debug("Exception", e);
}
return succeeded ? ValidationResult.VALID : new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_INVALID_OVA_DESTINATION_FOLDER, String.format("$vdsName %s", getVdsName()), String.format("$directory %s", getParameters().getDirectory()));
}
use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder in project ovirt-engine by oVirt.
the class ExtractOvaCommand method runAnsibleImportOvaPlaybook.
private boolean runAnsibleImportOvaPlaybook(List<String> diskPaths) {
AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("ovirt_import_ova_path", getParameters().getOvaPath()), new Pair<>("ovirt_import_ova_disks", String.join("+", diskPaths))).logFileDirectory(IMPORT_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-import-ova-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.IMPORT_OVA_PLAYBOOK);
boolean succeeded = false;
AnsibleReturnValue ansibleReturnValue = null;
try {
ansibleReturnValue = ansibleExecutor.runCommand(command);
succeeded = ansibleReturnValue.getAnsibleReturnCode() == AnsibleReturnCode.OK;
} catch (IOException | InterruptedException e) {
log.debug("Failed to extract OVA", e);
}
if (!succeeded) {
log.error("Failed to extract OVA. Please check logs for more details: {}", command.logFile());
return false;
}
return true;
}
Aggregations