Merge "Add allocate vip port when create loadbalancer in server side"
This commit is contained in:
commit
c87ec394c1
|
@ -158,6 +158,12 @@ class LoadBalancersController(base.BaseController):
|
|||
|
||||
validate.network_allowed_by_config(load_balancer.vip_network_id)
|
||||
|
||||
def _create_vip_port_if_not_exist(self, load_balancer_db):
|
||||
"""Create vip port."""
|
||||
network_driver = utils.get_network_driver()
|
||||
vip = network_driver.allocate_vip(load_balancer_db)
|
||||
return vip
|
||||
|
||||
@wsme_pecan.wsexpose(lb_types.LoadBalancerFullRootResponse,
|
||||
body=lb_types.LoadBalancerRootPOST, status_code=201)
|
||||
def post(self, load_balancer):
|
||||
|
@ -208,6 +214,13 @@ class LoadBalancersController(base.BaseController):
|
|||
db_lb = self.repositories.create_load_balancer_and_vip(
|
||||
lock_session, lb_dict, vip_dict)
|
||||
|
||||
# create vip port if not exist
|
||||
vip = self._create_vip_port_if_not_exist(db_lb)
|
||||
db_lb.vip.ip_address = vip.ip_address
|
||||
db_lb.vip.port_id = vip.port_id
|
||||
db_lb.vip.network_id = vip.network_id
|
||||
db_lb.vip.subnet_id = vip.subnet_id
|
||||
|
||||
if listeners or pools:
|
||||
db_pools, db_lists = self._graph_create(
|
||||
context.session, lock_session, db_lb, listeners, pools)
|
||||
|
|
|
@ -334,12 +334,20 @@ class AllowedAddressPairsDriver(neutron_base.BaseNeutronDriver):
|
|||
port = self.get_port(load_balancer.vip.port_id)
|
||||
return self._port_to_vip(port, load_balancer)
|
||||
|
||||
fixed_ip = {}
|
||||
if load_balancer.vip.subnet_id:
|
||||
fixed_ip['subnet_id'] = load_balancer.vip.subnet_id
|
||||
if load_balancer.vip.ip_address:
|
||||
fixed_ip['ip_address'] = load_balancer.vip.ip_address
|
||||
# It can be assumed that network_id exists
|
||||
port = {'port': {'name': 'octavia-lb-' + load_balancer.id,
|
||||
'network_id': load_balancer.vip.network_id,
|
||||
'admin_state_up': False,
|
||||
'device_id': 'lb-{0}'.format(load_balancer.id),
|
||||
'device_owner': OCTAVIA_OWNER}}
|
||||
|
||||
if fixed_ip:
|
||||
port['port']['fixed_ips'] = [fixed_ip]
|
||||
try:
|
||||
new_port = self.neutron_client.create_port(port)
|
||||
except Exception:
|
||||
|
|
|
@ -74,6 +74,7 @@ class BaseNeutronDriver(base.AbstractNetworkDriver):
|
|||
break
|
||||
return data_models.Vip(ip_address=fixed_ip.ip_address,
|
||||
subnet_id=fixed_ip.subnet_id,
|
||||
network_id=port.network_id,
|
||||
port_id=port.id,
|
||||
load_balancer=load_balancer,
|
||||
load_balancer_id=load_balancer.id)
|
||||
|
|
|
@ -384,7 +384,8 @@ class TestAllowedAddressPairsDriver(base.TestCase):
|
|||
'network_id': t_constants.MOCK_NETWORK_ID,
|
||||
'device_id': 'lb-1',
|
||||
'device_owner': allowed_address_pairs.OCTAVIA_OWNER,
|
||||
'admin_state_up': False
|
||||
'admin_state_up': False,
|
||||
'fixed_ips': [{'subnet_id': t_constants.MOCK_SUBNET_ID}]
|
||||
}
|
||||
}
|
||||
create_port.assert_called_once_with(exp_create_port_call)
|
||||
|
|
Loading…
Reference in New Issue