Esempio n. 1
0
    def import_to_machine(self, machine_node):
        """ Copy (import) the appliance to VirtualBox
        """
        logger.info('importing appliance from /%s as "%s"', BoxesStorage.get_relative_path(self.ovf),
                    machine_node.cfg_name)

        import virtualbox

        vbox = virtualbox.VirtualBox()
        appliance = vbox.create_appliance()
        progress = appliance.read(self.ovf)
        progress.wait_for_completion(-1)
        appliance.interpret()

        logger.info('... importing the machines')
        progress = appliance.import_machines([_virtualbox.library.ImportOptions.keep_natma_cs])
        logger.info('... waiting for import to finish')
        progress.wait_for_completion(-1)

        if len(appliance.machines) > 0:
            machine_uuid = appliance.machines[0]
            machine_node.cfg_uuid = machine_uuid
            logger.debug(machine_node.get_info())
        else:
            raise ImportException('no virtual machine created after import of %s' % machine_node.cfg_name)