Search in sources :

Example 6 with AnsibleCommandBuilder

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

the class HostUpgradeManager method update.

@Override
public void update(final VDS host) {
    try {
        AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(host.getHostName()).logFileDirectory(VdsDeployBase.HOST_DEPLOY_LOG_DIRECTORY).logFilePrefix("ovirt-host-mgmt-ansible").logFileName(host.getHostName()).logFileSuffix(CorrelationIdTracker.getCorrelationId()).playbook(AnsibleConstants.HOST_UPGRADE_PLAYBOOK);
        if (ansibleExecutor.runCommand(command).getAnsibleReturnCode() != AnsibleReturnCode.OK) {
            String error = String.format("Failed to update host '%1$s'.", host.getHostName());
            log.error(error);
            throw new RuntimeException(error);
        }
    } catch (InterruptedException | IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) IOException(java.io.IOException)

Example 7 with AnsibleCommandBuilder

use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder 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 8 with AnsibleCommandBuilder

use of org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder 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)

Example 9 with AnsibleCommandBuilder

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

the class GetVmFromOvaQuery method runAnsibleQueryOvaInfoPlaybook.

private String runAnsibleQueryOvaInfoPlaybook() {
    String hostname = vdsStaticDao.get(getParameters().getVdsId()).getHostName();
    AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(hostname).variables(new Pair<>("ovirt_query_ova_path", getParameters().getPath())).logFileDirectory(ExtractOvaCommand.IMPORT_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-query-ova-ansible").logFileName(hostname).verboseLevel(AnsibleVerbosity.LEVEL0).stdoutCallback(AnsibleConstants.OVA_QUERY_CALLBACK_PLUGIN).playbook(AnsibleConstants.QUERY_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 query OVA info", e);
    }
    if (!succeeded) {
        log.error("Failed to query OVA info");
        throw new EngineException(EngineError.GeneralException, "Failed to query OVA info");
    }
    return ansibleReturnValue.getStdout();
}
Also used : AnsibleReturnValue(org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue) AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) EngineException(org.ovirt.engine.core.common.errors.EngineException) IOException(java.io.IOException)

Aggregations

AnsibleCommandBuilder (org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder)9 IOException (java.io.IOException)6 AnsibleReturnValue (org.ovirt.engine.core.common.utils.ansible.AnsibleReturnValue)6 Pair (org.ovirt.engine.core.common.utils.Pair)5 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 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)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