Statistics
| Branch: | Tag: | Revision:

root / lib / opcodes.py @ 5c947f38

History | View | Annotate | Download (6.5 kB)

1 a8083063 Iustin Pop
#!/usr/bin/python
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 a8083063 Iustin Pop
# Copyright (C) 2006, 2007 Google Inc.
5 a8083063 Iustin Pop
#
6 a8083063 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 a8083063 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 a8083063 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 a8083063 Iustin Pop
# (at your option) any later version.
10 a8083063 Iustin Pop
#
11 a8083063 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 a8083063 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 a8083063 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 a8083063 Iustin Pop
# General Public License for more details.
15 a8083063 Iustin Pop
#
16 a8083063 Iustin Pop
# You should have received a copy of the GNU General Public License
17 a8083063 Iustin Pop
# along with this program; if not, write to the Free Software
18 a8083063 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 a8083063 Iustin Pop
# 02110-1301, USA.
20 a8083063 Iustin Pop
21 a8083063 Iustin Pop
22 a8083063 Iustin Pop
"""OpCodes module
23 a8083063 Iustin Pop

24 a8083063 Iustin Pop
This module implements the data structures which define the cluster
25 a8083063 Iustin Pop
operations - the so-called opcodes.
26 a8083063 Iustin Pop

27 a8083063 Iustin Pop

28 a8083063 Iustin Pop
This module implements the logic for doing operations in the cluster. There
29 a8083063 Iustin Pop
are two kinds of classes defined:
30 a8083063 Iustin Pop
  - opcodes, which are small classes only holding data for the task at hand
31 a8083063 Iustin Pop
  - logical units, which know how to deal with their specific opcode only
32 a8083063 Iustin Pop

33 a8083063 Iustin Pop
"""
34 a8083063 Iustin Pop
35 a8083063 Iustin Pop
# this are practically structures, so disable the message about too
36 a8083063 Iustin Pop
# few public methods:
37 a8083063 Iustin Pop
# pylint: disable-msg=R0903
38 a8083063 Iustin Pop
39 a8083063 Iustin Pop
class OpCode(object):
40 a8083063 Iustin Pop
  """Abstract OpCode"""
41 a8083063 Iustin Pop
  OP_ID = "OP_ABSTRACT"
42 a8083063 Iustin Pop
  __slots__ = []
43 a8083063 Iustin Pop
44 a8083063 Iustin Pop
  def __init__(self, **kwargs):
45 a8083063 Iustin Pop
    for key in kwargs:
46 a8083063 Iustin Pop
      if key not in self.__slots__:
47 a8083063 Iustin Pop
        raise TypeError, ("OpCode %s doesn't support the parameter '%s'" %
48 a8083063 Iustin Pop
                          (self.__class__.__name__, key))
49 a8083063 Iustin Pop
      setattr(self, key, kwargs[key])
50 a8083063 Iustin Pop
51 a8083063 Iustin Pop
52 a8083063 Iustin Pop
class OpInitCluster(OpCode):
53 a8083063 Iustin Pop
  """Initialise the cluster."""
54 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_INIT"
55 a8083063 Iustin Pop
  __slots__ = ["cluster_name", "secondary_ip", "hypervisor_type",
56 880478f8 Iustin Pop
               "vg_name", "mac_prefix", "def_bridge", "master_netdev"]
57 a8083063 Iustin Pop
58 a8083063 Iustin Pop
59 a8083063 Iustin Pop
class OpDestroyCluster(OpCode):
60 a8083063 Iustin Pop
  """Destroy the cluster."""
61 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DESTROY"
62 a8083063 Iustin Pop
  __slots__ = []
63 a8083063 Iustin Pop
64 a8083063 Iustin Pop
65 a8083063 Iustin Pop
class OpQueryClusterInfo(OpCode):
66 a8083063 Iustin Pop
  """Initialise the cluster."""
67 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_QUERY"
68 a8083063 Iustin Pop
  __slots__ = []
