def identify_file(input_file): """ Return True if the given file is of this format. """ try: f = file(input_file, "r") output = f.read() f.close() virtimage.parse(output, input_file) except RuntimeError: return False return True
def testMultipleNics(self): f = open(os.path.join(self.basedir, "image2nics.xml"), "r") xml = f.read() f.close() img = virtimage.parse(xml, ".") self.assertEqual(2, img.domain.interface)
def testImageParsing(self): f = open(os.path.join(self.basedir, "image.xml"), "r") xml = f.read() f.close() img = virtimage.parse(xml, ".") self.assertEqual("test-image", img.name) self.assertTrue(img.domain) self.assertEqual(5, len(img.storage)) self.assertEqual(2, len(img.domain.boots)) self.assertEqual(1, img.domain.interface) boot = img.domain.boots[0] self.assertEqual("xvdb", boot.drives[1].target)
def import_file(input_file): """ Import a configuration file. Raises if the file couldn't be opened, or parsing otherwise failed. """ vm = vmcfg.vm() try: f = file(input_file, "r") output = f.read() f.close() logging.debug("Importing virt-image XML:\n%s", output) config = virtimage.parse(output, input_file) except Exception, e: raise ValueError(_("Couldn't import file '%s': %s") % (input_file, e))