root / lib / hypervisor / hv_base.py @ 6b405598
History | View | Annotate | Download (5.3 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 | 07813a9e | Iustin Pop | def StartInstance(self, instance, block_devices): |
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 | cd42d0ad | Guido Trotter | @type instance_name: string
|
61 | c41eea6e | Iustin Pop | @param instance_name: the instance name
|
62 | 65a6f9b7 | Michael Hanselmann |
|
63 | c41eea6e | Iustin Pop | @return: tuple (name, id, memory, vcpus, state, times)
|
64 | 65a6f9b7 | Michael Hanselmann |
|
65 | 65a6f9b7 | Michael Hanselmann | """
|
66 | 65a6f9b7 | Michael Hanselmann | raise NotImplementedError |
67 | 65a6f9b7 | Michael Hanselmann | |
68 | 65a6f9b7 | Michael Hanselmann | def GetAllInstancesInfo(self): |
69 | 65a6f9b7 | Michael Hanselmann | """Get properties of all instances.
|
70 | 65a6f9b7 | Michael Hanselmann |
|
71 | c41eea6e | Iustin Pop | @return: list of tuples (name, id, memory, vcpus, stat, times)
|
72 | c41eea6e | Iustin Pop |
|
73 | 65a6f9b7 | Michael Hanselmann | """
|
74 | 65a6f9b7 | Michael Hanselmann | raise NotImplementedError |
75 | 65a6f9b7 | Michael Hanselmann | |
76 | 65a6f9b7 | Michael Hanselmann | def GetNodeInfo(self): |
77 | 65a6f9b7 | Michael Hanselmann | """Return information about the node.
|
78 | 65a6f9b7 | Michael Hanselmann |
|
79 | c41eea6e | Iustin Pop | @return: a dict with the following keys (values in MiB):
|
80 | c41eea6e | Iustin Pop | - memory_total: the total memory size on the node
|
81 | c41eea6e | Iustin Pop | - memory_free: the available memory on the node for instances
|
82 | c41eea6e | Iustin Pop | - memory_dom0: the memory used by the node itself, if available
|
83 | 65a6f9b7 | Michael Hanselmann |
|
84 | 65a6f9b7 | Michael Hanselmann | """
|
85 | 65a6f9b7 | Michael Hanselmann | raise NotImplementedError |
86 | 65a6f9b7 | Michael Hanselmann | |
87 | 637ce7f9 | Guido Trotter | @classmethod
|
88 | 5431b2e4 | Guido Trotter | def GetShellCommandForConsole(cls, instance, hvparams, beparams): |
89 | 65a6f9b7 | Michael Hanselmann | """Return a command for connecting to the console of an instance.
|
90 | 65a6f9b7 | Michael Hanselmann |
|
91 | 65a6f9b7 | Michael Hanselmann | """
|
92 | 65a6f9b7 | Michael Hanselmann | raise NotImplementedError |
93 | 65a6f9b7 | Michael Hanselmann | |
94 | 65a6f9b7 | Michael Hanselmann | def Verify(self): |
95 | 65a6f9b7 | Michael Hanselmann | """Verify the hypervisor.
|
96 | 65a6f9b7 | Michael Hanselmann |
|
97 | 65a6f9b7 | Michael Hanselmann | """
|
98 | 65a6f9b7 | Michael Hanselmann | raise NotImplementedError |
99 | 6e7275c0 | Iustin Pop | |
100 | cd42d0ad | Guido Trotter | def MigrationInfo(self, instance): |
101 | cd42d0ad | Guido Trotter | """Get instance information to perform a migration.
|
102 | cd42d0ad | Guido Trotter |
|
103 | cd42d0ad | Guido Trotter | By default assume no information is needed.
|
104 | cd42d0ad | Guido Trotter |
|
105 | cd42d0ad | Guido Trotter | @type instance: L{objects.Instance}
|
106 | cd42d0ad | Guido Trotter | @param instance: instance to be migrated
|
107 | cd42d0ad | Guido Trotter | @rtype: string/data (opaque)
|
108 | cd42d0ad | Guido Trotter | @return: instance migration information - serialized form
|
109 | cd42d0ad | Guido Trotter |
|
110 | cd42d0ad | Guido Trotter | """
|
111 | cd42d0ad | Guido Trotter | return '' |
112 | cd42d0ad | Guido Trotter | |
113 | cd42d0ad | Guido Trotter | def AcceptInstance(self, instance, info, target): |
114 | cd42d0ad | Guido Trotter | """Prepare to accept an instance.
|
115 | cd42d0ad | Guido Trotter |
|
116 | cd42d0ad | Guido Trotter | By default assume no preparation is needed.
|
117 | cd42d0ad | Guido Trotter |
|
118 | cd42d0ad | Guido Trotter | @type instance: L{objects.Instance}
|
119 | cd42d0ad | Guido Trotter | @param instance: instance to be accepted
|
120 | cd42d0ad | Guido Trotter | @type info: string/data (opaque)
|
121 | cd42d0ad | Guido Trotter | @param info: migration information, from the source node
|
122 | cd42d0ad | Guido Trotter | @type target: string
|
123 | cd42d0ad | Guido Trotter | @param target: target host (usually ip), on this node
|
124 | cd42d0ad | Guido Trotter |
|
125 | cd42d0ad | Guido Trotter | """
|
126 | cd42d0ad | Guido Trotter | pass
|
127 | cd42d0ad | Guido Trotter | |
128 | cd42d0ad | Guido Trotter | def FinalizeMigration(self, instance, info, success): |
129 | cd42d0ad | Guido Trotter | """Finalized an instance migration.
|
130 | cd42d0ad | Guido Trotter |
|
131 | cd42d0ad | Guido Trotter | Should finalize or revert any preparation done to accept the instance.
|
132 | cd42d0ad | Guido Trotter | Since by default we do no preparation, we also don't have anything to do
|
133 | cd42d0ad | Guido Trotter |
|
134 | cd42d0ad | Guido Trotter | @type instance: L{objects.Instance}
|
135 | cd42d0ad | Guido Trotter | @param instance: instance whose migration is being aborted
|
136 | cd42d0ad | Guido Trotter | @type info: string/data (opaque)
|
137 | cd42d0ad | Guido Trotter | @param info: migration information, from the source node
|
138 | cd42d0ad | Guido Trotter | @type success: boolean
|
139 | cd42d0ad | Guido Trotter | @param success: whether the migration was a success or a failure
|
140 | cd42d0ad | Guido Trotter |
|
141 | cd42d0ad | Guido Trotter | """
|
142 | cd42d0ad | Guido Trotter | pass
|
143 | cd42d0ad | Guido Trotter | |
144 | 6e7275c0 | Iustin Pop | def MigrateInstance(self, name, target, live): |
145 | 6e7275c0 | Iustin Pop | """Migrate an instance.
|
146 | 6e7275c0 | Iustin Pop |
|
147 | cd42d0ad | Guido Trotter | @type name: string
|
148 | cd42d0ad | Guido Trotter | @param name: name of the instance to be migrated
|
149 | cd42d0ad | Guido Trotter | @type target: string
|
150 | cd42d0ad | Guido Trotter | @param target: hostname (usually ip) of the target node
|
151 | cd42d0ad | Guido Trotter | @type live: boolean
|
152 | cd42d0ad | Guido Trotter | @param live: whether to do a live or non-live migration
|
153 | 6e7275c0 | Iustin Pop |
|
154 | 6e7275c0 | Iustin Pop | """
|
155 | 6e7275c0 | Iustin Pop | raise NotImplementedError |
156 | f48148c3 | Iustin Pop | |
157 | f48148c3 | Iustin Pop | @classmethod
|
158 | f48148c3 | Iustin Pop | def CheckParameterSyntax(cls, hvparams): |
159 | f48148c3 | Iustin Pop | """Check the given parameters for validity.
|
160 | f48148c3 | Iustin Pop |
|
161 | f48148c3 | Iustin Pop | This should check the passed set of parameters for
|
162 | f48148c3 | Iustin Pop | validity. Classes should extend, not replace, this function.
|
163 | f48148c3 | Iustin Pop |
|
164 | f48148c3 | Iustin Pop | @type hvparams: dict
|
165 | f48148c3 | Iustin Pop | @param hvparams: dictionary with parameter names/value
|
166 | f48148c3 | Iustin Pop | @raise errors.HypervisorError: when a parameter is not valid
|
167 | f48148c3 | Iustin Pop |
|
168 | f48148c3 | Iustin Pop | """
|
169 | f48148c3 | Iustin Pop | for key in hvparams: |
170 | f48148c3 | Iustin Pop | if key not in cls.PARAMETERS: |
171 | f48148c3 | Iustin Pop | raise errors.HypervisorError("Hypervisor parameter '%s'" |
172 | f48148c3 | Iustin Pop | " not supported" % key)
|
173 | f48148c3 | Iustin Pop | for key in cls.PARAMETERS: |
174 | f48148c3 | Iustin Pop | if key not in hvparams: |
175 | f48148c3 | Iustin Pop | raise errors.HypervisorError("Hypervisor parameter '%s'" |
176 | f48148c3 | Iustin Pop | " missing" % key)
|
177 | f48148c3 | Iustin Pop | |
178 | f48148c3 | Iustin Pop | def ValidateParameters(self, hvparams): |
179 | f48148c3 | Iustin Pop | """Check the given parameters for validity.
|
180 | f48148c3 | Iustin Pop |
|
181 | f48148c3 | Iustin Pop | This should check the passed set of parameters for
|
182 | f48148c3 | Iustin Pop | validity. Classes should extend, not replace, this function.
|
183 | f48148c3 | Iustin Pop |
|
184 | f48148c3 | Iustin Pop | @type hvparams: dict
|
185 | f48148c3 | Iustin Pop | @param hvparams: dictionary with parameter names/value
|
186 | f48148c3 | Iustin Pop | @raise errors.HypervisorError: when a parameter is not valid
|
187 | f48148c3 | Iustin Pop |
|
188 | f48148c3 | Iustin Pop | """
|
189 | f48148c3 | Iustin Pop | pass |