Statistics
| Branch: | Tag: | Revision:

root / lib / hypervisor / hv_base.py @ ff9efc03

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

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

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

72 65a6f9b7 Michael Hanselmann
    Returns:
73 65a6f9b7 Michael Hanselmann
      [(name, id, memory, vcpus, stat, times),...]
74 65a6f9b7 Michael Hanselmann
    """
75 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
76 65a6f9b7 Michael Hanselmann
77 65a6f9b7 Michael Hanselmann
  def GetNodeInfo(self):
78 65a6f9b7 Michael Hanselmann
    """Return information about the node.
79 65a6f9b7 Michael Hanselmann

80 65a6f9b7 Michael Hanselmann
    The return value is a dict, which has to have the following items:
81 65a6f9b7 Michael Hanselmann
      (all values in MiB)
82 65a6f9b7 Michael Hanselmann
      - memory_total: the total memory size on the node
83 65a6f9b7 Michael Hanselmann
      - memory_free: the available memory on the node for instances
84 65a6f9b7 Michael Hanselmann
      - memory_dom0: the memory used by the node itself, if available
85 65a6f9b7 Michael Hanselmann

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

93 65a6f9b7 Michael Hanselmann
    """
94 65a6f9b7 Michael Hanselmann
    raise NotImplementedError
95 65a6f9b7 Michael Hanselmann
96 65a6f9b7 Michael Hanselmann
  def Verify(self):
97 65a6f9b7 Michael Hanselmann
    """Verify the hypervisor.
98 65a6f9b7 Michael Hanselmann

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

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

110 6e7275c0 Iustin Pop
    Returns: none, errors will be signaled by exception.
111 6e7275c0 Iustin Pop

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

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

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

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

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

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

147 f48148c3 Iustin Pop
    """
148 f48148c3 Iustin Pop
    pass