lxcpp: provisioning implementation (part 1)
[platform/core/security/vasum.git] / libs / lxcpp / container-impl.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   ContainerImpl main class
22  */
23
24 #ifndef LXCPP_CONTAINER_IMPL_HPP
25 #define LXCPP_CONTAINER_IMPL_HPP
26
27 #include <sys/types.h>
28 #include <memory>
29
30 #include "lxcpp/container-config.hpp"
31 #include "lxcpp/container.hpp"
32 #include "lxcpp/namespace.hpp"
33
34 namespace lxcpp {
35
36 class ContainerImpl : public virtual Container {
37 public:
38     ContainerImpl(const std::string &name, const std::string &path);
39     ContainerImpl(pid_t guardPid);
40     ~ContainerImpl();
41
42     // Configuration
43     const std::string& getName() const;
44     const std::string& getRootPath() const;
45
46     pid_t getGuardPid() const;
47     pid_t getInitPid() const;
48
49     const std::vector<std::string>& getInit();
50     void setInit(const std::vector<std::string> &init);
51
52     void setLogger(const logger::LogType type,
53                    const logger::LogLevel level,
54                    const std::string &arg);
55
56     void setTerminalCount(const unsigned int count);
57
58     void setNamespaces(const int namespaces);
59     int getNamespaces() const;
60
61     // Execution actions
62     void start();
63     void stop();
64     void freeze();
65     void unfreeze();
66     void reboot();
67
68     // Other
69     void attach(const std::vector<std::string>& argv,
70                 const std::string& cwdInContainer);
71     void console();
72     bool isRunning() const;
73
74     // Network interfaces setup/config
75     /**
76      * adds interface configration.
77      * throws NetworkException if zoneif name already on list
78      */
79     void addInterfaceConfig(const std::string& hostif,
80                             const std::string& zoneif,
81                             InterfaceType type,
82                             const std::vector<InetAddr>& addrs,
83                             MacVLanMode mode);
84     void addInetConfig(const std::string& ifname, const InetAddr& addr);
85
86     // Network interfaces (runtime)
87     std::vector<std::string> getInterfaces() const;
88     NetworkInterfaceInfo getInterfaceInfo(const std::string& ifname) const;
89     void createInterface(const std::string& hostif,
90                          const std::string& zoneif,
91                          InterfaceType type,
92                          MacVLanMode mode);
93     void moveInterface(const std::string& ifname);
94     void destroyInterface(const std::string& ifname);
95     void setUp(const std::string& ifname);
96     void setDown(const std::string& ifname);
97     void addInetAddr(const std::string& ifname, const InetAddr& addr);
98     void delInetAddr(const std::string& ifname, const InetAddr& addr);
99
100     // Provisioning
101     void declareFile(const provision::File::Type type,
102                      const std::string& path,
103                      const int32_t flags,
104                      const int32_t mode);
105     const FileVector& getFiles() const;
106     void removeFile(const provision::File& item);
107
108     void declareMount(const std::string& source,
109                       const std::string& target,
110                       const std::string& type,
111                       const int64_t flags,
112                       const std::string& data);
113     const MountVector& getMounts() const;
114     void removeMount(const provision::Mount& item);
115
116     void declareLink(const std::string& source,
117                      const std::string& target);
118     const LinkVector& getLinks() const;
119     void removeLink(const provision::Link& item);
120
121 private:
122     ContainerConfig mConfig;
123 };
124
125 } // namespace lxcpp
126
127 #endif // LXCPP_CONTAINER_IMPL_HPP