root / lib / client / gnt_network.py @ b34864e8
History | View | Annotate | Download (11.5 kB)
1 | 9c784fb3 | Dimitris Aragiorgis | #
|
---|---|---|---|
2 | 9c784fb3 | Dimitris Aragiorgis | #
|
3 | 9c784fb3 | Dimitris Aragiorgis | |
4 | 2556424d | Iustin Pop | # Copyright (C) 2011, 2012 Google Inc.
|
5 | 9c784fb3 | Dimitris Aragiorgis | #
|
6 | 9c784fb3 | Dimitris Aragiorgis | # This program is free software; you can redistribute it and/or modify
|
7 | 9c784fb3 | Dimitris Aragiorgis | # it under the terms of the GNU General Public License as published by
|
8 | 9c784fb3 | Dimitris Aragiorgis | # the Free Software Foundation; either version 2 of the License, or
|
9 | 9c784fb3 | Dimitris Aragiorgis | # (at your option) any later version.
|
10 | 9c784fb3 | Dimitris Aragiorgis | #
|
11 | 9c784fb3 | Dimitris Aragiorgis | # This program is distributed in the hope that it will be useful, but
|
12 | 9c784fb3 | Dimitris Aragiorgis | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 9c784fb3 | Dimitris Aragiorgis | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 9c784fb3 | Dimitris Aragiorgis | # General Public License for more details.
|
15 | 9c784fb3 | Dimitris Aragiorgis | #
|
16 | 9c784fb3 | Dimitris Aragiorgis | # You should have received a copy of the GNU General Public License
|
17 | 9c784fb3 | Dimitris Aragiorgis | # along with this program; if not, write to the Free Software
|
18 | 9c784fb3 | Dimitris Aragiorgis | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 9c784fb3 | Dimitris Aragiorgis | # 02110-1301, USA.
|
20 | 9c784fb3 | Dimitris Aragiorgis | |
21 | 9c784fb3 | Dimitris Aragiorgis | """IP pool related commands"""
|
22 | 9c784fb3 | Dimitris Aragiorgis | |
23 | beb81ea5 | Dimitris Aragiorgis | # pylint: disable=W0401,W0614
|
24 | 9c784fb3 | Dimitris Aragiorgis | # W0401: Wildcard import ganeti.cli
|
25 | 9c784fb3 | Dimitris Aragiorgis | # W0614: Unused import %s from wildcard import (since we need cli)
|
26 | 9c784fb3 | Dimitris Aragiorgis | |
27 | 9c784fb3 | Dimitris Aragiorgis | from ganeti.cli import * |
28 | 9c784fb3 | Dimitris Aragiorgis | from ganeti import constants |
29 | 9c784fb3 | Dimitris Aragiorgis | from ganeti import opcodes |
30 | 9c784fb3 | Dimitris Aragiorgis | from ganeti import utils |
31 | b34864e8 | Michael Hanselmann | from ganeti import errors |
32 | 9c784fb3 | Dimitris Aragiorgis | from textwrap import wrap |
33 | 9c784fb3 | Dimitris Aragiorgis | |
34 | 9c784fb3 | Dimitris Aragiorgis | |
35 | 9c784fb3 | Dimitris Aragiorgis | #: default list of fields for L{ListNetworks}
|
36 | d5ed7dce | Dimitris Aragiorgis | _LIST_DEF_FIELDS = ["name", "network", "gateway", |
37 | 8140e24f | Dimitris Aragiorgis | "network_type", "mac_prefix", "group_list", "tags"] |
38 | 9c784fb3 | Dimitris Aragiorgis | |
39 | 9c784fb3 | Dimitris Aragiorgis | |
40 | 9c784fb3 | Dimitris Aragiorgis | def _HandleReservedIPs(ips): |
41 | b34864e8 | Michael Hanselmann | if ips is None: |
42 | b34864e8 | Michael Hanselmann | return None |
43 | b34864e8 | Michael Hanselmann | elif not ips: |
44 | b34864e8 | Michael Hanselmann | return []
|
45 | b34864e8 | Michael Hanselmann | else:
|
46 | b34864e8 | Michael Hanselmann | return utils.UnescapeAndSplit(ips, sep=",") |
47 | 9c784fb3 | Dimitris Aragiorgis | |
48 | 3c286190 | Dimitris Aragiorgis | |
49 | 9c784fb3 | Dimitris Aragiorgis | def AddNetwork(opts, args): |
50 | 9c784fb3 | Dimitris Aragiorgis | """Add a network to the cluster.
|
51 | 9c784fb3 | Dimitris Aragiorgis |
|
52 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
53 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
54 | 9c784fb3 | Dimitris Aragiorgis | @param args: a list of length 1 with the network name to create
|
55 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
56 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
57 | 9c784fb3 | Dimitris Aragiorgis |
|
58 | 9c784fb3 | Dimitris Aragiorgis | """
|
59 | 9c784fb3 | Dimitris Aragiorgis | (network_name, ) = args |
60 | 9c784fb3 | Dimitris Aragiorgis | |
61 | b34864e8 | Michael Hanselmann | if opts.network is None: |
62 | b34864e8 | Michael Hanselmann | raise errors.OpPrereqError("The --network option must be given", |
63 | b34864e8 | Michael Hanselmann | errors.ECODE_INVAL) |
64 | b34864e8 | Michael Hanselmann | |
65 | 8140e24f | Dimitris Aragiorgis | if opts.tags is not None: |
66 | 8140e24f | Dimitris Aragiorgis | tags = opts.tags.split(",")
|
67 | 8140e24f | Dimitris Aragiorgis | else:
|
68 | 8140e24f | Dimitris Aragiorgis | tags = [] |
69 | 8140e24f | Dimitris Aragiorgis | |
70 | b34864e8 | Michael Hanselmann | reserved_ips = _HandleReservedIPs(opts.add_reserved_ips) |
71 | b34864e8 | Michael Hanselmann | |
72 | b34864e8 | Michael Hanselmann | op = opcodes.OpNetworkAdd(network_name=network_name, |
73 | b34864e8 | Michael Hanselmann | gateway=opts.gateway, |
74 | b34864e8 | Michael Hanselmann | network=opts.network, |
75 | b34864e8 | Michael Hanselmann | gateway6=opts.gateway6, |
76 | b34864e8 | Michael Hanselmann | network6=opts.network6, |
77 | b34864e8 | Michael Hanselmann | mac_prefix=opts.mac_prefix, |
78 | b34864e8 | Michael Hanselmann | network_type=opts.network_type, |
79 | b34864e8 | Michael Hanselmann | add_reserved_ips=reserved_ips, |
80 | b34864e8 | Michael Hanselmann | conflicts_check=opts.conflicts_check, |
81 | b34864e8 | Michael Hanselmann | tags=tags) |
82 | 9c784fb3 | Dimitris Aragiorgis | SubmitOpCode(op, opts=opts) |
83 | 9c784fb3 | Dimitris Aragiorgis | |
84 | 9c784fb3 | Dimitris Aragiorgis | |
85 | 9c784fb3 | Dimitris Aragiorgis | def MapNetwork(opts, args): |
86 | 9c784fb3 | Dimitris Aragiorgis | """Map a network to a node group.
|
87 | 9c784fb3 | Dimitris Aragiorgis |
|
88 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
89 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
90 | 9c784fb3 | Dimitris Aragiorgis | @param args: a list of length 3 with network, nodegroup, mode, physlink
|
91 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
92 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
93 | 9c784fb3 | Dimitris Aragiorgis |
|
94 | 9c784fb3 | Dimitris Aragiorgis | """
|
95 | 9c784fb3 | Dimitris Aragiorgis | network = args[0]
|
96 | 9c784fb3 | Dimitris Aragiorgis | groups = args[1]
|
97 | 9c784fb3 | Dimitris Aragiorgis | mode = args[2]
|
98 | 9c784fb3 | Dimitris Aragiorgis | link = args[3]
|
99 | 9c784fb3 | Dimitris Aragiorgis | |
100 | 2556424d | Iustin Pop | # TODO: allow comma separated group names
|
101 | 2556424d | Iustin Pop | if groups == "all": |
102 | 9c784fb3 | Dimitris Aragiorgis | cl = GetClient() |
103 | 2556424d | Iustin Pop | (groups, ) = cl.QueryGroups([], ["name"], False) |
104 | 9c784fb3 | Dimitris Aragiorgis | else:
|
105 | 9c784fb3 | Dimitris Aragiorgis | groups = [groups] |
106 | 9c784fb3 | Dimitris Aragiorgis | |
107 | 9c784fb3 | Dimitris Aragiorgis | for group in groups: |
108 | 9c784fb3 | Dimitris Aragiorgis | op = opcodes.OpNetworkConnect(group_name=group, |
109 | 9c784fb3 | Dimitris Aragiorgis | network_name=network, |
110 | 9c784fb3 | Dimitris Aragiorgis | network_mode=mode, |
111 | 9c784fb3 | Dimitris Aragiorgis | network_link=link, |
112 | 9c784fb3 | Dimitris Aragiorgis | conflicts_check=opts.conflicts_check) |
113 | 9c784fb3 | Dimitris Aragiorgis | SubmitOpCode(op, opts=opts) |
114 | 9c784fb3 | Dimitris Aragiorgis | |
115 | 9c784fb3 | Dimitris Aragiorgis | |
116 | 9c784fb3 | Dimitris Aragiorgis | def UnmapNetwork(opts, args): |
117 | 9c784fb3 | Dimitris Aragiorgis | """Unmap a network from a node group.
|
118 | 9c784fb3 | Dimitris Aragiorgis |
|
119 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
120 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
121 | 9c784fb3 | Dimitris Aragiorgis | @param args: a list of length 3 with network, nodegorup
|
122 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
123 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
124 | 9c784fb3 | Dimitris Aragiorgis |
|
125 | 9c784fb3 | Dimitris Aragiorgis | """
|
126 | 9c784fb3 | Dimitris Aragiorgis | network = args[0]
|
127 | 9c784fb3 | Dimitris Aragiorgis | groups = args[1]
|
128 | 9c784fb3 | Dimitris Aragiorgis | |
129 | 9c784fb3 | Dimitris Aragiorgis | #TODO: allow comma separated group names
|
130 | 2556424d | Iustin Pop | if groups == "all": |
131 | 9c784fb3 | Dimitris Aragiorgis | cl = GetClient() |
132 | 2556424d | Iustin Pop | (groups, ) = cl.QueryGroups([], ["name"], False) |
133 | 9c784fb3 | Dimitris Aragiorgis | else:
|
134 | 9c784fb3 | Dimitris Aragiorgis | groups = [groups] |
135 | 9c784fb3 | Dimitris Aragiorgis | |
136 | 9c784fb3 | Dimitris Aragiorgis | for group in groups: |
137 | 9c784fb3 | Dimitris Aragiorgis | op = opcodes.OpNetworkDisconnect(group_name=group, |
138 | 9c784fb3 | Dimitris Aragiorgis | network_name=network, |
139 | 9c784fb3 | Dimitris Aragiorgis | conflicts_check=opts.conflicts_check) |
140 | 9c784fb3 | Dimitris Aragiorgis | SubmitOpCode(op, opts=opts) |
141 | 9c784fb3 | Dimitris Aragiorgis | |
142 | 9c784fb3 | Dimitris Aragiorgis | |
143 | 9c784fb3 | Dimitris Aragiorgis | def ListNetworks(opts, args): |
144 | 9c784fb3 | Dimitris Aragiorgis | """List Ip pools and their properties.
|
145 | 9c784fb3 | Dimitris Aragiorgis |
|
146 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
147 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
148 | 9c784fb3 | Dimitris Aragiorgis | @param args: networks to list, or empty for all
|
149 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
150 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
151 | 9c784fb3 | Dimitris Aragiorgis |
|
152 | 9c784fb3 | Dimitris Aragiorgis | """
|
153 | 9c784fb3 | Dimitris Aragiorgis | desired_fields = ParseFields(opts.output, _LIST_DEF_FIELDS) |
154 | 9c784fb3 | Dimitris Aragiorgis | fmtoverride = { |
155 | 9c784fb3 | Dimitris Aragiorgis | "group_list": (",".join, False), |
156 | 9c784fb3 | Dimitris Aragiorgis | "inst_list": (",".join, False), |
157 | 8140e24f | Dimitris Aragiorgis | "tags": (",".join, False), |
158 | 9c784fb3 | Dimitris Aragiorgis | } |
159 | 9c784fb3 | Dimitris Aragiorgis | |
160 | 9c784fb3 | Dimitris Aragiorgis | return GenericList(constants.QR_NETWORK, desired_fields, args, None, |
161 | 9c784fb3 | Dimitris Aragiorgis | opts.separator, not opts.no_headers,
|
162 | 9c784fb3 | Dimitris Aragiorgis | verbose=opts.verbose, format_override=fmtoverride) |
163 | 9c784fb3 | Dimitris Aragiorgis | |
164 | 9c784fb3 | Dimitris Aragiorgis | |
165 | 9c784fb3 | Dimitris Aragiorgis | def ListNetworkFields(opts, args): |
166 | 9c784fb3 | Dimitris Aragiorgis | """List network fields.
|
167 | 9c784fb3 | Dimitris Aragiorgis |
|
168 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
169 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
170 | 9c784fb3 | Dimitris Aragiorgis | @param args: fields to list, or empty for all
|
171 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
172 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
173 | 9c784fb3 | Dimitris Aragiorgis |
|
174 | 9c784fb3 | Dimitris Aragiorgis | """
|
175 | 9c784fb3 | Dimitris Aragiorgis | return GenericListFields(constants.QR_NETWORK, args, opts.separator,
|
176 | 9c784fb3 | Dimitris Aragiorgis | not opts.no_headers)
|
177 | 9c784fb3 | Dimitris Aragiorgis | |
178 | 9c784fb3 | Dimitris Aragiorgis | |
179 | beb81ea5 | Dimitris Aragiorgis | def ShowNetworkConfig(_, args): |
180 | 9c784fb3 | Dimitris Aragiorgis | """Show network information.
|
181 | 9c784fb3 | Dimitris Aragiorgis |
|
182 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
183 | 9c784fb3 | Dimitris Aragiorgis | @param args: should either be an empty list, in which case
|
184 | 9c784fb3 | Dimitris Aragiorgis | we show information about all nodes, or should contain
|
185 | 9c784fb3 | Dimitris Aragiorgis | a list of networks (names or UUIDs) to be queried for information
|
186 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
187 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
188 | 9c784fb3 | Dimitris Aragiorgis |
|
189 | 9c784fb3 | Dimitris Aragiorgis | """
|
190 | 9c784fb3 | Dimitris Aragiorgis | cl = GetClient() |
191 | 9c784fb3 | Dimitris Aragiorgis | result = cl.QueryNetworks(fields=["name", "network", "gateway", |
192 | 9c784fb3 | Dimitris Aragiorgis | "network6", "gateway6", |
193 | 9c784fb3 | Dimitris Aragiorgis | "mac_prefix", "network_type", |
194 | 9c784fb3 | Dimitris Aragiorgis | "free_count", "reserved_count", |
195 | 9c784fb3 | Dimitris Aragiorgis | "map", "group_list", "inst_list", |
196 | 9675661c | Dimitris Aragiorgis | "external_reservations",
|
197 | 9675661c | Dimitris Aragiorgis | "serial_no", "uuid"], |
198 | 9c784fb3 | Dimitris Aragiorgis | names=args, use_locking=False)
|
199 | 9c784fb3 | Dimitris Aragiorgis | |
200 | 9c784fb3 | Dimitris Aragiorgis | for (name, network, gateway, network6, gateway6,
|
201 | 9c784fb3 | Dimitris Aragiorgis | mac_prefix, network_type, free_count, reserved_count, |
202 | 9675661c | Dimitris Aragiorgis | mapping, group_list, instances, ext_res, serial, uuid) in result:
|
203 | 9c784fb3 | Dimitris Aragiorgis | size = free_count + reserved_count |
204 | 9c784fb3 | Dimitris Aragiorgis | ToStdout("Network name: %s", name)
|
205 | 9675661c | Dimitris Aragiorgis | ToStdout("UUID: %s", uuid)
|
206 | 9675661c | Dimitris Aragiorgis | ToStdout("Serial number: %d", serial)
|
207 | 9675661c | Dimitris Aragiorgis | ToStdout(" Subnet: %s", network)
|
208 | 9675661c | Dimitris Aragiorgis | ToStdout(" Gateway: %s", gateway)
|
209 | 9675661c | Dimitris Aragiorgis | ToStdout(" IPv6 Subnet: %s", network6)
|
210 | 9675661c | Dimitris Aragiorgis | ToStdout(" IPv6 Gateway: %s", gateway6)
|
211 | 9675661c | Dimitris Aragiorgis | ToStdout(" Mac Prefix: %s", mac_prefix)
|
212 | 9675661c | Dimitris Aragiorgis | ToStdout(" Type: %s", network_type)
|
213 | 9675661c | Dimitris Aragiorgis | ToStdout(" Size: %d", size)
|
214 | 9675661c | Dimitris Aragiorgis | ToStdout(" Free: %d (%.2f%%)", free_count,
|
215 | 965a542a | Michael Hanselmann | 100 * float(free_count) / float(size)) |
216 | 9675661c | Dimitris Aragiorgis | ToStdout(" Usage map:")
|
217 | 9c784fb3 | Dimitris Aragiorgis | idx = 0
|
218 | beb81ea5 | Dimitris Aragiorgis | for line in wrap(mapping, width=64): |
219 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" %s %s %d", str(idx).rjust(3), line.ljust(64), idx + 63) |
220 | 9c784fb3 | Dimitris Aragiorgis | idx += 64
|
221 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" (X) used (.) free")
|
222 | 9c784fb3 | Dimitris Aragiorgis | |
223 | 9c784fb3 | Dimitris Aragiorgis | if ext_res:
|
224 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" externally reserved IPs:")
|
225 | 9c784fb3 | Dimitris Aragiorgis | for line in wrap(ext_res, width=64): |
226 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" %s" % line)
|
227 | 9c784fb3 | Dimitris Aragiorgis | |
228 | 9c784fb3 | Dimitris Aragiorgis | if group_list:
|
229 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" connected to node groups:")
|
230 | 9c784fb3 | Dimitris Aragiorgis | for group in group_list: |
231 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" %s", group)
|
232 | 9c784fb3 | Dimitris Aragiorgis | else:
|
233 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" not connected to any node group")
|
234 | 9c784fb3 | Dimitris Aragiorgis | |
235 | 9c784fb3 | Dimitris Aragiorgis | if instances:
|
236 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" used by %d instances:", len(instances)) |
237 | 9c784fb3 | Dimitris Aragiorgis | for inst in instances: |
238 | 9c784fb3 | Dimitris Aragiorgis | ((ips, networks), ) = cl.QueryInstances([inst], |
239 | 9c784fb3 | Dimitris Aragiorgis | ["nic.ips", "nic.networks"], |
240 | 9c784fb3 | Dimitris Aragiorgis | use_locking=False)
|
241 | 9c784fb3 | Dimitris Aragiorgis | |
242 | 3c286190 | Dimitris Aragiorgis | l = lambda value: ", ".join(str(idx) + ":" + str(ip) |
243 | 9c784fb3 | Dimitris Aragiorgis | for idx, (ip, net) in enumerate(value) |
244 | 9c784fb3 | Dimitris Aragiorgis | if net == name)
|
245 | 9c784fb3 | Dimitris Aragiorgis | |
246 | beb81ea5 | Dimitris Aragiorgis | ToStdout(" %s : %s", inst, l(zip(ips, networks))) |
247 | 9c784fb3 | Dimitris Aragiorgis | else:
|
248 | 9c784fb3 | Dimitris Aragiorgis | ToStdout(" not used by any instances")
|
249 | 9c784fb3 | Dimitris Aragiorgis | |
250 | 9c784fb3 | Dimitris Aragiorgis | |
251 | 9c784fb3 | Dimitris Aragiorgis | def SetNetworkParams(opts, args): |
252 | 9c784fb3 | Dimitris Aragiorgis | """Modifies an IP address pool's parameters.
|
253 | 9c784fb3 | Dimitris Aragiorgis |
|
254 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
255 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
256 | 9c784fb3 | Dimitris Aragiorgis | @param args: should contain only one element, the node group name
|
257 | 9c784fb3 | Dimitris Aragiorgis |
|
258 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
259 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
260 | 9c784fb3 | Dimitris Aragiorgis |
|
261 | 9c784fb3 | Dimitris Aragiorgis | """
|
262 | 9c784fb3 | Dimitris Aragiorgis | |
263 | 9c784fb3 | Dimitris Aragiorgis | # TODO: add "network": opts.network,
|
264 | 9c784fb3 | Dimitris Aragiorgis | all_changes = { |
265 | 9c784fb3 | Dimitris Aragiorgis | "gateway": opts.gateway,
|
266 | 9c784fb3 | Dimitris Aragiorgis | "add_reserved_ips": _HandleReservedIPs(opts.add_reserved_ips),
|
267 | 9c784fb3 | Dimitris Aragiorgis | "remove_reserved_ips": _HandleReservedIPs(opts.remove_reserved_ips),
|
268 | 9c784fb3 | Dimitris Aragiorgis | "mac_prefix": opts.mac_prefix,
|
269 | 9c784fb3 | Dimitris Aragiorgis | "network_type": opts.network_type,
|
270 | 9c784fb3 | Dimitris Aragiorgis | "gateway6": opts.gateway6,
|
271 | 9c784fb3 | Dimitris Aragiorgis | "network6": opts.network6,
|
272 | 9c784fb3 | Dimitris Aragiorgis | } |
273 | 9c784fb3 | Dimitris Aragiorgis | |
274 | 9c784fb3 | Dimitris Aragiorgis | if all_changes.values().count(None) == len(all_changes): |
275 | 9c784fb3 | Dimitris Aragiorgis | ToStderr("Please give at least one of the parameters.")
|
276 | 9c784fb3 | Dimitris Aragiorgis | return 1 |
277 | 9c784fb3 | Dimitris Aragiorgis | |
278 | beb81ea5 | Dimitris Aragiorgis | # pylint: disable=W0142
|
279 | beb81ea5 | Dimitris Aragiorgis | op = opcodes.OpNetworkSetParams(network_name=args[0], **all_changes)
|
280 | 9c784fb3 | Dimitris Aragiorgis | |
281 | 9c784fb3 | Dimitris Aragiorgis | # TODO: add feedback to user, e.g. list the modifications
|
282 | 9c784fb3 | Dimitris Aragiorgis | SubmitOrSend(op, opts) |
283 | 9c784fb3 | Dimitris Aragiorgis | |
284 | 9c784fb3 | Dimitris Aragiorgis | |
285 | 9c784fb3 | Dimitris Aragiorgis | def RemoveNetwork(opts, args): |
286 | 9c784fb3 | Dimitris Aragiorgis | """Remove an IP address pool from the cluster.
|
287 | 9c784fb3 | Dimitris Aragiorgis |
|
288 | 9c784fb3 | Dimitris Aragiorgis | @param opts: the command line options selected by the user
|
289 | 9c784fb3 | Dimitris Aragiorgis | @type args: list
|
290 | 9c784fb3 | Dimitris Aragiorgis | @param args: a list of length 1 with the id of the IP address pool to remove
|
291 | 9c784fb3 | Dimitris Aragiorgis | @rtype: int
|
292 | 9c784fb3 | Dimitris Aragiorgis | @return: the desired exit code
|
293 | 9c784fb3 | Dimitris Aragiorgis |
|
294 | 9c784fb3 | Dimitris Aragiorgis | """
|
295 | 9c784fb3 | Dimitris Aragiorgis | (network_name,) = args |
296 | 9c784fb3 | Dimitris Aragiorgis | op = opcodes.OpNetworkRemove(network_name=network_name, force=opts.force) |
297 | 9c784fb3 | Dimitris Aragiorgis | SubmitOpCode(op, opts=opts) |
298 | 9c784fb3 | Dimitris Aragiorgis | |
299 | 9c784fb3 | Dimitris Aragiorgis | |
300 | 9c784fb3 | Dimitris Aragiorgis | commands = { |
301 | 9c784fb3 | Dimitris Aragiorgis | "add": (
|
302 | 9c784fb3 | Dimitris Aragiorgis | AddNetwork, ARGS_ONE_NETWORK, |
303 | 213076fe | Dimitris Aragiorgis | [DRY_RUN_OPT, NETWORK_OPT, GATEWAY_OPT, ADD_RESERVED_IPS_OPT, |
304 | 213076fe | Dimitris Aragiorgis | MAC_PREFIX_OPT, NETWORK_TYPE_OPT, NETWORK6_OPT, GATEWAY6_OPT, |
305 | 213076fe | Dimitris Aragiorgis | NOCONFLICTSCHECK_OPT, TAG_ADD_OPT], |
306 | 9c784fb3 | Dimitris Aragiorgis | "<network_name>", "Add a new IP network to the cluster"), |
307 | 9c784fb3 | Dimitris Aragiorgis | "list": (
|
308 | 9c784fb3 | Dimitris Aragiorgis | ListNetworks, ARGS_MANY_NETWORKS, |
309 | 9c784fb3 | Dimitris Aragiorgis | [NOHDR_OPT, SEP_OPT, FIELDS_OPT, VERBOSE_OPT], |
310 | 9c784fb3 | Dimitris Aragiorgis | "[<network_id>...]",
|
311 | 9c784fb3 | Dimitris Aragiorgis | "Lists the IP networks in the cluster. The available fields can be shown"
|
312 | 9c784fb3 | Dimitris Aragiorgis | " using the \"list-fields\" command (see the man page for details)."
|
313 | 9c784fb3 | Dimitris Aragiorgis | " The default list is (in order): %s." % utils.CommaJoin(_LIST_DEF_FIELDS)),
|
314 | 9c784fb3 | Dimitris Aragiorgis | "list-fields": (
|
315 | 9c784fb3 | Dimitris Aragiorgis | ListNetworkFields, [ArgUnknown()], [NOHDR_OPT, SEP_OPT], "[fields...]",
|
316 | 9c784fb3 | Dimitris Aragiorgis | "Lists all available fields for networks"),
|
317 | 9c784fb3 | Dimitris Aragiorgis | "info": (
|
318 | 9c784fb3 | Dimitris Aragiorgis | ShowNetworkConfig, ARGS_MANY_NETWORKS, [], |
319 | 9c784fb3 | Dimitris Aragiorgis | "[<network_name>...]", "Show information about the network(s)"), |
320 | 9c784fb3 | Dimitris Aragiorgis | "modify": (
|
321 | 9c784fb3 | Dimitris Aragiorgis | SetNetworkParams, ARGS_ONE_NETWORK, |
322 | 9c784fb3 | Dimitris Aragiorgis | [DRY_RUN_OPT, SUBMIT_OPT, ADD_RESERVED_IPS_OPT, REMOVE_RESERVED_IPS_OPT, |
323 | 9c784fb3 | Dimitris Aragiorgis | GATEWAY_OPT, MAC_PREFIX_OPT, NETWORK_TYPE_OPT, NETWORK6_OPT, GATEWAY6_OPT], |
324 | 9c784fb3 | Dimitris Aragiorgis | "<network_name>", "Alters the parameters of a network"), |
325 | 9c784fb3 | Dimitris Aragiorgis | "connect": (
|
326 | 9c784fb3 | Dimitris Aragiorgis | MapNetwork, |
327 | 9c784fb3 | Dimitris Aragiorgis | [ArgNetwork(min=1, max=1), ArgGroup(min=1, max=1), |
328 | e896ad3d | Michael Hanselmann | ArgChoice(min=1, max=1, choices=constants.NIC_VALID_MODES), |
329 | e896ad3d | Michael Hanselmann | ArgUnknown(min=1, max=1)], |
330 | 9c784fb3 | Dimitris Aragiorgis | [NOCONFLICTSCHECK_OPT], |
331 | 9c784fb3 | Dimitris Aragiorgis | "<network_name> <node_group> <mode> <link>",
|
332 | 9c784fb3 | Dimitris Aragiorgis | "Map a given network to the specified node group"
|
333 | 9c784fb3 | Dimitris Aragiorgis | " with given mode and link (netparams)"),
|
334 | 9c784fb3 | Dimitris Aragiorgis | "disconnect": (
|
335 | 9c784fb3 | Dimitris Aragiorgis | UnmapNetwork, |
336 | 9c784fb3 | Dimitris Aragiorgis | [ArgNetwork(min=1, max=1), ArgGroup(min=1, max=1)], |
337 | 9c784fb3 | Dimitris Aragiorgis | [NOCONFLICTSCHECK_OPT], |
338 | 9c784fb3 | Dimitris Aragiorgis | "<network_name> <node_group>",
|
339 | 9c784fb3 | Dimitris Aragiorgis | "Unmap a given network from a specified node group"),
|
340 | 9c784fb3 | Dimitris Aragiorgis | "remove": (
|
341 | 9c784fb3 | Dimitris Aragiorgis | RemoveNetwork, ARGS_ONE_NETWORK, [FORCE_OPT, DRY_RUN_OPT], |
342 | 9c784fb3 | Dimitris Aragiorgis | "[--dry-run] <network_id>",
|
343 | 9c784fb3 | Dimitris Aragiorgis | "Remove an (empty) network from the cluster"),
|
344 | 8140e24f | Dimitris Aragiorgis | "list-tags": (
|
345 | 8140e24f | Dimitris Aragiorgis | ListTags, ARGS_ONE_NETWORK, [], |
346 | 8140e24f | Dimitris Aragiorgis | "<network_name>", "List the tags of the given network"), |
347 | 8140e24f | Dimitris Aragiorgis | "add-tags": (
|
348 | 8140e24f | Dimitris Aragiorgis | AddTags, [ArgNetwork(min=1, max=1), ArgUnknown()], |
349 | 8140e24f | Dimitris Aragiorgis | [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT], |
350 | 8140e24f | Dimitris Aragiorgis | "<network_name> tag...", "Add tags to the given network"), |
351 | 8140e24f | Dimitris Aragiorgis | "remove-tags": (
|
352 | 8140e24f | Dimitris Aragiorgis | RemoveTags, [ArgNetwork(min=1, max=1), ArgUnknown()], |
353 | 8140e24f | Dimitris Aragiorgis | [TAG_SRC_OPT, PRIORITY_OPT, SUBMIT_OPT], |
354 | 8140e24f | Dimitris Aragiorgis | "<network_name> tag...", "Remove tags from given network"), |
355 | 9c784fb3 | Dimitris Aragiorgis | } |
356 | 9c784fb3 | Dimitris Aragiorgis | |
357 | 9c784fb3 | Dimitris Aragiorgis | |
358 | 9c784fb3 | Dimitris Aragiorgis | def Main(): |
359 | 8140e24f | Dimitris Aragiorgis | return GenericMain(commands, override={"tag_type": constants.TAG_NETWORK}) |