Oleksiy Petrenko | caad203 | 2018-04-20 14:42:46 +0300 | [diff] [blame] | 1 | from neutronv2.common import send, get_by_name_or_uuid |
| 2 | from neutronv2 import networks |
| 3 | try: |
| 4 | from urllib.parse import urlencode |
| 5 | except ImportError: |
| 6 | from urllib import urlencode |
| 7 | |
| 8 | RESOURCE_LIST_KEY = 'subnets' |
| 9 | |
| 10 | |
| 11 | @send('get') |
| 12 | def subnet_list(**kwargs): |
| 13 | url = '/subnets?{}'.format(urlencode(kwargs)) |
| 14 | return url, {} |
| 15 | |
| 16 | |
| 17 | @get_by_name_or_uuid(networks.network_list, networks.RESOURCE_LIST_KEY, |
| 18 | res_id_key='network_id') |
| 19 | @send('post') |
| 20 | def subnet_create(network_id, ip_version, cidr, **kwargs): |
| 21 | url = '/subnets' |
| 22 | json = { |
| 23 | 'subnet': { |
| 24 | 'network_id': network_id, |
| 25 | 'ip_version': ip_version, |
| 26 | 'cidr': cidr, |
| 27 | } |
| 28 | } |
| 29 | json['subnet'].update(kwargs) |
| 30 | return url, {'json': json} |
| 31 | |
| 32 | |
| 33 | @send('post') |
| 34 | def subnet_bulk_create(subnets, **kwargs): |
| 35 | url = '/subnets' |
| 36 | json = { |
| 37 | 'subnets': subnets, |
| 38 | } |
| 39 | return url, {'json': json} |
| 40 | |
| 41 | |
| 42 | @get_by_name_or_uuid(subnet_list, RESOURCE_LIST_KEY) |
| 43 | @send('get') |
| 44 | def subnet_get_details(subnet_id, **kwargs): |
| 45 | url = '/subnets/{}'.format(subnet_id) |
| 46 | return url, {} |
| 47 | |
| 48 | |
| 49 | @get_by_name_or_uuid(subnet_list, RESOURCE_LIST_KEY) |
| 50 | @send('put') |
| 51 | def subnet_update(subnet_id, **kwargs): |
| 52 | url = '/subnets/{}'.format(subnet_id) |
| 53 | json = { |
| 54 | 'subnet': kwargs, |
| 55 | } |
| 56 | return url, {'json': json} |
| 57 | |
| 58 | |
| 59 | @get_by_name_or_uuid(subnet_list, RESOURCE_LIST_KEY) |
| 60 | @send('delete') |
| 61 | def subnet_delete(subnet_id, **kwargs): |
| 62 | url = '/subnets/{}'.format(subnet_id) |
| 63 | return url, {} |