Pagination With Horizon And Multiple Tables In The Same View

I was making a custom dashboard for Horizon the other day. In one of my views I was using tabs and in each tab I had a table that supported pagination. There was a problem where when I would go to tab 2 page 2 I would get an error about not being able to load data for tab 1. It was pretty clear to me this was an issue with pagination. I tried various things to work around the bug I had but nothing seemed to work. I took the advice a good friend of mine always gives me when I get stuck “Dont trust the docs, they lie. Go read the code its the only source of truth.” so I did just that. I quickly found the answer to my problem. Inside the tables base class I found the class had a variable for pagination that defaulted to “marker” and in the comments for that particular variable it said “When using multiple tables in a single view this will need to be changed to differentiate between the tables.”. That was simple enough, like always I wish I had gone to read the code sooner. Now to implement the fix and get rid of my bug all I had to do was go to my table classes and add the following bits of code:

class ImageTable(tables.DataTable):
    name = tables.Column("name", verbose_name=_("Name"),
                         link="horizon:admin:images:detail")
    properties = tables.Column(images_md_to_str, verbose_name=_("Metadata"))

    class Meta(object):
        name = "images"
        verbose_name = _("Images")
        table_actions = (MetadataFilterAction, CreateImage, DeleteImage, )
        launch_actions = ()
        if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False):
            launch_actions = (LaunchImage,) + launch_actions
        if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True):
            launch_actions = (LaunchImageNG,) + launch_actions
        row_actions = launch_actions + (CreateVolumeFromImage,
                                        EditImage, UpdateMetadataImg,
                                        DeleteImage,)
        # Define the following 2 variables to fix pagination issues
        pagination_param = 'image_marker'
        prev_pagination_param = 'prev_image_marker'

Defining the pagination_param & prev_pagination_param and using a unique name for each class is all it takes to fix that issue. I hope this info comes in handy for someone out there. I spent more time on trying to fix this than Id care to admit 😉

Happy Stacking!

Adding Swift to DevStack

If you find yourself needing to enable Swift on DevStack and you already have DevStack deployed and running and do not want to redo the whole thing I can relate. I found myself in this exact spot tonight. By default DevStack does not enable Swift, but its really trivial to enable it. The tricky part may be once its enabled how do you make it work without just redoing the whole thing?

Getting Swift enabled is pretty simple. First open your local.conf file in your /home/stack/devstack directory using your favorite editor. Next add the following lines to it:
enable_service s-proxy s-object s-container s-account
And save the file. If you havent built your DevStack yet now you can simply proceed with ./stack.sh If you have already built your DevStack and its up and running simply proceed with ./unstack.sh and when that completes then proceed with the ./stack.sh During the install it will prompt you for a hash/passphrase and I just used the same password I used for the initial DevStack install. Once this process finishes you should have Swift added to your DevStack. Happy Stacking!