Beispiel #1
0
def getvlanid(root, service, servicepath, username, fabric, alloc_name):
    poolname = getvlanpool(fabric)
    id_allocator.id_request(service, servicepath, username, poolname,
                            alloc_name, False)
    vlanid = id_allocator.id_read(username, root, poolname, alloc_name)

    return vlanid
Beispiel #2
0
    def cb_create(self, tctx, root, service, proplist):
        self.log.info('Service create(service=', service._path, ')')
        pool_name = service.pool
        alloc_name = service.name
        id_allocator.id_request(
            service,
            "/services/id-vl:id-loop-python[name='%s']" % (service.name),
            tctx.username, pool_name, alloc_name, False)

        id = id_allocator.id_read(tctx.username, root, pool_name, alloc_name)
        if not id:
            self.log.info("Alloc not ready")
            return

        self.log.info('id = %s' % (id))

        id_allocator.id_request(
            service,
            "/services/id-vl:id-loop-python[name='%s']" % (service.name),
            tctx.username, pool_name, "specific_id", False, 20)

        id = id_allocator.id_read(tctx.username, root, pool_name,
                                  "specific_id")
        if not id:
            self.log.info("Alloc not ready")
            return
        self.log.info('id = %s' % (id))
Beispiel #3
0
    def cb_create(self, tctx, root, service, proplist):
        self.log.info("Service create(service=", service._path, ")")

        id_allocator.id_request(
            service,
            "/access-python[customer='%s']" % (service.customer),
            tctx.username,
            "vlans",
            service.customer,
            False,
        )
        vlan = id_allocator.id_read(tctx.username, root, "vlans",
                                    service.customer)
        if not vlan:
            self.log.info("VLAN not ready")
            return

        service.vlan = vlan

        custom_interface_description = root.location__location[
            service.device].location__address
        self.log.info("custom_interface_description : {}".format(
            custom_interface_description))
        template_vars = ncs.template.Variables()
        template_vars.add("VLAN", vlan)
        template_vars.add("ACCESS_GE_INTERFACE", service.access_ge_interface)
        template_vars.add("TRUNK_GE_INTERFACE", service.trunk_ge_interface)
        template_vars.add("ACCESS_INT_DESCRIPTION",
                          custom_interface_description)
        template = ncs.template.Template(service)
        template.apply("access-python-template", template_vars)
Beispiel #4
0
def allocate_resources(service, root, username, vpn_name, pe_name, ce_name):
    conn_name = '%s-%s' % (ce_name, pe_name)
    xpath = "/l3vpn-svc:l3vpn-svc/sites/site[site-id='%s']" % service.site_id

    id_request(service, xpath, username, VRF_ID_POOL_NAME, vpn_name, False)
    net_request(service, xpath, username, IP_ADDRESS_POOL_NAME, conn_name, 30)
    id_request(service, xpath, username, VLAN_ID_POOL_NAME, conn_name, False)

    return [
        id_read(username, root, VRF_ID_POOL_NAME, vpn_name),
        net_read(username, root, IP_ADDRESS_POOL_NAME, conn_name),
        id_read(username, root, VLAN_ID_POOL_NAME, conn_name)
    ]
