def get_task_tags(self, obj, obj_type, inuse_list): # get the reference dict vs_ref_dict = get_vs_ref() used_tag = 'in_use' # Check object present in list for tag. tenant = None if 'tenant_ref' in obj: link, tenant = get_name_and_entity(obj['tenant_ref']) key = PATH_KEY_MAP.get(obj_type, '') name = '%s-%s-%s' % (obj['name'], key, tenant) if inuse_list and name not in inuse_list: used_tag = 'not_in_use' tname = None if 'tenant_ref' in obj: entity, tname = get_name_and_entity(obj['tenant_ref']) # creating the equivalent key vs_ref_type = '%s$$%s$$%s' % (obj['name'], obj_type.lower(), tname) vs_ref_tags = None if vs_ref_type in vs_ref_dict: vs_ref_tags = vs_ref_dict[vs_ref_type] tags = [obj[NAME], CREATE_OBJECT, obj_type.lower(), used_tag] # eliminate nonetype in vs_ref_tags if vs_ref_tags: tags.extend(vs_ref_tags) return tags
def build_ansible_objects(self, obj_type, objs, ansible_dict, inuse_list): """ adds per object type ansible task :param obj_type type of object :param ansible_dict: output dict :param objs: Returns Ansible dict """ # get the reference dict vs_ref_dict = get_vs_ref() for obj in objs: task = deepcopy(obj) # Added tag for checking object ref. used_tag = 'in_use' if isinstance(task, str): continue for skip_field in self.skip_fields: task.pop(skip_field, None) self.transform_obj_refs(task) task.update(common_task_args) self.update_tenant(task) task_name = ("Create or Update %s: %s" % (obj_type, obj['name']) if 'name' in obj else obj_type) task_id = 'avi_%s' % obj_type.lower() # replacing test vips for both versions 17.1 and 16.4 if self.test_vip: test_vip = self.test_vip.split('.')[:3] if self.api_version == '16.4': if task.get('ip_address', []): task['ip_address']['addr']\ = '.'.join(test_vip + task['ip_address']['addr'].split('.')[3:]) else: if task.get('vip', []): for id, ip in enumerate(task['vip']): task['vip'][id]['ip_address']['addr']\ = '.'.join(test_vip + task['vip'][id]['ip_address']['addr'].split('.')[3:]) if task.get('vsvip_ref', []): task.get('vsvip_ref', []) task.update({'api_context': "{{api_context | default(omit)}}"}) task.update({API_VERSION: self.api_version}) # Check object present in list for tag. tenant = None if 'tenant_ref' in obj: link, tenant = get_name_and_entity(obj['tenant_ref']) key = PATH_KEY_MAP.get(obj_type, '') name = '%s-%s-%s' % (obj['name'], key, tenant) if inuse_list and name not in inuse_list: used_tag = 'not_in_use' tname = None if 'tenant_ref' in obj: entity, tname = get_name_and_entity(obj['tenant_ref']) # creating the equivalent key vs_ref_type = '%s$$%s$$%s' % (obj['name'], obj_type.lower(), tname) vs_ref_tags = None if vs_ref_type in vs_ref_dict: vs_ref_tags = vs_ref_dict[vs_ref_type] tags = [obj[NAME], CREATE_OBJECT, obj_type.lower(), used_tag] # eliminate nonetype in vs_ref_tags if vs_ref_tags: tags.extend(vs_ref_tags) ansible_dict[TASKS].append({ task_id: task, NAME: task_name, TAGS: tags }) return ansible_dict
def build_ansible_objects(self, obj_type, objs, ansible_dict, inuse_list): """ adds per object type ansible task :param obj_type type of object :param ansible_dict: output dict :param objs: Returns Ansible dict """ # get the reference dict vs_ref_dict = get_vs_ref() for obj in objs: task = deepcopy(obj) # Added tag for checking object ref. used_tag = 'in_use' if isinstance(task, str): continue for skip_field in self.skip_fields: task.pop(skip_field, None) self.transform_obj_refs(task) task.update(common_task_args) self.update_tenant(task) task_name = ("Create or Update %s: %s" % (obj_type, obj['name']) if 'name' in obj else obj_type) task_id = 'avi_%s' % obj_type.lower() # replacing test vips for both versions 17.1 and 16.4 if self.test_vip: test_vip = self.test_vip.split('.')[:3] if self.api_version == '16.4': if task.get('ip_address', []): task['ip_address']['addr']\ = '.'.join(test_vip + task['ip_address']['addr'].split('.')[3:]) else: if task.get('vip', []): for id, ip in enumerate(task['vip']): task['vip'][id]['ip_address']['addr']\ = '.'.join(test_vip + task['vip'][id]['ip_address']['addr'].split('.')[3:]) if task.get('vsvip_ref', []): task.get('vsvip_ref', []) task.update({'api_context': "{{api_context | default(omit)}}"}) task.update({API_VERSION: self.api_version}) # Check object present in list for tag. tenant = None if 'tenant_ref' in obj: link, tenant = get_name_and_entity(obj['tenant_ref']) key = PATH_KEY_MAP.get(obj_type, '') name = '%s-%s-%s' % (obj['name'], key, tenant) if inuse_list and name not in inuse_list: used_tag = 'not_in_use' tname = None if 'tenant_ref' in obj: entity, tname = get_name_and_entity(obj['tenant_ref']) # creating the equivalent key vs_ref_type = '%s$$%s$$%s' % (obj['name'], obj_type.lower(), tname) vs_ref_tags = None if vs_ref_type in vs_ref_dict: vs_ref_tags = vs_ref_dict[vs_ref_type] tags = [obj[NAME], CREATE_OBJECT, obj_type.lower(), used_tag] # eliminate nonetype in vs_ref_tags if vs_ref_tags: tags.extend(vs_ref_tags) ansible_dict[TASKS].append( { task_id: task, NAME: task_name, TAGS: tags }) return ansible_dict