def _collect_flavors(self, parsed_args):
        """Collect nova flavors in use.

        :returns: dictionary flavor name -> (flavor object, scale)
        """
        compute_client = self.app.client_manager.compute

        flavors = {f.name: f for f in compute_client.flavors.list()}
        result = {}

        message = "Provided --{}-flavor, '{}', does not exist"

        for target, (flavor_name,
                     scale) in (utils.get_roles_info(parsed_args).items()):
            if flavor_name is None or not scale:
                self.log.debug("--{}-flavor not used".format(target))
                continue

            try:
                flavor = flavors[flavor_name]
            except KeyError:
                raise exceptions.ProfileMatchingError(
                    message.format(target, flavor_name))

            result[flavor_name] = (flavor, scale)

        return result
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        bm_client = self.app.client_manager.baremetal

        flavors = self._collect_flavors(parsed_args)

        errors, warnings = utils.assign_and_verify_profiles(
            bm_client,
            flavors,
            assign_profiles=True,
            dry_run=parsed_args.dry_run)
        if errors:
            raise exceptions.ProfileMatchingError(
                _('Failed to validate and assign profiles.'))