{"id":14008193,"url":"https://github.com/scottdware/go-junos","last_synced_at":"2025-07-24T03:32:09.349Z","repository":{"id":25586621,"uuid":"29020827","full_name":"scottdware/go-junos","owner":"scottdware","description":"Go package for automation of Junos (Juniper Networks) devices.","archived":false,"fork":false,"pushed_at":"2020-08-09T14:34:46.000Z","size":346,"stargazers_count":80,"open_issues_count":6,"forks_count":41,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-10T11:02:42.998Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scottdware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-09T14:59:31.000Z","updated_at":"2024-04-21T18:19:04.000Z","dependencies_parsed_at":"2022-08-24T06:31:13.712Z","dependency_job_id":null,"html_url":"https://github.com/scottdware/go-junos","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottdware%2Fgo-junos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottdware%2Fgo-junos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottdware%2Fgo-junos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottdware%2Fgo-junos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scottdware","download_url":"https://codeload.github.com/scottdware/go-junos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227410494,"owners_count":17774758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-10T11:01:23.613Z","updated_at":"2024-11-30T19:30:49.988Z","avatar_url":"https://github.com/scottdware.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## go-junos\r\n[![GoDoc](https://godoc.org/github.com/scottdware/go-junos?status.svg)](https://godoc.org/github.com/scottdware/go-junos) [![Travis-CI](https://travis-ci.org/scottdware/go-junos.svg?branch=master)](https://travis-ci.org/scottdware/go-junos) [![Go Report Card](https://goreportcard.com/badge/github.com/scottdware/go-junos)](https://goreportcard.com/report/github.com/scottdware/go-junos)\r\n\r\nA Go package that interacts with Junos devices, as well as Junos Space, and allows you to do the following:\r\n\r\n* Run operational mode commands, such as `show`, `request`, etc..\r\n* Compare the active configuration to a rollback configuration (diff).\r\n* Rollback the configuration to a given state or a \"rescue\" config.\r\n* Configure devices by submitting commands, uploading a local file or from a remote FTP/HTTP server.\r\n* Commit operations: lock, unlock, commit, commit at, commit confirmed, commit full.\r\n* [Device views][views] - This will allow you to quickly get all the information on the device for the specified view.\r\n* [SRX] Convert from a zone-based address book to a global one.\r\n\r\nJunos Space \u003c= 15.2\r\n\r\n* Get information from Junos Space managed devices.\r\n* Add/remove devices from Junos Space.\r\n* List all software image packages that are in Junos Space.\r\n* Stage and deploy software images to devices from Junos Space.\r\n* Create, edit and delete address and service objects/groups.\r\n* Edit address and service groups by adding or removing objects to them.\r\n* View all policies managed by Junos Space.\r\n* Publish policies and update devices.\r\n* Add/modify polymorphic (variable) objects.\r\n\r\n### Installation\r\n`go get -u github.com/scottdware/go-junos`\r\n\r\n\u003e **Note:** This package makes all of it's calls over [Netconf][netconf-rfc] using the [go-netconf][go-netconf] package from\r\n [Juniper Networks][juniper]. Please make sure you allow Netconf communication to your devices:\r\n```\r\nset system services netconf ssh\r\nset security zones security-zone \u003cxxx\u003e interfaces \u003cxxx\u003e host-inbound-traffic system-services netconf\r\n```\r\n\r\n### Authentication Methods\r\nThere are two different ways you can authenticate against to device. Standard username/password combination, or use SSH keys.\r\nThere is an [AuthMethod][authmethod] struct which defines these methods that you will need to use in your code. Here is an example of \r\nconnecting to a device using only a username and password.\r\n\r\n```Go\r\nauth := \u0026junos.AuthMethod{\r\n    Credentials: []string{\"scott\", \"deathstar\"},\r\n}\r\n\r\njnpr, err := junos.NewSession(\"srx.company.com\", auth)\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n```\r\n\r\nIf you are using SSH keys, here is an example of how to connect:\r\n\r\n```Go\r\nauth := \u0026junos.AuthMethod{\r\n    Username:   \"scott\",\r\n    PrivateKey: \"/home/scott/.ssh/id_rsa\",\r\n    Passphrase: \"mysecret\",\r\n}\r\n\r\njnpr, err := junos.NewSession(\"srx.company.com\", auth)\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n```\r\n\r\nIf you do not have a passphrase tied to your private key, then you can omit the `Passphrase` field entirely. In the above example,\r\nwe are connecting from a *nix/Mac device, as shown by the private key path. No matter the OS, as long as you provide the location of the\r\nprivate key file, you should be fine.\r\n\r\nIf you are running Windows, and using PuTTY for all your SSH needs, then you will need to generate a public/private key pair by using\r\nPuttygen. Once you have generated it, you will need to export your private key using the OpenSSH format, and save it somewhere as shown below:\r\n\r\n![alt-text](https://raw.githubusercontent.com/scottdware/images/master/puttygen-export-openssh.png \"Puttygen private key export\")\r\n\r\n### Examples\r\nVisit the [GoDoc][godoc-go-junos] page for package documentation and examples.\r\n\r\nConnect to a device, and view the current config to rollback 1.\r\n```Go\r\nauth := \u0026junos.AuthMethod{\r\n    Credentials: []string{\"admin\", \"Juniper123!\"},\r\n}\r\n\r\njnpr, err := junos.NewSession(\"qfx-switch.company.com\", auth)\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n\r\ndefer jnpr.Close()\r\n\r\ndiff, err := jnpr.Diff(1)\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n\r\nfmt.Println(diff)\r\n\r\n// Will output the following\r\n\r\n[edit vlans]\r\n-   zzz-Test {\r\n-       vlan-id 999;\r\n-   }\r\n-   zzz-Test2 {\r\n-       vlan-id 1000;\r\n-   }\r\n```\r\n\r\nView the routing-instance configuration.\r\n```Go\r\nauth := \u0026junos.AuthMethod{\r\n    Username:   \"admin\",\r\n    PrivateKey: \"/home/scott/.ssh/id_rsa\",\r\n}\r\n\r\njnpr, err := junos.NewSession(\"srx.company.com\", auth)\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n\r\ndefer jnpr.Close()\r\n\r\nriConfig, err := jnpr.GetConfig(\"text\", \"routing-instances\")\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n\r\nfmt.Println(riConfig)\r\n\r\n// Will output the following\r\n\r\n## Last changed: 2017-03-24 12:26:58 EDT\r\nrouting-instances {\r\n    default-ri {\r\n        instance-type virtual-router;\r\n        interface lo0.0;\r\n        interface reth1.0;\r\n        routing-options {\r\n            static {\r\n                route 0.0.0.0/0 next-hop 10.1.1.1;\r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n### Views\r\nDevice views allow you to quickly gather information regarding a specific \"view,\" so that you may use that information\r\nhowever you wish. A good example, is using the \"interface\" view to gather all of the interface information on the device,\r\nthen iterate over that view to see statistics, interface settings, etc.\r\n\r\n\u003e **Note:** Some of the views aren't available for all platforms, such as the `ethernetswitch` and `virtualchassis` on an SRX or MX.\r\n\r\nCurrent out-of-the-box, built-in views are:\r\n\r\nViews | CLI equivilent\r\n--- | ---\r\n`arp` | `show arp`\r\n`route` | `show route`\r\n`bgp` | `show bgp summary`\r\n`interface` | `show interfaces`\r\n`vlan` | `show vlans`\r\n`ethernetswitch` | `show ethernet-switching table`\r\n`inventory` | `show chassis hardware`\r\n`virtualchassis` | `show virtual-chassis status`\r\n`staticnat` | `show security nat static rule all`\r\n`sourcenat` | `show security nat source rule all`\r\n`storage` | `show system storage`\r\n`firewallpolicy` | `show security policies` (SRX only)\r\n`lldp` | `show lldp neighbors`\r\n\r\n\u003e**NOTE**: Clustered SRX's will only show the NAT rules from one of the nodes, since they are duplicated on the other.\r\n\r\nWhen using the `interface` view, by default it will return all of the interfaces on the device. If you wish to see only a particular\r\ninterface and all of it's logical interfaces, you can optionally specify the name of an interface using the `option` parameter, e.g.:\r\n\r\n`jnpr.View(\"interface\", \"ge-0/0/0\")`\r\n\r\n##### Creating Custom Views\r\n\r\nYou can even create a custom view by creating a `struct` that models the XML output from using the `GetConfig()` function. Granted,\r\nthis is a little more work, and requires you to know a bit more about the Go language (such as unmarshalling XML), but if there's a custom\r\nview that you want to see, it's possible to do this for anything you want.\r\n\r\nI will be adding more views over time, but feel free to request ones you'd like to see by [emailing](mailto:scottdware@gmail.com) me, or drop\r\nme a line on [Twitter](https://twitter.com/scottdware).\r\n\r\n**Example:** View the ARP table on a device\r\n```Go\r\nview, err := jnpr.View(\"arp\")\r\nif err != nil {\r\n    fmt.Println(err)\r\n}\r\n\r\nfmt.Printf(\"# ARP entries: %d\\n\\n\", view.Arp.Count)\r\nfor _, a := range view.Arp.Entries {\r\n    fmt.Printf(\"MAC: %s\\n\", a.MACAddress)\r\n    fmt.Printf(\"IP: %s\\n\", a.IPAddress)\r\n    fmt.Printf(\"Interface: %s\\n\\n\", a.Interface)\r\n}\r\n\r\n// Will print out the following\r\n\r\n# ARP entries: 4\r\n\r\nMAC: 00:01:ab:cd:4d:73\r\nIP: 10.1.1.28\r\nInterface: reth0.1\r\n\r\nMAC: 00:01:ab:cd:0a:93\r\nIP: 10.1.1.30\r\nInterface: reth0.1\r\n\r\nMAC: 00:01:ab:cd:4f:8c\r\nIP: 10.1.1.33\r\nInterface: reth0.1\r\n\r\nMAC: 00:01:ab:cd:f8:30\r\nIP: 10.1.1.36\r\nInterface: reth0.1\r\n```\r\n\r\n[netconf-rfc]: https://tools.ietf.org/html/rfc6241\r\n[go-netconf]: https://github.com/Juniper/go-netconf\r\n[juniper]: http://www.juniper.net\r\n[godoc-go-junos]: https://godoc.org/github.com/scottdware/go-junos\r\n[views]: https://github.com/scottdware/go-junos#views\r\n[authmethod]: https://godoc.org/github.com/scottdware/go-junos#AuthMethod\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottdware%2Fgo-junos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottdware%2Fgo-junos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottdware%2Fgo-junos/lists"}