Oleksiy Petrenko | caad203 | 2018-04-20 14:42:46 +0300 | [diff] [blame^] | 1 | from neutronv2.common import send, get_by_name_or_uuid |
| 2 | try: |
| 3 | from urllib.parse import urlencode |
| 4 | except ImportError: |
| 5 | from urllib import urlencode |
| 6 | |
| 7 | RESOURCE_LIST_KEY = 'networks' |
| 8 | |
| 9 | |
| 10 | @send('get') |
| 11 | def network_list(**kwargs): |
| 12 | url = '/networks?{}'.format(urlencode(kwargs)) |
| 13 | return url, {} |
| 14 | |
| 15 | |
| 16 | @get_by_name_or_uuid(network_list, RESOURCE_LIST_KEY) |
| 17 | @send('get') |
| 18 | def network_get_details(network_id, **kwargs): |
| 19 | url = '/networks/{}?{}'.format(network_id, urlencode(kwargs)) |
| 20 | return url, {} |
| 21 | |
| 22 | |
| 23 | @get_by_name_or_uuid(network_list, RESOURCE_LIST_KEY) |
| 24 | @send('put') |
| 25 | def network_update(network_id, **kwargs): |
| 26 | url = '/networks/{}'.format(network_id) |
| 27 | json = { |
| 28 | 'network': kwargs, |
| 29 | } |
| 30 | return url, {'json': json} |
| 31 | |
| 32 | |
| 33 | @get_by_name_or_uuid(network_list, RESOURCE_LIST_KEY) |
| 34 | @send('delete') |
| 35 | def network_delete(network_id, **kwargs): |
| 36 | url = '/networks/{}'.format(network_id) |
| 37 | return url, {} |
| 38 | |
| 39 | |
| 40 | @send('post') |
| 41 | def network_create(**kwargs): |
| 42 | url = '/networks' |
| 43 | json = { |
| 44 | 'network': kwargs, |
| 45 | } |
| 46 | return url, {'json': json} |
| 47 | |
| 48 | |
| 49 | @send('post') |
| 50 | def network_bulk_create(networks, **kwargs): |
| 51 | url = '/networks' |
| 52 | json = { |
| 53 | 'networks': networks, |
| 54 | } |
| 55 | return url, {'json': json} |