Esempio n. 1
0
                        help="gNMI device (http://user:password@host:port)")
    args = parser.parse_args()
    device = urlparse(args.device)

    # log debug messages if verbose argument specified
    if args.verbose:
        logger = logging.getLogger("ydk")
        logger.setLevel(logging.INFO)
        handler = logging.StreamHandler()
        formatter = logging.Formatter(("%(asctime)s - %(name)s - "
                                       "%(levelname)s - %(message)s"))
        handler.setFormatter(formatter)
        logger.addHandler(handler)

    # create gNMI provider
    repository = Repository(YDK_REPO_DIR + device.hostname)
    provider = gNMIServiceProvider(repo=repository,
                                   address=device.hostname,
                                   port=device.port,
                                   username=device.username,
                                   password=device.password)
    # create CRUD service
    crud = CRUDService()

    isis = xr_clns_isis_cfg.Isis()  # create object
    config_isis(isis)  # add object configuration

    # create configuration on gNMI device
    crud.create(provider, isis)

    exit()
def config_bgp_ipv4(yang_repo="",
                    address="",
                    grpc_port="",
                    username="",
                    password="",
                    crud_op="add",
                    bgp={}):

     repository = Repository(yang_repo)
     provider = gNMIServiceProvider(repo=repository, 
                                    address=address, 
                                    port=int(grpc_port), 
                                    username=username, 
                                    password=password)

     gnmi_service = gNMIService()
     crud = CRUDService()

     ni = oc_ni.NetworkInstances.NetworkInstance()

     if "vrf" in list(bgp.keys()):
       ni.name = bgp["vrf"]
     else:
         print("Vrf for network Instance not specified")
         sys.exit(1)

     protocol = ni.protocols.Protocol()

     protocol.identifier =  oc_policy_types.BGP()
     protocol.name = "default"
     protocol.config.identifier = oc_policy_types.BGP()
     protocol.config.name = "default"

     if "as" in list(bgp.keys()):
         protocol.bgp.global_.config.as_ = int(bgp["as"])
     else:
         print("AS for BGP instance not specified")
         sys.exit(1)

     # Fill out your BGP object properly using the Openconfig Yang Model
     # You will need to bring up the IBGP neighbor between rtr1 and rtr4

     #global configs
     protocol.bgp.global_.config.router_id = bgp["router_id"]
     afi_safi = protocol.bgp.global_.afi_safis.AfiSafi()
     afi_safi.afi_safi_name = oc_bgp_types.IPV4UNICAST()
     afi_safi.config.enabled = True
     protocol.bgp.global_.afi_safis.afi_safi.append(afi_safi)
     
     #Peer-group configs
     peer_group = protocol.bgp.peer_groups.PeerGroup()
     peer_group.peer_group_name = bgp["peer-group-name"]
     peer_group.config.peer_group_name = bgp["peer-group-name"]
     peer_group.transport.config.local_address = bgp["peer-group-local-address"]
     afi_safi = peer_group.afi_safis.AfiSafi()
     afi_safi.afi_safi_name = oc_bgp_types.IPV4UNICAST()
     afi_safi.config.enabled = True
     peer_group.afi_safis.afi_safi.append(afi_safi)
     protocol.bgp.peer_groups.peer_group.append(peer_group)
     
     #Neighbor configs
     neighbor = protocol.bgp.neighbors.Neighbor()
     neighbor.config.peer_as = int(bgp["peer-as"])     
     neighbor.neighbor_address = bgp["neighbor"]
     neighbor.config.neighbor_address =  bgp["neighbor"]
     neighbor.config.peer_group = bgp["peer-group-name"]
     protocol.bgp.neighbors.neighbor.append(neighbor)

     ni.protocols.protocol.append(protocol)


     if crud_op == "add":
         response = crud.create(provider, ni)
     elif crud_op == "delete":
         response = crud.delete(provider, ni)
     elif crud_op is "update":
         response = crud.update(provider, ni)
     else:
         print("Invalid operation requested, allowed values =  add, update, delete")
         return False
     return response