root / lib / opcodes.py @ a8083063
History | View | Annotate | Download (5.8 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"] |
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 |
# instance opcodes
|
126 |
|
127 |
class OpCreateInstance(OpCode): |
128 |
"""Compute the list of instances."""
|
129 |
OP_ID = "OP_INSTANCE_CREATE"
|
130 |
__slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode", |
131 |
"disk_template", "snode", "swap_size", "mode", |
132 |
"vcpus", "ip", "bridge", "src_node", "src_path", "start", |
133 |
"wait_for_sync"]
|
134 |
|
135 |
|
136 |
class OpRemoveInstance(OpCode): |
137 |
"""Remove an instance."""
|
138 |
OP_ID = "OP_INSTANCE_REMOVE"
|
139 |
__slots__ = ["instance_name"]
|
140 |
|
141 |
|
142 |
class OpStartupInstance(OpCode): |
143 |
"""Remove an instance."""
|
144 |
OP_ID = "OP_INSTANCE_STARTUP"
|
145 |
__slots__ = ["instance_name", "force", "extra_args"] |
146 |
|
147 |
|
148 |
class OpShutdownInstance(OpCode): |
149 |
"""Remove an instance."""
|
150 |
OP_ID = "OP_INSTANCE_SHUTDOWN"
|
151 |
__slots__ = ["instance_name"]
|
152 |
|
153 |
|
154 |
class OpAddMDDRBDComponent(OpCode): |
155 |
"""Add a MD-DRBD component."""
|
156 |
OP_ID = "OP_INSTANCE_ADD_MDDRBD"
|
157 |
__slots__ = ["instance_name", "remote_node", "disk_name"] |
158 |
|
159 |
|
160 |
class OpRemoveMDDRBDComponent(OpCode): |
161 |
"""Remove a MD-DRBD component."""
|
162 |
OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
|
163 |
__slots__ = ["instance_name", "disk_name", "disk_id"] |
164 |
|
165 |
|
166 |
class OpReplaceDisks(OpCode): |
167 |
"""Replace disks of an instance."""
|
168 |
OP_ID = "OP_INSTANCE_REPLACE_DISKS"
|
169 |
__slots__ = ["instance_name", "remote_node"] |
170 |
|
171 |
|
172 |
class OpFailoverInstance(OpCode): |
173 |
"""Failover an instance."""
|
174 |
OP_ID = "OP_INSTANCE_FAILOVER"
|
175 |
__slots__ = ["instance_name", "ignore_consistency"] |
176 |
|
177 |
|
178 |
class OpConnectConsole(OpCode): |
179 |
"""Failover an instance."""
|
180 |
OP_ID = "OP_INSTANCE_CONSOLE"
|
181 |
__slots__ = ["instance_name"]
|
182 |
|
183 |
|
184 |
class OpActivateInstanceDisks(OpCode): |
185 |
"""Remove an instance."""
|
186 |
OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
|
187 |
__slots__ = ["instance_name"]
|
188 |
|
189 |
|
190 |
class OpDeactivateInstanceDisks(OpCode): |
191 |
"""Remove an instance."""
|
192 |
OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
|
193 |
__slots__ = ["instance_name"]
|
194 |
|
195 |
|
196 |
class OpQueryInstances(OpCode): |
197 |
"""Compute the list of instances."""
|
198 |
OP_ID = "OP_INSTANCE_QUERY"
|
199 |
__slots__ = ["output_fields"]
|
200 |
|
201 |
|
202 |
class OpQueryInstanceData(OpCode): |
203 |
"""Compute the run-time status of instances."""
|
204 |
OP_ID = "OP_INSTANCE_QUERY_DATA"
|
205 |
__slots__ = ["instances"]
|
206 |
|
207 |
|
208 |
class OpSetInstanceParms(OpCode): |
209 |
"""Change the parameters of an instance."""
|
210 |
OP_ID = "OP_INSTANCE_SET_PARMS"
|
211 |
__slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge"] |
212 |
|
213 |
|
214 |
# OS opcodes
|
215 |
class OpDiagnoseOS(OpCode): |
216 |
"""Compute the list of guest operating systems."""
|
217 |
OP_ID = "OP_OS_DIAGNOSE"
|
218 |
__slots__ = [] |
219 |
|
220 |
# Exports opcodes
|
221 |
class OpQueryExports(OpCode): |
222 |
"""Compute the list of exported images."""
|
223 |
OP_ID = "OP_BACKUP_QUERY"
|
224 |
__slots__ = ["nodes"]
|
225 |
|
226 |
class OpExportInstance(OpCode): |
227 |
"""Export an instance."""
|
228 |
OP_ID = "OP_BACKUP_EXPORT"
|
229 |
__slots__ = ["instance_name", "target_node", "shutdown"] |