18
18
from quantum.common import exceptions as exc
20
21
class QuantumEchoPlugin(object):
23
24
QuantumEchoPlugin is a demo plugin that doesn't
24
25
do anything but demonstrated the concept of a
25
26
concrete Quantum Plugin. Any call to this plugin
26
will result in just a "print" to std. out with
27
will result in just a "print" to std. out with
27
28
the name of the method that was called.
30
31
def get_all_networks(self, tenant_id):
32
33
Returns a dictionary containing all
33
34
<network_uuid, network_name> for
36
37
print("get_all_networks() called\n")
39
39
def create_network(self, tenant_id, net_name):
41
41
Creates a new Virtual Network, and assigns it
44
44
print("create_network() called\n")
47
46
def delete_network(self, tenant_id, net_id):
49
48
Deletes the network with the specified network identifier
52
51
print("delete_network() called\n")
55
53
def get_network_details(self, tenant_id, net_id):
57
55
Deletes the Virtual Network belonging to a the
60
58
print("get_network_details() called\n")
63
60
def rename_network(self, tenant_id, net_id, new_name):
65
62
Updates the symbolic name belonging to a particular
68
65
print("rename_network() called\n")
71
67
def get_all_ports(self, tenant_id, net_id):
73
69
Retrieves all port identifiers belonging to the
74
70
specified Virtual Network.
76
72
print("get_all_ports() called\n")
79
74
def create_port(self, tenant_id, net_id):
81
76
Creates a port on the specified Virtual Network.
83
78
print("create_port() called\n")
86
80
def delete_port(self, tenant_id, net_id, port_id):
88
82
Deletes a port on a specified Virtual Network,
93
87
print("delete_port() called\n")
96
89
def get_port_details(self, tenant_id, net_id, port_id):
98
91
This method allows the user to retrieve a remote interface
99
92
that is attached to this particular port.
101
94
print("get_port_details() called\n")
104
96
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
106
98
Attaches a remote interface to the specified port on the
107
99
specified Virtual Network.
109
101
print("plug_interface() called\n")
112
103
def unplug_interface(self, tenant_id, net_id, port_id):
114
105
Detaches a remote interface from the specified port on the
115
106
specified Virtual Network.
117
108
print("unplug_interface() called\n")
120
110
def get_interface_details(self, tenant_id, net_id, port_id):
122
112
Retrieves the remote interface that is attached at this
125
115
print("get_interface_details() called\n")
128
117
def get_all_attached_interfaces(self, tenant_id, net_id):
130
119
Retrieves all remote interfaces that are attached to
139
129
hard-coded data structures to aid in quantum
140
130
client/cli development
143
133
def get_all_networks(self, tenant_id):
145
135
Returns a dictionary containing all
146
136
<network_uuid, network_name> for
147
the specified tenant.
137
the specified tenant.
149
nets = {"001": "lNet1", "002": "lNet2" , "003": "lNet3"}
139
nets = {"001": "lNet1", "002": "lNet2", "003": "lNet3"}
150
140
print("get_all_networks() called\n")
154
143
def create_network(self, tenant_id, net_name):
156
145
Creates a new Virtual Network, and assigns it
169
157
print("delete_network() called\n")
172
159
def get_network_details(self, tenant_id, net_id):
174
161
retrieved a list of all the remote vifs that
175
162
are attached to the network
177
164
print("get_network_details() called\n")
178
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
165
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
166
"/tenant1/networks/10/121/vif1.1"]
179
167
return vifs_on_net
182
169
def rename_network(self, tenant_id, net_id, new_name):
184
171
Updates the symbolic name belonging to a particular
187
174
print("rename_network() called\n")
190
176
def get_all_ports(self, tenant_id, net_id):
192
178
Retrieves all port identifiers belonging to the
224
207
print("get_port_details() called\n")
225
208
#returns the remote interface UUID
226
209
return "/tenant1/networks/net_id/portid/vif2.1"
229
211
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
231
213
Attaches a remote interface to the specified port on the
232
214
specified Virtual Network.
234
216
print("plug_interface() called\n")
237
218
def unplug_interface(self, tenant_id, net_id, port_id):
239
220
Detaches a remote interface from the specified port on the
240
221
specified Virtual Network.
242
223
print("unplug_interface() called\n")
245
225
def get_interface_details(self, tenant_id, net_id, port_id):
247
227
Retrieves the remote interface that is attached at this
250
230
print("get_interface_details() called\n")
251
231
#returns the remote interface UUID
252
232
return "/tenant1/networks/net_id/portid/vif2.0"
255
234
def get_all_attached_interfaces(self, tenant_id, net_id):
257
236
Retrieves all remote interfaces that are attached to
260
239
print("get_all_attached_interfaces() called\n")
261
240
# returns a list of all attached remote interfaces
262
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
241
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
242
"/tenant1/networks/10/121/vif1.1"]
263
243
return vifs_on_net
266
246
class FakePlugin(object):
268
248
FakePlugin is a demo plugin that provides
273
253
#static data for networks and ports
276
'port-state': 'DOWN',
256
'port-state': 'DOWN',
285
'attachment': 'SomeFormOfVIFID'},
265
'attachment': 'SomeFormOfVIFID'},
267
'port-state': 'DOWN',
293
'net-name':'pippotest',
273
'net-name': 'pippotest',
294
274
'net-ports': _port_dict_1
299
'net-name':'cicciotest',
300
'net-ports': _port_dict_2
279
'net-name': 'cicciotest',
280
'net-ports': _port_dict_2
304
283
def __init__(self):
305
FakePlugin._net_counter=len(FakePlugin._networks)
284
FakePlugin._net_counter = len(FakePlugin._networks)
307
286
def _get_network(self, tenant_id, network_id):
308
287
network = FakePlugin._networks.get(network_id)
310
289
raise exc.NetworkNotFound(net_id=network_id)
314
292
def _get_port(self, tenant_id, network_id, port_id):
315
293
net = self._get_network(tenant_id, network_id)
316
294
port = net['net-ports'].get(int(port_id))
318
296
raise exc.PortNotFound(net_id=network_id, port_id=port_id)
321
299
def _validate_port_state(self, port_state):
322
if port_state.upper() not in ('UP','DOWN'):
300
if port_state.upper() not in ('UP', 'DOWN'):
323
301
raise exc.StateInvalid(port_state=port_state)
326
304
def _validate_attachment(self, tenant_id, network_id, port_id,
327
305
remote_interface_id):
328
306
network = self._get_network(tenant_id, network_id)
329
307
for port in network['net-ports'].values():
330
308
if port['attachment'] == remote_interface_id:
331
raise exc.AlreadyAttached(net_id = network_id,
333
att_id = port['attachment'],
334
att_port_id = port['port-id'])
309
raise exc.AlreadyAttached(net_id=network_id,
311
att_id=port['attachment'],
312
att_port_id=port['port-id'])
336
314
def get_all_networks(self, tenant_id):
338
316
Returns a dictionary containing all
339
317
<network_uuid, network_name> for
340
the specified tenant.
318
the specified tenant.
342
320
print("get_all_networks() called\n")
343
321
return FakePlugin._networks.values()
358
336
print("create_network() called\n")
359
337
FakePlugin._net_counter += 1
360
new_net_id=("0" * (3 - len(str(FakePlugin._net_counter)))) + \
338
new_net_id = ("0" * (3 - len(str(FakePlugin._net_counter)))) + \
361
339
str(FakePlugin._net_counter)
363
new_net_dict={'net-id':new_net_id,
366
FakePlugin._networks[new_net_id]=new_net_dict
341
new_net_dict = {'net-id': new_net_id,
342
'net-name': net_name,
344
FakePlugin._networks[new_net_id] = new_net_dict
367
345
# return network_id of the created network
368
346
return new_net_dict
370
348
def delete_network(self, tenant_id, net_id):
372
350
Deletes the network with the specified network identifier
413
391
print("get_port_details() called\n")
414
392
return self._get_port(tenant_id, net_id, port_id)
416
394
def create_port(self, tenant_id, net_id, port_state=None):
418
396
Creates a port on the specified Virtual Network.
420
398
print("create_port() called\n")
421
399
net = self._get_network(tenant_id, net_id)
422
400
# check port state
423
# TODO(salvatore-orlando): Validate port state in API?
401
# TODO(salvatore-orlando): Validate port state in API?
424
402
self._validate_port_state(port_state)
425
403
ports = net['net-ports']
426
new_port_id = max(ports.keys())+1
427
new_port_dict = {'port-id':new_port_id,
404
new_port_id = max(ports.keys()) + 1
405
new_port_dict = {'port-id': new_port_id,
428
406
'port-state': port_state,
429
407
'attachment': None}
430
408
ports[new_port_id] = new_port_dict
433
411
def update_port(self, tenant_id, net_id, port_id, port_state):
438
416
port = self._get_port(tenant_id, net_id, port_id)
439
417
self._validate_port_state(port_state)
440
418
port['port-state'] = port_state
443
421
def delete_port(self, tenant_id, net_id, port_id):
445
423
Deletes a port on a specified Virtual Network,
451
429
net = self._get_network(tenant_id, net_id)
452
430
port = self._get_port(tenant_id, net_id, port_id)
453
431
if port['attachment']:
454
raise exc.PortInUse(net_id=net_id,port_id=port_id,
432
raise exc.PortInUse(net_id=net_id, port_id=port_id,
455
433
att_id=port['attachment'])
457
435
net['net-ports'].pop(int(port_id))
459
437
raise exc.PortNotFound(net_id=net_id, port_id=port_id)
461
439
def get_interface_details(self, tenant_id, net_id, port_id):
466
444
print("get_interface_details() called\n")
467
445
port = self._get_port(tenant_id, net_id, port_id)
468
446
return port['attachment']
470
448
def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
472
450
Attaches a remote interface to the specified port on the
478
456
remote_interface_id)
479
457
port = self._get_port(tenant_id, net_id, port_id)
480
458
if port['attachment']:
481
raise exc.PortInUse(net_id=net_id,port_id=port_id,
459
raise exc.PortInUse(net_id=net_id, port_id=port_id,
482
460
att_id=port['attachment'])
483
461
port['attachment'] = remote_interface_id
485
463
def unplug_interface(self, tenant_id, net_id, port_id):
487
465
Detaches a remote interface from the specified port on the
492
470
# TODO(salvatore-orlando):
493
471
# Should unplug on port without attachment raise an Error?
494
472
port['attachment'] = None
496
#TODO - neeed to update methods from this point onwards
474
# TODO - neeed to update methods from this point onwards
497
475
def get_all_attached_interfaces(self, tenant_id, net_id):
499
477
Retrieves all remote interfaces that are attached to
502
480
print("get_all_attached_interfaces() called\n")
503
481
# returns a list of all attached remote interfaces
504
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0", "/tenant1/networks/10/121/vif1.1"]
482
vifs_on_net = ["/tenant1/networks/net_id/portid/vif2.0",
483
"/tenant1/networks/10/121/vif1.1"]
505
484
return vifs_on_net
b'\\ No newline at end of file'