Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
zone.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_LXC_ZONE_HPP
26 #define COMMON_LXC_ZONE_HPP
27 
28 #include <string>
29 #include <functional>
30 #include <sys/types.h>
31 
32 // fwd declaration of lxc internals
33 struct lxc_container;
34 
35 namespace vasum {
36 namespace lxc {
37 
38 
42 class LxcZone {
43 public:
44  typedef std::function<int()> Call;
45 
46  enum class State {
47  STOPPED,
48  STARTING,
49  RUNNING,
50  STOPPING,
51  ABORTING,
52  FREEZING,
53  FROZEN,
54  THAWED
55  };
56 
62  LxcZone(const std::string& lxcPath, const std::string& zoneName);
63  ~LxcZone();
64 
65  LxcZone(const LxcZone&) = delete;
66  LxcZone& operator=(const LxcZone&) = delete;
67 
71  std::string getName() const;
72 
77  std::string getConfigItem(const std::string& key);
78 
82  bool isDefined();
83 
87  static std::string toString(State state);
88 
92  State getState();
93 
98  bool waitForState(State state, int timeout);
99 
105  bool create(const std::string& templatePath, const char* const* argv);
106 
110  bool destroy();
111 
116  bool start(const char* const* argv);
117 
122  bool stop();
123 
127  bool reboot();
128 
132  bool shutdown(int timeout);
133 
137  bool freeze();
138 
142  bool unfreeze();
143 
147  pid_t getInitPid() const;
148 
156  bool runInZone(Call& call);
157 
170  bool createFile(const std::string& path,
171  const std::int32_t flags,
172  const std::int32_t mode,
173  int *fdPtr);
174 
175 private:
176  lxc_container* mLxcContainer;
177  bool setRunLevel(int runLevel);
178  void refresh();
179 };
180 
181 
182 } // namespace lxc
183 } // namespace vasum
184 
185 
186 #endif // COMMON_LXC_ZONE_HPP
bool isDefined()
Is zone defined (created)?
Definition: zone.cpp:132
State getState()
Get zone state.
Definition: zone.cpp:137
std::string getName() const
Get zone name.
Definition: zone.cpp:115
A class wrapping lxc container.
Definition: zone.hpp:42
bool reboot()
Reboot zone.
Definition: zone.cpp:249
lxc_container * mLxcContainer
Definition: zone.hpp:176
std::string getConfigItem(const std::string &key)
Get item from lxc config file.
Definition: zone.cpp:120
~LxcZone()
Definition: zone.cpp:110
bool createFile(const std::string &path, const std::int32_t flags, const std::int32_t mode, int *fdPtr)
Create a file inside the zone and return it's file descriptor.
Definition: zone.cpp:380
bool freeze()
Freeze (pause/lock) zone.
Definition: zone.cpp:305
bool runInZone(Call &call)
Attach to the Zone and run the call.
Definition: zone.cpp:354
pid_t getInitPid() const
Get pid of init process.
Definition: zone.cpp:332
bool stop()
Immediate stop the zone It kills all processes within this zone.
Definition: zone.cpp:240
bool destroy()
Destroy zone.
Definition: zone.cpp:179
bool shutdown(int timeout)
Gracefully shutdown zone.
Definition: zone.cpp:258
LxcZone(const std::string &lxcPath, const std::string &zoneName)
LxcZone constructor.
Definition: zone.cpp:99
std::function< int()> Call
Definition: zone.hpp:44
std::string key(const Arg1 &a1, const Args &...args)
Concatenates all parameters into one std::string.
Definition: kvstore-visitor-utils.hpp:60
static std::string toString(State state)
String representation of state.
Definition: zone.cpp:83
bool start(const char *const *argv)
Start zone.
Definition: zone.cpp:188
bool setRunLevel(int runLevel)
Definition: zone.cpp:337
LxcZone & operator=(const LxcZone &)=delete
bool waitForState(State state, int timeout)
Wait till zone is in specified state.
Definition: zone.cpp:323
bool create(const std::string &templatePath, const char *const *argv)
Create zone.
Definition: zone.cpp:143
void refresh()
Definition: zone.cpp:345
bool unfreeze()
Unfreeze zone.
Definition: zone.cpp:314
State
Definition: zone.hpp:46