69 a8083063 Iustin Pop
70 a8083063 Iustin Pop
71 a8083063 Iustin Pop
class OpClusterCopyFile(OpCode):
72 a8083063 Iustin Pop
  """Initialise the cluster."""
73 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_COPYFILE"
74 a8083063 Iustin Pop
  __slots__ = ["nodes", "filename"]
75 a8083063 Iustin Pop
76 a8083063 Iustin Pop
77 a8083063 Iustin Pop
class OpRunClusterCommand(OpCode):
78 a8083063 Iustin Pop
  """Initialise the cluster."""
79 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_RUNCOMMAND"
80 a8083063 Iustin Pop
  __slots__ = ["nodes", "command"]
81 a8083063 Iustin Pop
82 a8083063 Iustin Pop
83 a8083063 Iustin Pop
class OpVerifyCluster(OpCode):
84 a8083063 Iustin Pop
  """Initialise the cluster."""
85 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_VERIFY"
86 a8083063 Iustin Pop
  __slots__ = []
87 a8083063 Iustin Pop
88 a8083063 Iustin Pop
89 a8083063 Iustin Pop
class OpMasterFailover(OpCode):
90 a8083063 Iustin Pop
  """Initialise the cluster."""
91 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_MASTERFAILOVER"
92 a8083063 Iustin Pop
  __slots__ = []
93 a8083063 Iustin Pop
94 a8083063 Iustin Pop
95 a8083063 Iustin Pop
class OpDumpClusterConfig(OpCode):
96 a8083063 Iustin Pop
  """Initialise the cluster."""
97 a8083063 Iustin Pop
  OP_ID = "OP_CLUSTER_DUMPCONFIG"
98 a8083063 Iustin Pop
  __slots__ = []
99 a8083063 Iustin Pop
100 a8083063 Iustin Pop
101 a8083063 Iustin Pop
class OpRemoveNode(OpCode):
102 a8083063 Iustin Pop
  """Remove a node."""
103 a8083063 Iustin Pop
  OP_ID = "OP_NODE_REMOVE"
104 a8083063 Iustin Pop
  __slots__ = ["node_name"]
105 a8083063 Iustin Pop
106 a8083063 Iustin Pop
107 a8083063 Iustin Pop
class OpAddNode(OpCode):
108 a8083063 Iustin Pop
  """Add a node."""
109 a8083063 Iustin Pop
  OP_ID = "OP_NODE_ADD"
110 a8083063 Iustin Pop
  __slots__ = ["node_name", "primary_ip", "secondary_ip"]
111 a8083063 Iustin Pop
112 a8083063 Iustin Pop
113 a8083063 Iustin Pop
class OpQueryNodes(OpCode):
114 a8083063 Iustin Pop
  """Compute the list of nodes."""
115 a8083063 Iustin Pop
  OP_ID = "OP_NODE_QUERY"
116 a8083063 Iustin Pop
  __slots__ = ["output_fields"]
117 a8083063 Iustin Pop
118 a8083063 Iustin Pop
119 a8083063 Iustin Pop
class OpQueryNodeData(OpCode):
120 a8083063 Iustin Pop
  """Compute the node info."""
121 a8083063 Iustin Pop
  OP_ID = "OP_NODE_INFO"
122 a8083063 Iustin Pop
  __slots__ = ["nodes"]
123 a8083063 Iustin Pop
124 a8083063 Iustin Pop
125 dcb93971 Michael Hanselmann
class OpQueryNodeVolumes(OpCode):
126 dcb93971 Michael Hanselmann
  """Get list of volumes on node."""
127 dcb93971 Michael Hanselmann
  OP_ID = "OP_NODE_QUERYVOLS"
128 dcb93971 Michael Hanselmann
  __slots__ = ["nodes", "output_fields"]
