Example #1
0
    def validate_integrity(self):
        invalid = {}
        # validate networks integrity
        invalid_networks = list(set(self.info['networks']) -
                                set(self._get_all_networks_name()))
        if invalid_networks:
            invalid['networks'] = invalid_networks

        # validate storagepools integrity
        pool_uri = self.info['storagepool']
        pool_name = pool_name_from_uri(pool_uri)
        if pool_name not in self._get_all_storagepools_name():
            invalid['storagepools'] = [pool_name]

        # validate iso integrity
        # FIXME when we support multiples cdrom devices
        iso = self.info.get('cdrom')
        if iso:
            if os.path.exists(iso):
                st_mode = os.stat(iso).st_mode
                if not (stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode)):
                    invalid['cdrom'] = [iso]
            elif not check_url_path(iso):
                invalid['cdrom'] = [iso]

        self.info['invalid'] = invalid

        return self.info
Example #2
0
    def _is_iso_remote(self):
        if os.path.isfile(self.path):
            return False

        if check_url_path(self.path):
            return True

        raise IsoFormatError("KCHISO0001E", {'filename': self.path})
Example #3
0
    def _is_iso_remote(self):
        if os.path.exists(self.path):
            st_mode = os.stat(self.path).st_mode
            if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
                return False

        if check_url_path(self.path):
            return True

        raise IsoFormatError("KCHISO0001E", {'filename': self.path})
Example #4
0
def _get_disk_type(path):
    if check_url_path(path):
        return 'network'

    if not os.path.exists(path):
        raise InvalidParameter("KCHVMSTOR0003E", {'value': path})

    # Check if path is a valid local path
    if os.path.isfile(path):
        return 'file'

    r_path = os.path.realpath(path)
    if stat.S_ISBLK(os.stat(r_path).st_mode):
        return 'block'

    raise InvalidParameter("KCHVMSTOR0003E", {'value': path})
Example #5
0
def _check_path(path):
    if check_url_path(path):
        src_type = 'network'
    # Check if path is a valid local path
    elif os.path.exists(path):
        if os.path.isfile(path):
            src_type = 'file'
        else:
            r_path = os.path.realpath(path)
            if not stat.S_ISBLK(os.stat(r_path).st_mode):
                raise InvalidParameter("KCHVMSTOR0003E", {'value': path})

            src_type = 'block'
    else:
        raise InvalidParameter("KCHVMSTOR0003E", {'value': path})
    return src_type
Example #6
0
    def validate_integrity(self):
        invalid = {}
        # validate networks integrity
        invalid_networks = list(set(self.info['networks']) -
                                set(self._get_all_networks_name()))
        if invalid_networks:
            invalid['networks'] = invalid_networks

        # validate storagepools integrity
        pool_uri = self.info['storagepool']
        pool_name = pool_name_from_uri(pool_uri)
        if pool_name not in self._get_all_storagepools_name():
            invalid['storagepools'] = [pool_name]

        # validate iso integrity
        # FIXME when we support multiples cdrom devices
        iso = self.info['cdrom']
        if not (os.path.isfile(iso) or check_url_path(iso)):
            invalid['cdrom'] = [iso]

        self.info['invalid'] = invalid

        return self.info
Example #7
0
def _check_path(path):
    if check_url_path(path):
        src_type = 'network'
    # Check if path is a valid local path
    elif os.path.exists(path):
        if os.path.isfile(path):
            src_type = 'file'
        else:
            # Check if path is a valid cdrom drive
            with open('/proc/sys/dev/cdrom/info') as cdinfo:
                content = cdinfo.read()

            cds = re.findall("drive name:\t\t(.*)", content)
            if not cds:
                raise InvalidParameter("KCHVMSTOR0003E", {'value': path})

            drives = [os.path.join('/dev', p) for p in cds[0].split('\t')]
            if path not in drives:
                raise InvalidParameter("KCHVMSTOR0003E", {'value': path})

            src_type = 'block'
    else:
        raise InvalidParameter("KCHVMSTOR0003E", {'value': path})
    return src_type
Example #8
0
 def validate_distro(distro):
     if check_url_path(distro['path']):
         return distro['name']