예제 #1
0
def getintnet(root, service, username, alloc_name):
    poolname = getintpool(service)
    ip_allocator.net_request(
        service, "/vxlan-fabric:vxlan-fabric[name='{}']".format(service.name),
        username, poolname, alloc_name, 30)
    ip = ip_allocator.net_read(username, root, poolname, alloc_name)
    return ip
예제 #2
0
파일: main.py 프로젝트: maddn/ietf-l3vpn
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)
    ]
예제 #3
0
def get_lan_network(root, service, username, alloc_name):

    poolname = get_lan_pool_name(service)
    # reserve an IP
    ip_allocator.net_request(service,
                             "/dmvpn:dmvpn[name='{}']".format(service.name),
                             username,
                             poolname,
                             alloc_name,
                             29)
    ip = ip_allocator.net_read(username, root,
                               poolname,
                               alloc_name)
    return ip
예제 #4
0
    def allocate_ip_network(self, pool_name, request_name, subnet):
        allocation_name = safe_key(f'{self.ns_info_name}-{request_name}')
        service_xpath = f"/tme-demo:tme-demo/tenant[name='{self.tenant.name}']"

        ipaddress_allocator.net_request(self.tenant, service_xpath,
                                        self.username, safe_key(pool_name),
                                        allocation_name, subnet)

        ip_network = ipaddress_allocator.net_read(self.username, self.root,
                                                  safe_key(pool_name),
                                                  allocation_name)
        if not ip_network:
            self.log.info(allocation_name, ' ip network allocation not ready')
            self.ready = False
            return False

        return ip_network
예제 #5
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
        self.log.info('CIDR length = ', service.cidr_length)
        ip_allocator.net_request(service,
                                 "/services/ip-vl:ip-loop-python[name='%s']" % (service.name),
                                 tctx.username,
                                 pool_name,
                                 alloc_name,
                                 service.cidr_length)

        net = ip_allocator.net_read(tctx.username, root,
                                    pool_name, alloc_name)
        if not net:
            self.log.info("Alloc not ready")
            return
        self.log.info('net = %s' % (net))
예제 #6
0
    def allocate_ip_network(self, pool_name, request_name, subnet):
        allocation_name = safe_key('%s-%s' % (self.ns_info_id, request_name))
        service_xpath = ("/tme-demo:tme-demo/tenant[name='%s']" %
                         self.tenant.name)

        ipaddress_allocator.net_request(self.tenant,
                                        service_xpath, self.username,
                                        safe_key(pool_name), allocation_name,
                                        subnet)

        ip_network = ipaddress_allocator.net_read(self.username, self.root,
                                                  safe_key(pool_name),
                                                  allocation_name)
        if not ip_network:
            self.log.info('%s ip network allocation not ready' %
                          allocation_name)
            self.ready = False
            return False

        return ip_network
예제 #7
0
    def cb_create(self, tctx, root, service, proplist):
        self.log.info('Service create(service=', service._path, ')')
        plan = PlanComponent(service, "self", "ncs:self")
        plan.append_state("ncs:init")
        plan.append_state("topology-nodes:device-onboarding")
        plan.append_state("topology-nodes:fetch-sshkey")
        plan.append_state("topology-nodes:sync-from")
        plan.append_state("topology-nodes:day0-config")
        plan.append_state("ncs:ready")

        plan.set_reached("ncs:init")

        template = ncs.template.Template(service)

        try:
            template.apply('onboarding-node')
        except Exception as e:
            self.log.error("Onboarding node failed : " + str(e))
            plan.set_failed("topology-nodes:device-onboarding")
            return

        if not check_device(service):
            template.apply('device-onboarding-kicker')
            return

        plan.set_reached("topology-nodes:device-onboarding")

        try:
            with ncs.maapi.single_write_trans('admin',
                                              'admin',
                                              groups=['ncsadmin']) as t:
                root = ncs.maagic.get_root(t)
                device = root.devices.device[service.name]
                output = device.ssh.fetch_host_keys()
                self.log.info('[{}]fetch result: {}'.format(
                    service.name, output.result))
                t.apply()
        except Exception as e:
            self.log.error("Fetching ssh key failed : " + str(e))
            plan.set_failed("topology-nodes:fetch-sshkey")
            return

        plan.set_reached("topology-nodes:fetch-sshkey")

        try:
            with ncs.maapi.single_write_trans('admin',
                                              'admin',
                                              groups=['ncsadmin']) as t:
                root = ncs.maagic.get_root(t)
                device = root.devices.device[service.name]
                output = device.sync_from()
                self.log.info('Sync-from result: {}'.format(output.result))
                t.apply()
        except Exception as e:
            self.log.error("Sync-From failed : " + str(e))
            plan.set_failed("topology-nodes:sync-from")
            return

        plan.set_reached("topology-nodes:sync-from")

        pool_name = "deviceLoopbacks"
        allocation_name = service.name + "Loopback"

        ip_allocator.net_request(
            service,
            "/topology-nodes:topology-nodes[name='%s']" % (service.name),
            tctx.username, pool_name, allocation_name, 32)

        loopback_ip = ip_allocator.net_read(tctx.username, root, pool_name,
                                            allocation_name)
        if not loopback_ip:
            self.log.info("Alloc not ready")
            return

        vars = ncs.template.Variables()
        vars.add('loopback_ip', loopback_ip)
        vars.add('ASN', AS_No)
        template = ncs.template.Template(service)
        template.apply('day0-config', vars)

        plan.set_reached("topology-nodes:day0-config")
        plan.set_reached("ncs:ready")