Coder Social home page Coder Social logo

subclass_4 support about ansible-aci HOT 6 CLOSED

ciscodevnet avatar ciscodevnet commented on May 29, 2024
subclass_4 support

from ansible-aci.

Comments (6)

asegovianot avatar asegovianot commented on May 29, 2024

Hi,

when subclass 4 would be available?

from ansible-aci.

xinyuezhao avatar xinyuezhao commented on May 29, 2024

@asegovianot @kudtarkar1
Hi,

we've set it as our next task and will keep you updated.

And would you mind tell us your use case for this subclass_4 support?

from ansible-aci.

asegovianot avatar asegovianot commented on May 29, 2024

Hi,

I will use it to configure static routes inside a configured node on L3Out.

This would be the path in ACI:

uni/tn-[TENANT]/out-[L3OUT]/lnodep-[NODPROF]/rsnodeL3OutAtt-[NODE_DN]/rt-[x.x.x.x/Y]

    root_class=
        aci_class='fvTenant',
    subclass_1=
        aci_class='l3extOut',
       subclass_2=
        aci_class='l3extLNodeP',
      subclass_3=
        aci_class='l3extRsNodeL3OutAtt',
      subclass_4=
        aci_class='ipRouteP',
      child_classes=['ipNexthopP']

just yesterday I was testing and I modified the file aci.py from module_utils to add subclass_4 and I got that working fine to add and remove routes using subclass_4, My doubt is about code to do queries because I did not try it with that subclass, but to add or remove only routes in subclass_4 is working for me.

Really I will need also one subclass_5 more, because to configure vpc interfaces inside an L3Out this would be the path

   root_class=
        aci_class='fvTenant',
    subclass_1=
        aci_class='l3extOut',
       subclass_2=
        aci_class='l3extLNodeP',
      subclass_3=
        aci_class='l3extLIfP',
      subclass_4=
        aci_class='l3extRsNodeL3OutAtt',
      subclass_5=
        aci_class='l3extMember',
     child_classes=['l3extIp']

I need to check in more depth this last.
I don't care to share the code for subclass_4, if you want it, but I'm not a specialist in this, so maybe it could did any error, but to start working it's possible that you can use it

from ansible-aci.

anvitha-jain avatar anvitha-jain commented on May 29, 2024

Hi @asegovianot ,

Could you share your code for subclass_4 for verification?

from ansible-aci.

asegovianot avatar asegovianot commented on May 29, 2024

hi, sorry for the late response.
I'll copy only interesting parts of the code

def construct_url(self, root_class, subclass_1=None, subclass_2=None, subclass_3=None, subclass_4=None, child_classes=None):
        """
        This method is used to retrieve the appropriate URL path and filter_string to make the request to the APIC.

        :param root_class: The top-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_1: The second-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_2: The third-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_3: The fourth-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param sublass_4: The fifth-level class dictionary containing aci_class, aci_rn, target_filter, and module_object keys.
        :param child_classes: The list of child classes that the module supports along with the object.
        :type root_class: dict
        :type subclass_1: dict
        :type subclass_2: dict
        :type subclass_3: dict
        :type subclass_4: dict
        :type child_classes: list
        :return: The path and filter_string needed to build the full URL.
        """
        self.filter_string = ''

        if child_classes is None:
            self.child_classes = set()
        else:
            self.child_classes = set(child_classes)
        
        if subclass_4 is not None:
            self._construct_url_5(root_class, subclass_1, subclass_2, subclass_3, subclass_4)
        elif subclass_3 is not None:
            self._construct_url_4(root_class, subclass_1, subclass_2, subclass_3)
        elif subclass_2 is not None:
            self._construct_url_3(root_class, subclass_1, subclass_2)
        elif subclass_1 is not None:
            self._construct_url_2(root_class, subclass_1)
        else:
            self._construct_url_1(root_class)

        if 'port' in self.params and self.params['port'] is not None:
            self.url = '{protocol}://{host}:{port}/{path}'.format(path=self.path, **self.module.params)
        else:
            self.url = '{protocol}://{host}/{path}'.format(path=self.path, **self.module.params)

        if self.child_classes:
            # Append child_classes to filter_string if filter string is empty
            self.update_qs({'rsp-subtree': 'full', 'rsp-subtree-class': ','.join(sorted(self.child_classes))})

