Ask Your Question

How to get a list of projects and provide it as a dropdown menu in openstack

asked 2015-08-24 00:15:37 -0500

sanjana gravatar image

How to get the list of projects available in openstack? I want to provide these project names as dropdown option for forms.

edit retag flag offensive close merge delete


Have you looked at the OpenStack API documentation?

larsks gravatar imagelarsks ( 2015-08-24 11:13:53 -0500 )edit

Can you please tell me how i can use the same api in Horizon?

sanjana gravatar imagesanjana ( 2015-08-24 22:04:57 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-25 06:25:41 -0500

sanjana gravatar image

updated 2015-08-25 06:26:46 -0500

project = forms.ChoiceField(label=_("Project"), required=True)

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

def get_project_list_choices(self, request):
    project_choices = [('', _("Select a Project"))]
    list_of_projects = self._get_projects(request)
    for obj in list_of_projects:
    return project_choices

def _get_projects(self, request):
    projects = []
        projects, has_more = api.keystone.tenant_list(request)
    except Exception:
        msg = _('Project list cannot be retrieved.')
        exceptions.handle(request, msg)
    return projects

I am able to display the list of projects as a dropdown menu

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools



Asked: 2015-08-24 00:15:37 -0500

Seen: 449 times

Last updated: Aug 25 '15