Practical Ruby for System Administration (Expert's Voice in Open Source)
Format: PDF / Kindle (mobi) / ePub
Ruby has set the world on fire, proving itself a serious challenger to Perl and Python in all spheres. In particular, more and more people are discovering that Ruby's flexibility, superb feature set, and gentle learning curve make it a natural choice for system administration tasks, from the humblest server to the largest enterprise deployment.
Within the pages of Practical Ruby for System Administration, you'll learn the Ruby way to construct files, tap into clouds of data, build domain-specific languages, perform network traffic analysis, and more.
Based on author André Ben Hamou's own experiences working as a system administrator, this book will help you pick up practical tips on Ruby coding style, learn how to analyze and improve script performance, and make use of no-nonsense advice on scripting workflow, including testing and documentation.
Above all, you'll come to appreciate the sheer power of Ruby and the hundreds of benefits it offers for system administration.
- This book places equal emphasis on fundamental Ruby concepts as well as practical how-tos.
- It uses examples from other languages to ease the transition to Ruby.
- The book is concise, entertaining, and informative—unlike many books aimed at system administrators, which can be overly long and stodgy.
system administrator has time for neither. It is as though the spirit of the Turing test for intelligence has been applied to the Ruby type system. The result of this eminently commonsense approach is that types work for you (in the form of subclassing and variation), rather than the other way around. Type purists may argue that strong types make for strong code, but such purists would be missing the point that this is not weak typing in any way, shape, or form. Objects have a definite class, but
cool,” “some basic stuff you can do with Ruby and a quick rundown of how a Ruby process works,” and “deciding systematically whether to switch to/away from Ruby for a given job.” To borrow a truly virulent phrase from marketing droids, it’s important to “manage expectations” or you’ll just end up disappointed with a great language. Scripts Can Be Faster “Faster than what?” I hear you cry. Obviously, if I can reduce a program to a fundamental set of operations like a = b + c * d, then I’d
disk.reports.create(:mb_used => 15 * 1024). I think you’ll agree that the first form feels more natural and uncoupled from the details of the database structure than the second. The code for this method is in Listing 6-11. Listing 6-11. Adding a Setter to Complement the Getter Added in Listing 6-10 class Disk # previous code def usage=(value) reports.create(:mb_used => value) end end Now that we have a proper set of accessor methods for usage, it is apparent that this approach will not scale
443 proxy_host "localhost" (if proxy_port is set) proxy_port 8080 (if proxy_host is set) user nil password nil use_ssl false timeout 30 With the connection established, the next step is to make the remote procedure call. The call method exists in two variants: call (raises an exception or returns a result) and call2 (returns a success, result pair). Thus when writing code that deals with errors, we have two approaches: begin p server.call("math.Multiply", 23, 14) rescue
# render a representation of the resource end if request.delete? # delete the resource end end end 129 Hamou_821-0 C07.fm Page 130 Wednesday, May 30, 2007 4:42 AM 130 CHAPTER 7 ■ WORKING WITH ENTERPRISE DA TA So I could create a new unreleased book by posting HTML form data to www.beefybooks.com/ books/unreleased, or update one by adding a /15 to the end. This is a nice enough concept, but having to write these conditional blocks in every RESTful method is distinctly inelegant. Also, what