Beispiel #5
0
    def cb_create(self, tctx, root, service, proplist):
        self.log.info('Service create(service=', service._path, ')')

        vars = ncs.template.Variables()
        template = ncs.template.Template(service)

        # Setup VPC Domain Id Pool
        template.apply("vpc-domain-id-pool", vars)

        # PHASE - Configure Switch Pairs
        for pair in service.switch_pair:
            self.log.info("Processing Switch Pair {}".format(pair.name))

            # Allocate VPC Domain Ids for Switch Pairs
            self.log.info("Allocating VPC Domain Id for Switch Pair {}".format(
                pair.name))
            pool_name = "VPC-DOMAIN-ID-POOL-{}".format(service.name)
            alloc_name = "SWITCH-PAIR-{}".format(pair.name)
            id_allocator.id_request(service,
                                    "/vlan-fabric[name='%s']" % (service.name),
                                    tctx.username, pool_name, alloc_name,
                                    False)
            vpc_domain_id = id_allocator.id_read(
                tctx.username,
                root,
                pool_name,
                alloc_name,
            )
            self.log.info("vpc_domain_id = {}".format(vpc_domain_id))

            # Test if Allocations are ready
            if not vpc_domain_id:
                self.log.info("VPC Domain ID Allocation not ready - {}".format(
                    pair.name))
            else:
                # PHASE - VPC Domain Setup
                primary_ip_address = root.devices.device[
                    pair.primary].config.interface.mgmt["0"].ip.address.ipaddr

                vpc_vars = ncs.template.Variables()
                disable_trunk_negotiation = False
                vpc_vars.add("DISABLE_TRUNK_NEGOTIATION",
                             disable_trunk_negotiation)

                # Support pairs that lack a secondary - ie for PreProd
                if pair.secondary:
                    secondary_ip_address = root.devices.device[
                        pair.
                        secondary].config.interface.mgmt["0"].ip.address.ipaddr
                    vpc_vars.add("VPC_ENABLED", True)
                else:
                    secondary_ip_address = ""
                    vpc_vars.add("VPC_ENABLED", "")

                self.log.info(
                    "Primary IP Address: {}".format(primary_ip_address))
                self.log.info(
                    "Secondary IP Address: {}".format(secondary_ip_address))

                vpc_vars.add("VPC_DOMAIN_ID", vpc_domain_id)
                vpc_vars.add("VPC_PEERLINK_ID", pair.vpc_peerlink.id)
                vpc_vars.add("LAYER3", pair.layer3)
                vpc_vars.add("MTU_SIZE", "1500")

                self.log.info(
                    "Setting up VPC Domain on pair {} primary device {}".
                    format(pair.name, pair.primary))
                vpc_vars.add("DEVICE_NAME", pair.primary)
                vpc_vars.add("VPC_PEER_KEEPALIVE_SOURCE",
                             primary_ip_address.split("/")[0])
                vpc_vars.add("VPC_PEER_KEEPALIVE_DESTINATION",
                             secondary_ip_address.split("/")[0])
                # vpc_vars.add("", )
                self.log.info("vpc_vars=", vpc_vars)
                template.apply("vpc-domain-base", vpc_vars)

                if pair.secondary:
                    self.log.info(
                        "Setting up VPC Domain on pair {} secondary device {}".
                        format(pair.name, pair.secondary))
                    vpc_vars.add("DEVICE_NAME", pair.secondary)
                    vpc_vars.add("VPC_PEER_KEEPALIVE_SOURCE",
                                 secondary_ip_address.split("/")[0])
                    vpc_vars.add("VPC_PEER_KEEPALIVE_DESTINATION",
                                 primary_ip_address.split("/")[0])
                    # self.log.info("vpc_secondary_vars=", vpc_vars)
                    # vpc_vars.add("", )
                    template.apply("vpc-domain-base", vpc_vars)

                    # PHASE - VPC Peerlink Setup
                    for interface in pair.vpc_peerlink.interface:
                        vpc_pl_vars = ncs.template.Variables()
                        vpc_pl_vars.add("DISABLE_TRUNK_NEGOTIATION",
                                        disable_trunk_negotiation)
                        vpc_pl_vars.add("INTERFACE_ID", interface.interface)
                        vpc_pl_vars.add("PORTCHANNEL_ID", pair.vpc_peerlink.id)
                        vpc_pl_vars.add("DESCRIPTION", "VPC Peer Link")
                        vpc_pl_vars.add("MODE", "trunk")
                        vpc_pl_vars.add("VLAN_ID", "all")
                        vpc_pl_vars.add("MTU_SIZE", "1500")
                        # vpc_pl_vars.add("OLD_SWITCH", "false")

                        self.log.info(
                            "Setting up VPC Peerlink Interfaces on pair {} primary device {}"
                            .format(pair.name, pair.primary))
                        vpc_pl_vars.add("DEVICE_NAME", pair.primary)
                        self.log.info("vpc_pl_vars=", vpc_pl_vars)
                        template.apply("portchannel-member-interface",
                                       vpc_pl_vars)

                        if pair.secondary:
                            self.log.info(
                                "Setting up VPC Peerlink Interfaces on pair {} secondary device {}"
                                .format(pair.name, pair.secondary))
                            vpc_pl_vars.add("DEVICE_NAME", pair.secondary)
                            self.log.info("vpc_pl_vars=", vpc_pl_vars)
                            template.apply("portchannel-member-interface",
                                           vpc_pl_vars)

                # PHASE - Enable Jumbo Frames
                mtu_vars = ncs.template.Variables()
                mtu_vars.add("FRAME_SIZE", "9216")

                # Primary
                mtu_vars.add("DEVICE_NAME", pair.primary)
                self.log.info(
                    "Setting up Jumbo System MTU on pair {} primary device {}".
                    format(pair.name, pair.primary))
                self.log.info("mtu_vars=", mtu_vars)
                template.apply("system-jumbo-frames", mtu_vars)

                # Secondary
                if pair.secondary:
                    mtu_vars.add("DEVICE_NAME", pair.primary)
                    self.log.info(
                        "Setting up Jumbo System MTU on pair {} secondary device {}"
                        .format(pair.name, pair.secondary))
                    self.log.info("mtu_vars=", mtu_vars)
                    template.apply("system-jumbo-frames", mtu_vars)

                # PHASE - Interswitch Trunk Setup
                for trunk in pair.fabric_trunk:
                    trunk_vars = ncs.template.Variables()
                    trunk_vars.add("DISABLE_TRUNK_NEGOTIATION",
                                   disable_trunk_negotiation)
                    trunk_vars.add("INTERFACE_ID", trunk.interface)
                    trunk_vars.add("PORTCHANNEL_ID", trunk.portchannel_id)
                    trunk_description = "Interswitch Fabric Link"
                    trunk_vars.add("DESCRIPTION", trunk_description)
                    trunk_vars.add("MTU_SIZE", "9216")

                    if pair.secondary:
                        trunk_vars.add("VPC", True)
                    else:
                        trunk_vars.add("VPC", "")
                    trunk_vars.add("MODE", "trunk")
                    trunk_vars.add("VLAN_ID", "all")
                    # trunk_vars.add("OLD_SWITCH", "false")

                    self.log.info(
                        "Setting up Trunk {} on pair {} primary device {}".
                        format(trunk.portchannel_id, pair.name, pair.primary))
                    trunk_vars.add("DEVICE_NAME", pair.primary)
                    self.log.info("trunk_vars=", trunk_vars)
                    template.apply("portchannel-interface", trunk_vars)

                    if pair.secondary:
                        self.log.info(
                            "Setting up Trunk {} on pair {} secondary device {}"
                            .format(trunk.portchannel_id, pair.name,
                                    pair.secondary))
                        trunk_vars.add("DEVICE_NAME", pair.secondary)
                        self.log.info("trunk_vars=", trunk_vars)
                        template.apply("portchannel-interface", trunk_vars)

                    # PHASE - Configure Trunk Member Interfaces
                    for interface in trunk.interface:
                        trunk_vars.add("INTERFACE_ID", interface.interface)

                        self.log.info(
                            "Setting up Trunk {} Member Interface {} on pair {} primary device {}"
                            .format(trunk.portchannel_id, interface.interface,
                                    pair.name, pair.primary))
                        trunk_vars.add("DEVICE_NAME", pair.primary)
                        self.log.info("trunk_vars=", trunk_vars)
                        template.apply("portchannel-member-interface",
                                       trunk_vars)

                        if pair.secondary:
                            self.log.info(
                                "Setting up Trunk {} Member Interface {} on pair {} secondary device {}"
                                .format(trunk.portchannel_id,
                                        interface.interface, pair.name,
                                        pair.secondary))
                            trunk_vars.add("DEVICE_NAME", pair.secondary)
                            self.log.info("trunk_vars=", trunk_vars)
                            template.apply("portchannel-member-interface",
                                           trunk_vars)

        # PHASE - Configure individual switches
        for switch in service.switch:
            self.log.info("Processing Individual Switch {}".format(
                switch.device))
            switch_platform = {}
            switch_platform["name"] = root.devices.device[
                switch.device].platform.name
            switch_platform["version"] = root.devices.device[
                switch.device].platform.version
            switch_platform["model"] = root.devices.device[
                switch.device].platform.model
            self.log.info("Switch Platform Info: {}".format(switch_platform))

            if switch_platform["model"] != "NETSIM" and switch_platform[
                    "name"] == "ios" and int(
                        switch_platform["version"][0:2]) < 16:
                disable_trunk_negotiation = True
            else:
                disable_trunk_negotiation = False

            # PHASE - Enable Jumbo Frames
            # Limit to 3850 and 9300 Switcehs
            if "3850" in switch_platform["model"] or "9300" in switch_platform[
                    "model"]:
                mtu_vars = ncs.template.Variables()
                mtu_vars.add("FRAME_SIZE", "9198")
                mtu_vars.add("DEVICE_NAME", switch.device)
                self.log.info(
                    "Setting up Jumbo System MTU on switch {}".format(
                        switch.device))
                self.log.info("mtu_vars=", mtu_vars)
                template.apply("system-jumbo-frames", mtu_vars)

            # PHASE - Interswitch Trunk Setup
            for trunk in switch.fabric_trunk:
                trunk_vars = ncs.template.Variables()
                # if switch.oldswitch_fix:
                #     trunk_vars.add("OLD_SWITCH", "true")
                # else:
                #     trunk_vars.add("OLD_SWITCH", "false")
                trunk_vars.add("DEVICE_NAME", switch.device)
                trunk_vars.add("PORTCHANNEL_ID", trunk.portchannel_id)
                trunk_description = "Interswitch Fabric Link"
                trunk_vars.add("DESCRIPTION", trunk_description)
                trunk_vars.add("VPC", "")
                trunk_vars.add("MODE", "trunk")
                trunk_vars.add("VLAN_ID", "all")
                trunk_vars.add("DISABLE_TRUNK_NEGOTIATION",
                               disable_trunk_negotiation)
                trunk_vars.add("MTU_SIZE", "9216")

                self.log.info("Setting up Trunk {} on switch {}".format(
                    trunk.portchannel_id, switch.device))
                self.log.info("trunk_vars=", trunk_vars)
                template.apply("portchannel-interface", trunk_vars)

                # PHASE - Configure Trunk Member Interfaces
                for interface in trunk.interface:
                    trunk_vars.add("INTERFACE_ID", interface.interface)
                    self.log.info(
                        "Setting up Trunk {} Member Interface {} on switch {}".
                        format(trunk.portchannel_id, interface.interface,
                               switch.device))
                    self.log.info("trunk_vars=", trunk_vars)
                    template.apply("portchannel-member-interface", trunk_vars)
