]> git.ipfire.org Git - people/arne_f/network.git/blame - functions.ports
network: Add some initialization handlers.
[people/arne_f/network.git] / functions.ports
CommitLineData
711ffac1
MT
1#!/bin/bash
2# XXX header missing
3
4function port_dir() {
5 echo "${CONFIG_DIR}/ports"
6}
7
8function port_file() {
9 local port=${1}
10
11 assert isset port
12
13 echo "$(port_dir)/${port}"
14}
15
16function port_exists() {
17 local port=${1}
18
19 [ -f "${CONFIG_DIR}/ports/${port}" ]
20}
21
22function port_get_hook() {
23 local port=${1}
24
25 assert isset port
26
27 config_get_hook $(port_file ${port})
28}
29
30function port_is_attached() {
31 local port=${1}
32 shift
33
34 assert isset port
35
36 local zone
37 for zone in $(zones_get_all); do
38
39 assert isset zone
40 assert zone_exists ${zone}
41
42 if listmatch ${port} $(zone_get_ports ${zone}); then
43 echo "${zone}"
44 return ${EXIT_OK}
45 fi
46 done
47
48 return ${EXIT_ERROR}
49}
50
51function port_create() {
52 #local port=${1}
53 #shift
54 #
55 #if port_exists ${port}; then
56 # error "Port '${port}' does already exist."
57 # return ${EXIT_ERROR}
58 #fi
59
60 local hook=${1}
61 shift
62
63 if ! hook_exists port ${hook}; then
64 error "Port hook '${hook}' does not exist."
65 return ${EXIT_ERROR}
66 fi
67
68 #port_edit ${port} ${hook} $@
69 #
70 #if [ $? -ne ${EXIT_OK} ]; then
71 # port_destroy ${port}
72 #fi
73
74 hook_exec port ${hook} create $@
75}
76
77function port_destroy() {
78 local port=${1}
79
80 assert isset port
81
82 port_exists ${port} || return ${EXIT_OK}
83
84 local attached_zone=$(port_is_attached ${port})
85
86 if [ -n "${attached_zone}" ]; then
87 error "Cannot destroy port '${port}' which is attached to zone '${attached_zone}'."
88 return ${EXIT_ERROR}
89 fi
90
91 port_down ${port}
92
93 rm -f $(port_file ${port})
94}
95
96function port_edit() {
97 port_cmd edit $@
98}
99
100# XXX? Compatibility function
101function port_show() {
102 port_status $@
103}
104
105function port_up() {
106 port_cmd up $@
107}
108
109function port_down() {
110 port_cmd down $@
111}
112
113function port_status() {
114 port_cmd status $@
115}
116
117function port_cmd() {
118 local cmd=${1}
119 local port=${2}
120 shift 2
121
122 assert isset cmd
123 assert isset port
124
125 local hook=$(port_get_hook ${port})
126
127 assert isset hook
128
129 hook_exec port ${hook} ${cmd} ${port} $@
130}