/
create_public_vn.py
121 lines (111 loc) · 4.81 KB
/
create_public_vn.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import project_test
from common.contrail_test_init import ContrailTestInit
from common.connections import ContrailConnections
import os
import fixtures
from test import BaseTestCase
import time
from floating_ip import *
from vn_test import *
from control_node import *
from common import isolated_creds
from tcutils.util import Singleton
class PublicVn(fixtures.Fixture):
__metaclass__ = Singleton
def __init__(self, isolated_creds_obj, inputs, ini_file = None ,logger = None, mx_rt = None):
self.isolated_creds = isolated_creds_obj
self.username = self.isolated_creds.username
self.password = self.isolated_creds.password
self.inputs = inputs
self.ini_file = ini_file
self.logger = logger
self.public_vn = self.inputs.public_vn
self.public_tenant = self.inputs.admin_tenant
self.setUp()
self.create_public_vn(mx_rt)
self.create_floatingip_pool()
self.configure_control_nodes()
def setUp(self):
super(PublicVn, self).setUp()
self.project = self.isolated_creds.create_tenant(self.public_tenant)
self.inputs = self.isolated_creds.get_inputs(self.project)
self.connections = self.isolated_creds.get_connections(self.inputs)
if self.isolated_creds.__class__.__name__ == 'AdminIsolatedCreds':
# If AdminIsolatedCreds, one could add user to tenant
# Else, it is assumed that the administrator has taken
# care
self.isolated_creds.create_and_attach_user_to_tenant(
self.project,
self.username,
self.password)
self.project.set_sec_group_for_allow_all(\
self.public_tenant, 'default')
# end setUp
def create_public_vn(self,mx_rt = None):
if (('MX_GW_TEST' in os.environ) and (
os.environ.get('MX_GW_TEST') == '1')):
fip_pool_name = self.inputs.fip_pool_name
fvn_name = self.public_vn
fip_subnets = [self.inputs.fip_pool]
if not mx_rt:
mx_rt = self.inputs.mx_rt
self.public_vn_fixture = self.useFixture(
VNFixture(
project_name=self.project.project_name,
connections=self.connections,
vn_name=fvn_name,
inputs=self.inputs,
subnets=fip_subnets,
router_asn=self.inputs.router_asn,
rt_number=mx_rt,
router_external=True))
assert self.public_vn_fixture.verify_on_setup()
self.logger.info('created public VN:%s' % fvn_name)
# end createPublicVN
def create_floatingip_pool(self):
if (('MX_GW_TEST' in os.environ) and (
os.environ.get('MX_GW_TEST') == '1')):
fip_pool_name = self.inputs.fip_pool_name
fvn_name = self.public_vn
fip_subnets = [self.inputs.fip_pool]
self.fip_fixture = self.useFixture(
FloatingIPFixture(
project_name=self.public_tenant,
inputs=self.inputs,
connections=self.connections,
pool_name=fip_pool_name,
vn_id=self.public_vn_fixture.vn_id,
option='neutron',
vn_name=fvn_name))
assert self.fip_fixture.verify_on_setup()
self.logger.info('created FIP Pool:%s under Project:%s' %
(self.fip_fixture.pool_name,
self.project.project_name))
# end createfloatingip
def configure_control_nodes(self):
# Configuring all control nodes here
if (('MX_GW_TEST' in os.environ) and (
os.environ.get('MX_GW_TEST') == '1')):
router_name = self.inputs.ext_routers[0][0]
router_ip = self.inputs.ext_routers[0][1]
for entry in self.inputs.bgp_ips:
hostname = self.inputs.host_data[entry]['name']
entry_control_ip = self.inputs.host_data[
entry]['host_control_ip']
cn_fixture1 = self.useFixture(
CNFixture(
connections=self.connections,
router_name=hostname,
router_ip=entry_control_ip,
router_type='contrail',
inputs=self.inputs))
cn_fixturemx = self.useFixture(
CNFixture(
connections=self.connections,
router_name=router_name,
router_ip=router_ip,
router_type='mx',
inputs=self.inputs))
sleep(10)
assert cn_fixturemx.verify_on_setup()
# TODO Configure MX. Doing Manually For Now