Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / hv_base.py @ 3213d3c8

History | View | Annotate | Download (5.3 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2008 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
"""Base class for all hypervisors
23

24
"""
25

    
26
from ganeti import errors
27

    
28

    
29
class BaseHypervisor(object):
30
  """Abstract virtualisation technology interface
31

32
  The goal is that all aspects of the virtualisation technology are
33
  abstracted away from the rest of code.
34

35
  """
36
  PARAMETERS = []
37

    
38
  def __init__(self):
39
    pass
40

    
41
  def StartInstance(self, instance, block_devices, extra_args):
42
    """Start an instance."""
43
    raise NotImplementedError
44

    
45
  def StopInstance(self, instance, force=False):
46
    """Stop an instance."""
47
    raise NotImplementedError
48

    
49
  def RebootInstance(self, instance):
50
    """Reboot an instance."""
51
    raise NotImplementedError
52

    
53
  def ListInstances(self):
54
    """Get the list of running instances."""
55
    raise NotImplementedError
56

    
57
  def GetInstanceInfo(self, instance_name):
58
    """Get instance properties.
59

60
    @type instance_name: string
61
    @param instance_name: the instance name
62

63
    @return: tuple (name, id, memory, vcpus, state, times)
64

65
    """
66
    raise NotImplementedError
67

    
68
  def GetAllInstancesInfo(self):
69
    """Get properties of all instances.
70

71
    @return: list of tuples (name, id, memory, vcpus, stat, times)
72

73
    """
74
    raise NotImplementedError
75

    
76
  def GetNodeInfo(self):
77
    """Return information about the node.
78

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
83

84
    """
85
    raise NotImplementedError
86

    
87
  @classmethod
88
  def GetShellCommandForConsole(cls, instance, hvparams, beparams):
89
    """Return a command for connecting to the console of an instance.
90

91
    """
92
    raise NotImplementedError
93

    
94
  def Verify(self):
95
    """Verify the hypervisor.
96

97
    """
98
    raise NotImplementedError
99

    
100
  def MigrationInfo(self, instance):
101
    """Get instance information to perform a migration.
102

103
    By default assume no information is needed.
104

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
109

110
    """
111
    return ''
112

    
113
  def AcceptInstance(self, instance, info, target):
114
    """Prepare to accept an instance.
115

116
    By default assume no preparation is needed.
117

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
122
    @type target: string
123
    @param target: target host (usually ip), on this node
124

125
    """
126
    pass
127

    
128
  def FinalizeMigration(self, instance, info, success):
129
    """Finalized an instance migration.
130

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
133

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
140

141
    """
142
    pass
143

    
144
  def MigrateInstance(self, name, target, live):
145
    """Migrate an instance.
146

147
    @type name: string
148
    @param name: name of the instance to be migrated
149
    @type target: string
150
    @param target: hostname (usually ip) of the target node
151
    @type live: boolean
152
    @param live: whether to do a live or non-live migration
153

154
    """
155
    raise NotImplementedError
156

    
157
  @classmethod
158
  def CheckParameterSyntax(cls, hvparams):
159
    """Check the given parameters for validity.
160

161
    This should check the passed set of parameters for
162
    validity. Classes should extend, not replace, this function.
163

164
    @type hvparams:  dict
165
    @param hvparams: dictionary with parameter names/value
166
    @raise errors.HypervisorError: when a parameter is not valid
167

168
    """
169
    for key in hvparams:
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'"
176
                                     " missing" % key)
177

    
178
  def ValidateParameters(self, hvparams):
179
    """Check the given parameters for validity.
180

181
    This should check the passed set of parameters for
182
    validity. Classes should extend, not replace, this function.
183

184
    @type hvparams:  dict
185
    @param hvparams: dictionary with parameter names/value
186
    @raise errors.HypervisorError: when a parameter is not valid
187

188
    """
189
    pass