Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / hv_base.py @ f48148c3

History | View | Annotate | Download (4 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
    Args:
61
      instance_name: the instance name
62

63
    Returns:
64
      (name, id, memory, vcpus, state, times)
65

66
    """
67
    raise NotImplementedError
68

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

72
    Returns:
73
      [(name, id, memory, vcpus, stat, times),...]
74
    """
75
    raise NotImplementedError
76

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

80
    The return value is a dict, which has to have the following items:
81
      (all values in MiB)
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
85

86
    """
87
    raise NotImplementedError
88

    
89
  @staticmethod
90
  def GetShellCommandForConsole(instance):
91
    """Return a command for connecting to the console of an instance.
92

93
    """
94
    raise NotImplementedError
95

    
96
  def Verify(self):
97
    """Verify the hypervisor.
98

99
    """
100
    raise NotImplementedError
101

    
102
  def MigrateInstance(self, name, target, live):
103
    """Migrate an instance.
104

105
    Arguments:
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
109

110
    Returns: none, errors will be signaled by exception.
111

112
    """
113
    raise NotImplementedError
114

    
115

    
116
  @classmethod
117
  def CheckParameterSyntax(cls, hvparams):
118
    """Check the given parameters for validity.
119

120
    This should check the passed set of parameters for
121
    validity. Classes should extend, not replace, this function.
122

123
    @type hvparams:  dict
124
    @param hvparams: dictionary with parameter names/value
125
    @raise errors.HypervisorError: when a parameter is not valid
126

127
    """
128
    for key in hvparams:
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'"
135
                                     " missing" % key)
136

    
137
  def ValidateParameters(self, hvparams):
138
    """Check the given parameters for validity.
139

140
    This should check the passed set of parameters for
141
    validity. Classes should extend, not replace, this function.
142

143
    @type hvparams:  dict
144
    @param hvparams: dictionary with parameter names/value
145
    @raise errors.HypervisorError: when a parameter is not valid
146

147
    """
148
    pass