Ask Your Question
0

How to properly call __init__ on Horizon workflows.Action

asked 2015-01-29 11:48:35 -0500

eugene.goldberg gravatar image

In my custom Workflow, I have an action, which, among other things, should present the user with a list of available OpenStack images and flavors. My assumption is, that the best place to populate those two lists are within the __init__ method. Currently, mine looks like this:

class SetWorkflowInfoAction(workflows.Action):
    name = forms.CharField(max_length="255", label=_("Workload Name"))
    description = forms.CharField(widget=forms.Textarea,
                                  label=_("Description"), required=False)
    image_choices = []
    images = forms.ChoiceField(label=_("Images"), choices=image_choices)
    flavor_choices = []
    flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices)

    def __init__(self, request, image_choices=image_choices, flavor_choices=flavor_choices,
                 *args, **kwargs):
        super(SetWorkflowInfoAction, self).__init__(request, *args, **kwargs)

        image_choices = []
        flavor_choices = []

        images, self._more, self._prev = api.glance.image_list_detailed(
            self.request)
        flavors = api.nova.flavor_list(request, True)

        for image in images:
                image_choices.append((image.id, image.name))
        if len(image_choices) > 1:
            image_choices.insert(0, ('', _("Select an Image")))
        self.fields['images'].choices = image_choices

        for flavor in flavors:
                flavor_choices.append((flavor.id, flavor.name))
        if len(flavor_choices) > 1:
            flavor_choices.insert(0, ('', _("Select an Flavor")))
        self.fields['flavors'].choices = flavor_choices

    class Meta:
        name = _("Basic Workload Information")
        help_text = _("")
        slug = "set_workflow_info"

The trouble is - when I get to the point of calling __init__ I get this error:

File "/home/eugene/dev/horizon/openstack_dashboard/dashboards/mydashboard/workloads_panel/workflows.py", line 20, in __init__
    super(SetWorkflowInfoAction, self).__init__(request, *args, **kwargs)
TypeError: __init__() takes at least 3 arguments (2 given)

What is the proper way to call __init__ in such a way, so I could populate my images and flavors lists?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-01-29 16:02:03 -0500

eugene.goldberg gravatar image

All I had to do, is not to include these into the top-level init:

 image_choices=image_choices, flavor_choices=flavor_choices,

So the working version looks like this:

class SetWorkflowInfoAction(workflows.Action):
    name = forms.CharField(max_length="255", label=_("Workload Name"))
    description = forms.CharField(widget=forms.Textarea,
                                  label=_("Description"), required=False)
    image_choices = []
    images = forms.ChoiceField(label=_("Images"), choices=image_choices)
    flavor_choices = []
    flavors = forms.ChoiceField(label=_("Flavors"), choices=flavor_choices)

    def __init__(self, request,
                 *args, **kwargs):
        super(SetWorkflowInfoAction, self).__init__(request, *args, **kwargs)

        image_choices = []
        flavor_choices = []

        images, self._more, self._prev = api.glance.image_list_detailed(
            self.request)
        flavors = api.nova.flavor_list(request, True)

        for image in images:
                image_choices.append((image.id, image.name))
        if len(image_choices) > 1:
            image_choices.insert(0, ('', _("Select an Image")))
        self.fields['images'].choices = image_choices

        for flavor in flavors:
                flavor_choices.append((flavor.id, flavor.name))
        if len(flavor_choices) > 1:
            flavor_choices.insert(0, ('', _("Select an Flavor")))
        self.fields['flavors'].choices = flavor_choices

    class Meta:
        name = _("Basic Workload Information")
        help_text = _("")
        slug = "set_workflow_info"
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

1 follower

Stats

Asked: 2015-01-29 11:48:35 -0500

Seen: 159 times

Last updated: Jan 29 '15