blob: 4f9275aea7a25f634dbaffc42badff31d842d04f [file] [log] [blame]
Václav Kubernáte2e15ee2020-02-05 17:38:13 +01001/*
2 * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
8#include <boost/fusion/adapted.hpp>
9#include <boost/spirit/home/x3.hpp>
10#include <optional>
11#include <stdexcept>
12#include <unistd.h>
13#include "cli-netconf.hpp"
14
15SshProcess sshProcess(const std::string& target, const std::string& port)
16{
17 namespace bp = boost::process;
18 bp::pipe in;
19 bp::pipe out;
20 auto sshPath = bp::search_path("ssh");
21 if (sshPath.empty()) {
22 throw std::runtime_error("ssh not found in PATH.");
23 }
24 if (target.front() == '@') {
25 throw std::runtime_error("Invalid username.");
26 }
27 bp::child ssh(sshPath,
28 target,
29 "-p",
30 port,
31 "-s",
32 "netconf",
33 bp::std_out > out, bp::std_in < in);
34
35 return {std::move(ssh), std::move(in), std::move(out)};
36}