4 # Copyright (C) 2006, 2007 Google Inc.
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.
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.
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
24 This module implements the data structures which define the cluster
25 operations - the so-called opcodes.
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
35 # this are practically structures, so disable the message about too
37 # pylint: disable-msg=R0903
44 def __init__(self, **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])
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"]
59 class OpDestroyCluster(OpCode):
60 """Destroy the cluster."""
61 OP_ID = "OP_CLUSTER_DESTROY"
65 class OpQueryClusterInfo(OpCode):
66 """Query cluster information."""
67 OP_ID = "OP_CLUSTER_QUERY"
71 class OpClusterCopyFile(OpCode):
72 """Copy a file to multiple nodes."""
73 OP_ID = "OP_CLUSTER_COPYFILE"
74 __slots__ = ["nodes", "filename"]
77 class OpRunClusterCommand(OpCode):
78 """Run a command on multiple nodes."""
79 OP_ID = "OP_CLUSTER_RUNCOMMAND"
80 __slots__ = ["nodes", "command"]
83 class OpVerifyCluster(OpCode):
84 """Verify the cluster state."""
85 OP_ID = "OP_CLUSTER_VERIFY"
89 class OpMasterFailover(OpCode):
90 """Do a master failover."""
91 OP_ID = "OP_CLUSTER_MASTERFAILOVER"
95 class OpDumpClusterConfig(OpCode):
96 """Dump the cluster configuration."""
97 OP_ID = "OP_CLUSTER_DUMPCONFIG"
101 class OpRemoveNode(OpCode):
103 OP_ID = "OP_NODE_REMOVE"
104 __slots__ = ["node_name"]
107 class OpAddNode(OpCode):
109 OP_ID = "OP_NODE_ADD"
110 __slots__ = ["node_name", "primary_ip", "secondary_ip"]
113 class OpQueryNodes(OpCode):
114 """Compute the list of nodes."""
115 OP_ID = "OP_NODE_QUERY"
116 __slots__ = ["output_fields", "nodes"]
119 class OpQueryNodeVolumes(OpCode):
120 """Get list of volumes on node."""
121 OP_ID = "OP_NODE_QUERYVOLS"
122 __slots__ = ["nodes", "output_fields"]
127 class OpCreateInstance(OpCode):
128 """Create an instance."""
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",
136 class OpReinstallInstance(OpCode):
137 """Reinstall an instance's OS."""
138 OP_ID = "OP_INSTANCE_REINSTALL"
139 __slots__ = ["instance_name", "os_type"]
142 class OpRemoveInstance(OpCode):
143 """Remove an instance."""
144 OP_ID = "OP_INSTANCE_REMOVE"
145 __slots__ = ["instance_name"]
148 class OpStartupInstance(OpCode):
149 """Startup an instance."""
150 OP_ID = "OP_INSTANCE_STARTUP"
151 __slots__ = ["instance_name", "force", "extra_args"]
154 class OpShutdownInstance(OpCode):
155 """Shutdown an instance."""
156 OP_ID = "OP_INSTANCE_SHUTDOWN"
157 __slots__ = ["instance_name"]
160 class OpAddMDDRBDComponent(OpCode):
161 """Add a MD-DRBD component."""
162 OP_ID = "OP_INSTANCE_ADD_MDDRBD"
163 __slots__ = ["instance_name", "remote_node", "disk_name"]
166 class OpRemoveMDDRBDComponent(OpCode):
167 """Remove a MD-DRBD component."""
168 OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
169 __slots__ = ["instance_name", "disk_name", "disk_id"]
172 class OpReplaceDisks(OpCode):
173 """Replace the disks of an instance."""
174 OP_ID = "OP_INSTANCE_REPLACE_DISKS"
175 __slots__ = ["instance_name", "remote_node"]
178 class OpFailoverInstance(OpCode):
179 """Failover an instance."""
180 OP_ID = "OP_INSTANCE_FAILOVER"
181 __slots__ = ["instance_name", "ignore_consistency"]
184 class OpConnectConsole(OpCode):
185 """Connect to an instance's console."""
186 OP_ID = "OP_INSTANCE_CONSOLE"
187 __slots__ = ["instance_name"]
190 class OpActivateInstanceDisks(OpCode):
191 """Activate an instance's disks."""
192 OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
193 __slots__ = ["instance_name"]
196 class OpDeactivateInstanceDisks(OpCode):
197 """Deactivate an instance's disks."""
198 OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
199 __slots__ = ["instance_name"]
202 class OpQueryInstances(OpCode):
203 """Compute the list of instances."""
204 OP_ID = "OP_INSTANCE_QUERY"
205 __slots__ = ["output_fields"]
208 class OpQueryInstanceData(OpCode):
209 """Compute the run-time status of instances."""
210 OP_ID = "OP_INSTANCE_QUERY_DATA"
211 __slots__ = ["instances"]
214 class OpSetInstanceParms(OpCode):
215 """Change the parameters of an instance."""
216 OP_ID = "OP_INSTANCE_SET_PARMS"
217 __slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge"]
221 class OpDiagnoseOS(OpCode):
222 """Compute the list of guest operating systems."""
223 OP_ID = "OP_OS_DIAGNOSE"
227 class OpQueryExports(OpCode):
228 """Compute the list of exported images."""
229 OP_ID = "OP_BACKUP_QUERY"
230 __slots__ = ["nodes"]
232 class OpExportInstance(OpCode):
233 """Export an instance."""
234 OP_ID = "OP_BACKUP_EXPORT"
235 __slots__ = ["instance_name", "target_node", "shutdown"]
239 class OpGetTags(OpCode):
240 """Returns the tags of the given object."""
241 OP_ID = "OP_TAGS_GET"
242 __slots__ = ["kind", "name"]
245 class OpSetTag(OpCode):
246 """Sets the value of a tag on a given object."""
247 OP_ID = "OP_TAGS_SET"
248 __slots__ = ["kind", "name", "tag"]
251 class OpDelTag(OpCode):
252 """Remove a tag from a given object."""
253 OP_ID = "OP_TAGS_DEL"
254 __slots__ = ["kind", "name", "tag"]