lxcpp: provisioning implementation (part 1)
[platform/core/security/vasum.git] / libs / lxcpp / container.hpp
1 /*
2  *  Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License version 2.1 as published by the Free Software Foundation.
7  *
8  *  This library is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *  Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with this library; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 /**
19  * @file
20  * @author  Mateusz Malicki (m.malicki2@samsung.com)
21  * @brief   Container interface
22  */
23
24 #ifndef LXCPP_CONTAINER_HPP
25 #define LXCPP_CONTAINER_HPP
26
27 #include "lxcpp/network-config.hpp"
28 #include "lxcpp/provision-config.hpp"
29 #include "lxcpp/logger-config.hpp"
30
31 #include <sys/types.h>
32
33 #include <string>
34 #include <functional>
35 #include <vector>
36
37 namespace lxcpp {
38
39 struct NetworkInterfaceInfo {
40     const std::string ifname;
41     const NetStatus status;
42     const std::string macaddr;
43     const int mtu;
44     const int flags;
45     const std::vector<InetAddr> addrs;
46 };
47
48 class Container {
49 public:
50     virtual ~Container() {};
51
52     // Configuration
53     virtual const std::string& getName() const = 0;
54     virtual const std::string& getRootPath() const = 0;
55
56     virtual pid_t getGuardPid() const = 0;
57     virtual pid_t getInitPid() const = 0;
58
59     virtual const std::vector<std::string>& getInit() = 0;
60     virtual void setInit(const std::vector<std::string> &init) = 0;
61
62     virtual void setLogger(const logger::LogType type,
63                            const logger::LogLevel level,
64                            const std::string &arg = "") = 0;
65
66     virtual void setTerminalCount(const unsigned int count) = 0;
67
68     virtual void setNamespaces(const int namespaces) = 0;
69     virtual int getNamespaces() const = 0;
70
71     // Execution actions
72     virtual void start() = 0;
73     virtual void stop() = 0;
74     virtual void freeze() = 0;
75     virtual void unfreeze() = 0;
76     virtual void reboot() = 0;
77
78     // Other
79     virtual void attach(const std::vector<std::string>& argv,
80                         const std::string& cwdInContainer) = 0;
81     virtual void console() = 0;
82     virtual bool isRunning() const = 0;
83
84     // Network interfaces setup/config
85     virtual void addInterfaceConfig(const std::string& hostif,
86                                     const std::string& zoneif,
87                                     InterfaceType type,
88                                     const std::vector<InetAddr>& addrs,
89                                     MacVLanMode mode) = 0;
90     virtual void addInetConfig(const std::string& ifname, const InetAddr& addr) = 0;
91
92     // Network interfaces (runtime)
93     virtual std::vector<std::string> getInterfaces() const = 0;
94     virtual NetworkInterfaceInfo getInterfaceInfo(const std::string& ifname) const = 0;
95     virtual void createInterface(const std::string& hostif,
96                                  const std::string& zoneif,
97                                  InterfaceType type,
98                                  MacVLanMode mode) = 0;
99     virtual void destroyInterface(const std::string& ifname) = 0;
100     virtual void moveInterface(const std::string& ifname) = 0;
101     virtual void setUp(const std::string& ifname) = 0;
102     virtual void setDown(const std::string& ifname) = 0;
103     virtual void addInetAddr(const std::string& ifname, const InetAddr& addr) = 0;
104     virtual void delInetAddr(const std::string& ifname, const InetAddr& addr) = 0;
105
106     // Provisioning
107     virtual void declareFile(const provision::File::Type type,
108                              const std::string& path,
109                              const int32_t flags,
110                              const int32_t mode) = 0;
111     virtual const FileVector& getFiles() const = 0;
112     virtual void removeFile(const provision::File& item) = 0;
113
114     virtual void declareMount(const std::string& source,
115                               const std::string& target,
116                               const std::string& type,
117                               const int64_t flags,
118                               const std::string& data) = 0;
119     virtual const MountVector& getMounts() const = 0;
120     virtual void removeMount(const provision::Mount& item) = 0;
121
122     virtual void declareLink(const std::string& source,
123                              const std::string& target) = 0;
124     virtual const LinkVector& getLinks() const = 0;
125     virtual void removeLink(const provision::Link& item) = 0;
126 };
127
128 } // namespace lxcpp
129
130 #endif // LXCPP_CONTAINER_HPP