Link Search Menu Expand Document
  1. Zscaler ZPA Servers API
    1. Overview
    2. References
    3. Class Methods
    4. Adding a ZPA Server
    5. Deleting a ZPA Server
    6. Getting information on a ZPA Server
    7. Listing all ZPA Servers
    8. Updating a ZPA Server

Zscaler ZPA Servers API

Overview

Server objects in ZPA are used to define the virtual or physical servers that host an application.

When you define a Server using the ZPA API, you’ll also want to assign it to a Server Group so that you can assign it to an Application Segment.

References

Class Methods

The pyZscaler Servers Class can be accessed via zpa.servers.

The following methods are supported by pyZscaler for ZPA Servers:

Adding a ZPA Server

This section details how you can add a Server in ZPA using pyZscaler.

Class Methods used

  • add_server()

Prerequisites

The following parameters are required to add a new server:

  • name
  • address

Example

Adding a server with a name of mgmt.server.dc.example.com and address of 192.0.2.10. We won’t be setting enabled to True in this case; the server will be left in the disabled state.

from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    # Add a server called mgmt.server.dc.example.com
    zpa.servers.add_server('mgmt.server.dc-p.example.com',
                           address='192.0.2.10')

Detailed Example

Add a server with the following configuration:

  • Server name is webfe.server.dc-p.example.com
  • IP address is 192.0.2.11
  • Description is Web Frontend Server in Primary DC
  • Assign Server to Server Group with ID of 916196382959075481
  • Enable the server
from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    # Add a server called mgmt.server.dc.example.com
    zpa.servers.add_server('webfe.server.dc-p.example.com',
                           address='192.0.2.11',
                           description='Web Frontend Server in Primary DC',
                           app_server_group_ids=['916196382959075481'],
                           enabled=True)

Deleting a ZPA Server

This section details how you can delete a Server in ZPA using pyZscaler.

Class Methods used

  • delete_server()

Prerequisites

You’ll need the id of the server you want to delete.

Example

Delete a ZPA Server with an id of 716195282989075421.

from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    zpa.servers.delete_server('716195282989075421')

Getting information on a ZPA Server

This section details how you can get information on a Server in ZPA using pyZscaler.

Class Methods used

  • get_server()

Prerequisites

Example

Print information for a ZPA Server with an id of 716195282989075422.

from pprint import pprint
from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    # Print all information for the server
    pprint(zpa.servers.get_server('716195282989075422'))

    ## Print the server groups that this server belongs to
    server = zpa.servers.get_server('716195282989075422')
    try:
        for group_id in server['app_server_group_ids']:
            print(group_id)
    except KeyError:
        print('No Server Groups.')

Listing all ZPA Servers

This section details how you can list all Servers in ZPA using pyZscaler.

Class Methods used

  • list_servers()

Example

Iterate through the list of ZPA Servers and print information for each Server.

from pprint import pprint
from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    # Iterate server list and print each server record
    for server in zpa.servers.list_servers():
        pprint(server)

Updating a ZPA Server

This section details how you can update a Server Group in ZPA using pyZscaler.

Class Methods used

  • update_server()

Prerequisites

You’ll need the id for the Server that you want to update.

Example

  • Update a Server of id of 716195282989075425
  • Change the name to DC Jumpbox
  • Add Server to an app_server_group_id of 916196382959075481.
from pprint import pprint
from pyzscaler.zpa import ZPA

with ZPA() as zpa:
    
    # Update server with id of 716195282989075425
    zpa.servers.update_server('716195282989075425',
                              name='DC Jumpbox',
                              app_server_group_ids=['916196382959075481'])