def _construct_url_5(self, root, third, sec, parent, obj):
        """
        This method is used by construct_url when the object is the fifth-level class.
        """
        root_class = root['aci_class']
        root_rn = root['aci_rn']
        root_filter = root['target_filter']
        root_obj = root['module_object']
        third_class = third['aci_class']
        third_rn = third['aci_rn']
        third_filter = third['target_filter']
        third_obj = third['module_object']
        sec_class = sec['aci_class']
        sec_rn = sec['aci_rn']
        sec_filter = sec['target_filter']
        sec_obj = sec['module_object']
        parent_class = parent['aci_class']
        parent_rn = parent['aci_rn']
        parent_filter = parent['target_filter']
        parent_obj = parent['module_object']
        obj_class = obj['aci_class']
        obj_rn = obj['aci_rn']
        obj_filter = obj['target_filter']
        mo = obj['module_object']
        
        if self.child_classes is None:
            self.child_classes = [obj_class]

        #[AST] - contruct url with subclass_4 for create or delete config
        if self.module.params['state'] in ('absent', 'present'):
            # State is absent or present
            self.path = 'api/mo/uni/{0}/{1}/{2}/{3}/{4}.json'.format(root_rn, third_rn, sec_rn, parent_rn, obj_rn)
            self.update_qs({'rsp-prop-include': 'config-only'})
        # TODO: Add all missing cases
        #[AST] added elif for third_obj. This part is only for querys.
        elif root_obj is None:
            self.child_classes.add(obj_class)
            self.path = 'api/class/{0}.json'.format(obj_class)
            self.update_qs({'query-target-filter': self.build_filter(obj_class, obj_filter)})
        elif third_obj is None:
            self.child_classes.add(obj_class)
            self.path = 'api/mo/uni/{0}.json'.format(root_rn)
            # NOTE: No need to select by root_filter
            # self.update_qs({'query-target-filter': self.build_filter(root_class, root_filter)})
            # TODO: Filter by sec_filter, parent and obj_filter
            self.update_qs({'rsp-subtree-filter': self.build_filter(obj_class, obj_filter)})
        elif sec_obj is None:
            self.child_classes.add(obj_class)
            self.path = 'api/mo/uni/{0}/{1}.json'.format(root_rn, third_rn)
            # NOTE: No need to select by sec_filter
            # self.update_qs({'query-target-filter': self.build_filter(sec_class, sec_filter)})
            # TODO: Filter by parent_filter and obj_filter
            self.update_qs({'rsp-subtree-filter': self.build_filter(obj_class, obj_filter)})
        elif parent_obj is None:
            self.child_classes.add(obj_class)
            self.path = 'api/mo/uni/{0}/{1}/{2}.json'.format(root_rn, third_rn, sec_rn)
            # NOTE: No need to select by sec_filter
            # self.update_qs({'query-target-filter': self.build_filter(sec_class, sec_filter)})
            # TODO: Filter by parent_filter and obj_filter
            self.update_qs({'rsp-subtree-filter': self.build_filter(obj_class, obj_filter)})
        elif mo is None:
            self.child_classes.add(obj_class)
            self.path = 'api/mo/uni/{0}/{1}/{2}/{3}.json'.format(root_rn, third_rn, sec_rn, parent_rn)
            # NOTE: No need to select by parent_filter
            # self.update_qs({'query-target-filter': self.build_filter(parent_class, parent_filter)})
        else:
            # Query for a specific object of the module's class
            self.path = 'api/mo/uni/{0}/{1}/{2}/{3}/{4}.json'.format(root_rn, third_rn, sec_rn, parent_rn, obj_rn)

from ansible-aci.

asegovianot avatar asegovianot commented on May 29, 2024

Hi, I had looking at your code: "aci_l3out_static_routes" and I think it would be good if you add child_class "ipNexthop" inside new subclass_4 to add next hop for static route:

       subclass_4=dict(
            aci_class='ipRouteP',
            aci_rn='rt-[{0}]'.format(ip),
            module_object=ip,
            target_filter={'name': ip},
        ),
        child_classes=['ipNexthopP'],
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='ipRouteP',
            class_config=dict(
                ip=ip,
                pref=route_preference,
            ),
            child_configs=[
                {'ipNexthopP': {'attributes': {
                  'nhAddr': next_hop, 
                  'pref': nh_preference,}}},
            ],

from ansible-aci.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.