Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / hv_base.py @ 5661b908

History | View | Annotate | Download (3.9 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
    @param instance_name: the instance name
61

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

64
    """
65
    raise NotImplementedError
66

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

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

72
    """
73
    raise NotImplementedError
74

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

78
    @return: a dict with the following keys (values in MiB):
79
          - memory_total: the total memory size on the node
80
          - memory_free: the available memory on the node for instances
81
          - memory_dom0: the memory used by the node itself, if available
82

83
    """
84
    raise NotImplementedError
85

    
86
  @staticmethod
87
  def GetShellCommandForConsole(instance):
88
    """Return a command for connecting to the console of an instance.
89

90
    """
91
    raise NotImplementedError
92

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

96
    """
97
    raise NotImplementedError
98

    
99
  def MigrateInstance(self, name, target, live):
100
    """Migrate an instance.
101

102
    Arguments:
103
      - name: the name of the instance
104
      - target: the target of the migration (usually will be IP and not name)
105
      - live: whether to do live migration or not
106

107
    Returns: none, errors will be signaled by exception.
108

109
    """
110
    raise NotImplementedError
111

    
112

    
113
  @classmethod
114
  def CheckParameterSyntax(cls, hvparams):
115
    """Check the given parameters for validity.
116

117
    This should check the passed set of parameters for
118
    validity. Classes should extend, not replace, this function.
119

120
    @type hvparams:  dict
121
    @param hvparams: dictionary with parameter names/value
122
    @raise errors.HypervisorError: when a parameter is not valid
123

124
    """
125
    for key in hvparams:
126
      if key not in cls.PARAMETERS:
127
        raise errors.HypervisorError("Hypervisor parameter '%s'"
128
                                     " not supported" % key)
129
    for key in cls.PARAMETERS:
130
      if key not in hvparams:
131
        raise errors.HypervisorError("Hypervisor parameter '%s'"
132
                                     " missing" % key)
133

    
134
  def ValidateParameters(self, hvparams):
135
    """Check the given parameters for validity.
136

137
    This should check the passed set of parameters for
138
    validity. Classes should extend, not replace, this function.
139

140
    @type hvparams:  dict
141
    @param hvparams: dictionary with parameter names/value
142
    @raise errors.HypervisorError: when a parameter is not valid
143

144
    """
145
    pass