Preface

More and more, network administration and software development are converging. On the one hand, there is a push to develop new services that can be provisioned and managed at very high speeds and at a scale that would not be possible without software. This is typically known as software-defined networking (SDN). On the other hand, there is also a push for network administrators to deploy and manage existing services more efficiently by using automation to assist with day-to-day tasks. This book focuses on the latter problem.

While day-to-day network administration may not be the “hot” topic of the day, it is essential. Even very complex SDN solutions are built upon the foundation laid by a well-managed, reliable network. And, while the latest SDN technologies may come and go, it does not appear likely that the need for sound network management practices will disappear anytime soon.

Just as new technologies have presented some interesting and powerful solutions to certain network design problems, Junos supports a number of automation tools that present interesting and powerful solutions to common network automation tasks. Consider some of these possibilities:

  • Representing your devices as Python objects and using Python to manage your devices

  • Managing your devices from a central provisioning/administration system such as Ansible or Puppet

  • Customizing the Junos software to detect and block commits that violate your network standards

  • Developing custom CLI commands that present the information you need in the way you want to see it

  • Programming the Junos software with the intelligence to automatically react to network events

  • Provisioning customers and services using a dynamically applied template

  • Deploying new devices into your network rapidly

This book covers these items, and more. Our aim is to teach you about some of the automation technologies that the Junos software includes or supports. You should also gain new ideas about ways you can apply automation to problems or repetitive tasks in your network—perhaps even things you had not realized were handled so easily through automation.

The goal of this book is to make you successful at deploying automation tools to manage Junos devices in your network. We have attempted to thoroughly cover the things you need to know in order to use a variety of network automation tools. Some information about these tools is available elsewhere; however, the information is not consolidated into one place. Also, the other information that is currently available may be missing important details that are important to understand in order to successfully use the tools to solve real-world problems. Finally, having information about multiple tools in one place lets you compare features and functionality to determine which tool is most suitable to solve any given automation task.

Depending on your background, you may be approaching this as a network engineer who is trying to create automation tools to make your job easier, or as a software developer who is tasked with writing tools to automate network management tasks. Whichever of these two backgrounds most closely matches yours, this book should provide you with information to help you achieve your goal.

We have personally seen the benefits of automation in our careers. Even 15 years ago, network automation was a key competitive advantage in large service provider networks. We have also seen the tools and techniques change and improve over the years. Through the exciting improvements in automation tools, the benefits of automation have only increased. As we share this knowledge with you, we hope you will likewise find it useful. We hope you will come to understand—if you don’t already—why we chose the subtitle “Doing More with Less.”

Assumptions

In this book, we assume that you have access to a device running the Junos software that you can use to follow the examples in this book, as well as to practice your newly acquired skills. Except where otherwise noted, the book covers the features available in Junos release 15.1 and generally assumes the feature set of an MX series product line.

We also assume that you have access to a Unix/Linux host that you can use to install and run some of the tools discussed in the book. If you don’t have access to a physical machine, there are free virtualization products that should enable you to quickly create a virtual machine to meet this need.

In this book, we assume a moderate knowledge of working with the Junos software. In Chapter 1, we cover some basic information about this software. Depending on your background, you may need to supplement this with additional outside education. In addition to some hands-on experience, you might consider reading Aviva Garrett’s Junos Cookbook (O’Reilly) or Day One: Junos Tips, Techniques, and Templates 2011, edited by Jonathan Looney et al. (Juniper Networks Books).

We also assume a basic knowledge of IP routing, Layer 2 switching, and routing protocols. While not critical to understanding the automation tools themselves, this knowledge will help you understand some of the examples used in the book.

Finally, we assume a basic knowledge of Python programming. We use Python 2.7 for a number of examples in the book. While we explain some of the more advanced Python code, it will be helpful to understand the basics of Python programming before you start. If you want to learn more about Python, you may find it helpful to consult another O’Reilly book, such as Learning Python by Mark Lutz.

How to Read This Book

We recommend that everyone read Chapters 1 and 2, which provide important foundational material about the way the Junos software works and the way you can manage it programmatically. Even if you already have deep familiarity with the Junos software, we think these chapters contain important information that may prove helpful to you. Later chapters will assume the knowledge found in these two chapters.

From there, you can explore the remaining chapters. We recommend you read the whole book and explore the tools that are available to you. If you don’t already know about all of these tools, you may find it helpful to learn the situations in which each tool excels. This knowledge will help you choose the best tool for each automation task.

If you do choose to skip around, be aware that some chapters build on others. For example, some of the information in Chapter 5 is prerequisite information for Chapters 6 and 7. Similarly, some of the information in Chapters 4 and 8 is useful background information for understanding Chapter 10.

Finally, everyone should read Chapter 11, which contains examples of the ways you can use the tools in this book to help automate real-world network administration tasks. That chapter also contains important suggestions for best practices you should follow while writing automation for your network.

What’s in This Book?

Chapter 1, Introduction

This chapter provides important foundational material about the operation of the Junos software’s management system.

Chapter 2, RPC Mechanisms

This chapter describes the way you use remote procedure calls (RPCs) to manage the Junos software.

Chapter 3, The RESTful API Service

This chapter describes the Junos RESTful API and provides examples of using the RESTful API to manage the Junos software.

Chapter 4, Junos PyEZ

