Skip to content

Commit b8edc19

Browse files
rkavitha-hclBibhuprasad Singh
authored and
Bibhuprasad Singh
committed
Integrated Rebootbackend changes
1 parent 572bd35 commit b8edc19

11 files changed

+1096
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?ignore
2+
XML representation of dbus interface created by: sonic-host-services/host_modules/gnoi_reboot.py
3+
4+
XML generated on switch by executing:
5+
dbus-send --system --type=method_call --print-reply --dest=org.SONiC.HostService.gnoi_reboot /org/SONiC/HostService/gnoi_reboot org.freedesktop.DBus.Introspectable.Introspect
6+
7+
C++ header file generated by:
8+
sudo apt-get install libdbus-c++-dev
9+
dbusxx-xml2cpp ./gnoi_reboot.xml --proxy=gnoi_reboot_dbus.h
10+
?>
11+
12+
<node name="/org/SONiC/HostService/gnoi_reboot">
13+
<interface name="org.freedesktop.DBus.Introspectable">
14+
<method name="Introspect">
15+
<arg direction="out" type="s" />
16+
</method>
17+
</interface>
18+
<interface name="org.SONiC.HostService.gnoi_reboot">
19+
<method name="issue_reboot">
20+
<arg direction="in" type="as" name="options" />
21+
<arg direction="out" type="i" />
22+
<arg direction="out" type="s" />
23+
</method>
24+
<method name="get_reboot_status">
25+
<arg direction="out" type="i" />
26+
<arg direction="out" type="s" />
27+
</method>
28+
</interface>
29+
</node>
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
/*
3+
* This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT!
4+
*/
5+
6+
#ifndef __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
7+
#define __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
8+
9+
#include <dbus-c++/dbus.h>
10+
11+
#include <cassert>
12+
13+
namespace org {
14+
namespace SONiC {
15+
namespace HostService {
16+
17+
class gnoi_reboot_proxy : public ::DBus::InterfaceProxy {
18+
public:
19+
gnoi_reboot_proxy()
20+
: ::DBus::InterfaceProxy("org.SONiC.HostService.gnoi_reboot") {}
21+
22+
public:
23+
/* properties exported by this interface */
24+
public:
25+
/* methods exported by this interface,
26+
* this functions will invoke the corresponding methods on the remote objects
27+
*/
28+
void issue_reboot(const std::vector<std::string>& options, int32_t& argout0,
29+
std::string& argout1) {
30+
::DBus::CallMessage call;
31+
::DBus::MessageIter wi = call.writer();
32+
33+
wi << options;
34+
call.member("issue_reboot");
35+
::DBus::Message ret = invoke_method(call);
36+
::DBus::MessageIter ri = ret.reader();
37+
38+
ri >> argout0;
39+
ri >> argout1;
40+
}
41+
42+
void get_reboot_status(int32_t& argout0, std::string& argout1) {
43+
::DBus::CallMessage call;
44+
call.member("get_reboot_status");
45+
::DBus::Message ret = invoke_method(call);
46+
::DBus::MessageIter ri = ret.reader();
47+
48+
ri >> argout0;
49+
ri >> argout1;
50+
}
51+
52+
public:
53+
/* signal handlers for this interface
54+
*/
55+
56+
private:
57+
/* unmarshalers (to unpack the DBus message before calling the actual signal
58+
* handler)
59+
*/
60+
};
61+
62+
} // namespace HostService
63+
} // namespace SONiC
64+
} // namespace org
65+
#endif //__dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "interfaces.h"
2+
3+
#include <dbus-c++/dbus.h> // DBus
4+
5+
// #include "component_state_helper.h"
6+
#include "reboot_interfaces.h"
7+
8+
constexpr char kRebootBusName[] = "org.SONiC.HostService.gnoi_reboot";
9+
constexpr char kRebootPath[] = "/org/SONiC/HostService/gnoi_reboot";
10+
11+
constexpr char kContainerShutdownBusName[] =
12+
"org.SONiC.HostService.gnoi_container_shutdown";
13+
constexpr char kContainerShutdownPath[] =
14+
"/org/SONiC/HostService/gnoi_container_shutdown";
15+
16+
// DBus::BusDispatcher dispatcher;
17+
DBus::Connection& HostServiceDbus::getConnection(void) {
18+
static DBus::Connection* connPtr = nullptr;
19+
if (connPtr == nullptr) {
20+
static DBus::BusDispatcher dispatcher;
21+
DBus::default_dispatcher = &dispatcher;
22+
23+
static DBus::Connection conn = DBus::Connection::SystemBus();
24+
connPtr = &conn;
25+
}
26+
return *connPtr;
27+
}
28+
29+
DbusInterface::DbusResponse HostServiceDbus::Reboot(
30+
const std::string& jsonRebootRequest) {
31+
int32_t status;
32+
33+
GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
34+
std::string retString;
35+
std::vector<std::string> options;
36+
options.push_back(jsonRebootRequest);
37+
try {
38+
reboot_client.issue_reboot(options, status, retString);
39+
} catch (DBus::Error& ex) {
40+
return DbusResponse{
41+
DbusStatus::DBUS_FAIL,
42+
"HostServiceDbus::Reboot: failed to call reboot host service"};
43+
}
44+
45+
// gnoi_reboot.py returns 0 for success, 1 for failure
46+
if (status == 0) {
47+
// Successful reboot response is an empty string.
48+
return DbusResponse{DbusStatus::DBUS_SUCCESS, ""};
49+
}
50+
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
51+
}
52+
53+
DbusInterface::DbusResponse HostServiceDbus::RebootStatus(
54+
const std::string& jsonStatusRequest) {
55+
GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath);
56+
int32_t status;
57+
std::string retString;
58+
59+
try {
60+
reboot_client.get_reboot_status(status, retString);
61+
} catch (DBus::Error& ex) {
62+
return DbusResponse{
63+
DbusStatus::DBUS_FAIL,
64+
"HostServiceDbus::RebootStatus: failed to call reboot status "
65+
"host service"};
66+
}
67+
68+
// gnoi_reboot.py returns 0 for success, 1 for failure
69+
if (status == 0) {
70+
return DbusResponse{DbusStatus::DBUS_SUCCESS, retString};
71+
}
72+
return DbusResponse{DbusStatus::DBUS_FAIL, retString};
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
#include <dbus-c++/dbus.h>
3+
4+
#include <string>
5+
6+
#include "gnoi_reboot_dbus.h" // auto generated gnoi_reboot_proxy
7+
#include "reboot_interfaces.h"
8+
9+
/* Reboot is a request to the reboot sonic host service to request a reboot
10+
from the platform. This takes as an argument a string based json formatted
11+
Reboot request from
12+
system.proto.’https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L107
13+
*/
14+
15+
class GnoiDbusReboot : public org::SONiC::HostService::gnoi_reboot_proxy,
16+
public DBus::IntrospectableProxy,
17+
public DBus::ObjectProxy {
18+
public:
19+
GnoiDbusReboot(DBus::Connection& connection, const char* dbus_bus_name_p,
20+
const char* dbus_obj_name_p)
21+
: DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {}
22+
};
23+
24+
/* DbusResponse consists of STATUS: success/fail: i.e. was the dbus request
25+
successful DbusResponse.json_string: string based json formatted RebootResponse
26+
defined here:
27+
https://github.com/openconfig/gnoi/blob/73a1e7675c5f963e7810bd3828203f2758eb47e8/system/system.proto#L119
28+
*/
29+
30+
class HostServiceDbus : public DbusInterface {
31+
public:
32+
DbusInterface::DbusResponse Reboot(
33+
const std::string& json_reboot_request) override;
34+
DbusInterface::DbusResponse RebootStatus(
35+
const std::string& json_status_request) override;
36+
37+
private:
38+
static DBus::Connection& getConnection(void);
39+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <time.h>
4+
5+
#include "status_code_util.h"
6+
7+
namespace rebootbackend {
8+
9+
extern bool sigterm_requested;
10+
struct NotificationResponse {
11+
swss::StatusCode status;
12+
std::string json_string;
13+
};
14+
15+
} // namespace rebootbackend
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
class DbusInterface {
6+
public:
7+
enum class DbusStatus {
8+
DBUS_SUCCESS,
9+
DBUS_FAIL,
10+
};
11+
12+
struct DbusResponse {
13+
DbusStatus status;
14+
std::string json_string;
15+
};
16+
17+
virtual ~DbusInterface() = default;
18+
virtual DbusResponse Reboot(const std::string& jsonRebootRequest) = 0;
19+
virtual DbusResponse RebootStatus(const std::string& jsonStatusRequest) = 0;
20+
};

0 commit comments

Comments
 (0)