4
* Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
5
* Copyright © 2012 Canonical Ltd.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License version 2, as
9
* published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "../lxc/lxccontainer.h"
25
#include <sys/types.h>
30
#define MYNAME "lxctest1"
32
int main(int argc, char *argv[])
34
struct lxc_container *c;
37
if ((c = lxc_container_new(MYNAME)) == NULL) {
38
fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
43
if (c->is_defined(c)) {
44
fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
48
if (!c->set_config_item(c, "lxc.network.type", "veth")) {
49
fprintf(stderr, "%d: failed to set network type\n", __LINE__);
52
c->set_config_item(c, "lxc.network.link", "lxcbr0");
53
c->set_config_item(c, "lxc.network.flags", "up");
54
if (!c->createl(c, "ubuntu", "-r", "lucid", NULL)) {
55
fprintf(stderr, "%d: failed to create a lucid container\n", __LINE__);
59
if (!c->is_defined(c)) {
60
fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
64
c->load_config(c, NULL);
66
if (!c->startl(c, 0, NULL)) {
67
fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
70
fprintf(stderr, "%d: %s started, you have 60 seconds to test a console\n", __LINE__, MYNAME);
71
sleep(60); // wait a minute to let user connect to console
73
if (!c->shutdown(c, 60)) {
74
fprintf(stderr, "%d: failed to shut down %s\n", __LINE__, MYNAME);
79
fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
83
if (c->is_defined(c)) {
84
fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
88
fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);