Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 1862d460

History | View | Annotate | Download (7.7 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
    - list of instances with degraded disks (that should be activated)
97

98
  In normal operation, both lists should be empty. A non-empty
99
  instance list is still ok (errors were fixed) but non-empty node
100
  list means some node is down, and probably there are unfixable drbd
101
  errors.
102

103
  Note that only instances that are drbd-based are taken into
104
  consideration. This might need to be revisited in the future.
105

106
  """
107
  OP_ID = "OP_CLUSTER_VERIFY_DISKS"
108
  __slots__ = []
109

    
110

    
111
class OpMasterFailover(OpCode):
112
  """Do a master failover."""
113
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
114
  __slots__ = []
115

    
116

    
117
class OpDumpClusterConfig(OpCode):
118
  """Dump the cluster configuration."""
119
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
120
  __slots__ = []
121

    
122

    
123
class OpRenameCluster(OpCode):
124
  """Rename the cluster."""
125
  OP_ID = "OP_CLUSTER_RENAME"
126
  __slots__ = ["name"]
127

    
128

    
129
# node opcodes
130

    
131
class OpRemoveNode(OpCode):
132
  """Remove a node."""
133
  OP_ID = "OP_NODE_REMOVE"
134
  __slots__ = ["node_name"]
135

    
136

    
137
class OpAddNode(OpCode):
138
  """Add a node."""
139
  OP_ID = "OP_NODE_ADD"
140
  __slots__ = ["node_name", "primary_ip", "secondary_ip"]
141

    
142

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

    
148

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

    
154

    
155
# instance opcodes
156

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

    
165

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

    
171

    
172
class OpRemoveInstance(OpCode):
173
  """Remove an instance."""
174
  OP_ID = "OP_INSTANCE_REMOVE"
175
  __slots__ = ["instance_name", "ignore_failures"]
176

    
177

    
178
class OpRenameInstance(OpCode):
179
  """Rename an instance."""
180
  OP_ID = "OP_INSTANCE_RENAME"
181
  __slots__ = ["instance_name", "ignore_ip", "new_name"]
182

    
183

    
184
class OpStartupInstance(OpCode):
185
  """Startup an instance."""
186
  OP_ID = "OP_INSTANCE_STARTUP"
187
  __slots__ = ["instance_name", "force", "extra_args"]
188

    
189

    
190
class OpShutdownInstance(OpCode):
191
  """Shutdown an instance."""
192
  OP_ID = "OP_INSTANCE_SHUTDOWN"
193
  __slots__ = ["instance_name"]
194

    
195

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

    
202

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

    
208

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

    
214

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

    
220

    
221
class OpFailoverInstance(OpCode):
222
  """Failover an instance."""
223
  OP_ID = "OP_INSTANCE_FAILOVER"
224
  __slots__ = ["instance_name", "ignore_consistency"]
225

    
226

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

    
232

    
233
class OpActivateInstanceDisks(OpCode):
234
  """Activate an instance's disks."""
235
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
236
  __slots__ = ["instance_name"]
237

    
238

    
239
class OpDeactivateInstanceDisks(OpCode):
240
  """Deactivate an instance's disks."""
241
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
242
  __slots__ = ["instance_name"]
243

    
244

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

    
250

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

    
256

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

    
262

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

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

    
275
class OpExportInstance(OpCode):
276
  """Export an instance."""
277
  OP_ID = "OP_BACKUP_EXPORT"
278
  __slots__ = ["instance_name", "target_node", "shutdown"]
279

    
280

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

    
287

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

    
293

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

    
299

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