Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ b63ed789

History | View | Annotate | Download (7.9 kB)

1
#
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
  """Query cluster information."""
67
  OP_ID = "OP_CLUSTER_QUERY"
68
  __slots__ = []
69

    
70

    
71
class OpClusterCopyFile(OpCode):
72
  """Copy a file to multiple nodes."""
73
  OP_ID = "OP_CLUSTER_COPYFILE"
74
  __slots__ = ["nodes", "filename"]
75

    
76

    
77
class OpRunClusterCommand(OpCode):
78
  """Run a command on multiple nodes."""
79
  OP_ID = "OP_CLUSTER_RUNCOMMAND"
80
  __slots__ = ["nodes", "command"]
81

    
82

    
83
class OpVerifyCluster(OpCode):
84
  """Verify the cluster state."""
85
  OP_ID = "OP_CLUSTER_VERIFY"
86
  __slots__ = []
87

    
88

    
89
class OpVerifyDisks(OpCode):
90
  """Verify the cluster disks.
91

92
  Parameters: none
93

94
  Result: two lists:
95
    - list of node names with bad data returned (unreachable, etc.)
96
    - dist of node names with broken volume groups (values: error msg)
97
    - list of instances with degraded disks (that should be activated)
98
    - dict of instances with missing logical volumes (values: (node, vol)
99
      pairs with details about the missing volumes)
100

101
  In normal operation, all lists should be empty. A non-empty instance
102
  list (3rd element of the result) is still ok (errors were fixed) but
103
  non-empty node list means some node is down, and probably there are
104
  unfixable drbd errors.
105

106
  Note that only instances that are drbd-based are taken into
107
  consideration. This might need to be revisited in the future.
108

109
  """
110
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
111
  __slots__ = []
112

    
113

    
114
class OpMasterFailover(OpCode):
115
  """Do a master failover."""
116
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
117
  __slots__ = []
118

    
119

    
120
class OpDumpClusterConfig(OpCode):
121
  """Dump the cluster configuration."""
122
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
123
  __slots__ = []
124

    
125

    
126
class OpRenameCluster(OpCode):
127
  """Rename the cluster."""
128
  OP_ID = "OP_CLUSTER_RENAME"
129
  __slots__ = ["name"]
130

    
131

    
132
# node opcodes
133

    
134
class OpRemoveNode(OpCode):
135
  """Remove a node."""
136
  OP_ID = "OP_NODE_REMOVE"
137
  __slots__ = ["node_name"]
138

    
139

    
140
class OpAddNode(OpCode):
141
  """Add a node."""
142
  OP_ID = "OP_NODE_ADD"
143
  __slots__ = ["node_name", "primary_ip", "secondary_ip"]
144

    
145

    
146
class OpQueryNodes(OpCode):
147
  """Compute the list of nodes."""
148
  OP_ID = "OP_NODE_QUERY"
149
  __slots__ = ["output_fields", "names"]
150

    
151

    
152
class OpQueryNodeVolumes(OpCode):
153
  """Get list of volumes on node."""
154
  OP_ID = "OP_NODE_QUERYVOLS"
155
  __slots__ = ["nodes", "output_fields"]
156

    
157

    
158
# instance opcodes
159

    
160
class OpCreateInstance(OpCode):
161
  """Create an instance."""
162
  OP_ID = "OP_INSTANCE_CREATE"
163
  __slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode",
164
               "disk_template", "snode", "swap_size", "mode",
165
               "vcpus", "ip", "bridge", "src_node", "src_path", "start",
166
               "wait_for_sync", "ip_check", "mac"]
167

    
168

    
169
class OpReinstallInstance(OpCode):
170
  """Reinstall an instance's OS."""
171
  OP_ID = "OP_INSTANCE_REINSTALL"
172
  __slots__ = ["instance_name", "os_type"]
173

    
174

    
175
class OpRemoveInstance(OpCode):
176
  """Remove an instance."""
177
  OP_ID = "OP_INSTANCE_REMOVE"
178
  __slots__ = ["instance_name", "ignore_failures"]
179

    
180

    
181
class OpRenameInstance(OpCode):
182
  """Rename an instance."""
183
  OP_ID = "OP_INSTANCE_RENAME"
184
  __slots__ = ["instance_name", "ignore_ip", "new_name"]
185

    
186

    
187
class OpStartupInstance(OpCode):
188
  """Startup an instance."""
