How can i obtain the resources based on the project and user selected in Horizon?

asked 2015-08-27 01:52:40 -0500

sanjana gravatar image

updated 2015-08-27 01:55:18 -0500

# I have a workflow with three fields
    class CreateAction(workflows.Action):

        project = forms.ChoiceField(label=_("Project"),
        user = forms.ChoiceField(label=_("User"),
        resource = forms.ChoiceField(label=_("Resource"),

    #Here the choices for resource must be based on the project and the user values.
    #How can i get the values of project and user from the workflow?

    def __init__(self, request, *args, **kwargs):
            super(CreateAlarmInfoAction, self).__init__(request, *args, **kwargs)
            self.fields['project'].choices = (

            self.fields['user'].choices = (

            self.fields['resource'].choices = (
    #In this method, to get a list of resources i need to pass the previously selected project and user id
        def get_resource_list_choices(self, request):
            resource_choices = [('', _("Select a resource"))]
            list_of_resources = self._get_resources(request)
            for obj in list_of_resources:
                if is not None and not in resource_choices:
            return resource_choices
    #I also have to pass the project id and user id in the ceilometer api
        def _get_resources(self, request):
            resources = []
                resources = api.ceilometer.resource_list(request)

            except Exception:
                msg = _('Resource list cannot be retrieved.')
                exceptions.handle(request, msg)
            return resources

   # I am fetching the user list as follows

     def get_user_list_choices(self, request):
            user_choices = [('', _("Select a user"))]
            list_of_users = self._get_users(request)
            for obj in list_of_users:
                user_choices.append((, obj.username))
            return user_choices

        def _get_users(self, request):
            users = []
                users = api.keystone.user_list(request)
            except Exception:
                msg = _('User list cannot be retrieved.')
                exceptions.handle(request, msg)
            return users
  #  similarly the project list is also fetched
edit retag flag offensive close merge delete