add random lb/pool/listener name when name not set

When name variable not set then use random name for lb/pool/listener.
It is very useful during troublshooting when we have many loadbalancers
and pools. we can easily correlate which loadbalancer belongs to what
pool with name.

Example: http://paste.openstack.org/show/804049/

Change-Id: Ibc0c6e7adc6cbdf87c1d1c5ec42f6954d6995253
This commit is contained in:
Satish Patel 2021-03-30 16:50:09 +00:00
parent 7ecb5b8819
commit cac2998a2d
2 changed files with 19 additions and 5 deletions

View File

@ -89,7 +89,8 @@ class LoadBalancerDriver(base.DriverBase):
return False
def lb_create(self, vip, pool, hm=None, az=None, flavor_id=None):
def lb_create(self, vip, pool, cluster_name, hm=None, az=None,
flavor_id=None):
"""Create a LBaaS instance
:param vip: A dict containing the properties for the VIP;
@ -117,9 +118,11 @@ class LoadBalancerDriver(base.DriverBase):
LOG.exception(msg)
return False, msg
try:
lb_name = 'senlin-lb-%s' % cluster_name
lb = self.oc().loadbalancer_create(
subnet_id, network_id, vip.get('address', None),
vip['admin_state_up'], availability_zone=az,
vip['admin_state_up'], name=lb_name,
availability_zone=az,
flavor_id=flavor_id)
except exception.InternalError as ex:
msg = ('Failed in creating loadbalancer: %s.'
@ -138,11 +141,13 @@ class LoadBalancerDriver(base.DriverBase):
# Create listener
try:
listener_name = 'senlin-listener-%s' % cluster_name
listener = self.oc().listener_create(lb.id, vip['protocol'],
vip['protocol_port'],
vip.get('connection_limit',
None),
vip['admin_state_up'])
vip['admin_state_up'],
name=listener_name)
except exception.InternalError as ex:
msg = 'Failed in creating lb listener: %s.' % str(ex)
LOG.exception(msg)
@ -157,10 +162,12 @@ class LoadBalancerDriver(base.DriverBase):
# Create pool
try:
pool_name = 'senlin-pool-%s' % cluster_name
pool = self.oc().pool_create(pool['lb_method'], listener.id,
pool['protocol'],
pool['session_persistence'],
pool['admin_state_up'])
pool['admin_state_up'],
name=pool_name)
except exception.InternalError as ex:
msg = 'Failed in creating lb pool: %s.' % str(ex)
LOG.exception(msg)

View File

@ -307,6 +307,10 @@ class LoadBalancingPolicy(base.Policy):
_('ID of octavia loadbalancer flavor to use for creation '
'of the loadbalancer.'),
default=None,
),
LB_NAME: schema.String(
_('Name of octavia loadbalancer.'),
default=None,
)
}
@ -402,6 +406,9 @@ class LoadBalancingPolicy(base.Policy):
lb_driver = self.lbaas(cluster.user, cluster.project)
lb_driver.lb_status_timeout = self.lb_status_timeout
# Set default name variable senlin cluster name
cluster_name = cluster.name
# TODO(Anyone): Check if existing nodes has conflicts regarding the
# subnets. Each VM addresses detail has a key named to the network
# which can be used for validation.
@ -416,7 +423,7 @@ class LoadBalancingPolicy(base.Policy):
else:
res, data = lb_driver.lb_create(self.vip_spec, self.pool_spec,
self.hm_spec, self.az_spec,
self.flavor_id_spec)
self.flavor_id_spec, cluster_name)
if res is False:
return False, data