4 # Copyright (C) 2006, 2007, 2008 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
22 """Base class for all hypervisors
26 from ganeti import errors
29 class BaseHypervisor(object):
30 """Abstract virtualisation technology interface
32 The goal is that all aspects of the virtualisation technology are
33 abstracted away from the rest of code.
41 def StartInstance(self, instance, block_devices, extra_args):
42 """Start an instance."""
43 raise NotImplementedError
45 def StopInstance(self, instance, force=False):
46 """Stop an instance."""
47 raise NotImplementedError
49 def RebootInstance(self, instance):
50 """Reboot an instance."""
51 raise NotImplementedError
53 def ListInstances(self):
54 """Get the list of running instances."""
55 raise NotImplementedError
57 def GetInstanceInfo(self, instance_name):
58 """Get instance properties.
60 @type instance_name: string
61 @param instance_name: the instance name
63 @return: tuple (name, id, memory, vcpus, state, times)
66 raise NotImplementedError
68 def GetAllInstancesInfo(self):
69 """Get properties of all instances.
71 @return: list of tuples (name, id, memory, vcpus, stat, times)
74 raise NotImplementedError
76 def GetNodeInfo(self):
77 """Return information about the node.
79 @return: a dict with the following keys (values in MiB):
80 - memory_total: the total memory size on the node
81 - memory_free: the available memory on the node for instances
82 - memory_dom0: the memory used by the node itself, if available
85 raise NotImplementedError
88 def GetShellCommandForConsole(cls, instance, hvparams, beparams):
89 """Return a command for connecting to the console of an instance.
92 raise NotImplementedError
95 """Verify the hypervisor.
98 raise NotImplementedError
100 def MigrationInfo(self, instance):
101 """Get instance information to perform a migration.
103 By default assume no information is needed.
105 @type instance: L{objects.Instance}
106 @param instance: instance to be migrated
107 @rtype: string/data (opaque)
108 @return: instance migration information - serialized form
113 def AcceptInstance(self, instance, info, target):
114 """Prepare to accept an instance.
116 By default assume no preparation is needed.
118 @type instance: L{objects.Instance}
119 @param instance: instance to be accepted
120 @type info: string/data (opaque)
121 @param info: migration information, from the source node
123 @param target: target host (usually ip), on this node
128 def FinalizeMigration(self, instance, info, success):
129 """Finalized an instance migration.
131 Should finalize or revert any preparation done to accept the instance.
132 Since by default we do no preparation, we also don't have anything to do
134 @type instance: L{objects.Instance}
135 @param instance: instance whose migration is being aborted
136 @type info: string/data (opaque)
137 @param info: migration information, from the source node
138 @type success: boolean
139 @param success: whether the migration was a success or a failure
144 def MigrateInstance(self, name, target, live):
145 """Migrate an instance.
148 @param name: name of the instance to be migrated
150 @param target: hostname (usually ip) of the target node
152 @param live: whether to do a live or non-live migration
155 raise NotImplementedError
158 def CheckParameterSyntax(cls, hvparams):
159 """Check the given parameters for validity.
161 This should check the passed set of parameters for
162 validity. Classes should extend, not replace, this function.
165 @param hvparams: dictionary with parameter names/value
166 @raise errors.HypervisorError: when a parameter is not valid
170 if key not in cls.PARAMETERS:
171 raise errors.HypervisorError("Hypervisor parameter '%s'"
172 " not supported" % key)
173 for key in cls.PARAMETERS:
174 if key not in hvparams:
175 raise errors.HypervisorError("Hypervisor parameter '%s'"
178 def ValidateParameters(self, hvparams):
179 """Check the given parameters for validity.
181 This should check the passed set of parameters for
182 validity. Classes should extend, not replace, this function.
185 @param hvparams: dictionary with parameter names/value
186 @raise errors.HypervisorError: when a parameter is not valid