Search in sources :

Example 1 with AnsibleReturnValue

use of org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue 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()));
    }
}
Also used : SizeUnit(org.ovirt.engine.core.common.utils.SizeConverter.SizeUnit) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 2 with AnsibleReturnValue

use of org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue 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);
    }
}
Also used : HostUpgradeManagerResult(org.ovirt.engine.core.common.HostUpgradeManagerResult) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with AnsibleReturnValue

use of org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue 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;
}
Also used : AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) IOException(java.io.IOException) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 4 with AnsibleReturnValue

use of org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue in project ovirt-engine by oVirt.

the class InstallVdsInternalCommand method runAnsibleHostDeployPlaybook.

private void runAnsibleHostDeployPlaybook(Cluster hostCluster) throws IOException, InterruptedException {
    // TODO: Remove when we remove support for legacy oVirt node:
    if (getVds().getVdsType().equals(VDSType.oVirtVintageNode)) {
        log.warn("Skipping Ansible runner, because it isn't supported for legacy oVirt node.");
        return;
    }
    AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("host_deploy_cluster_version", hostCluster.getCompatibilityVersion()), new Pair<>("host_deploy_cluster_name", hostCluster.getName()), new Pair<>("host_deploy_gluster_enabled", hostCluster.supportsGlusterService()), new Pair<>("host_deploy_virt_enabled", hostCluster.supportsVirtService()), new Pair<>("host_deploy_vdsm_port", getVds().getPort()), new Pair<>("host_deploy_override_firewall", getParameters().getOverrideFirewall()), new Pair<>("host_deploy_firewall_type", hostCluster.getFirewallType().name()), new Pair<>("ansible_port", getVds().getSshPort()), new Pair<>("host_deploy_post_tasks", AnsibleConstants.HOST_DEPLOY_POST_TASKS_FILE_PATH), new Pair<>("host_deploy_ovn_tunneling_interface", NetworkUtils.getHostIp(getVds())), new Pair<>("host_deploy_ovn_central", getOvnCentral())).logFileDirectory(VdsDeployBase.HOST_DEPLOY_LOG_DIRECTORY).logFilePrefix("ovirt-host-deploy-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.HOST_DEPLOY_PLAYBOOK);
    AuditLogable logable = new AuditLogableImpl();
    logable.setVdsName(getVds().getName());
    logable.setVdsId(getVds().getId());
    logable.setCorrelationId(getCorrelationId());
    auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_INSTALL_STARTED);
    AnsibleReturnValue ansibleReturnValue = ansibleExecutor.runCommand(command);
    if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
        throw new VdsInstallException(VDSStatus.InstallFailed, String.format("Failed to execute Ansible host-deploy role. Please check logs for more details: %1$s", command.logFile()));
    }
    auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_INSTALL_FINISHED);
}
Also used : AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 5 with AnsibleReturnValue

use of org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue in project ovirt-engine by oVirt.

the class RemoveVdsCommand method runAnsibleRemovePlaybook.

@SuppressWarnings("unchecked")
private void runAnsibleRemovePlaybook() {
    AuditLogable logable = new AuditLogableImpl();
    logable.setVdsName(getVds().getName());
    logable.setVdsId(getVds().getId());
    logable.setCorrelationId(getCorrelationId());
    try {
        AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).playbook(AnsibleConstants.HOST_REMOVE_PLAYBOOK);
        auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_HOST_REMOVE_STARTED);
        AnsibleReturnValue ansibleReturnValue = ansibleExecutor.runCommand(command);
        logable.addCustomValue("LogFile", command.logFile().getAbsolutePath());
        if (ansibleReturnValue.getAnsibleReturnCode() != AnsibleReturnCode.OK) {
            auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_HOST_REMOVE_FAILED);
        } else {
            auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_HOST_REMOVE_FINISHED);
        }
    } catch (Exception e) {
        logable.addCustomValue("Message", e.getMessage());
        auditLogDirector.log(logable, AuditLogType.VDS_ANSIBLE_HOST_REMOVE_EXECUTION_FAILED);
    }
}
Also used : AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)

Aggregations

AnsibleCommandBuilder (org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder)6 AnsibleReturnValue (org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue)6 IOException (java.io.IOException)3 Pair (org.ovirt.engine.core.common.utils.Pair)3 AuditLogable (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable)3 AuditLogableImpl (org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)3 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 ArrayList (java.util.ArrayList)1 HostUpgradeManagerResult (org.ovirt.engine.core.common.HostUpgradeManagerResult)1 StorageDevice (org.ovirt.engine.core.common.businessentities.gluster.StorageDevice)1 SizeUnit (org.ovirt.engine.core.common.utils.SizeConverter.SizeUnit)1