You are previewing Mastering CloudForms Automation.
O'Reilly logo
Mastering CloudForms Automation

Book Description

Learn how to work with the Automate feature of CloudForms, the powerful Red Hat cloud management platform that lets you administer your virtual infrastructure, including hybrid public and private clouds. This practical hands-on introduction shows you how to increase your operational efficiency by automating day-to-day tasks that now require manual input. Throughout the book, author Peter McGowan provides a combination of theoretical information and practical coding examples to help you learn the Automate object model. With this CloudForms feature, you can create auto-scalable cloud applications, eliminate manual decisions and operations when provisioning virtual machines and cloud instances, and manage your complete virtual machine lifecycle.

Table of Contents

  1. Preface
    1. A Brief Word on Terminology
    2. Who Should Read This Book?
    3. Why I Wrote This Book
    4. Versions and Releases
    5. Navigating This Book
      1. Part I, Working with CloudForms Automate
      2. Part II, Provisioning Virtual Machines
      3. Part III, Working with Services
      4. Part IV, Retirement
      5. Part V, Integration
      6. Part VI, Miscellaneous
    6. Online Resources
      1. Official Documentation
      2. Code Repositories
      3. Forums
      4. Blogs
    7. Conventions Used in This Book
    8. Using Code Examples
    9. Safari® Books Online
    10. How to Contact Us
    11. Acknowledgments
  2. I. Working with CloudForms Automate
  3. 1. Introduction to CloudForms
    1. What Is CloudForms?
    2. Providers
      1. Cloud Providers
      2. Infrastructure Providers
      3. Configuration Management Providers
      4. Container Providers
      5. Mixing and Matching Providers
    3. The Capabilities of CloudForms
      1. Insight
      2. Control
      3. Automate
      4. Integrate
    4. The CloudForms Appliance
      1. Ruby and Rails
    5. Projects, Products, and Some History
      1. ManageIQ (the Project)
      2. Red Hat CloudForms (the Product)
      3. CloudForms Management Engine (the Appliance)
    6. Summary
      1. Further Reading
  4. 2. Introduction to the Automate Datastore
    1. The Automate Explorer
    2. The Automate Datastore
    3. Domains
      1. Domain Priority
      2. Importing/Exporting Domains
      3. Copying Objects Between Domains
      4. Importing Old Format Exports
    4. Namespaces
    5. Classes
      1. Schemas
      2. Adding or Editing a Schema
      3. Relationships
    6. Instances
    7. Methods
    8. Summary
      1. Further Reading
  5. 3. Writing and Running Our Own Automation Scripts
    1. Creating the Environment
      1. Adding a New Domain
      2. Adding a Namespace
      3. Adding a Class
      4. Editing the Schema
    2. Hello, World!
      1. Adding a New Instance
      2. Adding a New Method
    3. Running the Instance
    4. Exit Status Codes
    5. Summary
  6. 4. Using Schema Variables
    1. Preparing the Schema
    2. The Instance
    3. The Method
    4. Running the Instance
    5. Summary
  7. 5. Working with Virtual Machines
    1. Custom Attributes
    2. Creating the Service Dialog
    3. Creating the Instance and Method
      1. The Code
      2. Creating the /System Entry Point
    4. Running Automation Scripts from a Button
      1. Creating the Button Group
      2. Creating the Button
      3. Running the Instance
    5. Summary
      1. Further Reading
  8. 6. Peeping Under the Hood
    1. A Little Rails Knowledge (Goes a Long Way)
      1. Plain Old Ruby
      2. Model-View-Controller
      3. Active Record Associations
      4. Rails Helper Methods (.find_by_*)
    2. Service Models
    3. Service Model Object Properties
      1. Attributes
      2. Virtual Columns
      3. Associations
      4. Methods
    4. Distributed Ruby
    5. Summary
      1. Further Reading
  9. 7. $evm and the Workspace
    1. $evm.log
    2. $evm.root
    3. $evm.object, $evm.current, and $evm.parent
    4. $evm.vmdb
      1. Single-Argument Form
      2. Two-Argument Form
    5. $evm.execute
      1. Examples
    6. $evm.instantiate
    7. Summary
      1. Further Reading
  10. 8. A Practical Example: Enforcing Anti-Affinity Rules
    1. Task
    2. Solution
      1. relocate_vm
      2. send_email
      3. Main Code
    3. Summary
      1. Further Reading
  11. 9. Using Tags from Automate
    1. Creating Tags and Categories
    2. Assigning and Removing Tags
    3. Testing Whether an Object Is Tagged
    4. Retrieving an Object’s Tags
    5. Searching for Specifically Tagged Objects
      1. Practical Example
    6. Getting the List of Tag Categories
    7. Getting the List of Tags in a Category
    8. Finding a Tag’s Name, Given Its Description
    9. Finding a Specific Tag (MiqAeServiceClassification) Object
    10. Deleting a Tag Category
    11. Summary
      1. Further Reading
  12. 10. Investigative Debugging
    1. InspectMe
    2. object_walker
      1. Black or Whitelisting Associations
      2. object_walker_reader
    3. Rails Console
    4. Rails db
    5. Summary
      1. Further Reading
  13. 11. Ways of Entering Automate
    1. Buttons and Simulation
    2. RESTful API
    3. Control Policy Actions
    4. Alerts
    5. Service Dialog Dynamic Elements
    6. Finding Out How Our Method Has Been Called
    7. Summary
      1. Further Reading
  14. 12. Requests and Tasks
    1. The Need for Approval
    2. Request and Task Objects
    3. Approval
    4. Object Class Ancestry
    5. Context
    6. Object Contents
      1. Dumping the Object Contents
      2. Comparing the Objects
    7. Summary
      1. Further Reading
  15. 13. State Machines
    1. Building a State Machine
      1. State Machine Schema Field Columns
      2. State Machine Example
    2. State Variables
      1. Setting State Result
      2. State Retries
      3. Getting the State Machine Name
      4. Getting the Current Step in the State Machine
      5. Getting the on_entry, on_exit, on_error Status State
    3. State Machine Enhancements in CloudForms 4.0
      1. Error Recovery
      2. Skipping States
      3. Jumping to a Specific State
      4. Nested State Machines
    4. Saving Variables Between State Retries
    5. Summary
      1. Further Reading
  16. 14. More Advanced Schema Features
    1. Messages
      1. Specifying Our Own Messages
    2. Assertions
    3. Collections
    4. Summary
  17. 15. Event Processing
    1. Event Processing Component Parts
      1. The Event Stream Object
      2. The Event Switchboard
      3. Event Handlers
    2. Catching and Handling External Events
      1. Event Catching
      2. Event Processing
    3. Creating and Processing Internal Events
      1. Event-Initiated Control Policy Processing
      2. Event-Initiated Alert Processing
    4. Event-Initiated Automation Request Workflows
      1. Step 1: The request_created Event
      2. Step 2: The request_approved Event
      3. Step 3: The request_starting Event
      4. Step 4: Automation Task Processing
    5. Extending Automate Event Handling
      1. Adding a New Automation Instance to /System/Event/EmsEvent/
    6. Summary
    7. Next Steps
  18. II. Provisioning Virtual Machines
  19. 16. Provisioning a Virtual Machine
    1. The Provisioning Process
    2. Group-Specific Considerations, and Common Processing
    3. Summary
  20. 17. The Provisioning Profile
    1. Location
    2. Schema
    3. Customizing the Profile
    4. Profile Processing in Detail
      1. The Provisioning Dialog
      2. VM Name (Pass 1)
      3. Approval
      4. Quota
      5. VM Name (Pass 2)
      6. VM Provisioning State Machine
    5. Summary
      1. Further Reading
  21. 18. Approval
    1. Approval Workflow
      1. Request Created Event
      2. Methods
      3. Request Pending Event
    2. Overriding the Defaults
      1. Template Tagging
    3. VM Provisioning–Related Email
    4. Summary
      1. Further Reading
  22. 19. Quota Management
    1. Quotas in Cloudforms 4.0
      1. Quota Source
    2. Quota Workflow
    3. Summary
      1. Further Reading
  23. 20. The Options Hash
    1. Request Object (miq_provision_request)
    2. Task Object (miq_provision)
      1. Adding Network Adapters
    3. Correlation with the Provisioning Dialog
    4. Adding Our Own Options: The ws_values Hash
    5. Summary
  24. 21. The Provisioning State Machine
    1. State Machine Schema
    2. Filling in the Blanks
    3. Summary
  25. 22. Customizing Virtual Machine Provisioning
    1. Scenario
    2. Task
    3. Methodology
      1. Step 1: Extend the State Machine
      2. Step 2: Disable Auto-Power-On
      3. Step 3: Create Our New Instances and Methods
      4. Step 4: Add Our New Instances to the Copied State Machine
      5. Step 5: Provision a Virtual Machine
    4. Summary
      1. Further Reading
  26. 23. Virtual Machine Naming During Provisioning
    1. VM Name-Related Provisioning Options
      1. Inputs to the Naming Process
      2. Outputs from the Naming Process
    2. Name Processing
      1. Provisioning a Single VM or Instance
      2. Provisioning Multiple VMs or Instances in a Single Request
    3. Customizing the Naming Process
    4. Summary
      1. Further Reading
  27. 24. Virtual Machine Placement During Provisioning
    1. Placement Methods
    2. Method Description
    3. Customising Placement
      1. Using Alternative Placement Methods
    4. Summary
      1. Further Reading
  28. 25. The Provisioning Dialog
    1. Tabs and Input Fields
    2. Dialog YAML
    3. Selection of VM Provisioning Dialog
    4. Group-Specific Dialogs
      1. Example: Expanding the Dialog
    5. Summary
      1. Further Reading
  29. 26. Virtual Machine Provisioning Objects
    1. Object Overview
    2. The Provision Request Object
      1. Request Context
      2. Task Context
    3. The Provision Task Object
    4. The Source Object
    5. The Destination Object
    6. Summary
  30. 27. Creating Provisioning Requests Programmatically
    1. Making the Call
    2. Argument List
      1. version
      2. templateFields
      3. vmFields
      4. requester
      5. tags
      6. additionalValues (aka ws_values)
      7. emsCustomAttributes
      8. miqCustomAttributes
    3. Setting Placement Options
    4. Summary
      1. Further Reading
  31. 28. Integrating with Satellite 6 During Provisioning
    1. Hosts and Content Hosts
    2. The Satellite 6 Host Entry
    3. Non-CloudForms Preparation
      1. Creating the Host Groups in Satellite 6
      2. Creating the Activation Keys in Satellite 6
      3. Adding an SSH Key to the VMware Template
    4. Installing and Configuring Ansible on the CloudForms Appliance
    5. Modifying the CloudForms Provisioning Workflow
      1. RegisterSatellite
      2. ActivateSatellite
    6. Testing the Integration: Provisioning a New VM
    7. Summary
      1. Further Reading
  32. III. Working with Services
  33. 29. Service Dialogs
    1. Dialog Elements
    2. Dynamic Elements
      1. Populating the Dynamic Fields
    3. Read-Only and Protected Elements
      1. Programmatically Populating a Read-Only Text Box
    4. Element Validation
    5. Using the Input from One Element in Another Element’s Dynamic Method
      1. Example
    6. Summary
      1. Further Reading
  34. 30. The Service Provisioning State Machine
    1. Class and Instances
    2. Passing Service Dialog Options to the Child and Grandchild Tasks
    3. Accessing the Service Dialog Options
      1. ConfigureChildDialog
    4. Summary
      1. VM Naming for Services
  35. 31. Catalog{Item,Bundle}Initialization
    1. CatalogItemInitialization
      1. Service Dialog Element Naming Convention
    2. CatalogBundleInitialization
    3. Summary
      1. Further Reading
  36. 32. Approval and Quota
    1. Triggering Events
    2. Approval
      1. Customizing Approval
    3. Quota
      1. Email
    4. Summary
  37. 33. Creating a Service Catalog Item
    1. The Service Dialog
      1. Finding the Correct Element Names
      2. Creating the Service Dialog
    2. Creating the Service Catalog Item
      1. Create a Catalog
      2. Creating the Catalog Item
    3. Ordering the Catalog Item
    4. Summary
      1. Further Reading
  38. 34. Creating a Service Catalog Bundle
    1. Creating the Service Dialog for the Bundle
    2. Preparing the Service Catalog Items
    3. Creating the Service Catalog Bundle
    4. Ordering the Catalog Bundle
    5. Summary
      1. Further Reading
  39. 35. Service Objects
    1. Object Structure
      1. Service Template Provision Task
      2. Service Template Provisioning Request
      3. Child miq_request_task
      4. Grandchild miq_request_task
    2. Summary
  40. 36. Log Analysis During Service Provisioning
    1. Initial Request
    2. Profile Lookup
    3. Request Processing and Approval
    4. Service Template Provisioning Tasks
    5. VM Provisioning Task
    6. Service State Machine CheckProvisioned
    7. VM State Machine CheckProvisioned
    8. Virtual Machine Provision Complete
    9. Service Provision Complete
    10. Summary
  41. 37. Service Hierarchies
    1. Organizing Our Services
      1. Creating an Empty Service
    2. Adding VMs and Services to Existing Services
      1. Adding the Button
    3. Summary
  42. 38. Service Reconfiguration
    1. Reconfigure Entry Point
    2. Service Design
    3. Adding a Configuration Management Provider
    4. Automate Datastore Components
      1. Creating the Namespaces and State Machines
      2. Email Classes
      3. Policies
    5. Modifying the VM Provision Workflow
    6. Service Dialog
      1. Elements
    7. Instances and Methods
      1. Dynamic Dialogs
      2. Configuration-Related Methods
    8. Testing
    9. Summary
  43. 39. Service Tips and Tricks
    1. Test Virtual Machine Provisioning First
    2. Re-create the Service Item if the Template Changes
    3. Custom State Machines
    4. Summary
  44. IV. Retirement
  45. 40. Virtual Machine and Instance Retirement
    1. Initiating Retirement
    2. Retirement-Related Attributes and Methods
    3. VM Retirement State Machine
      1. StartRetirement
      2. PreRetirement/CheckPreRetirement
      3. RemoveFromProvider/CheckRemovedFromProvider
      4. FinishRetirement
      5. DeleteFromVMDB
    4. Summary
      1. Further Reading
  46. 41. Service Retirement
    1. Defining a Service Retirement Entry Point
    2. Initiating Retirement
    3. Retirement-Related Attributes and Methods
    4. Service Retirement State Machine
      1. StartRetirement
      2. RetireService/CheckServiceRetired
      3. FinishRetirement
      4. DeleteServiceFromVMDB
    5. Summary
  47. V. Integration
  48. 42. Calling Automation Using the RESTful API
    1. API Entry Point
    2. Returning Results to the Caller
    3. Authentication and auto_approve
    4. Zone Implications
    5. run_via_api
    6. Summary
      1. Further Reading
  49. 43. Automation Request Approval
    1. Implementing a Custom Approval Workflow
      1. Namespace
      2. Group Profile
      3. State Machine
      4. Email Classes
    2. Policies
      1. AutomationRequest_created
      2. AutomationRequest_pending
    3. Testing
    4. Summary
  50. 44. Calling External Services
    1. Calling a SOAP API Using the Savon Gem
    2. Calling an OpenStack API Using the fog Gem
    3. Reading from a MySQL Database Using the MySQL Gem
    4. Summary
      1. Further Reading
  51. VI. Miscellaneous
  52. 45. Distributed Automation Processing
    1. Nondistributed Automation Operations
    2. Distributed Automation Operations
    3. Tracing Queueing/Dequeueing Operations
    4. Detailed Queue Analysis
      1. Monitoring the Queue During an Automation Operation
    5. Troubleshooting
    6. Summary
  53. 46. Argument Passing and Handling
    1. Case 1: Calling from a Button
    2. Case 2: Calling from the RESTful API
    3. Case 3: Calling from a Relationship or Automate Datastore URI
    4. Case 4: Passing Arguments via the ws_values Hash During a VM Provision
    5. Passing Arguments When Calling a Method in the Same Class
    6. Summary
  54. 47. Miscellaneous Tips
    1. Updating the Appliance
    2. The ManageIQ Coding Style and Standards Guide
    3. Defensive Programming
    4. Catch Exceptions
    5. Use an External IDE
    6. Version Control
    7. Use Configuration Domains
    8. Summary
  55. Index