Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 1 | from types import StringTypes |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 2 | from core.models import DeploymentNetwork |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 3 | from django.contrib.auth import authenticate |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 4 | |
| 5 | def _get_deployment_networks(filter): |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 6 | if isinstance(filter, StringTypes) and filter.isdigit(): |
| 7 | filter = int(filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 8 | if isinstance(filter, int): |
| 9 | deployment_networks = DeploymentNetwork.objects.filter(id=filter) |
| 10 | elif isinstance(filter, StringTypes): |
| 11 | deployment_networks = DeploymentNetwork.objects.filter(name=filter) |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 12 | elif isinstance(filter, dict): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 13 | deployment_networks = DeploymentNetwork.objects.filter(**filter) |
| 14 | else: |
| 15 | deployment_networks = [] |
| 16 | return deployment_networks |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 17 | |
| 18 | def add_deployment_network(auth, name): |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 19 | user = authenticate(username=auth.get('username'), |
| 20 | password=auth.get('password')) |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 21 | deployment = DeploymentNetwork(name=name) |
| 22 | deployment.save() |
| 23 | return deployment |
| 24 | |
| 25 | def delete_deployment_network(auth, filter={}): |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 26 | user = authenticate(username=auth.get('username'), |
| 27 | password=auth.get('password')) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 28 | deployments = _get_deployment_networks(filter) |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 29 | for deployment in deployments: |
| 30 | deployment.delete() |
| 31 | return 1 |
| 32 | |
| 33 | def get_deployment_networks(auth, filter={}): |
Tony Mack | 09080c6 | 2013-05-06 16:57:54 -0400 | [diff] [blame] | 34 | user = authenticate(username=auth.get('username'), |
| 35 | password=auth.get('password')) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 36 | deployments = _get_deployment_networks(filter) |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 37 | return deployments |
| 38 | |
| 39 | |
| 40 | |