129 dcb93971 Michael Hanselmann
130 dcb93971 Michael Hanselmann
131 a8083063 Iustin Pop
# instance opcodes
132 a8083063 Iustin Pop
133 a8083063 Iustin Pop
class OpCreateInstance(OpCode):
134 a8083063 Iustin Pop
  """Compute the list of instances."""
135 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CREATE"
136 a8083063 Iustin Pop
  __slots__ = ["instance_name", "mem_size", "disk_size", "os_type", "pnode",
137 a8083063 Iustin Pop
               "disk_template", "snode", "swap_size", "mode",
138 a8083063 Iustin Pop
               "vcpus", "ip", "bridge", "src_node", "src_path", "start",
139 a8083063 Iustin Pop
               "wait_for_sync"]
140 a8083063 Iustin Pop
141 a8083063 Iustin Pop
142 fe7b0351 Michael Hanselmann
class OpReinstallInstance(OpCode):
143 fe7b0351 Michael Hanselmann
  """Reinstall an instance."""
144 fe7b0351 Michael Hanselmann
  OP_ID = "OP_INSTANCE_REINSTALL"
145 d0834de3 Michael Hanselmann
  __slots__ = ["instance_name", "os_type"]
146 fe7b0351 Michael Hanselmann
147 fe7b0351 Michael Hanselmann
148 a8083063 Iustin Pop
class OpRemoveInstance(OpCode):
149 a8083063 Iustin Pop
  """Remove an instance."""
150 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE"
151 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
152 a8083063 Iustin Pop
153 a8083063 Iustin Pop
154 a8083063 Iustin Pop
class OpStartupInstance(OpCode):
155 a8083063 Iustin Pop
  """Remove an instance."""
156 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_STARTUP"
157 a8083063 Iustin Pop
  __slots__ = ["instance_name", "force", "extra_args"]
158 a8083063 Iustin Pop
159 a8083063 Iustin Pop
160 a8083063 Iustin Pop
class OpShutdownInstance(OpCode):
161 a8083063 Iustin Pop
  """Remove an instance."""
162 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SHUTDOWN"
163 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
164 a8083063 Iustin Pop
165 a8083063 Iustin Pop
166 a8083063 Iustin Pop
class OpAddMDDRBDComponent(OpCode):
167 a8083063 Iustin Pop
  """Add a MD-DRBD component."""
168 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ADD_MDDRBD"
169 a8083063 Iustin Pop
  __slots__ = ["instance_name", "remote_node", "disk_name"]
170 a8083063 Iustin Pop
171 a8083063 Iustin Pop
172 a8083063 Iustin Pop
class OpRemoveMDDRBDComponent(OpCode):
173 a8083063 Iustin Pop
  """Remove a MD-DRBD component."""
174 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REMOVE_MDDRBD"
175 a8083063 Iustin Pop
  __slots__ = ["instance_name", "disk_name", "disk_id"]
176 a8083063 Iustin Pop
177 a8083063 Iustin Pop
178 a8083063 Iustin Pop
class OpReplaceDisks(OpCode):
179 a8083063 Iustin Pop
  """Replace disks of an instance."""
180 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_REPLACE_DISKS"
181 a8083063 Iustin Pop
  __slots__ = ["instance_name", "remote_node"]
182 a8083063 Iustin Pop
183 a8083063 Iustin Pop
184 a8083063 Iustin Pop
class OpFailoverInstance(OpCode):
185 a8083063 Iustin Pop
  """Failover an instance."""
186 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_FAILOVER"
187 a8083063 Iustin Pop
  __slots__ = ["instance_name", "ignore_consistency"]
188 a8083063 Iustin Pop
189 a8083063 Iustin Pop
190 a8083063 Iustin Pop
class OpConnectConsole(OpCode):
191 a8083063 Iustin Pop
  """Failover an instance."""
192 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_CONSOLE"
193 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
194 a8083063 Iustin Pop
195 a8083063 Iustin Pop
196 a8083063 Iustin Pop
class OpActivateInstanceDisks(OpCode):
197 a8083063 Iustin Pop
  """Remove an instance."""
