74
75
"args": {"network_id": network_ref['id']}})
77
def bind_vnics_to_ports(context, vnic_ids, is_vpn):
78
"""Gets a fixed ips from the pool."""
80
_get_network_topic(context),
81
{"method": "allocate_fixed_ips",
82
"args": {"vnic_ids": vnic_ids,
85
def setup_compute_network(context, vnic_ids, is_vpn):
87
driver = utils.import_object(FLAGS.ns_vlan_network_agent_driver)
88
for vnic_id in vnic_ids:
89
network_ref = db_api.network_get_by_ethernet_card(context, vnic_id)
90
driver.ensure_vlan_bridge(network_ref['vlan'],
91
network_ref['bridge'])
93
def teardown_compute_network(context, vnic_ids):
94
"""Clean up compute node."""
95
for vnic_id in vnic_ids:
96
fixed_ip = vnic_id.get('fixed_ip')
97
if not FLAGS.stub_network and fixed_ip:
98
floating_ips = fixed_ip.get('floating_ips') or []
100
for floating_ip in floating_ips:
101
address = floating_ip['address']
103
network_topic = _queue_get_for(context,
104
FLAGS.ns_vlan_network_topic,
109
{"method": "disassociate_floating_ip",
110
"args": {"floating_address": address}})
112
address = fixed_ip['address']
114
# NOTE(vish): Currently, nothing needs to be done on the
115
# network node until release. If this changes,
117
db_api.fixed_ip_update(context.elevated(), address,
120
def requires_file_injection():
121
"""This service does not requires file injection."""
124
def get_network_info(context, vnic_id):
125
"""Gets all the data related to IP network.
126
The output is a dictionary containing the following keys:
127
cidr, cidrv6, netmask, netmask_v6 gateway, gateway_v6,
128
dhcp_server, broadcast, dns, ra_server, mac_address,
129
ip_address, bridge, and address_v6
131
ethernet_card = db_api.ethernet_card_get(context, vnic_id)
132
if not ethernet_card:
133
raise ValueError("Invalid vnic ID!")
135
# Get the IP address associated with this VNIC
136
ip_address = db_api.ip_address_get_by_ethernet_card(context,
139
raise ValueError("VNIC is not mapped to IP!")
141
network = ip_address.network
142
if network['cidr_v6']:
143
ipv6_addr = utils.to_global_ipv6(network['cidr_v6'],
144
ethernet_card['mac_address'])
148
net, mask = common.get_net_and_mask(network['cidr'])
149
return dict(mac_address=ethernet_card['mac_address'],
150
ip_address=ip_address['address'], bridge=network['bridge'],
151
cidr=network['cidr'], netmask=network['netmask'],
152
gateway=network['gateway'], broadcast=network['broadcast'],
153
dns=network['dns'], dhcp_server=network['gateway'],
154
cidr_v6=network['cidr_v6'], address_v6=ipv6_addr,
155
ra_server=network['ra_server'],
156
netmask_v6=network['netmask_v6'],
157
gateway_v6=network['gateway_v6'],
78
class NetworkAgentService(object):
79
"""An OpenStack network agent service object."""
81
interface.implements(service.INetworkOpenStackApiService)
83
def bind_vnics_to_ports(self, context, vnic_ids, is_vpn):
84
"""Gets a fixed ips from the pool.
87
context: Nova context needed for DB access.
88
vnic_ids: list of VNIC IDs
89
is_vpn: Boolean to check if the call is for VPN.
92
_get_network_topic(context),
93
{"method": "allocate_fixed_ips",
94
"args": {"vnic_ids": vnic_ids,
97
def setup_compute_network(self, context, vnic_ids, is_vpn):
98
"""Set up the compute node for networking.
101
context: Nova context needed for DB access.
102
vnic_ids: list of VNIC IDs
103
is_vpn: Boolean to check if the call is for VPN.
105
driver = utils.import_object(FLAGS.ns_vlan_network_agent_driver)
106
for vnic_id in vnic_ids:
107
network_ref = db_api.network_get_by_ethernet_card(context, vnic_id)
108
driver.ensure_vlan_bridge(network_ref['vlan'],
109
network_ref['bridge'])
111
def teardown_compute_network(self, context, vnic_ids):
112
"""Clean up the compute node.
115
context: Nova context needed for DB access.
116
vnic_ids: list of VNIC IDs
118
for vnic_id in vnic_ids:
119
fixed_ip = vnic_id.get('fixed_ip')
120
if not FLAGS.stub_network and fixed_ip:
121
floating_ips = fixed_ip.get('floating_ips') or []
123
for floating_ip in floating_ips:
124
address = floating_ip['address']
126
network_topic = _queue_get_for(context,
127
FLAGS.ns_vlan_network_topic,
132
{"method": "disassociate_floating_ip",
133
"args": {"floating_address": address}})
135
address = fixed_ip['address']
137
# NOTE(vish): Currently, nothing needs to be done on the
138
# network node until release. If this changes,
140
db_api.fixed_ip_update(context.elevated(), address,
143
def requires_file_injection(self):
144
"""This service does not requires file injection.
148
def get_network_info(self, context, vnic_id):
149
"""Gets network data for a given VNIC.
152
context: Nova context needed for DB access.
153
vnic_id: VNIC ID to get the network information for.
156
A dictionary containing the following keys:
157
cidr, cidrv6, netmask, netmask_v6 gateway, gateway_v6,
158
dhcp_server, broadcast, dns, ra_server, mac_address,
159
ip_address, bridge, and address_v6
161
ethernet_card = db_api.ethernet_card_get(context, vnic_id)
162
if not ethernet_card:
163
raise ValueError("Invalid vnic ID!")
165
# Get the IP address associated with this VNIC
166
ip_address = db_api.ip_address_get_by_ethernet_card(context,
169
raise ValueError("VNIC is not mapped to IP!")
171
network = ip_address.network
172
if network['cidr_v6']:
173
ipv6_addr = utils.to_global_ipv6(network['cidr_v6'],
174
ethernet_card['mac_address'])
178
net, mask = common.get_net_and_mask(network['cidr'])
179
return dict(mac_address=ethernet_card['mac_address'],
180
ip_address=ip_address['address'], bridge=network['bridge'],
181
cidr=network['cidr'], netmask=network['netmask'],
182
gateway=network['gateway'], broadcast=network['broadcast'],
183
dns=network['dns'], dhcp_server=network['gateway'],
184
cidr_v6=network['cidr_v6'], address_v6=ipv6_addr,
185
ra_server=network['ra_server'],
186
netmask_v6=network['netmask_v6'],
187
gateway_v6=network['gateway_v6'],