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