198 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_ACTIVATE_DISKS"
199 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
200 a8083063 Iustin Pop
201 a8083063 Iustin Pop
202 a8083063 Iustin Pop
class OpDeactivateInstanceDisks(OpCode):
203 a8083063 Iustin Pop
  """Remove an instance."""
204 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_DEACTIVATE_DISKS"
205 a8083063 Iustin Pop
  __slots__ = ["instance_name"]
206 a8083063 Iustin Pop
207 a8083063 Iustin Pop
208 a8083063 Iustin Pop
class OpQueryInstances(OpCode):
209 a8083063 Iustin Pop
  """Compute the list of instances."""
210 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY"
211 a8083063 Iustin Pop
  __slots__ = ["output_fields"]
212 a8083063 Iustin Pop
213 a8083063 Iustin Pop
214 a8083063 Iustin Pop
class OpQueryInstanceData(OpCode):
215 a8083063 Iustin Pop
  """Compute the run-time status of instances."""
216 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_QUERY_DATA"
217 a8083063 Iustin Pop
  __slots__ = ["instances"]
218 a8083063 Iustin Pop
219 a8083063 Iustin Pop
220 a8083063 Iustin Pop
class OpSetInstanceParms(OpCode):
221 a8083063 Iustin Pop
  """Change the parameters of an instance."""
222 a8083063 Iustin Pop
  OP_ID = "OP_INSTANCE_SET_PARMS"
223 a8083063 Iustin Pop
  __slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge"]
224 a8083063 Iustin Pop
225 a8083063 Iustin Pop
226 a8083063 Iustin Pop
# OS opcodes
227 a8083063 Iustin Pop
class OpDiagnoseOS(OpCode):
228 a8083063 Iustin Pop
  """Compute the list of guest operating systems."""
229 a8083063 Iustin Pop
  OP_ID = "OP_OS_DIAGNOSE"
230 a8083063 Iustin Pop
  __slots__ = []
231 a8083063 Iustin Pop
232 a8083063 Iustin Pop
# Exports opcodes
233 a8083063 Iustin Pop
class OpQueryExports(OpCode):
234 a8083063 Iustin Pop
  """Compute the list of exported images."""
235 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_QUERY"
236 a8083063 Iustin Pop
  __slots__ = ["nodes"]
237 a8083063 Iustin Pop
238 a8083063 Iustin Pop
class OpExportInstance(OpCode):
239 a8083063 Iustin Pop
  """Export an instance."""
240 a8083063 Iustin Pop
  OP_ID = "OP_BACKUP_EXPORT"
241 a8083063 Iustin Pop
  __slots__ = ["instance_name", "target_node", "shutdown"]
242 5c947f38 Iustin Pop
243 5c947f38 Iustin Pop
244 5c947f38 Iustin Pop
# Tags opcodes
245 5c947f38 Iustin Pop
class OpGetTags(OpCode):
246 5c947f38 Iustin Pop
  """Returns the tags of the given object."""
247 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_GET"
248 5c947f38 Iustin Pop
  __slots__ = ["kind", "name"]
249 5c947f38 Iustin Pop
250 5c947f38 Iustin Pop
251 5c947f38 Iustin Pop
class OpSetTag(OpCode):
252 5c947f38 Iustin Pop
  """Sets the value of a tag on a given object."""
253 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_SET"
254 5c947f38 Iustin Pop
  __slots__ = ["kind", "name", "tag"]
255 5c947f38 Iustin Pop
256 5c947f38 Iustin Pop
257 5c947f38 Iustin Pop
class OpDelTag(OpCode):
258 5c947f38 Iustin Pop
  """Remove a tag from a given object."""
259 5c947f38 Iustin Pop
  OP_ID = "OP_TAGS_DEL"
260 5c947f38 Iustin Pop
  __slots__ = ["kind", "name", "tag"]