netscaler cookbook
A collection of resources for managing Citrix NetScaler (Nitro API).
This has been written so that adding a missing NetScaler resource should be easy.
Creating a new resource
- All resources should have required attributes: hostname, username, password, and the resource name
- All other attributes (payload for rest call) should default to nil.
- Use http://<netscaler_ip>/nitro/v1/config/<resource_name> to see available payload options.
Creating a new provider
- Actions supported:
- :create - calls
create_resource
- :update - calls
update_resource
- :delete - calls
delete_resource
- :bind - calls
bind_resource
- Attributes in the payload should be passed in as a hash
resource_type
should be the the feature that you're manipulating (ie server, lbvserver, etc)resource_id
should be set to the key of the resource (ie name, servicegroupname, etc)- Be carefull of chef reserved words. If you look at the
netscaler_server
resource/provider you'll see I use the payload key as my attribute names for everthing except forservername
which doesn't exist as a key for theserver
resource type. The key in the options hash is still 'name' though. The options hash key has to match the netscaler payload key.
Supported Platforms
- Any supported by chef
Library Methods
Netscaler::Helper
A collection of methods for CRUD operations on NetScaler
Methods
Name | Vars | Description |
---|---|---|
create_resource | resource_type, resource_id, hostname, username, password, payload = {} | Make a post call to the netscaler |
update_resource | resource_type, resource_id, hostname, username, password, payload = {} | Make a put call to the netscaler |
delete_resource | resource_type, resource_id, hostname, username, password, payload = {} | Make a delete call to the netscaler |
Library Classes
Netscaler::Utilites
A utility class used by Netscaler::Helper
Methods
Name | Vars | Description |
---|---|---|
resource_exists? | resource_type, resource | Check if a resource exists |
key_value_exists? | resource_type, resource, key, value | Check if a key/value exists |
binding_exists? | bind_type, resource_id, bind_type_id | Check if a binding exists |
build_request | method, resource_type, resource, options | Create the rest call |
build_url | method, primary_hostname, resource_type, resource, resource_id, binding | Create the url used for the rest call |
find_primary | method, resource_type, resource, resource_id, binding, payload | Given an array of options, find the primary Netscaler |
save_config | Save the netscaler configuration | |
logout | Log out of the netscaler |
Examples
# New netscaler instance
netscalers = search(:node, "role:netscaler AND chef_environment:#{node.chef_environment}"
netscaler_ips = netscalers.map { |n| n['ipaddress'] }
ns = Netscaler::Utilities.new(
:hostname => netscaler_ips,
:username => 'iamgroot',
:password => 'iamgroot'
)
# Check if a StarLord server exists
resource_exists = ns.resource_exists?('server','StarLord')
# Check if server StarLord exists
server_exists = ns.resource_exists?('server','StarLord')
# Check if StarLord server is UP in Guardians service group
server_up = ns.key_value_exists?(
'server_servicegroup_binding',
'StarLord',
'svrstate',
'UP'
)
# GET request for server StarLord
request = ns.build_request('get', 'server', 'StarLord')
response = request.execute
# Build the rest request to get StarLord server info
url = ns.build_url('get', '123.456.12.34', 'server', 'StarLord')
# Find the primary netscaler given an array
primary = ns.find_primary
# Save the configuration file
ns.save_config
# Logout of the netscaler
ns.logout
Resources/Providers
The idea here is that every rest call will eventually be represented with a new resource/provider. Below are a few examples to get you started.
netscaler_server
Actions
- :create: Create a resource
- :update: Update an existing resource
- :delete: Delete an existing resource
Examples
# Create a new server called StarLord
netscaler_server "Create StarLord" do
servername 'StarLord'
hostname '123.45.123.1'
domainresolveretry 6
username 'iamgroot'
password 'iamgroot'
domain 'mydomain.com'
action :create
end
# Update a server called StarLord
netscaler_server 'Update StarLord' do
servername 'StarLord'
hostname '123.45.123.1'
domainresolveretry 22
username 'iamgroot'
password 'iamgroot'
action :update
end
# Delete a server called StarLord
netscaler_server 'Delete StarLord' do
servername 'StarLord'
hostname '123.45.123.1'
username 'iamgroot'
password 'iamgroot'
action :delete
end
netscaler_servicegroup
Actions
- :create: Create a resource
- :update: Update an existing resource
- :delete: Delete an existing resource
- :bind: Bind one resource to another
Examples
# Create a service group called Guardians
netscaler_servicegroup 'Create Guardians' do
servicegroupname 'Guardians'
servicetype 'HTTP'
comment 'Something good, something bad'
hostname '123.45.123.1'
username 'iamgroot'
password 'iamgroot'
action :create
end
# Bind server StarLord to service group FannyUrAunt
netscaler_servicegroup 'Bind StarLord' do
hostname '172.16.198.2'
username 'iamgroot'
password 'iamgroot'
servicegroupname 'Guardians'
servername 'StarLord'
port 80
action :bind
end
List of created resources/providers
- netscaler_server
- netscaler_servicegroup
TO DO
- More/better testing
- Add more resource/providers
Contributing
- Fork the repository on Github
- Create a named feature branch (i.e.
add-new-recipe
) - Write your change
- Write tests for your change (if applicable)
- Run the tests, ensuring they all pass
- Submit a Pull Request
License and Authors
Author:: Daptiv Engineering (dl_teamengineering@daptiv.com)