From 2a2dbaffb3285c51121a9ea39cb666844648d299 Mon Sep 17 00:00:00 2001 From: Varun Lodaya Date: Fri, 1 Jul 2016 09:50:22 -0700 Subject: [PATCH] Custom Attribute Support for LBaaSv2 This fix adds neutron_plugin changes to read custom attributes while configuring lbaasv2 Change-Id: I971213a10c4976c69d8b6b6bca4aae8149bb809d Closes-Bug: #1596706 --- .../loadbalancer/v2/loadbalancer_pool.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/v2/loadbalancer_pool.py b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/v2/loadbalancer_pool.py index 5a5f428..32db6fd 100644 --- a/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/v2/loadbalancer_pool.py +++ b/neutron_plugin_contrail/plugins/opencontrail/loadbalancer/v2/loadbalancer_pool.py @@ -46,6 +46,16 @@ def make_properties(self, pool): props.persistence_cookie_name = sp['cookie_name'] return props + def create_update_custom_attributes(self, custom_attributes, kvps): + kvp_array = [] + for custom_attribute in custom_attributes or []: + for key,value in custom_attribute.iteritems(): + kvp = KeyValuePair(key, value) + kvp_array.append(kvp) + + kvps.set_key_value_pair(kvp_array) + return True + def _get_listeners(self, pool): ll_list = [] ll_back_refs = pool.get_loadbalancer_listener_refs() @@ -71,6 +81,13 @@ def make_dict(self, pool, fields=None): if value is not None: res[mapping] = value + custom_attributes = [] + kvps = pool.get_loadbalancer_pool_custom_attributes() + if kvps: + custom_attributes = [{kvp.get_key(): kvp.get_value()} \ + for kvp in kvps.get_key_value_pair() or []] + res['custom_attributes'] = [custom_attributes] + if props.session_persistence: sp = {'type': props.session_persistence} if props.session_persistence == 'APP_COOKIE': @@ -180,6 +197,13 @@ def create(self, context, pool): pool_id=pool_exists[0]['uuid']) pool.set_loadbalancer_listener(ll) + # Custom attributes + if p['custom_attributes'] != attr.ATTR_NOT_SPECIFIED: + custom_attributes = KeyValuePairs() + self.create_update_custom_attributes(p['custom_attributes'], + custom_attributes) + pool.set_loadbalancer_pool_custom_attributes(custom_attributes) + self._api.loadbalancer_pool_create(pool) return self.make_dict(pool) @@ -205,4 +229,15 @@ def update_properties(self, pool_db, id, p): pool_db.set_loadbalancer_pool_properties(props) change = True + if 'custom_attributes' in p: + custom_attributes = pool_db.get_loadbalancer_pool_custom_attributes() + # Make sure to initialize custom_attributes + if not custom_attributes: + custom_attributes = KeyValuePairs() + + if self.create_update_custom_attributes(p['custom_attributes'], + custom_attributes): + pool_db.set_loadbalancer_pool_custom_attributes(custom_attributes) + change = True + return change