This chapter describes the way you can use the PyEZ Python package to manage the Junos software. The chapter also describes the way you can use YAML and Jinja2 to extend the functionality of PyEZ.

Chapter 5, Commit Scripts

This chapter describes the way you can use commit scripts to customize the commit process. The chapter also introduces SLAX, a language you can use to write op, commit, and event scripts.

Chapter 6, Op Scripts

This chapter describes the way you can use op scripts to add custom command-line interface (CLI) commands or customize the output from existing commands.

Chapter 7, Event Scripts and Event Policies

This chapter describes the way you can use event scripts and event policies to program the Junos software to automatically respond to events it observes.

Chapter 8, Initial Provisioning

This chapter introduces the ZTP and Netconify tools you can use to automate the initial configuration of new Junos devices.

Chapter 9, Puppet

This chapter describes the way you can add a Puppet agent to the Junos software and manage the Junos software using the Puppet system.

Chapter 10, Ansible

This chapter introduces the way you can manage the Junos software using the Ansible automation engine.

Chapter 11, Putting Automation into Practice

This chapter begins by describing various scenarios where you might use automation and the way you can use the tools described in the book to meet the needs presented by these scenarios. The chapter and book conclude by discussing some best practices to consider as you write your own automation programs.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, file and directory names, file extensions, and RPCs.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Also used for commands and command-line options.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This element signifies a tip or suggestion.

Note

This element signifies a general note.

Caution

This element indicates a warning or caution.

Using Code Examples

Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/AutomatingJunosAdministration.

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Automating Junos Administration by Jonathan Looney and Stacy Smith (O’Reilly). Copyright 2016 Jonathan Looney and Stacy Smith, 978-1-491-92888-2.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online (www.safaribooksonline.com) is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of plans and pricing for enterprise, government, and education, and individuals.

Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/automating-junos.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

We would like to acknowledge and express our gratitude to our management team, who not only had the vision for this book, but gave us the time and resources needed to turn that vision into reality. If it weren’t for Pallavi Mahajan, Piyush Rai, and Ken Sacca, this book would not have been possible. They each embody the Juniper Way.

Patrick Ames has been a constant champion of this book and a helpful guide to its authors. We appreciate his continual encouragement and support, as well as his practical advice in writing this book.

It has truly been a pleasure to work with everyone at O’Reilly, including Courtney Allen and Brian Anderson, Colleen Cole, Rebecca Demarest, and Rachel Head.

We would like to thank our lead technical reviewers, Phil Shafer and Diogo Montagner. Phil is the “father” of the Junos user interface and probably knows more about the Junos management system than anyone else. Diogo supports a major Australian ISP and brought a real-world perspective to his review. We appreciate their insights and helpful suggestions.

In addition to our lead technical reviewers, several professionals at Juniper Networks took time from their busy schedules to help us better understand the material in this book and to provide technical review of the finished product. We appreciate Sri Ram Sankar, Raymond Cheh, and Edward Arcuri taking time to meet with us in the early stages of the project. They provided feedback on early outlines and helped us understand some of the subtleties of the features in the book. In addition, David Gethings, Maruf Yunus, Deepak Jadhav, Guy Davies, Damien Garros, Nitin Kumar, Rick Sherman, Lalit Shinde, Nilesh Simaria, and Ajay Kumar Chintala provided assistance in answering questions, reviewing drafts, or discussing ideas. We also appreciate the automation work that Jeremy Schulman did during his time at Juniper Networks, which resulted in a legacy of automation tools and information that forms an important foundation for much of the automation work related to Junos. Many of these folks are also directly responsible for creating the rich set of automation tools presented in this book. We appreciate their help in keeping us honest, and also their work creating great software.

In addition to the people we’ve named, many other unnamed contributors to internal and external network automation discussion groups have unwittingly contributed to this book. We thank them for sharing their real-world network automation problems and solutions. Their questions and insights have been useful input into understanding the challenges faced by our readers.

We have attempted to thank all of those who assisted us, but if we have accidentally missed you, we apologize and we appreciate your help!

From Jonathan Looney

I would like to thank my wife, Elisabeth, and my children, Isabel and David, for selflessly supporting me as I worked on this book in addition to my already busy schedule. I appreciate their encouragement even as they sacrificed date nights, meals together, and evenings of “chase” as I devoted time to this project. I look forward to making up for those missed activities soon.

I would also like to thank Stacy for putting up with me over the past year as we worked on the book. Writing a book is never easy and could easily strain a friendship. I appreciate his helpful suggestions on improving my chapters and his patience with me even through our disagreements. I have enjoyed working with him, and look forward to continuing our friendship.

Finally, I would like to thank the many people who have spent time teaching and mentoring me over the years. I would like to thank the managers in my career who gave me freedom to explore new ideas and try new things. And I would like to thank the people who have believed in me and encouraged me to try things I wasn’t sure I could accomplish. In a sense, they are all responsible for this book.

From Stacy Smith

I would like to acknowledge my wife, Wanda, and my sons, Ezra and Eli, for extending patience and grace as I spent many evenings and weekends working on this project. Your willingness to support me in this endeavor were key to its success. Thank you for your sacrifice.

I would also like to thank Jonathan for inviting me to write with him. It’s always a pleasure to work with someone so talented, yet so humble. I’m grateful to have had that opportunity many times in the last 13 years, and I hope it continues for many years to come. Thanks for your friendship.

Get Automating Junos Administration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.