1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# Copyright (c) 2017 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import logging
from vio.pub.msapi.extsys import get_vim_by_id
from vio.pub.vim.drivers.vimsdk import neutron_v2_0
from vio.pub.vim.vimapi.network.OperateNetwork import BaseNet,translate
logger = logging.getLogger(__name__)
class OperateSubnet(BaseNet):
keys_mapping = {"tenantId": "project_id",
"networkId": "network_id",
"ipVersion": "ip_version",
"gaetwayIp": "gateway_ip",
"dnsNameservers": "dns_nameservers",
"hostRoutes": "host_routes",
"allocationPools": "allocation_pools",
"enableDhcp": "is_dhcp_enabled"
}
def ___init__(self, params):
super(OperateSubnet, self).__init__(params)
def _convert(self, subnet):
result = {}
result['status'] = 'ok'
result['id'] = subnet.id
result['networkId'] = subnet.network_id
result['name'] = subnet.name
result['allocationPools'] = subnet.allocation_pools
result['gatewayIp'] = subnet.gateway_ip
result['dnsNameServers'] = subnet.dns_nameservers
result['ipVersion'] = subnet.ip_version
result['enableDhcp'] = subnet.is_dhcp_enabled
result['hostRoutes'] = subnet.host_routes
result['cidr'] = subnet.cidr
return result
def create_subnet(self, vimid, tenantid, body):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info, tenantid)
body = translate(self.keys_mapping, body)
subnet = network.subnet_create(**body)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
resp = self._convert(subnet)
resp.update(vim_dict)
return resp
def list_subnet(self, vimid, tenantid, subnetid, ignore_missing=False):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info, tenantid)
subnet = network.subnet_get(subnetid, ignore_missing=ignore_missing)
if subnet is None:
return subnet
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
resp = self._convert(subnet)
resp.update(vim_dict)
return resp
def delete_subnet(self, vimid, tenantid, subnetid):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info, tenantid)
return network.subnet_delete(subnetid)
def list_subnets(self, vimid, tenantid, **query):
vim_info = self.get_vim_info(vimid)
network = self.auth(vim_info, tenantid)
query.update({"project_id": tenantid})
resp = network.subnets_get(**query)
vim_dict = {"vimName": vim_info['name'], "vimId": vim_info['vimId'], "tenantId": tenantid}
subnets = {'subnets': []}
if resp:
for subnet in resp:
subnets['subnets'].append(self._convert(subnet))
subnets.update(vim_dict)
return subnets
|