root / lib / opcodes.py @ d0834de3
History | View | Annotate | Download (6.1 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2006, 2007 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""OpCodes module
|
23 |
|
24 |
This module implements the data structures which define the cluster
|
25 |
operations - the so-called opcodes.
|
26 |
|
27 |
|
28 |
This module implements the logic for doing operations in the cluster. There
|
29 |
are two kinds of classes defined:
|
30 |
- opcodes, which are small classes only holding data for the task at hand
|
31 |
- logical units, which know how to deal with their specific opcode only
|
32 |
|
33 |
"""
|
34 |
|
35 |
# this are practically structures, so disable the message about too
|
36 |
# few public methods:
|
37 |
# pylint: disable-msg=R0903
|
38 |
|
39 |
class OpCode(object): |
40 |
"""Abstract OpCode"""
|
41 |
OP_ID = "OP_ABSTRACT"
|
42 |
__slots__ = [] |
43 |
|
44 |
def __init__(self, **kwargs): |
45 |
for key in kwargs: |
46 |
if key not in self.__slots__: |
47 |
raise TypeError, ("OpCode %s doesn't support the parameter '%s'" % |
48 |
(self.__class__.__name__, key))
|
49 |
setattr(self, key, kwargs[key]) |
50 |
|
51 |
|
52 |
class OpInitCluster(OpCode): |
53 |
"""Initialise the cluster."""
|
54 |
OP_ID = "OP_CLUSTER_INIT"
|
55 |
__slots__ = ["cluster_name", "secondary_ip", "hypervisor_type", |
56 |
"vg_name", "mac_prefix", "def_bridge", "master_netdev"] |
57 |
|
58 |
|
59 |
class OpDestroyCluster(OpCode): |
60 |
"""Destroy the cluster."""
|
61 |
OP_ID = "OP_CLUSTER_DESTROY"
|
62 |
__slots__ = [] |
63 |
|
64 |
|
65 |
class OpQueryClusterInfo(OpCode): |
66 |
"""Initialise the cluster."""
|
67 |
OP_ID = "OP_CLUSTER_QUERY"
|
68 |
__slots__ = [] |
69 |
|
70 |
|
71 |
class OpClusterCopyFile(OpCode): |
72 |
"""Initialise the cluster."""
|
73 |
OP_ID = "OP_CLUSTER_COPYFILE"
|
74 |
__slots__ = ["nodes", "filename"] |
75 |
|
76 |
|
77 |
class OpRunClusterCommand(OpCode): |
78 |
"""Initialise the cluster."""
|
79 |
OP_ID = "OP_CLUSTER_RUNCOMMAND"
|
80 |
__slots__ = ["nodes", "command"] |
81 |
|
82 |
|
83 |
class OpVerifyCluster(OpCode): |
84 |
"""Initialise the cluster."""
|
85 |
OP_ID = "OP_CLUSTER_VERIFY"
|
86 |
__slots__ = [] |
87 |
|
88 |
|
89 |
class OpMasterFailover(OpCode): |
90 |
"""Initialise the cluster."""
|
91 |
OP_ID = "OP_CLUSTER_MASTERFAILOVER"
|
92 |
__slots__ = [] |
93 |
|
94 |
|
95 |
class OpDumpClusterConfig(OpCode): |
96 |
"""Initialise the cluster."""
|
97 |
OP_ID = "OP_CLUSTER_DUMPCONFIG"
|
98 |
__slots__ = [] |
99 |
|
100 |
|
101 |
class OpRemoveNode(OpCode): |
102 |
"""Remove a node."""
|
103 |
OP_ID = "OP_NODE_REMOVE"
|
104 |
__slots__ = ["node_name"]
|
105 |
|
106 |
|
107 |
class OpAddNode(OpCode): |
108 |
"""Add a node."""
|
109 |
OP_ID = "OP_NODE_ADD"
|
110 |
__slots__ = ["node_name", "primary_ip", "secondary_ip"] |
111 |
|
112 |
|
113 |
class OpQueryNodes(OpCode): |
114 |
"""Compute the list of nodes."""
|
115 |
OP_ID = "OP_NODE_QUERY"
|
116 |
__slots__ = ["output_fields"]
|
117 |
|
118 |
|
119 |
class OpQueryNodeData(OpCode): |
120 |
"""Compute the node info."""
|
121 |
OP_ID = "OP_NODE_INFO"
|
122 |
__slots__ = ["nodes"]
|
123 |
|
124 |
|
125 |
class OpQueryNodeVolumes(OpCode): |
126 |
"""Get list of volumes on node."""
|
127 |
OP_ID = "OP_NODE_QUERYVOLS"
|
128 |
__slots__ = ["nodes", "output_fields"] |
129 |
|
130 |
|
131 |
# instance opcodes
|
132 |
|
133 |
class OpCreateInstance(OpCode): |
134 |
"""Compute the list of instances."""
|
135 |
OP_ID = "OP_INSTANCE_CREATE"
|
136 |
__slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode", |
137 |
"disk_template", "snode", "swap_size", "mode", |
138 |
"vcpus", "ip", "bridge", "src_node", "src_path", "start", |
139 |
"wait_for_sync"]
|
140 |
|
141 |
|
142 |
class OpReinstallInstance(OpCode): |
143 |
"""Reinstall an instance."""
|
144 |
OP_ID = "OP_INSTANCE_REINSTALL"
|
145 |
__slots__ = ["instance_name", "os_type"] |
146 |
|
147 |
|
148 |
class OpRemoveInstance(OpCode): |
149 |
"""Remove an instance."""
|
150 |
OP_ID = "OP_INSTANCE_REMOVE"
|
151 |
__slots__ = ["instance_name"]
|
152 |
|
153 |
|
154 |
class OpStartupInstance(OpCode): |
155 |
"""Remove an instance."""
|
156 |
OP_ID = "OP_INSTANCE_STARTUP"
|
157 |
__slots__ = ["instance_name", "force", "extra_args"] |
158 |
|
159 |
|
160 |
class OpShutdownInstance(OpCode): |
161 |
"""Remove an instance."""
|
162 |
OP_ID = "OP_INSTANCE_SHUTDOWN"
|
163 |
__slots__ = ["instance_name"]
|
164 |
|
165 |
|
166 |
class OpAddMDDRBDComponent(OpCode): |
167 |
"""Add a MD-DRBD component."""
|
168 |
OP_ID = "OP_INSTANCE_ADD_MDDRBD"
|
169 |
__slots__ = ["instance_name", "remote_node", "disk_name"] |
170 |
|
171 |
|
172 |
class OpRemoveMDDRBDComponent(OpCode): |
173 |
"""Remove a MD-DRBD component."""
|
174 |
OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
|
175 |
__slots__ = ["instance_name", "disk_name", "disk_id"] |
176 |
|
177 |
|
178 |
class OpReplaceDisks(OpCode): |
179 |
"""Replace disks of an instance."""
|
180 |
OP_ID = "OP_INSTANCE_REPLACE_DISKS"
|
181 |
__slots__ = ["instance_name", "remote_node"] |
182 |
|
183 |
|
184 |
class OpFailoverInstance(OpCode): |
185 |
"""Failover an instance."""
|
186 |
OP_ID = "OP_INSTANCE_FAILOVER"
|
187 |
__slots__ = ["instance_name", "ignore_consistency"] |
188 |
|
189 |
|
190 |
class OpConnectConsole(OpCode): |
191 |
"""Failover an instance."""
|
192 |
OP_ID = "OP_INSTANCE_CONSOLE"
|
193 |
__slots__ = ["instance_name"]
|
194 |
|
195 |
|
196 |
class OpActivateInstanceDisks(OpCode): |
197 |
"""Remove an instance."""
|
198 |
OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
|
199 |
__slots__ = ["instance_name"]
|
200 |
|
201 |
|
202 |
class OpDeactivateInstanceDisks(OpCode): |
203 |
"""Remove an instance."""
|
204 |
OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
|
205 |
__slots__ = ["instance_name"]
|
206 |
|
207 |
|
208 |
class OpQueryInstances(OpCode): |
209 |
"""Compute the list of instances."""
|
210 |
OP_ID = "OP_INSTANCE_QUERY"
|
211 |
__slots__ = ["output_fields"]
|
212 |
|
213 |
|
214 |
class OpQueryInstanceData(OpCode): |
215 |
"""Compute the run-time status of instances."""
|
216 |
OP_ID = "OP_INSTANCE_QUERY_DATA"
|
217 |
__slots__ = ["instances"]
|
218 |
|
219 |
|
220 |
class OpSetInstanceParms(OpCode): |
221 |
"""Change the parameters of an instance."""
|
222 |
OP_ID = "OP_INSTANCE_SET_PARMS"
|
223 |
__slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge"] |
224 |
|
225 |
|
226 |
# OS opcodes
|
227 |
class OpDiagnoseOS(OpCode): |
228 |
"""Compute the list of guest operating systems."""
|
229 |
OP_ID = "OP_OS_DIAGNOSE"
|
230 |
__slots__ = [] |
231 |
|
232 |
# Exports opcodes
|
233 |
class OpQueryExports(OpCode): |
234 |
"""Compute the list of exported images."""
|
235 |
OP_ID = "OP_BACKUP_QUERY"
|
236 |
__slots__ = ["nodes"]
|
237 |
|
238 |
class OpExportInstance(OpCode): |
239 |
"""Export an instance."""
|
240 |
OP_ID = "OP_BACKUP_EXPORT"
|
241 |
__slots__ = ["instance_name", "target_node", "shutdown"] |