Beispiel #6
0
 def request_id(self, pool_name, allocation_name):
     id_allocator.id_request(self.service, self.xpath, self.username,
                             pool_name, allocation_name, False)
Beispiel #7
0
    def cb_create(self, tctx, root, service, proplist):
        self.log.info('Service create(service=', service._path, ')')

        self_plan = PlanComponent(service, 'self', 'ncs:self')
        self_plan.append_state('ncs:init')
        self_plan.append_state('ncs:ready')
        self_plan.set_reached('ncs:init')

        ready_count = 0
        igp_domain = root.sr_migrate__igp_domain[service.igp_domain]

        for router in igp_domain.router:
            router_plan = PlanComponent(service, router.name,
                                        'sr-migrate:router-migration')
            router_plan.append_state('ncs:init')
            router_plan.append_state('sr-migrate:segment-routing-enabled')
            router_plan.append_state('sr-migrate:connectivity-test')
            router_plan.append_state('sr-migrate:sr-imposition-preferred')
            router_plan.append_state('sr-migrate:label-imposition-test')
            router_plan.append_state('sr-migrate:ldp-disabled')
            router_plan.append_state('ncs:ready')
            router_plan.set_reached('ncs:init')

            requested_prefix_sid = -1
            if router.custom_prefix_sid:
                requested_prefix_sid = router.custom_prefix_sid

            allocation_name = '%s-%s' % (service.igp_domain, router.name)

            id_allocator.id_request(
                service, "/ncs:services/sr-migrate:sr-migrate" +
                "[sr-migrate:igp-domain='%s']" % service.igp_domain,
                tctx.username, igp_domain.sid_pool, allocation_name, False,
                requested_prefix_sid
            )

            prefix_sid = id_allocator.id_read(
                tctx.username, root, igp_domain.sid_pool, allocation_name)

            if not prefix_sid:
                self.log.info('Prefix-sid for router %s not ready' %
                              router.name)
                continue

            self.log.info('Allocated prefix-sid %d for router %s' %
                          (prefix_sid, router.name))
            router.prefix_sid = prefix_sid

            if service.enable_segment_routing:
                template = ncs.template.Template(router)
                template.apply('enable-segment-routing')
                router_plan.set_reached('sr-migrate:segment-routing-enabled')
                ready_count += 1

        if ready_count != len(igp_domain.router.keys()):
            return

        igp_domain.sr_migrate_test_request.create('connectivity-test')

        if not check_test_results(service.connectivity_test_results,
                                  'sr-migrate:connectivity-test'):
            self.log.info('Connectivity test not passed')
            return

        if service.prefer_sr_imposition:
            for router in igp_domain.router:
                template = ncs.template.Template(router)
                template.apply('prefer-sr-imposition')
                set_plan_reached(service, router,
                                 'sr-migrate:sr-imposition-preferred')

            igp_domain.sr_migrate_test_request.create('label-imposition-test')
            if not check_test_results(service.label_imposition_test_results,
                                      'sr-migrate:label-imposition-test'):
                self.log.info('Label imposition test not passed')
                return

            if service.disable_ldp:
                for router in igp_domain.router:
                    disable_ldp(root, igp_domain)
                    set_plan_reached(service, router, 'sr-migrate:ldp-disabled')
                    set_plan_reached(service, router, 'ncs:ready')

                self_plan.set_reached('ncs:ready')
                self.log.info('Service ready - %s migration complete' %
                              (service.igp_domain))