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