1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Client side of the network RPC API.
21
from nova.openstack.common import cfg
22
from nova.openstack.common import jsonutils
23
from nova.openstack.common import rpc
24
from nova.openstack.common.rpc import proxy as rpc_proxy
27
CONF.import_opt('network_topic', 'nova.config')
30
class NetworkAPI(rpc_proxy.RpcProxy):
31
'''Client side of the network rpc API.
35
1.0 - Initial version.
36
1.1 - Adds migrate_instance_[start|finish]
37
1.2 - Make migrate_instance_[start|finish] a little more flexible
41
# NOTE(russellb): This is the default minimum version that the server
42
# (manager) side must implement unless otherwise specified using a version
43
# argument to self.call()/cast()/etc. here. It should be left as X.0 where
44
# X is the current major API version (1.0, 2.0, ...). For more information
45
# about rpc API versioning, see the docs in
46
# openstack/common/rpc/dispatcher.py.
48
BASE_RPC_API_VERSION = '1.0'
50
def __init__(self, topic=None):
51
topic = topic if topic else CONF.network_topic
52
super(NetworkAPI, self).__init__(
54
default_version=self.BASE_RPC_API_VERSION)
56
def get_all_networks(self, ctxt):
57
return self.call(ctxt, self.make_msg('get_all_networks'))
59
def get_network(self, ctxt, network_uuid):
60
return self.call(ctxt, self.make_msg('get_network',
61
network_uuid=network_uuid))
63
# TODO(russellb): Convert this to named arguments. It's a pretty large
64
# list, so unwinding it all is probably best done in its own patch so it's
66
def create_networks(self, ctxt, **kwargs):
67
return self.call(ctxt, self.make_msg('create_networks', **kwargs))
69
def delete_network(self, ctxt, uuid, fixed_range):
70
return self.call(ctxt, self.make_msg('delete_network',
71
uuid=uuid, fixed_range=fixed_range))
73
def disassociate_network(self, ctxt, network_uuid):
74
return self.call(ctxt, self.make_msg('disassociate_network',
75
network_uuid=network_uuid))
77
def get_fixed_ip(self, ctxt, id):
78
return self.call(ctxt, self.make_msg('get_fixed_ip', id=id))
80
def get_fixed_ip_by_address(self, ctxt, address):
81
return self.call(ctxt, self.make_msg('get_fixed_ip_by_address',
84
def get_floating_ip(self, ctxt, id):
85
return self.call(ctxt, self.make_msg('get_floating_ip', id=id))
87
def get_floating_pools(self, ctxt):
88
return self.call(ctxt, self.make_msg('get_floating_pools'))
90
def get_floating_ip_by_address(self, ctxt, address):
91
return self.call(ctxt, self.make_msg('get_floating_ip_by_address',
94
def get_floating_ips_by_project(self, ctxt):
95
return self.call(ctxt, self.make_msg('get_floating_ips_by_project'))
97
def get_floating_ips_by_fixed_address(self, ctxt, fixed_address):
98
return self.call(ctxt, self.make_msg(
99
'get_floating_ips_by_fixed_address',
100
fixed_address=fixed_address))
102
def get_instance_id_by_floating_address(self, ctxt, address):
103
return self.call(ctxt, self.make_msg(
104
'get_instance_id_by_floating_address',
107
def get_backdoor_port(self, ctxt):
108
return self.call(ctxt, self.make_msg('get_backdoor_port'))
110
def get_vifs_by_instance(self, ctxt, instance_id):
111
# NOTE(vish): When the db calls are converted to store network
112
# data by instance_uuid, this should pass uuid instead.
113
return self.call(ctxt, self.make_msg('get_vifs_by_instance',
114
instance_id=instance_id))
116
def get_vif_by_mac_address(self, ctxt, mac_address):
117
return self.call(ctxt, self.make_msg('get_vif_by_mac_address',
118
mac_address=mac_address))
120
def allocate_floating_ip(self, ctxt, project_id, pool, auto_assigned):
121
return self.call(ctxt, self.make_msg('allocate_floating_ip',
122
project_id=project_id, pool=pool, auto_assigned=auto_assigned))
124
def deallocate_floating_ip(self, ctxt, address, affect_auto_assigned):
125
return self.call(ctxt, self.make_msg('deallocate_floating_ip',
126
address=address, affect_auto_assigned=affect_auto_assigned))
128
def associate_floating_ip(self, ctxt, floating_address, fixed_address,
129
affect_auto_assigned):
130
return self.call(ctxt, self.make_msg('associate_floating_ip',
131
floating_address=floating_address, fixed_address=fixed_address,
132
affect_auto_assigned=affect_auto_assigned))
134
def disassociate_floating_ip(self, ctxt, address, affect_auto_assigned):
135
return self.call(ctxt, self.make_msg('disassociate_floating_ip',
136
address=address, affect_auto_assigned=affect_auto_assigned))
138
def allocate_for_instance(self, ctxt, instance_id, instance_uuid,
139
project_id, host, rxtx_factor, vpn,
141
return self.call(ctxt, self.make_msg('allocate_for_instance',
142
instance_id=instance_id, instance_uuid=instance_uuid,
143
project_id=project_id, host=host, rxtx_factor=rxtx_factor,
144
vpn=vpn, requested_networks=requested_networks))
146
def deallocate_for_instance(self, ctxt, instance_id, project_id, host):
147
return self.call(ctxt, self.make_msg('deallocate_for_instance',
148
instance_id=instance_id, project_id=project_id, host=host))
150
def add_fixed_ip_to_instance(self, ctxt, instance_id, host, network_id):
151
return self.call(ctxt, self.make_msg('add_fixed_ip_to_instance',
152
instance_id=instance_id, host=host, network_id=network_id))
154
def remove_fixed_ip_from_instance(self, ctxt, instance_id, host, address):
155
return self.call(ctxt, self.make_msg('remove_fixed_ip_from_instance',
156
instance_id=instance_id, host=host, address=address))
158
def add_network_to_project(self, ctxt, project_id, network_uuid):
159
return self.call(ctxt, self.make_msg('add_network_to_project',
160
project_id=project_id, network_uuid=network_uuid))
162
def get_instance_nw_info(self, ctxt, instance_id, instance_uuid,
163
rxtx_factor, host, project_id):
164
return self.call(ctxt, self.make_msg('get_instance_nw_info',
165
instance_id=instance_id, instance_uuid=instance_uuid,
166
rxtx_factor=rxtx_factor, host=host, project_id=project_id))
168
def validate_networks(self, ctxt, networks):
169
return self.call(ctxt, self.make_msg('validate_networks',
172
def get_instance_uuids_by_ip_filter(self, ctxt, filters):
173
return self.call(ctxt, self.make_msg('get_instance_uuids_by_ip_filter',
176
def get_dns_domains(self, ctxt):
177
return self.call(ctxt, self.make_msg('get_dns_domains'))
179
def add_dns_entry(self, ctxt, address, name, dns_type, domain):
180
return self.call(ctxt, self.make_msg('add_dns_entry', address=address,
181
name=name, dns_type=dns_type, domain=domain))
183
def modify_dns_entry(self, ctxt, address, name, domain):
184
return self.call(ctxt, self.make_msg('modify_dns_entry',
185
address=address, name=name, domain=domain))
187
def delete_dns_entry(self, ctxt, name, domain):
188
return self.call(ctxt, self.make_msg('delete_dns_entry',
189
name=name, domain=domain))
191
def delete_dns_domain(self, ctxt, domain):
192
return self.call(ctxt, self.make_msg('delete_dns_domain',
195
def get_dns_entries_by_address(self, ctxt, address, domain):
196
return self.call(ctxt, self.make_msg('get_dns_entries_by_address',
197
address=address, domain=domain))
199
def get_dns_entries_by_name(self, ctxt, name, domain):
200
return self.call(ctxt, self.make_msg('get_dns_entries_by_name',
201
name=name, domain=domain))
203
def create_private_dns_domain(self, ctxt, domain, av_zone):
204
return self.call(ctxt, self.make_msg('create_private_dns_domain',
205
domain=domain, av_zone=av_zone))
207
def create_public_dns_domain(self, ctxt, domain, project):
208
return self.call(ctxt, self.make_msg('create_public_dns_domain',
209
domain=domain, project=project))
211
def setup_networks_on_host(self, ctxt, instance_id, host, teardown):
212
# NOTE(tr3buchet): the call is just to wait for completion
213
return self.call(ctxt, self.make_msg('setup_networks_on_host',
214
instance_id=instance_id, host=host, teardown=teardown))
216
def set_network_host(self, ctxt, network_ref):
217
network_ref_p = jsonutils.to_primitive(network_ref)
218
return self.call(ctxt, self.make_msg('set_network_host',
219
network_ref=network_ref_p))
221
def rpc_setup_network_on_host(self, ctxt, network_id, teardown, host):
222
# NOTE(tr3buchet): the call is just to wait for completion
223
return self.call(ctxt, self.make_msg('rpc_setup_network_on_host',
224
network_id=network_id, teardown=teardown),
225
topic=rpc.queue_get_for(ctxt, self.topic, host))
227
# NOTE(russellb): Ideally this would not have a prefix of '_' since it is
228
# a part of the rpc API. However, this is how it was being called when the
229
# 1.0 API was being documented using this client proxy class. It should be
230
# changed if there was ever a 2.0.
231
def _rpc_allocate_fixed_ip(self, ctxt, instance_id, network_id, address,
233
return self.call(ctxt, self.make_msg('_rpc_allocate_fixed_ip',
234
instance_id=instance_id, network_id=network_id,
235
address=address, vpn=vpn),
236
topic=rpc.queue_get_for(ctxt, self.topic, host))
238
def deallocate_fixed_ip(self, ctxt, address, host):
239
return self.call(ctxt, self.make_msg('deallocate_fixed_ip',
240
address=address, host=host),
241
topic=rpc.queue_get_for(ctxt, self.topic, host))
243
# NOTE(russellb): Ideally this would not have a prefix of '_' since it is
244
# a part of the rpc API. However, this is how it was being called when the
245
# 1.0 API was being documented using this client proxy class. It should be
246
# changed if there was ever a 2.0.
247
def _associate_floating_ip(self, ctxt, floating_address, fixed_address,
249
return self.call(ctxt, self.make_msg('_associate_floating_ip',
250
floating_address=floating_address, fixed_address=fixed_address,
251
interface=interface),
252
topic=rpc.queue_get_for(ctxt, self.topic, host))
254
# NOTE(russellb): Ideally this would not have a prefix of '_' since it is
255
# a part of the rpc API. However, this is how it was being called when the
256
# 1.0 API was being documented using this client proxy class. It should be
257
# changed if there was ever a 2.0.
258
def _disassociate_floating_ip(self, ctxt, address, interface, host):
259
return self.call(ctxt, self.make_msg('_disassociate_floating_ip',
260
address=address, interface=interface),
261
topic=rpc.queue_get_for(ctxt, self.topic, host))
263
def lease_fixed_ip(self, ctxt, address, host):
264
self.cast(ctxt, self.make_msg('lease_fixed_ip', address=address),
265
topic=rpc.queue_get_for(ctxt, self.topic, host))
267
def release_fixed_ip(self, ctxt, address, host):
268
self.cast(ctxt, self.make_msg('release_fixed_ip', address=address),
269
topic=rpc.queue_get_for(ctxt, self.topic, host))
271
def migrate_instance_start(self, ctxt, instance_uuid, rxtx_factor,
272
project_id, source_compute, dest_compute,
273
floating_addresses, host=None):
274
topic = rpc.queue_get_for(ctxt, self.topic, host)
275
return self.call(ctxt, self.make_msg(
276
'migrate_instance_start',
277
instance_uuid=instance_uuid,
278
rxtx_factor=rxtx_factor,
279
project_id=project_id,
280
source=source_compute,
282
floating_addresses=floating_addresses),
286
def migrate_instance_finish(self, ctxt, instance_uuid, rxtx_factor,
287
project_id, source_compute, dest_compute,
288
floating_addresses, host=None):
289
topic = rpc.queue_get_for(ctxt, self.topic, host)
290
return self.call(ctxt, self.make_msg(
291
'migrate_instance_finish',
292
instance_uuid=instance_uuid,
293
rxtx_factor=rxtx_factor,
294
project_id=project_id,
295
source=source_compute,
297
floating_addresses=floating_addresses),