Validate flavor data.

           Validate a list of actual flavors vs a list of expected flavors.
761503
def validate_flavor_data(self, expected, actual):
        
        self.log.debug('Validating flavor data...')
        self.log.debug('actual: {}'.format(repr(actual)))
        act = [a.name for a in actual]
        return self._validate_list_data(expected, act)
206244
def _validated(self, data):
        """"""
        errors = []
        for sub in self.schemas:
            try:
                return sub(data)
            except NotValid as ex:
                errors.extend(ex.args)

        raise NotValid(' and '.join(errors))
262584
def associate_flavor(self, flavor, body):
        """"""
        return self.post(self.flavor_profile_bindings_path %
                         (flavor), body=body)
1333964
def validate(self, value):
        """"""
        if value in list(self.choices.keys()):
            self._choice = value
            return True
        try:
            self._choice = list(self.choices.keys())[int(value)]
            return True
        except (ValueError, IndexError):
            self.error_message = '%s is not a valid choice.' % value
            return False
323338
def flavor_access_list(self, **kwargs):
        '''
        
        '''
        flavor_id = kwargs.get('flavor_id')
        nt_ks = self.compute_conn
        ret = {flavor_id: []}
        flavor_accesses = nt_ks.flavor_access.list(flavor=flavor_id, **kwargs)
        for project in flavor_accesses:
            ret[flavor_id].append(project.tenant_id)
        return ret
690597
def validate_experimental(context, param, value):
    """"""
    if value is None:
        return
    config = ExperimentConfiguration(value)
    config.validate()
    return config
483223
def _validate_list_data(self, expected, actual):
        """"""
        for e in expected:
            if e not in actual:
                return "expected item {} not found in actual list".format(e)
        return None
772743
def _validate_data(data):
    
    data_keys = set(data.keys())
    extra_keys = data_keys - set(ALLOWED_KEYS)
    missing_keys = set(REQUIRED_KEYS) - data_keys

    if extra_keys:
        raise ValueError(
            'Invalid data keys {!r}'.format(', '.join(extra_keys))
        )

    if missing_keys:
        raise ValueError(
            'Missing keys {!r}'.format(', '.join(missing_keys))
        )
994654
def _validated(self, data):
        """"""
        for sub in self.schemas:
            data = sub(data)
        return data
595904
def _validate_entities(self, stages):
        
        if not stages:
            raise TypeError(expected_type=Stage, actual_type=type(stages))

        if not isinstance(stages, list):
            stages = [stages]

        for value in stages:
            if not isinstance(value, Stage):
                raise TypeError(expected_type=Stage, actual_type=type(value))

        return stages
1148452
def verify_data(self, data):
        '''
        
        '''
        errors = []
        if 'state' not in data:
            errors.append('Missing "state" data')
        if 'fun' not in data:
            errors.append('Missing "fun" data')
        if 'name' not in data:
            errors.append('Missing "name" data')
        if data['name'] and not isinstance(data['name'], six.string_types):
            errors.append(
                'ID \'{0}\' {1}is not formed as a string, but is a {2}'.format(
                    data['name'],
                    'in SLS \'{0}\' '.format(data['__sls__'])
                        if '__sls__' in data else '',
                    type(data['name']).__name__
                )
            )
        if errors:
            return errors
        full = data['state'] + '.' + data['fun']
        if full not in self.states:
            if '__sls__' in data:
                errors.append(
                    'State \'{0}\' was not found in SLS \'{1}\''.format(
                        full,
                        data['__sls__']
                        )
                    )
                reason = self.states.missing_fun_string(full)
                if reason:
                    errors.append('Reason: {0}'.format(reason))
            else:
                errors.append(
                        'Specified state \'{0}\' was not found'.format(
                            full
                            )
                        )
        else:
            # First verify that the parameters are met
            aspec = salt.utils.args.get_function_argspec(self.states[full])
            arglen = 0
            deflen = 0
            if isinstance(aspec.args, list):
                arglen = len(aspec.args)
            if isinstance(aspec.defaults, tuple):
                deflen = len(aspec.defaults)
            for ind in range(arglen - deflen):
                if aspec.args[ind] not in data:
                    errors.append(
                        'Missing parameter {0} for state {1}'.format(
                            aspec.args[ind],
                            full
                        )
                    )
        # If this chunk has a recursive require, then it will cause a
        # recursive loop when executing, check for it
        reqdec = ''
        if 'require' in data:
            reqdec = 'require'
        if 'watch' in data:
            # Check to see if the service has a mod_watch function, if it does
            # not, then just require
            # to just require extend the require statement with the contents
            # of watch so that the mod_watch function is not called and the
            # requisite capability is still used
            if '{0}.mod_watch'.format(data['state']) not in self.states:
                if 'require' in data:
                    data['require'].extend(data.pop('watch'))
                else:
                    data['require'] = data.pop('watch')
                reqdec = 'require'
            else:
                reqdec = 'watch'
        if reqdec:
            for req in data[reqdec]:
                reqfirst = next(iter(req))
                if data['state'] == reqfirst:
                    if (fnmatch.fnmatch(data['name'], req[reqfirst])
                            or fnmatch.fnmatch(data['__id__'], req[reqfirst])):
                        err = ('Recursive require detected in SLS {0} for'
                               ' require {1} in ID {2}').format(
                                   data['__sls__'],
                                   req,
                                   data['__id__'])
                        errors.append(err)
        return errors
