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.
61 instance_name: the instance name
64 (name, id, memory, vcpus, state, times)
67 raise NotImplementedError
69 def GetAllInstancesInfo(self):
70 """Get properties of all instances.
73 [(name, id, memory, vcpus, stat, times),...]
75 raise NotImplementedError
77 def GetNodeInfo(self):
78 """Return information about the node.
80 The return value is a dict, which has to have the following items:
82 - memory_total: the total memory size on the node
83 - memory_free: the available memory on the node for instances
84 - memory_dom0: the memory used by the node itself, if available
87 raise NotImplementedError
90 def GetShellCommandForConsole(instance):
91 """Return a command for connecting to the console of an instance.
94 raise NotImplementedError
97 """Verify the hypervisor.
100 raise NotImplementedError
102 def MigrateInstance(self, name, target, live):
103 """Migrate an instance.
106 - name: the name of the instance
107 - target: the target of the migration (usually will be IP and not name)
108 - live: whether to do live migration or not
110 Returns: none, errors will be signaled by exception.
113 raise NotImplementedError
117 def CheckParameterSyntax(cls, hvparams):
118 """Check the given parameters for validity.
120 This should check the passed set of parameters for
121 validity. Classes should extend, not replace, this function.
124 @param hvparams: dictionary with parameter names/value
125 @raise errors.HypervisorError: when a parameter is not valid
129 if key not in cls.PARAMETERS:
130 raise errors.HypervisorError("Hypervisor parameter '%s'"
131 " not supported" % key)
132 for key in cls.PARAMETERS:
133 if key not in hvparams:
134 raise errors.HypervisorError("Hypervisor parameter '%s'"
137 def ValidateParameters(self, hvparams):
138 """Check the given parameters for validity.
140 This should check the passed set of parameters for
141 validity. Classes should extend, not replace, this function.
144 @param hvparams: dictionary with parameter names/value
145 @raise errors.HypervisorError: when a parameter is not valid