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 openstack.client import OpenStackClient |
| 3 | from openstack.driver import OpenStackDriver |
| 4 | from core.api.auth import auth_check |
| 5 | from core.models import DeploymentNetwork |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 6 | |
| 7 | def _get_deployment_networks(filter): |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 8 | if isinstance(filter, StringTypes) and filter.isdigit(): |
| 9 | filter = int(filter) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 10 | if isinstance(filter, int): |
| 11 | deployment_networks = DeploymentNetwork.objects.filter(id=filter) |
| 12 | elif isinstance(filter, StringTypes): |
| 13 | deployment_networks = DeploymentNetwork.objects.filter(name=filter) |
Tony Mack | 5df6c55 | 2013-04-11 21:24:17 -0400 | [diff] [blame] | 14 | elif isinstance(filter, dict): |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 15 | deployment_networks = DeploymentNetwork.objects.filter(**filter) |
| 16 | else: |
| 17 | deployment_networks = [] |
| 18 | return deployment_networks |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 19 | |
| 20 | def add_deployment_network(auth, name): |
| 21 | auth_check(auth) |
| 22 | deployment = DeploymentNetwork(name=name) |
| 23 | deployment.save() |
| 24 | return deployment |
| 25 | |
| 26 | def delete_deployment_network(auth, filter={}): |
| 27 | auth_check(auth) |
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={}): |
| 34 | auth_check(auth) |
Tony Mack | 29c287f | 2013-04-11 21:07:16 -0400 | [diff] [blame] | 35 | deployments = _get_deployment_networks(filter) |
Tony Mack | 2d81e63 | 2013-04-09 02:34:10 -0400 | [diff] [blame] | 36 | return deployments |
| 37 | |
| 38 | |
| 39 | |