189
  OP_ID = "OP_INSTANCE_STARTUP"
190
  __slots__ = ["instance_name", "force", "extra_args"]
191

    
192

    
193
class OpShutdownInstance(OpCode):
194
  """Shutdown an instance."""
195
  OP_ID = "OP_INSTANCE_SHUTDOWN"
196
  __slots__ = ["instance_name"]
197

    
198

    
199
class OpRebootInstance(OpCode):
200
  """Reboot an instance."""
201
  OP_ID = "OP_INSTANCE_STARTUP"
202
  __slots__ = ["instance_name", "reboot_type", "extra_args",
203
               "ignore_secondaries" ]
204

    
205

    
206
class OpAddMDDRBDComponent(OpCode):
207
  """Add a MD-DRBD component."""
208
  OP_ID = "OP_INSTANCE_ADD_MDDRBD"
209
  __slots__ = ["instance_name", "remote_node", "disk_name"]
210

    
211

    
212
class OpRemoveMDDRBDComponent(OpCode):
213
  """Remove a MD-DRBD component."""
214
  OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
215
  __slots__ = ["instance_name", "disk_name", "disk_id"]
216

    
217

    
218
class OpReplaceDisks(OpCode):
219
  """Replace the disks of an instance."""
220
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
221
  __slots__ = ["instance_name", "remote_node", "mode", "disks"]
222

    
223

    
224
class OpFailoverInstance(OpCode):
225
  """Failover an instance."""
226
  OP_ID = "OP_INSTANCE_FAILOVER"
227
  __slots__ = ["instance_name", "ignore_consistency"]
228

    
229

    
230
class OpConnectConsole(OpCode):
231
  """Connect to an instance's console."""
232
  OP_ID = "OP_INSTANCE_CONSOLE"
233
  __slots__ = ["instance_name"]
234

    
235

    
236
class OpActivateInstanceDisks(OpCode):
237
  """Activate an instance's disks."""
238
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
239
  __slots__ = ["instance_name"]
240

    
241

    
242
class OpDeactivateInstanceDisks(OpCode):
243
  """Deactivate an instance's disks."""
244
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
245
  __slots__ = ["instance_name"]
246

    
247

    
248
class OpQueryInstances(OpCode):
249
  """Compute the list of instances."""
250
  OP_ID = "OP_INSTANCE_QUERY"
251
  __slots__ = ["output_fields", "names"]
252

    
253

    
254
class OpQueryInstanceData(OpCode):
255
  """Compute the run-time status of instances."""
256
  OP_ID = "OP_INSTANCE_QUERY_DATA"
257
  __slots__ = ["instances"]
258

    
259

    
260
class OpSetInstanceParms(OpCode):
261
  """Change the parameters of an instance."""
262
  OP_ID = "OP_INSTANCE_SET_PARMS"
263
  __slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge", "mac"]
264

    
265

    
266
# OS opcodes
267
class OpDiagnoseOS(OpCode):
268
  """Compute the list of guest operating systems."""
269
  OP_ID = "OP_OS_DIAGNOSE"
270
  __slots__ = []
271

    
272
# Exports opcodes
273
class OpQueryExports(OpCode):
274
  """Compute the list of exported images."""
275
  OP_ID = "OP_BACKUP_QUERY"
276
  __slots__ = ["nodes"]
277

    
278
class OpExportInstance(OpCode):
279
  """Export an instance."""
280
  OP_ID = "OP_BACKUP_EXPORT"
281
  __slots__ = ["instance_name", "target_node", "shutdown"]
282

    
283

    
284
# Tags opcodes
285
class OpGetTags(OpCode):
286
  """Returns the tags of the given object."""
287
  OP_ID = "OP_TAGS_GET"
288
  __slots__ = ["kind", "name"]
289

    
290

    
291
class OpSearchTags(OpCode):
292
  """Searches the tags in the cluster for a given pattern."""
293
  OP_ID = "OP_TAGS_SEARCH"
294
  __slots__ = ["pattern"]
295

    
296

    
297
class OpAddTags(OpCode):
298
  """Add a list of tags on a given object."""
299
  OP_ID = "OP_TAGS_SET"
300
  __slots__ = ["kind", "name", "tags"]
301

    
302

    
303
class OpDelTags(OpCode):
304
  """Remove a list of tags from a given object."""
305
  OP_ID = "OP_TAGS_DEL"
306
  __slots__ = ["kind", "name", "tags"]