4 # Copyright (C) 2011 Google Inc.
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.
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.
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
22 """Converter tools between ovf and ganeti config file
29 from ganeti import errors
30 from ganeti import utils
33 class Converter(object):
34 """Converter class for OVF packages.
36 Converter is a class above both ImporterOVF and ExporterOVF. It's purpose is
37 to provide a common interface for the two.
39 @type options: optparse.Values
40 @ivar options: options parsed from the command line
41 @type output_dir: string
42 @ivar output_dir: directory to which the results of conversion shall be
44 @type temp_file_manager: L{utils.TemporaryFileManager}
45 @ivar temp_file_manager: container for temporary files created during
47 @type temp_dir: string
48 @ivar temp_dir: temporary directory created then we deal with OVA
51 def __init__(self, input_path, options):
52 """Initialize the converter.
54 @type input_path: string
55 @param input_path: path to the Converter input file
56 @type options: optparse.Values
57 @param options: command line options
59 @raise errors.OpPrereqError: if file does not exist
62 input_path = os.path.abspath(input_path)
63 if not os.path.isfile(input_path):
64 raise errors.OpPrereqError("File does not exist: %s" % input_path)
65 self.options = options
66 self.temp_file_manager = utils.TemporaryFileManager()
68 self.output_dir = None
69 self._ReadInputData(input_path)
71 def _ReadInputData(self, input_path):
72 """Reads the data on which the conversion will take place.
74 @type input_path: string
75 @param input_path: absolute path to the Converter input file
78 raise NotImplementedError()
81 """Parses the data and creates a structure containing all required info.
84 raise NotImplementedError()
87 """Saves the gathered configuration in an apropriate format.
90 raise NotImplementedError()
93 """Cleans the temporary directory, if one was created.
96 self.temp_file_manager.Cleanup()
98 shutil.rmtree(self.temp_dir)
102 class OVFImporter(Converter):
103 def _ReadInputData(self, input_path):
113 class OVFExporter(Converter):
114 def _ReadInputData(self, input_path):