blob: 3a29969b839c37ecf9b63795e236724fbd7353b7 [file] [log] [blame]
Oleksiy Petrenkocaad2032018-04-20 14:42:46 +03001from neutronv2.common import send, get_by_name_or_uuid
2from neutronv2 import networks
3try:
4 from urllib.parse import urlencode
5except ImportError:
6 from urllib import urlencode
7
8RESOURCE_LIST_KEY = 'subnets'
9
10
11@send('get')
12def 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')
20def 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')
34def 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')
44def 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')
51def 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')
61def subnet_delete(subnet_id, **kwargs):
62 url = '/subnets/{}'.format(subnet_id)
63 return url, {}