403136
def validate(self, *args, **kwds):
        
        if self.behavior:
            return self.behavior.validate(self, *args, **kwds)
        return True
569045
def sort_flavor_list(request, flavors, with_menu_label=True):
    
    def get_key(flavor, sort_key):
        try:
            return getattr(flavor, sort_key)
        except AttributeError:
            LOG.warning('Could not find sort key "%s". Using the default '
                        '"ram" instead.', sort_key)
            return getattr(flavor, 'ram')
    try:
        flavor_sort = getattr(settings, 'CREATE_INSTANCE_FLAVOR_SORT', {})
        sort_key = flavor_sort.get('key', 'ram')
        rev = flavor_sort.get('reverse', False)
        if not callable(sort_key):
            def key(flavor):
                return get_key(flavor, sort_key)
        else:
            key = sort_key

        if with_menu_label:
            flavor_list = [(flavor.id, '%s' % flavor.name)
                           for flavor in sorted(flavors, key=key, reverse=rev)]
        else:
            flavor_list = sorted(flavors, key=key, reverse=rev)
        return flavor_list
    except Exception:
        exceptions.handle(request,
                          _('Unable to sort instance flavors.'))
        return []
1185815
def _validate_args(env, args):
    """"""

    if all([args['cpu'], args['flavor']]):
        raise exceptions.ArgumentError(
            '[-c | --cpu] not allowed with [-f | --flavor]')

    if all([args['memory'], args['flavor']]):
        raise exceptions.ArgumentError(
            '[-m | --memory] not allowed with [-f | --flavor]')

    if all([args['dedicated'], args['flavor']]):
        raise exceptions.ArgumentError(
            '[-d | --dedicated] not allowed with [-f | --flavor]')

    if all([args['host_id'], args['flavor']]):
        raise exceptions.ArgumentError(
            '[-h | --host-id] not allowed with [-f | --flavor]')

    if all([args['userdata'], args['userfile']]):
        raise exceptions.ArgumentError(
            '[-u | --userdata] not allowed with [-F | --userfile]')

    image_args = [args['os'], args['image']]
    if all(image_args):
        raise exceptions.ArgumentError(
            '[-o | --os] not allowed with [--image]')

    while not any([args['os'], args['image']]):
        args['os'] = env.input("Operating System Code", default="", show_default=False)
        if not args['os']:
            args['image'] = env.input("Image", default="", show_default=False)
1124136
def update_flavor(self, flavor, body):
        """"""
        return self.put(self.flavor_path % (flavor), body=body)
679366
def validate(self):
        """"""
        errors = []
        app = errors.append

        if not self.hint_cores >= self.mpi_procs * self.omp_threads >= self.min_cores:
            app("self.hint_cores >= mpi_procs * omp_threads >= self.min_cores not satisfied")

        if self.omp_threads > self.hw.cores_per_node:
            app("omp_threads > hw.cores_per_node")

        if self.mem_per_proc > self.hw.mem_per_node:
            app("mem_mb >= self.hw.mem_per_node")

        if not self.max_mem_per_proc >= self.mem_per_proc >= self.min_mem_per_proc:
            app("self.max_mem_per_proc >= mem_mb >= self.min_mem_per_proc not satisfied")

        if self.priority <= 0:
            app("priority must be > 0")

        if not (1 <= self.min_cores <= self.hw.num_cores >= self.hint_cores):
            app("1 <= min_cores <= hardware num_cores >= hint_cores not satisfied")

        if errors:
            raise self.Error(str(self) + "\n".join(errors))
1294436
def flavor_access_list(flavor_id, profile=None, **kwargs):
    '''
    
    '''
    conn = _auth(profile, **kwargs)
    return conn.flavor_access_list(flavor_id=flavor_id, **kwargs)