Exemple #1
0
    def add_iso(self, path):
        """Copy an ISO to ISOs directory"""
        # Check that file exists
        if not os.path.isfile(path):
            raise InvalidISOPathException('Error: \'%s\' is not a file or does not exist' % path)

        filename = Iso.get_filename_from_path(path)
        Iso.overwrite_check(filename, DirectoryLocation.ISO_STORAGE_DIR + '/' + filename)

        shutil.copy(path, DirectoryLocation.ISO_STORAGE_DIR)

        return self.get_iso_by_name(filename)
Exemple #2
0
    def add_iso(self, path):
        """Copy an ISO to ISOs directory"""
        # Check that file exists
        if not os.path.isfile(path):
            raise InvalidISOPathException('Error: \'%s\' is not a file or does not exist' % path)

        filename = Iso.get_filename_from_path(path)
        Iso.overwrite_check(filename, DirectoryLocation.ISO_STORAGE_DIR + '/' + filename)

        shutil.copy(path, DirectoryLocation.ISO_STORAGE_DIR)

        return self.get_iso_by_name(filename)
Exemple #3
0
    def getCurrentDisk(self):
        """Returns the path of the disk currently attached to the VM"""
        # Import cdrom XML template
        domain_config = self.vm_object.getLibvirtConfig()
        source_xml = domain_config.find(
            './devices/disk[@device="cdrom"]/source')

        if (source_xml is not None):
            filename = Iso.get_filename_from_path(source_xml.get('file'))
            return Iso(filename)
        else:
            return None
Exemple #4
0
    def add_from_url(self, url, name=None):
        """Download an ISO from given URL and save in ISO directory"""
        # Work out name from URL if name is not supplied
        if name is None:
            # Parse URL to get path part
            url_parse = urlparse.urlparse(url)
            name = Iso.get_filename_from_path(url_parse.path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        # Open file
        iso = urllib2.urlopen(url)

        # Read file in 16KB chunks
        chunk_size = 16 * 1024

        # Save ISO
        with open(output_path, 'wb') as file:
            while True:
                chunk = iso.read(chunk_size)
                if not chunk:
                    break
                file.write(chunk)
        iso.close()

        iso_object = self.add_iso(output_path)

        os.remove(output_path)
        os.rmdir(temp_directory)
        return iso_object
Exemple #5
0
    def getCurrentDisk(self):
        """Returns the path of the disk currently attached to the VM"""
        # Import cdrom XML template
        domain_config = self.vm_object.get_libvirt_config()
        source_xml = domain_config.find('./devices/disk[@device="cdrom"]/source')

        if source_xml is not None:
            filename = Iso.get_filename_from_path(source_xml.get('file'))
            return Iso(filename)
        else:
            return None
Exemple #6
0
    def add_iso_from_stream(self, path, name=None):
        """Import ISO, writing binary data to the ISO file"""
        if name is None:
            name = Iso.get_filename_from_path(path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        iso_writer = IsoWriter(output_path, self, temp_directory, path)
        self._register_object(iso_writer)
        return iso_writer
Exemple #7
0
    def add_iso_from_stream(self, path, name=None):
        """Import ISO, writing binary data to the ISO file"""
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MANAGE_ISO)
        if name is None:
            name = Iso.get_filename_from_path(path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        iso_writer = IsoWriter(output_path, self, temp_directory, path)
        self._register_object(iso_writer)
        return iso_writer
Exemple #8
0
    def add_iso_from_stream(self, path, name=None):
        """Import ISO, writing binary data to the ISO file"""
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MANAGE_ISO
        )
        if name is None:
            name = Iso.get_filename_from_path(path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        iso_writer = IsoWriter(output_path, self, temp_directory, path)
        self._register_object(iso_writer)
        return iso_writer
Exemple #9
0
    def add_from_url(self, url, name=None, node=None):
        """Download an ISO from given URL and save in ISO directory"""
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MANAGE_ISO
        )

        if node is not None and node != get_hostname():
            remote_node = self._get_registered_object('cluster').get_remote_node(node)
            remote_factory = remote_node.get_connection('iso_factory')
            remote_iso = remote_factory.add_from_url(url=url, name=name)
            remote_node.annotate_object(remote_iso)
            return remote_iso.get_name()

        # Work out name from URL if name is not supplied
        if name is None:
            # Parse URL to get path part
            url_parse = urlparse.urlparse(url)
            name = Iso.get_filename_from_path(url_parse.path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        # Open file
        iso = urllib2.urlopen(url)

        # Read file in 16KB chunks
        chunk_size = 16 * 1024

        # Save ISO
        with open(output_path, 'wb') as file:
            while True:
                chunk = iso.read(chunk_size)
                if not chunk:
                    break
                file.write(chunk)
        iso.close()

        iso_object = self.add_iso(output_path)

        os.remove(output_path)
        os.rmdir(temp_directory)
        return iso_object.get_name()
Exemple #10
0
    def add_from_url(self, url, name=None, node=None):
        """Download an ISO from given URL and save in ISO directory"""
        self._get_registered_object('auth').assert_permission(
            PERMISSIONS.MANAGE_ISO)

        if node is not None and node != get_hostname():
            remote_node = self._get_registered_object(
                'cluster').get_remote_node(node)
            remote_factory = remote_node.get_connection('iso_factory')
            remote_iso = remote_factory.add_from_url(url=url, name=name)
            remote_node.annotate_object(remote_iso)
            return remote_iso.get_name()

        # Work out name from URL if name is not supplied
        if name is None:
            # Parse URL to get path part
            url_parse = urlparse.urlparse(url)
            name = Iso.get_filename_from_path(url_parse.path)

        # Get temporary directory to store ISO
        temp_directory = tempfile.mkdtemp()
        output_path = temp_directory + '/' + name

        # Open file
        iso = urllib2.urlopen(url)

        # Read file in 16KB chunks
        chunk_size = 16 * 1024

        # Save ISO
        with open(output_path, 'wb') as file:
            while True:
                chunk = iso.read(chunk_size)
                if not chunk:
                    break
                file.write(chunk)
        iso.close()

        iso_object = self.add_iso(output_path)

        os.remove(output_path)
        os.rmdir(temp_directory)
        return iso_object.get_name()
Exemple #11
0
 def get_iso_by_name(self, iso_name, node=None):
     """Create and register Iso object"""
     if iso_name not in Factory.CACHED_OBJECTS:
         Factory.CACHED_OBJECTS[iso_name] = Iso(iso_name)
         self._register_object(Factory.CACHED_OBJECTS[iso_name])
     return Factory.CACHED_OBJECTS[iso_name]
Exemple #12
0
 def get_iso_by_name(self, iso_name):
     """Create and register Iso object"""
     iso_object = Iso(iso_name)
     self._register_object(iso_object)
     return iso_object