-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkManager.cpp
More file actions
91 lines (69 loc) · 2.15 KB
/
Copy pathNetworkManager.cpp
File metadata and controls
91 lines (69 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "NetworkManager.h"
#include <libopi/SysInfo.h>
#include <libopi/NetworkConfig.h>
#include <libutils/Logger.h>
using namespace OPI;
using namespace Utils;
namespace KGP
{
NetworkManager::NetworkManager()
{
logg << Logger::Debug << "NetworkManager starting up" << lend;
this->net = make_shared<OPI::NetUtils::NullConfig>();
// Check dependencies, a bit uggly concider refactor if more versions added
SysInfo::OSType os = sysinfo.OS();
if( os != SysInfo::OSType::OSDebian && os != SysInfo::OSType::OSRaspbian )
{
logg << Logger::Alert << "Network manager: unsupported platform: " << sysinfo.OSTypeText[os] << lend;
return;
}
string version = sysinfo.OSVersion();
/*
* We allow Bullseye with a warning for now.
* Buster is concidered tested and stable.
* All other versions unsupported for now!
*
* TODO: Generalize? Query implementations?
*/
if( version == "bullseye" )
{
logg << Logger::Notice << "Note, currently untested debian version!" << lend;
}
else if( version != "buster")
{
logg << Logger::Alert << "Unsupported raspbian/debian version: " << version << lend;
return;
}
if( os == SysInfo::OSType::OSDebian )
{
logg << Logger::Debug << "Running on valid debian system" << lend;
this->net = make_shared<OPI::NetUtils::DebianNetworkConfig>();
}
if( os == SysInfo::OSType::OSRaspbian )
{
logg << Logger::Debug << "Running on valid raspbian system" << lend;
this->net = make_shared<OPI::NetUtils::RaspbianNetworkConfig>();
}
}
NetworkManager &NetworkManager::Instance()
{
static NetworkManager mgr;
return mgr;
}
json NetworkManager::GetConfiguration(const string &interface)
{
return this->net->GetInterface(interface);
}
bool NetworkManager::StaticConfiguration(const string &interface, const string &ip, const string &netmask, const string &gateway, const list<string>& dns)
{
this->net->SetStatic(interface,ip, netmask, gateway, dns);
this->net->WriteConfig();
return this->net->RestartInterface( interface );
}
bool NetworkManager::DynamicConfiguration(const string &interface)
{
this->net->SetDHCP(interface);
this->net->WriteConfig();
return this->net->RestartInterface( interface );
}
} // KGP