Ask Your Question
0

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

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

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

Comments

Have you looked at the OpenStack API documentation? http://developer.openstack.org/api-re...

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

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

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

1 answer

Sort by ยป oldest newest most voted
2

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

sanjana gravatar image

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

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

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

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:
        project_choices.append((obj.id, obj.name))
    return project_choices

def _get_projects(self, request):
    projects = []
    try:
        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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

2 followers

Stats

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

Seen: 332 times

Last updated: Aug 25 '15