1Rex::Commands::Box(3) User Contributed Perl DocumentationRex::Commands::Box(3)
2
3
4
6 Rex::Commands::Box - Functions / Class to manage Virtual Machines
7
9 This is a Module to manage Virtual Machines or Cloud Instances in a
10 simple way. Currently it supports Amazon, KVM and VirtualBox.
11
12 Version <= 1.0: All these functions will not be reported.
13
15 use Rex::Commands::Box;
16
17 set box => "VBox";
18
19 group all_my_boxes => map { get_box($_->{name})->{ip} } list_boxes;
20
21 task mytask => sub {
22
23 box {
24 my ($box) = @_;
25 $box->name("boxname");
26 $box->url("http://box.rexify.org/box/base-image.box");
27
28 $box->network(1 => {
29 type => "nat",
30 });
31
32 $box->network(1 => {
33 type => "bridged",
34 bridge => "eth0",
35 });
36
37 $box->forward_port(ssh => [2222, 22]);
38
39 $box->share_folder(myhome => "/home/myuser");
40
41 $box->auth(
42 user => "root",
43 password => "box",
44 );
45
46 $box->setup(qw/task_to_customize_box/);
47
48 };
49
50 };
51
53 new(name => $box_name)
54 Constructor if used in OO mode.
55
56 my $box = Rex::Commands::Box->new(name => "box_name");
57
58 box(sub {})
59 With this function you can create a new Rex/Box. The first parameter of
60 this function is the Box object. With this object you can define your
61 box.
62
63 box {
64 my ($box) = @_;
65 $box->name("boxname");
66 $box->url("http://box.rexify.org/box/base-image.box");
67
68 $box->network(1 => {
69 type => "nat",
70 });
71
72 $box->network(1 => {
73 type => "bridged",
74 bridge => "eth0",
75 });
76
77 $box->forward_port(ssh => [2222, 22]);
78
79 $box->share_folder(myhome => "/home/myuser");
80
81 $box->auth(
82 user => "root",
83 password => "box",
84 );
85
86 $box->setup(qw/task_to_customize_box/);
87 };
88
89 list_boxes
90 This function returns an array of hashes containing all information
91 that can be gathered from the hypervisor about the Rex/Box. This
92 function doesn't start a Rex/Box.
93
94 use Data::Dumper;
95 task "get_infos", sub {
96 my @all_boxes = list_boxes;
97 print Dumper(\@all_boxes);
98 };
99
100 get_box($box_name)
101 This function tries to gather all information of a Rex/Box. This
102 function also starts a Rex/Box to gather all information of the running
103 system.
104
105 use Data::Dumper;
106 task "get_box_info", sub {
107 my $data = get_box($box_name);
108 print Dumper($data);
109 };
110
111 boxes($action, @data)
112 With this function you can control your boxes. Currently there are 3
113 actions.
114
115 init
116 This action can only be used if you're using a YAML file to
117 describe your Rex/Boxes.
118
119 task "prepare_boxes", sub {
120 boxes "init";
121 };
122
123 start
124 This action start one or more Rex/Boxes.
125
126 task "start_boxes", sub {
127 boxes "start", "box1", "box2";
128 };
129
130 stop
131 This action stop one or more Rex/Boxes.
132
133 task "stop_boxes", sub {
134 boxes "stop", "box1", "box2";
135 };
136
137
138
139perl v5.32.1 2021-03-06 Rex::Commands::Box(3)