dewiring 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +15 -0
  2. data/bin/wire +7 -0
  3. data/bin/wire-network-container.sh +547 -0
  4. data/lib/test_fig.rb +46 -0
  5. data/lib/wire/cli/cli_commands.rb +88 -0
  6. data/lib/wire/cli/main_cli.rb +129 -0
  7. data/lib/wire/cli.rb +8 -0
  8. data/lib/wire/commands/base_command.rb +139 -0
  9. data/lib/wire/commands/down_command.rb +69 -0
  10. data/lib/wire/commands/down_command_handler.rb +199 -0
  11. data/lib/wire/commands/init_command.rb +89 -0
  12. data/lib/wire/commands/init_interactive.rb +75 -0
  13. data/lib/wire/commands/spec_command.rb +240 -0
  14. data/lib/wire/commands/spec_templates.rb +134 -0
  15. data/lib/wire/commands/up_command.rb +69 -0
  16. data/lib/wire/commands/up_command_handler.rb +193 -0
  17. data/lib/wire/commands/updown_command_base.rb +80 -0
  18. data/lib/wire/commands/validate_command.rb +64 -0
  19. data/lib/wire/commands/verify_command.rb +196 -0
  20. data/lib/wire/commands/verify_command_handler.rb +134 -0
  21. data/lib/wire/commands.rb +19 -0
  22. data/lib/wire/common.rb +42 -0
  23. data/lib/wire/execution/local_exec.rb +110 -0
  24. data/lib/wire/execution.rb +7 -0
  25. data/lib/wire/model/appgroup_validation.rb +45 -0
  26. data/lib/wire/model/loader.rb +49 -0
  27. data/lib/wire/model/network_validation.rb +111 -0
  28. data/lib/wire/model/project.rb +64 -0
  29. data/lib/wire/model/state.rb +154 -0
  30. data/lib/wire/model/validation.rb +66 -0
  31. data/lib/wire/model/verification.rb +37 -0
  32. data/lib/wire/model.rb +13 -0
  33. data/lib/wire/resource/bridge.rb +76 -0
  34. data/lib/wire/resource/dhcp_range_config.rb +135 -0
  35. data/lib/wire/resource/fig_adapter.rb +127 -0
  36. data/lib/wire/resource/ip_binary.rb +141 -0
  37. data/lib/wire/resource/ipaddr_ext.rb +38 -0
  38. data/lib/wire/resource/ipaddr_on_intf.rb +108 -0
  39. data/lib/wire/resource/network_injection.rb +138 -0
  40. data/lib/wire/resource/resource.rb +52 -0
  41. data/lib/wire/resource.rb +14 -0
  42. data/lib/wire/version.rb +14 -0
  43. data/lib/wire.rb +24 -0
  44. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzU2MDIzZWQ2ZjM5OTgxMmNhMjkwYTU3YjE2M2RiMTRhM2JjMmU3Zg==
