blob: b70e7bc279dc007ef6518a2716815ac9c08d615f [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
Václav Kubernátd7d793c2020-11-26 03:15:48 +010035 return {.process = std::move(ssh), .std_in = std::move(in), .std_out = std::move(out)};
Václav Kubernáte2e15ee2020-02-05 17:38:13 +010036}