| 1 |
# All Rights Reserved 2018 |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 |
# not use this file except in compliance with the License. You may obtain |
| 5 |
# a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 |
# License for the specific language governing permissions and limitations |
| 13 |
# under the License. |
| 14 |
|
| 15 |
import copy |
| 16 |
|
| 17 |
from oslo_utils import uuidutils |
| 18 |
|
| 19 |
|
| 20 |
class FakeL2GW: |
| 21 |
|
| 22 |
@staticmethod |
| 23 |
def create_l2gw(num_dev=1, num_if=1, attrs=None): |
| 24 |
"""Create one fake L2 Gateway.""" |
| 25 |
attrs = attrs or {} |
| 26 |
interfaces = [{'name': 'interface' + |
| 27 |
uuidutils.generate_uuid(dashed=False)} for |
| 28 |
iface in range(num_if)] |
| 29 |
devices = [{'device_name': 'device' + |
| 30 |
uuidutils.generate_uuid(dashed=False), |
| 31 |
'interfaces': interfaces} for dev in range(num_dev)] |
| 32 |
l2gw_attrs = { |
| 33 |
'id': uuidutils.generate_uuid(), |
| 34 |
'name': 'test-l2gw' + uuidutils.generate_uuid(dashed=False), |
| 35 |
'tenant_id': uuidutils.generate_uuid(), |
| 36 |
'devices': devices |
| 37 |
} |
| 38 |
|
| 39 |
l2gw_attrs.update(attrs) |
| 40 |
return copy.deepcopy(l2gw_attrs) |
| 41 |
|
| 42 |
@staticmethod |
| 43 |
def create_l2gws(attrs=None, count=1): |
| 44 |
"""Create multiple fake L2 Gateways.""" |
| 45 |
|
| 46 |
l2gws = [] |
| 47 |
for i in range(0, count): |
| 48 |
if attrs is None: |
| 49 |
attrs = {'id': 'fake_id%d' % i} |
| 50 |
elif getattr(attrs, 'id', None) is None: |
| 51 |
attrs['id'] = 'fake_id%d' % i |
| 52 |
l2gws.append(FakeL2GW.create_l2gw(attrs=attrs)) |
| 53 |
|
| 54 |
return l2gws |
| 55 |
|
| 56 |
|
| 57 |
class FakeL2GWConnection: |
| 58 |
|
| 59 |
@staticmethod |
| 60 |
def create_l2gw_connection(attrs=None): |
| 61 |
"""Create a fake l2gw connection.""" |
| 62 |
|
| 63 |
attrs = attrs or {} |
| 64 |
l2gw_connection_attrs = { |
| 65 |
'network_id': uuidutils.generate_uuid(), |
| 66 |
'l2_gateway_id': uuidutils.generate_uuid(), |
| 67 |
'segmentation_id': '42', |
| 68 |
'tenant_id': uuidutils.generate_uuid(), |
| 69 |
'id': uuidutils.generate_uuid() |
| 70 |
} |
| 71 |
|
| 72 |
l2gw_connection_attrs.update(attrs) |
| 73 |
return copy.deepcopy(l2gw_connection_attrs) |
| 74 |
|
| 75 |
@staticmethod |
| 76 |
def create_l2gw_connections(attrs=None, count=1): |
| 77 |
l2gw_connections = [] |
| 78 |
|
| 79 |
for i in range(0, count): |
| 80 |
if attrs is None: |
| 81 |
attrs = {'id': 'fake_id%d' % i} |
| 82 |
elif getattr(attrs, 'id', None) is None: |
| 83 |
attrs['id'] = 'fake_id%d' % i |
| 84 |
l2gw_connections.append(FakeL2GWConnection.create_l2gw_connection( |
| 85 |
attrs=attrs)) |
| 86 |
|
| 87 |
return l2gw_connections |