Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 07bd8a51

History | View | Annotate | Download (6.7 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
  """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 OpMasterFailover(OpCode):
90
  """Do a master failover."""
91
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
92
  __slots__ = []
93

    
94

    
95
class OpDumpClusterConfig(OpCode):
96
  """Dump the cluster configuration."""
97
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
98
  __slots__ = []
99

    
100

    
101
class OpRenameCluster(OpCode):
102
  """Rename the cluster."""
103
  OP_ID = "OP_CLUSTER_RENAME"
104
  __slots__ = ["name"]
105

    
106

    
107
# node opcodes
108

    
109
class OpRemoveNode(OpCode):
110
  """Remove a node."""
111
  OP_ID = "OP_NODE_REMOVE"
112
  __slots__ = ["node_name"]
113

    
114

    
115
class OpAddNode(OpCode):
116
  """Add a node."""
117
  OP_ID = "OP_NODE_ADD"
118
  __slots__ = ["node_name", "primary_ip", "secondary_ip"]
119

    
120

    
121
class OpQueryNodes(OpCode):
122
  """Compute the list of nodes."""
123
  OP_ID = "OP_NODE_QUERY"
124
  __slots__ = ["output_fields", "names"]
125

    
126

    
127
class OpQueryNodeVolumes(OpCode):
128
  """Get list of volumes on node."""
129
  OP_ID = "OP_NODE_QUERYVOLS"
130
  __slots__ = ["nodes", "output_fields"]
131

    
132

    
133
# instance opcodes
134

    
135
class OpCreateInstance(OpCode):
136
  """Create an instance."""
137
  OP_ID = "OP_INSTANCE_CREATE"
138
  __slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode",
139
               "disk_template", "snode", "swap_size", "mode",
140
               "vcpus", "ip", "bridge", "src_node", "src_path", "start",
141
               "wait_for_sync"]
142

    
143

    
144
class OpReinstallInstance(OpCode):
145
  """Reinstall an instance's OS."""
146
  OP_ID = "OP_INSTANCE_REINSTALL"
147
  __slots__ = ["instance_name", "os_type"]
148

    
149

    
150
class OpRemoveInstance(OpCode):
151
  """Remove an instance."""
152
  OP_ID = "OP_INSTANCE_REMOVE"
153
  __slots__ = ["instance_name"]
154

    
155

    
156
class OpRenameInstance(OpCode):
157
  """Rename an instance."""
158
  OP_ID = "OP_INSTANCE_RENAME"
159
  __slots__ = ["instance_name", "ignore_ip", "new_name"]
160

    
161

    
162
class OpStartupInstance(OpCode):
163
  """Startup an instance."""
164
  OP_ID = "OP_INSTANCE_STARTUP"
165
  __slots__ = ["instance_name", "force", "extra_args"]
166

    
167

    
168
class OpShutdownInstance(OpCode):
169
  """Shutdown an instance."""
170
  OP_ID = "OP_INSTANCE_SHUTDOWN"
171
  __slots__ = ["instance_name"]
172

    
173

    
174
class OpAddMDDRBDComponent(OpCode):
175
  """Add a MD-DRBD component."""
176
  OP_ID = "OP_INSTANCE_ADD_MDDRBD"
177
  __slots__ = ["instance_name", "remote_node", "disk_name"]
178

    
179

    
180
class OpRemoveMDDRBDComponent(OpCode):
181
  """Remove a MD-DRBD component."""
182
  OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
183
  __slots__ = ["instance_name", "disk_name", "disk_id"]
184

    
185

    
186
class OpReplaceDisks(OpCode):
187
  """Replace the disks of an instance."""
188
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
189
  __slots__ = ["instance_name", "remote_node"]
190

    
191

    
192
class OpFailoverInstance(OpCode):
193
  """Failover an instance."""
194
  OP_ID = "OP_INSTANCE_FAILOVER"
195
  __slots__ = ["instance_name", "ignore_consistency"]
196

    
197

    
198
class OpConnectConsole(OpCode):
199
  """Connect to an instance's console."""
200
  OP_ID = "OP_INSTANCE_CONSOLE"
201
  __slots__ = ["instance_name"]
202

    
203

    
204
class OpActivateInstanceDisks(OpCode):
205
  """Activate an instance's disks."""
206
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
207
  __slots__ = ["instance_name"]
208

    
209

    
210
class OpDeactivateInstanceDisks(OpCode):
211
  """Deactivate an instance's disks."""
212
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
213
  __slots__ = ["instance_name"]
214

    
215

    
216
class OpQueryInstances(OpCode):
217
  """Compute the list of instances."""
218
  OP_ID = "OP_INSTANCE_QUERY"
219
  __slots__ = ["output_fields", "names"]
220

    
221

    
222
class OpQueryInstanceData(OpCode):
223
  """Compute the run-time status of instances."""
224
  OP_ID = "OP_INSTANCE_QUERY_DATA"
225
  __slots__ = ["instances"]
226

    
227

    
228
class OpSetInstanceParms(OpCode):
229
  """Change the parameters of an instance."""
230
  OP_ID = "OP_INSTANCE_SET_PARMS"
231
  __slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge"]
232

    
233

    
234
# OS opcodes
235
class OpDiagnoseOS(OpCode):
236
  """Compute the list of guest operating systems."""
237
  OP_ID = "OP_OS_DIAGNOSE"
238
  __slots__ = []
239

    
240
# Exports opcodes
241
class OpQueryExports(OpCode):
242
  """Compute the list of exported images."""
243
  OP_ID = "OP_BACKUP_QUERY"
244
  __slots__ = ["nodes"]
245

    
246
class OpExportInstance(OpCode):
247
  """Export an instance."""
248
  OP_ID = "OP_BACKUP_EXPORT"
249
  __slots__ = ["instance_name", "target_node", "shutdown"]
250

    
251

    
252
# Tags opcodes
253
class OpGetTags(OpCode):
254
  """Returns the tags of the given object."""
255
  OP_ID = "OP_TAGS_GET"
256
  __slots__ = ["kind", "name"]
257

    
258

    
259
class OpSetTag(OpCode):
260
  """Sets the value of a tag on a given object."""
261
  OP_ID = "OP_TAGS_SET"
262
  __slots__ = ["kind", "name", "tag"]
263

    
264

    
265
class OpDelTag(OpCode):
266
  """Remove a tag from a given object."""
267
  OP_ID = "OP_TAGS_DEL"
268
  __slots__ = ["kind", "name", "tag"]