def convert_cookie(self, name, profile, skipped, tenant): method = profile.get('method', 'insert') if not method == 'insert': LOG.warn("Skipped cookie method not supported for profile '%s' " % name) conv_utils.add_status_row('persistence', 'cookie', name, 'skipped') return None supported_attr = [ "cookie-name", "defaults-from", "expiration", "method" ] ignore_lst = ['always-send'] parent_obj = super(PersistenceConfigConvV11, self) supported_attr += ignore_lst skipped += [ attr for attr in profile.keys() if attr not in supported_attr ] cookie_name = profile.get("cookie-name", None) timeout = profile.get("expiration", '1') timeout = parent_obj.convert_timeout(timeout) persist_profile = { "name": name, "app_cookie_persistence_profile": { "prst_hdr_name": cookie_name, "timeout": timeout }, "server_hm_down_recovery": "HM_DOWN_PICK_NEW_SERVER", "persistence_type": "PERSISTENCE_TYPE_APP_COOKIE", } if tenant: persist_profile['tenant_ref'] = tenant return persist_profile
def convert_external(self, monitor_dict, f5_monitor, skipped, input_dir, name): script_vars = "" ext_attr = ["run", "args", "user-defined"] for key in f5_monitor.keys(): if key not in ('args', 'run') and '\"' in f5_monitor[key]: ext_attr.append(key) param_value = f5_monitor[key].replace('\"', '') script_vars += "%s=%s," % (key, param_value) if script_vars: script_vars = script_vars[:-1] skipped = [key for key in skipped if key not in ext_attr] cmd_code = f5_monitor.get("run", None) cmd_params = f5_monitor.get("args", None) cmd_code = cmd_code.replace('\"', '') if cmd_code else None cmd_params = cmd_params.replace('\"', '') if cmd_params else None if cmd_code: cmd_code = conv_utils.upload_file(input_dir + os.path.sep + cmd_code) else: LOG.warn("Skipped monitor: %s for no value in run attribute" % name) conv_utils.add_status_row("monitor", "external", name, "skipped") monitor_dict['error'] = True return None monitor_dict["type"] = "HEALTH_MONITOR_EXTERNAL" ext_monitor = { "command_code": cmd_code, "command_parameters": cmd_params, "command_variables": script_vars } monitor_dict["external_monitor"] = ext_monitor return skipped
def convert_external(self, monitor_dict, f5_monitor, skipped, input_dir, name): ext_attr = ["run", "args", "user-defined"] skipped = [key for key in skipped if key not in ext_attr] monitor_dict["type"] = "HEALTH_MONITOR_EXTERNAL" cmd_code = f5_monitor.get("run", 'none') user_defined_vars = "" for m_key in f5_monitor.keys(): if 'user-defined_' in m_key: var_value = f5_monitor[m_key] var_key = m_key.replace('user-defined_', '') skipped.remove(m_key) user_defined_vars += '%s=%s,' % (var_key, var_value) user_defined_vars = user_defined_vars[:-1] cmd_code = None if cmd_code == 'none' else cmd_code if cmd_code: cmd_code = conv_utils.upload_file(input_dir + os.path.sep + cmd_code) else: LOG.warn("Skipped monitor: %s for no value in run attribute" % name) conv_utils.add_status_row("monitor", "external", name, "skipped") monitor_dict['error'] = True return None ext_monitor = { "command_code": cmd_code, "command_parameters": f5_monitor.get("args", None), "command_variables": user_defined_vars } monitor_dict["external_monitor"] = ext_monitor return skipped
def convert(self, f5_config, avi_config, user_ignore): pool_list = [] pool_config = f5_config.get('pool', {}) user_ignore = user_ignore.get('pool', {}) avi_config['VrfContext'] = [] avi_config['PoolGroup'] = [] avi_config['PriorityLabels'] = [] for pool_name in pool_config.keys(): LOG.debug("Converting Pool: %s" % pool_name) f5_pool = pool_config[pool_name] if not f5_pool: LOG.debug("Empty pool skipped for conversion :%s" % pool_name) conv_utils.add_status_row('pool', None, pool_name, 'skipped') continue try: converted_objs = self.convert_pool(pool_name, f5_config, avi_config, user_ignore) pool_list += converted_objs['pools'] if 'pg_obj' in converted_objs: avi_config['PoolGroup'].append(converted_objs['pg_obj']) LOG.debug("Conversion successful for Pool: %s" % pool_name) except: LOG.error("Failed to convert pool: %s" % pool_name, exc_info=True) conv_utils.add_status_row('pool', None, pool_name, 'Error') labels = avi_config.pop('PriorityLabels', None) if labels: labels = list(set(labels)) labels = map(int, labels) labels.sort(reverse=True) labels = map(str, labels) priority_labels = { "name": "numeric_priority_labels", "equivalent_labels": [{ "labels": labels }], } avi_config['PriorityLabels'] = [priority_labels] avi_config['Pool'] = pool_list LOG.debug("Converted %s pools" % len(pool_list)) f5_config.pop('pool', {})
def convert_cookie(self, name, profile, skipped, tenant): method = profile.get('cookie mode', 'insert') if not method == 'insert': LOG.warn("Skipped cookie method not supported for profile '%s' " % name) conv_utils.add_conv_status('persistence', 'cookie', name, 'skipped') return None supported_attr = [ "cookie name", "mode", "defaults from", "cookie mode", "cookie hash offset", "cookie hash length", "cookie expiration" ] skipped += [ attr for attr in profile.keys() if attr not in supported_attr ] cookie_name = profile.get("cookie name", None) if not cookie_name: LOG.error("Missing Required field cookie name in: %s", name) conv_utils.add_status_row('profile', 'persist-cookie', name, 'skipped') return None timeout = profile.get("cookie expiration", '1') if timeout == 'immediate': timeout = '0' parent_obj = super(PersistenceConfigConvV10, self) if 'd ' in timeout: timeout = timeout.replace('d ', ':') elif 'd' in timeout: timeout = timeout.replace('d', '') timeout = parent_obj.convert_timeout(timeout) persist_profile = { "name": name, "app_cookie_persistence_profile": { "prst_hdr_name": cookie_name, "timeout": timeout }, "server_hm_down_recovery": "HM_DOWN_PICK_NEW_SERVER", "persistence_type": "PERSISTENCE_TYPE_APP_COOKIE", } if tenant: persist_profile['tenant_ref'] = tenant return persist_profile
def convert(self, f5_config, avi_config, input_dir, user_ignore): LOG.debug("Converting health monitors") avi_config["HealthMonitor"] = [] m_user_ignore = user_ignore.get('monitor', {}) monitor_config = f5_config.pop("monitor", {}) for key in monitor_config.keys(): f5_monitor = monitor_config[key] if not f5_monitor: if " " in key: m_type, name = key.split(" ") else: m_type = None name = key conv_utils.add_status_row('monitor', m_type, name, 'skipped') LOG.warn("Empty config for monitor: %s " % name) continue f5_monitor = self.get_defaults(monitor_config, key) monitor_type, name = self.get_name_type(f5_monitor, key) try: LOG.debug("Converting monitor: %s" % name) if monitor_type not in self.supported_types: LOG.warn("Monitor type not supported by Avi : " + name) conv_utils.add_status_row('monitor', monitor_type, name, 'skipped') continue avi_monitor = self.convert_monitor(f5_monitor, key, monitor_config, input_dir, m_user_ignore) if not avi_monitor: continue avi_config["HealthMonitor"].append(avi_monitor) LOG.debug("Conversion successful for monitor: %s" % name) except: LOG.error("Failed to convert monitor: %s" % key, exc_info=True) if name: conv_utils.add_status_row('monitor', monitor_type, name, 'error') else: conv_utils.add_status_row('monitor', key, key, 'error') LOG.debug("Converted %s health monitors" % len(avi_config["HealthMonitor"]))
def update_conv_status_for_skip(self, persist_mode, name): conv_utils.add_status_row("profile", 'persist', name, "skipped")
def update_conv_status_for_error(self, name, persist_mode, key): if name: conv_utils.add_status_row("profile", 'persist', name, "error") else: conv_utils.add_status_row("profile", 'persist', key, "error")
def update_conv_status_for_error(self, name, persist_mode, key): if name: conv_utils.add_status_row("persistence", persist_mode, name, "error") else: conv_utils.add_status_row("persistence", key, key, "error")