Tony Mack | bd3b26e | 2013-04-30 17:43:48 -0400 | [diff] [blame] | 1 | import os |
Tony Mack | ed163d7 | 2013-05-02 20:05:42 -0400 | [diff] [blame] | 2 | import sys |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame^] | 3 | #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings") |
Tony Mack | bd3b26e | 2013-04-30 17:43:48 -0400 | [diff] [blame] | 4 | import time |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame^] | 5 | from core.models.site import Site |
| 6 | from openstack.manager import OpenStackManager |
Tony Mack | bd3b26e | 2013-04-30 17:43:48 -0400 | [diff] [blame] | 7 | |
| 8 | class SiteAgent: |
| 9 | def run(self): |
Tony Mack | ed163d7 | 2013-05-02 20:05:42 -0400 | [diff] [blame] | 10 | manager = OpenStackManager() |
| 11 | # exit if openstack is disable or unavailable |
| 12 | if manager.enabled and manager.has_openstack: |
| 13 | # fill in null tenant ids |
| 14 | sites = Site.objects.filter(tenant_id__in=[None, '']) |
| 15 | for site in sites: |
| 16 | # calling save() on the model should force the tenant_id to be set |
| 17 | site.os_manager = manager |
| 18 | site.save() |
Tony Mack | bd3b26e | 2013-04-30 17:43:48 -0400 | [diff] [blame] | 19 | |
| 20 | if __name__ == '__main__': |
| 21 | SiteAgent().run() |
| 22 | |