Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.9 kB)

1 65a6f9b7 Michael Hanselmann
#
2 65a6f9b7 Michael Hanselmann
#
3 65a6f9b7 Michael Hanselmann
4 65a6f9b7 Michael Hanselmann
# Copyright (C) 2006, 2007, 2008 Google Inc.
5 65a6f9b7 Michael Hanselmann
#
6 65a6f9b7 Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 65a6f9b7 Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 65a6f9b7 Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 65a6f9b7 Michael Hanselmann
# (at your option) any later version.
10 65a6f9b7 Michael Hanselmann
#
11 65a6f9b7 Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 65a6f9b7 Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 65a6f9b7 Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 65a6f9b7 Michael Hanselmann
# General Public License for more details.
15 65a6f9b7 Michael Hanselmann
#
16 65a6f9b7 Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 65a6f9b7 Michael Hanselmann
# along with this program; if not, write to the Free Software
18 65a6f9b7 Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 65a6f9b7 Michael Hanselmann
# 02110-1301, USA.
20 65a6f9b7 Michael Hanselmann
21 65a6f9b7 Michael Hanselmann
22 65a6f9b7 Michael Hanselmann
"""Base class for all hypervisors
23 65a6f9b7 Michael Hanselmann

24 65a6f9b7 Michael Hanselmann
"""
25 65a6f9b7 Michael Hanselmann
26 f48148c3 Iustin Pop
from ganeti import errors
27 f48148c3 Iustin Pop
28 f48148c3 Iustin Pop
29 65a6f9b7 Michael Hanselmann
class BaseHypervisor(object):
30 65a6f9b7 Michael Hanselmann
  """Abstract virtualisation technology interface
31 65a6f9b7 Michael Hanselmann

32 f48148c3 Iustin Pop
  The goal is that all aspects of the virtualisation technology are
33 f48148c3 Iustin Pop
  abstracted away from the rest of code.
34 65a6f9b7 Michael Hanselmann

35 65a6f9b7 Michael Hanselmann
  """
36 f48148c3 Iustin Pop
  PARAMETERS = []
37 f48148c3 Iustin Pop
38 65a6f9b7 Michael Hanselmann
  def __init__(self):
39 65a6f9b7 Michael Hanselmann
    pass
40 65a6f9b7 Michael Hanselmann
41 65a6f9b7 Michael Hanselmann
  def StartInstance(self, instance, block_devices, extra_args):
42 65a6f9b7 Michael Hanselmann
    """Start an instance."""
43 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
44 65a6f9b7 Michael Hanselmann
45 65a6f9b7 Michael Hanselmann
  def StopInstance(self, instance, force=False):
46 65a6f9b7 Michael Hanselmann
    """Stop an instance."""
47 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
48 65a6f9b7 Michael Hanselmann
49 65a6f9b7 Michael Hanselmann
  def RebootInstance(self, instance):
50 65a6f9b7 Michael Hanselmann
    """Reboot an instance."""
51 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
52 65a6f9b7 Michael Hanselmann
53 65a6f9b7 Michael Hanselmann
  def ListInstances(self):
54 65a6f9b7 Michael Hanselmann
    """Get the list of running instances."""
55 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
56 65a6f9b7 Michael Hanselmann
57 65a6f9b7 Michael Hanselmann
  def GetInstanceInfo(self, instance_name):
58 65a6f9b7 Michael Hanselmann
    """Get instance properties.
59 65a6f9b7 Michael Hanselmann

60 c41eea6e Iustin Pop
    @param instance_name: the instance name
61 65a6f9b7 Michael Hanselmann

62 c41eea6e Iustin Pop
    @return: tuple (name, id, memory, vcpus, state, times)
63 65a6f9b7 Michael Hanselmann

64 65a6f9b7 Michael Hanselmann
    """
65 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
66 65a6f9b7 Michael Hanselmann
67 65a6f9b7 Michael Hanselmann
  def GetAllInstancesInfo(self):
68 65a6f9b7 Michael Hanselmann
    """Get properties of all instances.
69 65a6f9b7 Michael Hanselmann

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

72 65a6f9b7 Michael Hanselmann
    """
73 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
74 65a6f9b7 Michael Hanselmann
75 65a6f9b7 Michael Hanselmann
  def GetNodeInfo(self):
76 65a6f9b7 Michael Hanselmann
    """Return information about the node.
77 65a6f9b7 Michael Hanselmann

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

83 65a6f9b7 Michael Hanselmann
    """
84 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
85 65a6f9b7 Michael Hanselmann
86 65a6f9b7 Michael Hanselmann
  @staticmethod
87 65a6f9b7 Michael Hanselmann
  def GetShellCommandForConsole(instance):
88 65a6f9b7 Michael Hanselmann
    """Return a command for connecting to the console of an instance.
89 65a6f9b7 Michael Hanselmann

90 65a6f9b7 Michael Hanselmann
    """
91 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
92 65a6f9b7 Michael Hanselmann
93 65a6f9b7 Michael Hanselmann
  def Verify(self):
94 65a6f9b7 Michael Hanselmann
    """Verify the hypervisor.
95 65a6f9b7 Michael Hanselmann

96 65a6f9b7 Michael Hanselmann
    """
97 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
98 6e7275c0 Iustin Pop
99 6e7275c0 Iustin Pop
  def MigrateInstance(self, name, target, live):
100 6e7275c0 Iustin Pop
    """Migrate an instance.
101 6e7275c0 Iustin Pop

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

107 6e7275c0 Iustin Pop
    Returns: none, errors will be signaled by exception.
108 6e7275c0 Iustin Pop

109 6e7275c0 Iustin Pop
    """
110 6e7275c0 Iustin Pop
    raise NotImplementedError
111 f48148c3 Iustin Pop
112 f48148c3 Iustin Pop
113 f48148c3 Iustin Pop
  @classmethod
114 f48148c3 Iustin Pop
  def CheckParameterSyntax(cls, hvparams):
115 f48148c3 Iustin Pop
    """Check the given parameters for validity.
116 f48148c3 Iustin Pop

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

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

124 f48148c3 Iustin Pop
    """
125 f48148c3 Iustin Pop
    for key in hvparams:
126 f48148c3 Iustin Pop
      if key not in cls.PARAMETERS:
127 f48148c3 Iustin Pop
        raise errors.HypervisorError("Hypervisor parameter '%s'"
128 f48148c3 Iustin Pop
                                     " not supported" % key)
129 f48148c3 Iustin Pop
    for key in cls.PARAMETERS:
130 f48148c3 Iustin Pop
      if key not in hvparams:
131 f48148c3 Iustin Pop
        raise errors.HypervisorError("Hypervisor parameter '%s'"
132 f48148c3 Iustin Pop
                                     " missing" % key)
133 f48148c3 Iustin Pop
134 f48148c3 Iustin Pop
  def ValidateParameters(self, hvparams):
135 f48148c3 Iustin Pop
    """Check the given parameters for validity.
136 f48148c3 Iustin Pop

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

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

144 f48148c3 Iustin Pop
    """
145 f48148c3 Iustin Pop
    pass