We might have more than one load balancer that we would like to manage and monitor. Therefore we'll create a simple configuration file that identifies every one of them and would also contain login details and service groups.

Since it's going to be used by people who are reasonably comfortable with scripting and is not a script targeting simple users, we can create a Python file with statically defined variables and import it.

Listing 2-6 is the example I will be using throughout this chapter.

Listing 2-6. A configuration file with load balancer details #!/usr/bin/env python netscalers = {

'default' 'primary'

primary {

As you can see, we have two netscalers here, primary and secondary, with different IP addresses (you can have different users and passwords as well). No service groups are defined yet; we can add those later when we need to.

Within our tools, if we need to access this configuration data we would retrieve it as shown in Listing 2-7.

Listing 2-7. Accessing configuration data import ns_config as config

# to access configuration of the 'primary' loadbalancer username_pri = config.netscalers['primary']['USERNAME']

# to access configuration of the default loadbalancer default_lb = config.netscalers['default'] username_def = config.netscalers[default_lb]['USERNAME']

Was this article helpful?

0 0

Post a comment