1Rex::Commands::Cloud(3)User Contributed Perl DocumentatioRnex::Commands::Cloud(3)
2
3
4
6 Rex::Commands::Cloud - Cloud Management Commands
7
9 With this Module you can manage different Cloud services. Currently it
10 supports Amazon EC2, Jiffybox and OpenStack.
11
12 Version <= 1.0: All these functions will not be reported.
13
15 use Rex::Commands::Cloud;
16
17 cloud_service "Amazon";
18 cloud_auth "your-access-key", "your-private-access-key";
19 cloud_region "ec2.eu-west-1.amazonaws.com";
20
21 task "list", sub {
22 print Dumper cloud_instance_list;
23 print Dumper cloud_volume_list;
24 };
25
26 task "create", sub {
27 my $vol_id = cloud_volume create => { size => 1, zone => "eu-west-1a", };
28
29 cloud_instance create => {
30 image_id => "ami-xxxxxxx",
31 name => "test01",
32 key => "my-key",
33 volume => $vol_id,
34 zone => "eu-west-1a",
35 };
36 };
37
38 task "destroy", sub {
39 cloud_volume detach => "vol-xxxxxxx";
40 cloud_volume delete => "vol-xxxxxxx";
41
42 cloud_instance terminate => "i-xxxxxxx";
43 };
44
46 cloud_service($cloud_service)
47 Define which cloud service to use.
48
49 Services
50 Amazon
51 Jiffybox
52 OpenStack
53
54 cloud_auth($param1, $param2, ...)
55 Set the authentication for the cloudservice.
56
57 For example for Amazon it is:
58
59 cloud_auth($access_key, $secret_access_key);
60
61 For JiffyBox:
62
63 cloud_auth($auth_key);
64
65 For OpenStack:
66
67 cloud_auth(
68 tenant_name => 'tenant',
69 username => 'user',
70 password => 'password',
71 );
72
73 cloud_region($region)
74 Set the cloud region.
75
76 cloud_instance_list
77 Get all instances of a cloud service.
78
79 task "list", sub {
80 for my $instance (cloud_instance_list()) {
81 say "Arch : " . $instance->{"architecture"};
82 say "IP : " . $instance->{"ip"};
83 say "ID : " . $instance->{"id"};
84 say "State : " . $instance->{"state"};
85 }
86 };
87
88 There are some parameters for this function that can change the
89 gathering of ip addresses for some cloud providers (like OpenStack).
90
91 task "list", sub {
92 my @instances = cloud_instance_list
93 private_network => 'private',
94 public_network => 'public',
95 public_ip_type => 'floating',
96 private_ip_type => 'fixed';
97 };
98
99 cloud_volume_list
100 Get all volumes of a cloud service.
101
102 task "list-volumes", sub {
103 for my $volume (cloud_volume_list()) {
104 say "ID : " . $volume->{"id"};
105 say "Zone : " . $volume->{"zone"};
106 say "State : " . $volume->{"state"};
107 say "Attached : " . $volume->{"attached_to"};
108 }
109 };
110
111 cloud_network_list
112 Get all networks of a cloud service.
113
114 task "network-list", sub {
115 for my $network (cloud_network_list()) {
116 say "network : " . $network->{network};
117 say "name : " . $network->{name};
118 say "id : " . $network->{id};
119 }
120 };
121
122 cloud_image_list
123 Get a list of all available cloud images.
124
125 cloud_upload_key
126 Upload public SSH key to cloud provider
127
128 private_key '~/.ssh/mykey
129 public_key '~/.ssh/mykey.pub';
130
131 task "cloudprovider", sub {
132 cloud_upload_key;
133
134 cloud_instance create => {
135 ...
136 };
137 };
138
139 get_cloud_instances_as_group
140 Get a list of all running instances of a cloud service. This can be
141 used for a group definition.
142
143 group fe => "fe01", "fe02", "fe03";
144 group ec2 => get_cloud_instances_as_group();
145
146 cloud_instance($action, $data)
147 This function controls all aspects of a cloud instance.
148
149 create
150 Create a new instance.
151
152 cloud_instance create => {
153 image_id => "ami-xxxxxx",
154 key => "ssh-key",
155 name => "fe-ec2-01", # name is not necessary
156 volume => "vol-yyyyy", # volume is not necessary
157 zone => "eu-west-1a", # zone is not necessary
158 floating_ip => "89.39.38.160" # floating_ip is not necessary
159 };
160
161 start
162 Start an existing instance
163
164 cloud_instance start => "instance-id";
165
166 stop
167 Stop an existing instance
168
169 cloud_instance stop => "instance-id";
170
171 terminate
172 Terminate an instance. This will destroy all data and remove the
173 instance.
174
175 cloud_instance terminate => "i-zzzzzzz";
176
177 get_cloud_regions
178 Returns all regions as an array.
179
180 cloud_volume($action , $data)
181 This function controlls all aspects of a cloud volume.
182
183 create
184 Create a new volume. Size is in Gigabytes.
185
186 task "create-vol", sub {
187 my $vol_id = cloud_volume create => { size => 1, zone => "eu-west-1a", };
188 };
189
190 attach
191 Attach a volume to an instance.
192
193 task "attach-vol", sub {
194 cloud_volume attach => "vol-xxxxxx", to => "server-id";
195 };
196
197 detach
198 Detach a volume from an instance.
199
200 task "detach-vol", sub {
201 cloud_volume detach => "vol-xxxxxx", from => "server-id";
202 };
203
204 delete
205 Delete a volume. This will destroy all data.
206
207 task "delete-vol", sub {
208 cloud_volume delete => "vol-xxxxxx";
209 };
210
211 get_cloud_floating_ip
212 Returns first available floating IP
213
214 task "get_floating_ip", sub {
215
216 my $ip = get_cloud_floating_ip;
217
218 my $instance = cloud_instance create => {
219 image_id => 'edffd57d-82bf-4ffe-b9e8-af22563741bf',
220 name => 'instance1',
221 plan_id => 17,
222 floating_ip => $ip
223 };
224 };
225
226 cloud_network
227 create
228 Create a new network.
229
230 task "create-net", sub {
231 my $net_id = cloud_network create => { cidr => '192.168.0.0/24', name => "mynetwork", };
232 };
233
234 delete
235 Delete a network.
236
237 task "delete-net", sub {
238 cloud_network delete => '18a4ccf8-f14a-a10d-1af4-4ac7fee08a81';
239 };
240
241 get_cloud_availability_zones
242 Returns all availability zones of a cloud services. If available.
243
244 task "get-zones", sub {
245 print Dumper get_cloud_availability_zones;
246 };
247
248 get_cloud_plans
249 Retrieve information of the available cloud plans. If supported.
250
251 get_cloud_operating_systems
252 Retrieve information of the available cloud plans. If supported.
253
254 cloud_object
255 Returns the cloud object itself.
256
257
258
259perl v5.34.0 2022-01-19 Rex::Commands::Cloud(3)