Develop > Server Automation Platform > SA CLI methods > SA CLI method tutorial

SA CLI method tutorial

This topic introduces you to the SA CLI methods with examples you can try in your own environment. After completing this tutorial, you should be able to run SA CLI methods, examine the self file of an SA object, and create a script that invokes SA CLI methods on multiple servers.

Before starting the tutorial, you need the following capabilities:

  • You can log on to the SA Client.
  • Your SA user has Read & Write permissions on at least one managed server. Typically assigned by a security administrator, permissions are discussed in the Server Automation Administer section on the HPE SSO portal.
  • Your SA user has all OGSH permissions on the same managed server. For information on these permissions, see the “aaa Utility” section in the Server Automation Using Guide on the HPE SSO portal.
  • You are familiar with the OGSH and the OGFS. If these features are new to you, before proceeding with this tutorial, see the Global Shell section inthe Server Automation Using Guide on the HPE SSO portal.

The example commands in this tutorial operate on a Windows server named abc.example.com. This server belongs to a server group named All Windows Servers. When trying out these commands, substitute abc.example.com with the host name of the managed server you have permission to access.

  1. Open an OGSH session.

    You can open a Global Shell session from within the SA Client. From the Actions menu, select Global Shell. You can also open an OGSH session from a terminal client running on your desktop. For instructions, see Opening a Global Shell Session section in the Server Automation Using Guide on the HPE SSO portal.
  2. List the SA CLI methods for a server.

    The method subdirectory of a specific server contains executable files—the methods you can run for that server. The following example lists the SA CLI methods for the abc.example.com server:

    $ cd /opsw/Server/@/abc.example.com/method
    $ ls -1
    addDeviceGroups
    attachPolicies
    attachVirtualColumn
    checkDuplex
    clearCustAttrs
    ...


    These methods have instance context – they act on a specific server instance (in this case, abc.example.com). The server instance can be inferred from the path of the method. Methods with static context are discussed in step 5.
  3. Run an SA CLI method without parameters.

    To display the public server groups that abc.example.com belongs to, invoke the getDeviceGroups method:

    $ cd /opsw/Server/@/abc.example.com/method
    $ ./getDeviceGroups
    Accounting App
    All Windows Servers
    Visalia Vendors
  4. Run a method with a parameter.

    Command-line parameters for methods are indicated by name-value pairs, separated by white space characters. In the following invocation of setCustomer, the parameter name is customer and the value is 20039. The :i at the end of the parameter name is an ID format specifier, which is discussed in a later step.

    The following method invocation changes the customer of the abc.example.com server from Opsware to C39. The ID of customer C39 is 20039.

    $ cd /opsw/Server/@/abc.example.com
    $ cat attr/customer ; echo
    Opsware
    $ method/setCustomer customer:i=20039
    $ cat attr/customer ; echo
    C39
  5. List the static context methods for managed servers.

    Static context methods reside under the /opsw/api directory. These methods are not limited to a specific instance of an object.

    To list the static methods for servers, enter the following commands:

    $ cd /opsw/api/com/opsware/server/ServerService/method

    $ ls


    The methods listed are the same as those displayed in step 2.
  6. Run a method with the self parameter.

    This step invokes getDeviceGroups as a static context method. Unlike the instance context method shown in step 3, the static context method requires the self parameter to identify the server instance.
    For example, suppose that the abc.example.com server has an ID of 530039. To list the groups of this server, enter the following commands:

    $ cd /opsw/api/com/opsware/server/ServerService/method
    $ ./getDeviceGroups self:i=530039
    Accounting App
    All Windows Servers
    Visalia Vendors


    Compare this invocation of getDeviceGroups with the invocation in step 3 that demonstrates instance context. Both invocations run the same underlying method in the API and return the same results.
  7. Examine the self file of a server.

    Within SA, each managed server is an object. However, OGFS is a file system, not an object model. The self file provides access to various representations of an SA object. These representations are the ID, name, and structure.

    The default representation for a server is its name. For example, to display the name of a server, enter the following commands:

    $ cd /opsw/Server/@/abc.example.com
    $ cat self ; echo
    abc.example.com

    If you know the ID of a server, you can get the name from the self file, as in the following example:

    $ cat /opsw/.Server.ID/530039/self ; echo
    abc.example.com
  8. Indicate an ID format specifier on a self file.

    To select a particular representation of the self file, enter a period, then the file name, followed by the format specifier. For example, the following cat command includes the format specifier (:i) to display the server ID:

    $ cd /opsw/Server/@/abc.example.com
    $ cat .self:i ; echo
    com.opsware.server.ServerRef:530039


    This output shows that the ID of abc.example.com is 530039. The com.opsware.server.ServerRef is the class name of a server reference, the corresponding object in the SA API.

    Note The leading period is required with format specifiers on files and method return values, but is not indicated with method parameters.

  9. Indicate the structure format specifier.

    The structure format specifier (:s) indicates the attributes of a complex object. The attributes are displayed as name-value pairs, all enclosed in curly braces. Structure formats are used to specify method parameters on the command-line that are complex objects. For an example method call, see Complex objects and arrays as parameters.

    The following example displays abc.example.com with the structure format:

    $ cd /opsw/Server/@/abc.example.com
    $ cat .self:s ; echo
    {
    managementIP="192.168.8.217"
    modifiedBy="spujare"
    manufacturer="DELL COMPUTER CORPORATION"
    use="UNKNOWN"
    discoveredDate=1149012848000
    origin="ASSIMILATED"
    osSPVersion="SP4"
    locale="English_United States.1252"
    reporting=false
    netBIOSName=
    previousSWReg=1150673874000
    osFlavor="Windows 2000 Advanced Server"
    . . .


    The attributes of a server are also represented by the files in the attr directory, for example:

    $ pwd
    /opsw/Server/@/abc.example.com
    $ cat attr/osFlavor ; echo
    Windows 2000 Advanced Server
  10. Create a script that invokes an SA CLI method.

    The example script shown in this step iterates through the servers of the public server group named All Windows Servers. On each server, the script runs the getCommCheckTime SA CLI method.

    First, return to your home directory in the OGFS:

    $ cd
    $ cd public/bin


    Next, run the vi editor:

    $ vi

    In vi, insert the following lines to create a bash script:

    #!/bin/bash
    # iterate_time.sh

    METHOD_DIR="/opsw/api/com/opsware/server/ServerService/method"
    GROUP_NAME="All Windows Servers"
    cd "/opsw/Group/Public/$GROUP_NAME/@/Server"

    for SERVER_NAME in *
    do
    SERVER_ID=`cat $SERVER_NAME/.self:i`
    echo $SERVER_NAME
    $METHOD_DIR/getCommCheckTime self:i=$SERVER_ID
    echo
    echo
    done


    Save the file in vi, naming it iterate_time.sh. Quit vi.

    Change the permissions of iterate_time.sh with chmod, and then run it:

    $ chmod 755 iterate_time.sh
    $ ./iterate_time.sh
    abc.example.com
    2006/06/20 16:46:56.000
    . . .