5
+ data.tar.gz: !binary |-
6
+ ZTZmZWM4NDZiMTU5ZWRkOTkzZjk0YTJjNjQ4MmFhNWQ5N2VkMjUwNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2NjMjBhOTgwYjAzMDY2MTA2YTM4OTNmNDM4NGI0OTk2MDdhM2Q0NGJiNmJi
10
+ MTcwYzE3ZjllODQ5NWQwZTZiNzU3OTA4Yzg3NWY1YWU5MmZhZTdiNmU5ZWI0
11
+ N2YxNDM5YTdjODgxZTEwN2IwOGNmZWQ4MThjNjUyNzQyYzY0YjM=
12
+ data.tar.gz: !binary |-
13
+ OWY1NTc0Yzg5NTEwYTVmZGUxNjkzZTczYjQ5ZDk3NzUzYzg2OGM0ZjdlN2Q5
14
+ M2Y1YjBmMmM4NTA4YjgwOWVmZGE2YmQ2MjI4NWUzNDM3NTc1NjNmNzg3ZWE0
15
+ YzJlMTdhMTM3YTg4MGM4ZmU3ZjY1ODZjMTk2ZDc1ZGYwMmQzODc=
data/bin/wire ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib')
4
+
5
+ require 'wire'
6
+
7
+
@@ -0,0 +1,547 @@
1
+ #!/bin/bash
2
+ #
3
+ # attach-container.sh
4
+ # MIT License
5
+ #
6
+ # attaches multiple containers to multiple ovs bridges
7
+ #
8
+
9
+ # Display usage and help
10
+ function usage() {
11
+ echo 'attach-container.sh <COMMAND> [OPTIONS] -- <device:bridge> [<device:bridge>] <container-id> [<container-id>]'
12
+ echo ' where COMMAND is one of'
13
+ echo ' verify verify given container/device/bridge options'
14
+ echo ' attach attach devices to bridges and containers'
15
+ echo ' detach detach devices from bridges and containers'
16
+ echo ' where OPTIONS are'
17
+ echo ' -n/--noop only print commands, do not change'
18
+ echo ' -d/--debug show debug output'
19
+ echo ' Examples:'
20
+ echo ' attach-containers.sh attach -- eth1:br1 eth2:br2 02978729 12673482'
21
+ echo ' attach-containers.sh verify -- eth1:br1 eth2:br2 02978729 12673482'
22
+ echo ' attach-containers.sh detach -- eth1:br1 eth2:br2 02978729 12673482'
23
+ }
24
+
25
+
26
+ # -- FUNCTION ----------------------------------------------------------------
27
+ # Name: split_args
28
+ # Description: Splits up args after -- and puts them in DEVICE_ARR/ID_ARR arrays
29
+ # ----------------------------------------------------------------------------
30
+ function split_args() {
31
+ for ARG in $@; do
32
+ if [[ "$ARG" =~ .*:.* ]] ; then
33
+ DEVICE_ARR="$DEVICE_ARR $ARG"
34
+ else
35
+ ID_ARR="$ID_ARR $ARG"
36
+ fi
37
+ done
38
+ }
39
+
40
+ # DEBUG and dummy output
41
+ function nodebug() {
42
+ echo $* >/dev/null
43
+ }
44
+ function debug() {
45
+ [[ "$QUIET" != "1" ]] && echo DEBUG $*
46
+ }
47
+ function log_error() {
48
+ echo ERROR $* >&2
49
+ }
50
+ function log_ok() {
51
+ [[ "$QUIET" != "1" ]] && echo OK $*
52
+ }
53
+
54
+ NOOP=
55
+ MODE=
56
+ ACTION=
57
+ DEBUG=nodebug
58
+
59
+ while :
60
+ do
61
+ case "$1" in
62
+ verify | attach | detach)
63
+ ACTION=$1
64
+ shift
65
+ ;;
66
+ -h | --help)
67
+ usage
68
+ exit 0
69
+ ;;
70
+ -n | --noop)
71
+ NOOP=1
72
+ shift
73
+ ;;
74
+ -d | --debug)
75
+ DEBUG=debug
76
+ shift
77
+ ;;
78
+ --) # End of all options
79
+ shift
80
+ break
81
+ ;;
82
+ -*)
83
+ echo "Error: Unknown option: $1" >&2
84
+ exit 1
85
+ ;;
86
+ *) # No more options
87
+ break
88
+ ;;
89
+ esac
90
+ done
91
+
92
+ # Check mandatory input arguments
93
+ if [[ -z "$ACTION" ]]; then
94
+ log_error No action given, see usage
95
+ usage
96
+ exit 1
97
+ fi
98
+
99
+ split_args $@
100
+
101
+ if [[ -z "$DEVICE_ARR" ]]; then
102
+ log_error No device/bridge part specified.
103
+ usage
104
+ exit 2
105
+ fi
106
+ if [[ -z "$ID_ARR" ]]; then
107
+ log_error No container ids specified.
108
+ usage
109
+ exit 3
110
+ fi
111
+
112
+ [[ "$NOOP" -eq 1 ]] && MODE='echo NOOP% '
113
+
114
+ # DEBUG
115
+ PS4='+|${BASH_SOURCE##*/} ${LINENO}${FUNCNAME[0]:+ ${FUNCNAME[0]}}| '
116
+
117
+ # locate binaries
118
+ # TODO: add defaults
119
+ IP=$(which ip)
120
+ OVS_VSCTL=$(which ovs-vsctl)
121
+ DOCKER=$(which docker)
122
+
123
+ # -- FUNCTION ----------------------------------------------------------------
124
+ # Name: container_process
125
+ # Description: Given ID of container, this returns the Process id
126
+ # Parameters
127
+ # 1: Docker Container ID
128
+ # Returns : Container Process ID
129
+ # ----------------------------------------------------------------------------
130
+ function container_process() {
131
+ T="$1"
132
+ local PID=$(sudo docker inspect -f '{{ .State.Pid }}' "$T")
133
+
134
+ echo $PID
135
+ }
136
+
137
+ # -- FUNCTION ----------------------------------------------------------------
138
+ # Name: link_netns
139
+ # Description: Puts link in /var/run/netns according to given process id
140
+ # Parameters
141
+ # 1: Container Process ID
142
+ # ----------------------------------------------------------------------------
143
+ function link_netns() {
144
+ $MODE sudo mkdir -p /var/run/netns
145
+ local PID="$1"
146
+ $MODE sudo ln -s /proc/$PID/ns/net /var/run/netns/$PID
147
+ }
148
+
149
+ # -- FUNCTION ----------------------------------------------------------------
150
+ # Name: unlink_netns
151
+ # Description: removes link from /var/run/netns
152
+ # Parameters
153
+ # 1: Container Process ID
154
+ # ----------------------------------------------------------------------------
155
+ function unlink_netns() {
156
+ local PID=$1
157
+ $MODE sudo rm /var/run/netns/$PID
158
+ }
159
+
160
+ # -- FUNCTION ----------------------------------------------------------------
161
+ # Name: get_mtu
162
+ # Description: Retrieves the MTU for a given device
163
+ # Parameters
164
+ # 1: Device
165
+ # Returns : MTU
166
+ # ----------------------------------------------------------------------------
167
+ function get_mtu() {
168
+ local DEV=$1
169
+ local MTU=$(ip link show $DEV | grep mtu | sed -e 's/.*mtu \([0-9]*\) .*/\1/')
170
+
171
+ echo $MTU
172
+ }
173
+
174
+ # -- FUNCTION ----------------------------------------------------------------
175
+ # Name: add_peer_interfaces
176
+ # Description: creates the host/container peer interfaces
177
+ # Parameters
178
+ # 1: Host interface name
179
+ # 2: Container Interface name
180
+ # 3: mtu on bridge
181
+ # ----------------------------------------------------------------------------
182
+ function add_peer_interfaces() {
183
+ local HOST_IF=$1
184
+ local CONTAINER_IF=$2
185
+ local MTU=$3
186
+ $MODE sudo $IP link add name $HOST_IF mtu $MTU type veth peer name $CONTAINER_IF mtu $MTU
187
+ return $?
188
+ }
189
+
190
+ # -- FUNCTION ----------------------------------------------------------------
191
+ # Name: add_device_to_switch
192
+ # Description: Adds an interface device to given ovs bridge
193
+ # Parameters
194
+ # 1: interface name
195
+ # 2: ovs bridge name
196
+ # ----------------------------------------------------------------------------
197
+ function add_device_to_switch() {
198
+ local HOST_IF=$1
199
+ local SWITCH=$2
200
+ $MODE sudo $OVS_VSCTL add-port $SWITCH $HOST_IF
201
+ return $?
202
+ }
203
+
204
+ # -- FUNCTION ----------------------------------------------------------------
205
+ # Name: remove_device_from_switch
206
+ # Description: Removes an interface device from given ovs bridge
207
+ # Parameters
208
+ # 1: interface name
209
+ # 2: ovs bridge name
210
+ # ----------------------------------------------------------------------------
211
+ function remove_device_from_switch() {
212
+ local HOST_IF=$1
213
+ local SWITCH=$2
214
+ $MODE sudo $OVS_VSCTL del-port $SWITCH $HOST_IF
215
+ return $?
216
+ }
217
+
218
+ # -- FUNCTION ----------------------------------------------------------------
219
+ # Name: configure_interfaces
220
+ # Description: brings container interfaces up, sets namespace and names
221
+ # see: https://docs.docker.com/articles/networking/#how-docker-networks-a-container
222
+ # Parameters
223
+ # 1: Host interface name
224
+ # 2: Container Interface name (peer)
225
+ # 3: Namespace (=container pid)
226
+ # 4: container device name
227
+ # ----------------------------------------------------------------------------
228
+ function configure_interfaces() {
229
+ local HOST_IF=$1
230
+ local CONTAINER_IF=$2
231
+ local NS=$3
232
+ local DEVICE=$4
233
+ $MODE sudo $IP link set $HOST_IF up && \
234
+ $MODE sudo $IP link set $CONTAINER_IF netns $NS && \
235
+ $MODE sudo $IP netns exec $NS ip link set $CONTAINER_IF name $DEVICE
236
+ return $?
237
+ }
238
+
239
+ # -- FUNCTION ----------------------------------------------------------------
240
+ # Name: delete_interfaces
241
+ # Description: deletes the interface pair on host
242
+ # Parameters
243
+ # 1: Host interface name
244
+ # 2: Container Interface name (peer)
245
+ # 3: Namespace (=container pid)
246
+ # 4: container device name
247
+ # Returns : exit code of ip link delete command
248
+ # ----------------------------------------------------------------------------
249
+ function delete_interfaces() {
250
+ local HOST_IF=$1
251
+ local CONTAINER_IF=$2
252
+ local NS=$3
253
+ local DEVICE=$4
254
+ $MODE sudo $IP link delete $HOST_IF type veth peer name $CONTAINER_IF
255
+ return $?
256
+ }
257
+
258
+ # -- FUNCTION ----------------------------------------------------------------
259
+ # Name: has_interfaces
260
+ # Description: checks if container/host is set up correctly
261
+ # Parameters
262
+ # 1: Host interface name
263
+ # 2: Container Interface name (peer)
264
+ # 3: Namespace (=container pid)
265
+ # 4: container device name
266
+ # Returns : 0=ok, 1=failed
267
+ # ----------------------------------------------------------------------------
268
+ function has_interfaces() {
269
+ local HOST_IF=$1
270
+ local CONTAINER_IF=$2
271
+ local NS=$3
272
+ local DEVICE=$4
273
+
274
+ # container device
275
+ $MODE sudo $IP netns exec $NS $IP link show $DEVICE >/dev/null 2>&1
276
+ if [[ $? -ne 0 ]]; then
277
+ return 1
278
+ fi
279
+ # check if we have an ip
280
+ $MODE sudo $IP netns exec $NS $IP addr show $DEVICE 2>&1 | grep 'inet ' >/dev/null 2>&1
281
+ if [[ $? -ne 0 ]]; then
282
+ return 1
283
+ fi
284
+
285
+ # host devices
286
+ $MODE sudo $IP link show $HOST_IF >/dev/null 2>&1
287
+ if [[ $? -ne 0 ]]; then
288
+ return 1
289
+ fi
290
+
291
+ # TODO: CHeck container interface
292
+
293
+ return 0
294
+ }
295
+
296
+ # -- FUNCTION ----------------------------------------------------------------
297
+ # Name: dhcp_container
298
+ # Description: calls dhclient for interface of namespace
299
+ # Parameters
300
+ # 1: Namespace (=container pid)
301
+ # 2: container device name
302
+ # Returns : 0=ok, 1=failed
303
+ # ----------------------------------------------------------------------------
304
+ function dhcp_container() {
305
+ local NS=$1
306
+ local DEVICE=$2
307
+ $MODE sudo $IP netns exec $NS dhclient -v -1 $DEVICE
308
+ return $?
309
+ }
310
+
311
+ # == AGGREGATE FUNCTIONS =====================================================
312
+
313
+ # -- FUNCTION ----------------------------------------------------------------
314
+ # Name: handle_verify
315
+ # Checks if
316
+ # - container ids are valid
317
+ # - pids can be queried
318
+ # - bridges exist and are up
319
+ # - container device names not yet in use
320
+ # Returns : 0=ok, 1=failed
321
+ # ----------------------------------------------------------------------------
322
+ function handle_verify() {
323
+ local RES=0
324
+
325
+ # ensure there are containers running before continuing
326
+ CURRENT_IDS=$(sudo $DOCKER ps -q --no-trunc)
327
+ if [[ -z "$CURRENT_IDS" ]]; then
328
+ log_error No running containers found.
329
+ exit 10
330
+ fi
331
+
332
+ for DEVICE_PAIR in $DEVICE_ARR; do
333
+ BRIDGE=$(echo $DEVICE_PAIR | awk -F':' '{ print $2 }' )
334
+ $DEBUG Checking $BRIDGE
335
+ sudo $OVS_VSCTL br-exists $BRIDGE
336
+ if [[ $? -eq 0 ]]; then
337
+ log_ok $BRIDGE
338
+ else
339
+ log_error Unable to find ovs bridge $BRIDGE
340
+ RES=1
341
+ fi
342
+ done
343
+
344
+ # iterate given container ids
345
+ for ID in $ID_ARR; do
346
+ $DEBUG Checking $ID
347
+ if [[ ! $CURRENT_IDS =~ $ID ]]; then
348
+ log_error No container for $ID found, skipping...
349
+ RES=1
350
+ else
351
+ # get pid
352
+ PID=$(container_process $ID)
353
+ if [[ -z $PID ]]; then
354
+ log_error Unable to grab PID for $ID, skipping
355
+ RES=1
356
+ else
357
+ log_ok $ID
358
+
359
+ # with pid, check given devices
360
+ # on host and in container
361
+
362
+ $DEBUG - Checking devices in $ID
363
+ link_netns "${PID}"
364
+
365
+ # iterate given devices
366
+ for DEVICE_PAIR in $DEVICE_ARR; do
367
+ INTF=$(echo "$DEVICE_PAIR" | awk -F':' '{ print $1 }' )
368
+ $DEBUG -- Checking $INTF
369
+ HOST_IFNAME=v${INTF}h${PID}
370
+ CONTAINER_IFNAME=v${INTF}c${PID}
371
+
372
+ has_interfaces $HOST_IFNAME $CONTAINER_IFNAME $PID $INTF
373
+ if [[ $? -eq 0 ]]; then
374
+ log_ok "$ID"/"$PID" has a "$CONTAINER_IFNAME", host has a "$HOST_IFNAME"
375
+ else
376
+ log_error "$ID"/"$PID" does not have correct devices
377
+ RES=1
378
+ fi
379
+ done
380
+
381
+ unlink_netns "${PID}"
382
+ fi
383
+ fi
384
+ done
385
+
386
+ return $RES
387
+ }
388
+
389
+ # -- FUNCTION ----------------------------------------------------------------
390
+ # Name: handle_attach
391
+ # Description: attaches all containers (of $ID_ARR) to all bridges ($DEVICE_ADDR)
392
+ # with its local interface names. Calls dhclient for all interfaces.
393
+ # Returns : 0=ok, 1=failed
394
+ # ----------------------------------------------------------------------------
395
+ function handle_attach() {
396
+ local RES=0
397
+
398
+ # iterate given container ids
399
+ for TARGET in $ID_ARR; do
400
+ $DEBUG Attaching $TARGET
401
+
402
+ TARGET_PID=$(container_process $TARGET)
403
+ $DEBUG PID of $TARGET is $TARGET_PID
404
+
405
+ link_netns ${TARGET_PID}
406
+
407
+ # iterate given devices
408
+ for DEVICE_PAIR in $DEVICE_ARR; do
409
+ INTF=$(echo $DEVICE_PAIR | awk -F':' '{ print $1 }' )
410
+ BRIDGE=$(echo $DEVICE_PAIR | awk -F':' '{ print $2 }' )
411
+ $DEBUG Attaching $INTF to $BRIDGE
412
+
413
+ BRIDGEDEV_MTU=$(get_mtu $BRIDGE)
414
+ if [[ -z "$BRIDGEDEV_MTU" ]]; then
415
+ log_error querying mtu of $BRIDGE, aborting
416
+ RES=1
417
+ break
418
+ fi
419
+
420
+ HOST_IFNAME=v${INTF}h${TARGET_PID}
421
+ CONTAINER_IFNAME=v${INTF}c${TARGET_PID}
422
+ $DEBUG - interface pair names are ${HOST_IFNAME}/${CONTAINER_IFNAME}
423
+
424
+ $DEBUG - creating peer interfaces
425
+ add_peer_interfaces $HOST_IFNAME $CONTAINER_IFNAME $BRIDGEDEV_MTU
426
+ if [[ $? -ne 0 ]]; then
427
+ log_error creating peer interfaces. aborting
428
+ RES=1
429
+ continue
430
+ fi
431
+
432
+ $DEBUG - adding $HOST_IFNAME to $BRIDGE
433
+ add_device_to_switch $HOST_IFNAME $BRIDGE
434
+ if [[ $? -ne 0 ]]; then
435
+ log_error adding device to bridge. aborting
436
+ RES=1
437
+ continue
438
+ fi
439
+
440
+ $DEBUG - configuring interfaces
441
+ configure_interfaces $HOST_IFNAME $CONTAINER_IFNAME $TARGET_PID $INTF
442
+ if [[ $? -ne 0 ]]; then
443
+ log_error configuring interfaces. aborting
444
+ RES=1
445
+ continue
446
+ fi
447
+
448
+ $DEBUG - dhcp requesting address
449
+ dhcp_container $TARGET_PID $INTF
450
+ if [[ $? -ne 0 ]]; then
451
+ log_error running dhcp. aborting
452
+ RES=1
453
+ continue
454
+ fi
455
+ done
456
+
457
+ unlink_netns $TARGET_PID
458
+ done
459
+
460
+ return $RES
461
+ }
462
+
463
+ # -- FUNCTION ----------------------------------------------------------------
464
+ # Name: handle_detach
465
+ # Description: detaches all containers (of $ID_ARR) from all bridges ($DEVICE_ADDR)
466
+ # Removes eth/veth pairs from host
467
+ # Returns : 0=ok, 1=failed
468
+ # ----------------------------------------------------------------------------
469
+ function handle_detach() {
470
+ local RES=0
471
+
472
+ # iterate given container ids
473
+ for TARGET in $ID_ARR; do
474
+ $DEBUG Detaching $TARGET
475
+
476
+ TARGET_PID=$(container_process $TARGET)
477
+ $DEBUG PID of $TARGET is $TARGET_PID
478
+
479
+ link_netns ${TARGET_PID}
480
+
481
+ # iterate given devices
482
+ for DEVICE_PAIR in $DEVICE_ARR; do
483
+ INTF=$(echo $DEVICE_PAIR | awk -F':' '{ print $1 }' )
484
+ BRIDGE=$(echo $DEVICE_PAIR | awk -F':' '{ print $2 }' )
485
+
486
+ HOST_IFNAME=v${INTF}h${TARGET_PID}
487
+ CONTAINER_IFNAME=v${INTF}c${TARGET_PID}
488
+ $DEBUG - interface pair names are ${HOST_IFNAME}/${CONTAINER_IFNAME}
489
+
490
+ $DEBUG - removing $HOST_IFNAME from $BRIDGE
491
+ remove_device_from_switch $HOST_IFNAME $BRIDGE
492
+ if [[ $? -ne 0 ]]; then
493
+ log_error removing device from bridge. aborting
494
+ RES=1
495
+ break
496
+ fi
497
+
498
+ $DEBUG - delete interfaces
499
+ delete_interfaces $HOST_IFNAME $CONTAINER_IFNAME $TARGET_PID $INTF
500
+ if [[ $? -ne 0 ]]; then
501
+ log_error deleting interfaces
502
+ RES=1
503
+ break
504
+ fi
505
+ done
506
+
507
+ unlink_netns $TARGET_PID
508
+ done
509
+
510
+ return $RES
511
+ }
512
+
513
+ # ========= MAIN ========================================================
514
+
515
+ if [[ "$ACTION" == "verify" ]]; then
516
+ handle_verify
517
+ if [[ $? -eq 0 ]]; then
518
+ log_ok
519
+ exit 0
520
+ else
521
+ echo FAILED
522
+ exit 100
523
+ fi
524
+ fi
525
+
526
+ if [[ "$ACTION" == "attach" ]]; then
527
+ handle_attach
528
+ if [[ $? -eq 0 ]]; then
529
+ log_ok
530
+ exit 0
531
+ else
532
+ echo FAILED
533
+ exit 100
534
+ fi
535
+ fi
536
+
537
+ if [[ "$ACTION" == "detach" ]]; then
538
+ handle_detach
539
+ if [[ $? -eq 0 ]]; then
540
+ log_ok
541
+ exit 0
542
+ else
543
+ echo FAILED
544
+ exit 100
545
+ fi
546
+ fi
547
+
data/lib/test_fig.rb ADDED
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ # The MIT License (MIT)
4
+ # Copyright (c) 2014 Andreas Schmidt, andreas@de-wiring.net
5
+ #
6
+
7
+ require 'rubygems'
8
+
9
+ #
10
+ # modules
11
+ #
12
+ require_relative 'wire/common.rb'
13
+ require_relative 'wire/cli.rb'
14
+ require_relative 'wire/commands.rb'
15
+ require_relative 'wire/model.rb'
16
+ require_relative 'wire/execution.rb'
17
+ require_relative 'wire/resource.rb'
18
+
19
+ include Wire
20
+
21
+ $log.level = Logger::DEBUG
22
+
23
+ fa = Wire::Resource::FigAdapter.new('wiredmz', 'test/d1/fig/fig_dmz.yaml')
24
+ pp fa
25
+
26
+ $log.info 'Checking if containers are up'
27
+ r = fa.up?
28
+ $log.info "Result=#{r}"
29
+
30
+ $log.info 'Bringing it up...'
31
+ r = fa.up
32
+ $log.info "Result=#{r}"
33
+
34
+ $log.info 'Checking if containers are up'
35
+ r = fa.up?
36
+ $log.info "Result=#{r}"
37
+
38
+ $log.info "IDs=#{fa.up_ids}"
39
+
40
+ $log.info 'Taking it down...'
41
+ r = fa.down
42
+ $log.info "Result=#{r}"
43
+
44
+ $log.info 'Checking if containers are up'
45
+ r = fa.up?
46
+ $log.info "Result=#{r}"
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+
3
+ # The MIT License (MIT)
4
+ # Copyright (c) 2014 Andreas Schmidt, andreas@de-wiring.net
5
+ #
6
+
7
+ # Wire module
8
+ module Wire
9
+ # WireCLI
10
+ # thor command line class
11
+ #
12
+ class WireCommands
13
+ # internal array of +commands+ (as objects)
14
+ attr_reader :commands
15
+
16
+ # initialize wirecommands object
17
+ def initialize
18
+ initialize_commands
19
+ end
20
+
21
+ # pre-build array of available commands
22
+ # see @commands
23
+ def initialize_commands
24
+ @commands = {
25
+ :init_command => InitCommand.new,
26
+ :validate_command => ValidateCommand.new,
27
+ :verify_command => VerifyCommand.new,
28
+ :spec_command => SpecCommand.new,
29
+ :up_command => UpCommand.new,
30
+ :down_command => DownCommand.new
31
+ } unless @commands
32
+ end
33
+
34
+ # :reek:DuplicateCode
35
+ # run the init command on +target_dir+ model
36
+ def run_init(target_dir)
37
+ commands[:init_command].run({ :target_dir => target_dir })
38
+ end
39
+
40
+ # :reek:DuplicateCode
41
+ # run the validate command on +target_dir+ model
42
+ def run_validate(target_dir)
43
+ commands[:validate_command].run({ :target_dir => target_dir })
44
+ end
45
+
46
+ # run the verify command on +target_dir+ model
47
+ def run_verify(target_dir)
48
+ cmd_ver_obj = commands[:verify_command]
49
+ cmd_ver_obj.run({ :target_dir => target_dir })
50
+ if cmd_ver_obj.findings.size == 0
51
+ puts 'OK, system is conforming to model'.color(:green)
52
+ else
53
+ puts 'ERROR, detected inconsistencies/errors:'.color(:red)
54
+ cmd_ver_obj.findings.each do |val_error|
55
+ puts val_error.to_s
56
+ end
57
+ end
58
+ end
59
+
60
+ # run the up command on +target_dir+ model
61
+ def run_up(target_dir)
62
+ # :reek:DuplicateCode
63
+ if commands[:up_command].run({ :target_dir => target_dir })
64
+ puts 'OK'.color(:green)
65
+ else
66
+ puts 'ERROR, detected errors'.color(:red)
67
+ end
68
+ end
69
+
70
+ # run the down command on +target_dir+ model
71
+ def run_down(target_dir)
72
+ # :reek:DuplicateCode
73
+ if commands[:down_command].run({ :target_dir => target_dir })
74
+ puts 'OK'.color(:green)
75
+ else
76
+ puts 'ERROR, detected errors'.color(:red)
77
+ end
78
+ end
79
+
80
+ # run the spec command on +target_dir+ model
81
+ def run_spec(target_dir, b_run)
82
+ commands[:spec_command].run({
83
+ :target_dir => target_dir,
84
+ :auto_run => b_run
85
+ })
86
+ end
87
+ end
88
+ end