BigAdmin System Administration Portal
Sun Docs
Print-friendly VersionPrint-friendly Version

Getting Started With the Sun Connection Satellite Python API

Juergen Fleischer, September 21, 2007

This article describes how to use the Python API scripts within Sun Connection's satellite deployment architecture to automate complex tasks which would otherwise require lots of time using the GUI.


Prerequisites

To use the Sun Connection Python API, the following software must be installed on your Sun Connection system:

  • Version 1.1.x of Sun Connection's satellite deployment architecture on Solaris 10 OS or supported Linux OS.

    For a list of the supported operating systems, see http://www.sun.com/bigadmin/features/hub_articles/cgi_baseline.jsp.

  • The Python interpreter must be installed and added to the $PATH variable on your Sun Connection system:

    • For a Solaris platform-based Sun Connection system, install the Python packages SUNWPython, SUNWPython-share, SUNWTcl, and SUNWTk. The Python packages are included in the Solaris 10 OS installation media. Refer to the system documentation for installation procedures.

    • For a Linux platform-based Sun Connection system, refer to your Linux OS documentation to identify and install all Python RPMs.


Installing the Sun Connection Python API Software and Downloading the Python API Scripts

This section provides the procedures for installing the Sun Connection Python API software and creating the API scripts on your Sun Connection system.

To Install the Sun Connection Python API Software

  1. Log in as root (su - root) to your Sun Connection system.
  2. Change directory to where you downloaded and uncompressed the Sun Connection installation software.
  3. Change directory to UCE-1.1.1-314/rpms.
  4. Install the Sun Connection Python API software.
    • On a Solaris-based Sun Connection server, type the following commands:

      pkgadd -d SUNWucelos.architecture.pkg

      pkgadd -d SUNWucepa.architecture.pkg

      where architecture is the platform architecture type, either sparc or i386

      For example:

      # pkgadd -d SUNWucelos.sparc.pkg
      # pkgadd -d SUNWucepa.sparc.pkg

      The Python API software is installed to the directory /opt/SUNWuce/api/python.

    • On a Linux-based Sun Connection server, type the following commands:

      rpm -U sun-uce-api-1.1.1-314.x86_64.rpm

      rpm -U sun-uce-api-python-1.1.1-314.x86_64.rpm

      The Python API software is installed to the directory /usr/local/uce/api/python.

To Download the Python API Scripts

The Python API software must be configured with the name and port of the Sun Connection server. The required information is contained in the .uce.rc files of the agent, CLI or console software. If at least one of these components is installed, use the script init_api.sh to perform all configuration tasks as described in the following steps.

  1. Log in as root (su - root) to your Sun Connection system.
  2. Create a directory for the Python API scripts.
    • Solaris OS:

      # mkdir /opt/SUNWuce/scripts

    • Linux OS:

      # mkdir /usr/local/uce/scripts

    Creating a separate Python scripts directory ensures that the Python API scripts are not deleted during an upgrade.

    Add the Python scripts directory to your $PATH environment variable.

  3. Change directory to the scripts directory that you created in the previous step.
  4. Download the Python scripts to the script directory you created in the previous step.

    Right-click the following links to download the three scripts:

  5. Use the dos2unixcommand to remove DOS characters and the .txt file extension from each script.
    # dos2unix -ascii -iso init_api.sh.txt init_api.sh
    # dos2unix -ascii -iso  create_profile.py.txt create_profile.py
    # dos2unix -ascii -iso  store_api_login.py.txt store_api_login.py

    Verify the .sh and .py files and then delete the .txt versions if desired.

  6. Type chmod 755 *.
  7. Create a dedicated Sun Connection Python API user account.

    For example, api.

    Refer to your Sun Connection documentation for user account creation procedures.


Configuring the Python API Software

The API software must be configured with the name and port of the Sun Connection server. The required information is contained in the .uce.rc files of the agent, CLI, or console software. If at least one of these components is installed, use the script init_api.sh to perform all configuration tasks.

To Configure the Python API Software

  1. Log in as the dedicated Sun Connection Python API user to your Sun Connection system.

    Add the following directory to the $PATH variable:

    • Solaris OS:

      /opt/SUNWuce/scripts

    • Linux OS:

      /usr/local/uce/scripts

  2. Change to the scripts directory.
  3. Initialize the Python API.
    # ./init_api.sh

    The Sun Connection Python API configuration are created and saved in the directory $HOME/.uce_python.


Encrypting and Using the Dedicated User Account Name and Password

The dedicated user account and password should be encrypted and stored on the server instead of being included as plain text in the scripts. The API script store_api_login.py performs this task.

To Encrypt, Store, and Use the Dedicated User Account and Password

Before You Begin

The path to the Python interpreter directory and to the API scripts directory that you created must be added to the dedicated account $PATH variable. See To Download the Python API Scripts above.

  1. Log in as the dedicated Sun Connection Python API user to your Sun Connection system.
  2. Type the command store_api_login.py.

    You are prompted for the account name and password. For example:

    # store_api_login.py 
         Username: api
         Password:
         User/Password successfully stored.

    After running the store_api_login.py script, you will not be prompted for the account name and password each time you run Python API scripts.


Using the Python API Scripts

Example Python API scripts are located in /opt/SUNWuce/api/python/examples on a Solaris OS system, and in /usr/local/uce/api/python/examples on a Linux OS system.

To get started, a simple but useful example for an API script is the create_profile.py script, which creates a profile from a text list of patches.

For example, assume you have created the file SAP_recommended.txt, which contains the following entries:

118918-17
121563-02
121118-06

Once you have created the list of text patches, you can generate the profile using the create_profile.py Python script. For example:

# create_profile.py
    Please enter the file with the patch list: SAP_recommended.txt
    Name of the channel (e.g. SOLARIS8_SPARC, SOLARIS10_X86): SOLARIS10_SPARC
    Name of the profile to be created: SAP-Baseline
    Username: api
    Password:
    Creating an API instance ...
    Trying to login ...
    Successfully logged in ...
    Adding patch 118918-17 for channel SOLARIS10_SPARC
    Adding patch 121563-02 for channel SOLARIS10_SPARC
    Adding patch 121118-06 for channel SOLARIS10_SPARC
    new profile SAP-Baseline successfully created

The Python API Documentation

The Python API class and data structure documentation is found by using the pydoc module. The pydoc module is bundled with the Python API as a pydoc script that is usually installed in the same directory as the Python interpreter.

To Find the Documentation

  1. (Optional) The pydoc script should be in your path like the Python interpreter is. If you cannot find the pydoc script, you can create it using your preferred text editor. The pydoc script consists of the following three lines.
    #!/usr/sfw/bin/python
    import pydoc
    pydoc.cli()

    The first line contains the full path to the Python interpreter and should be adjusted if required.

  2. Access the library.
    $ cd library

    where library is the path to the library directory.

    • For Solaris: /opt/SUNWuce/api/python/lib

    • For Linux: /opt/local/uce/api/python/lib

  3. Run one of the following pydoc commands to obtain the desired information.
    $ pydoc PyOsApi/OsApi.py
    $ pydoc PyOsApi/OsApiConstants.py
    $ pydoc PyOsApi/OsApiExceptions.py
    $ pydoc PyOsApi/DataStructures/OsApiDataStructures.py
Example 1 Results of Running the pydoc PyOsApi/OsApi.py Command
$ pydoc PyOsApi/OsApi.py

Help on module OsApi:

NAME
    OsApi

FILE
    /opt/SUNWuce/api/python/lib/PyOsApi/OsApi.py

CLASSES
    OsApi

class OsApi
     |  The OsApi class is the API class.
     |  Its methods provide the direct operations.
     |  It imports methods from the lower-level C API,
     |  included in the package.
     |
     |  Methods defined here:
     |
     |  ActivateChannel(self, channel_name)
     |      The ActivateChannel method activates a supported channel for use in
     |      an API session. It will be available in the next session from
     |      GetAvailableChannels.
     |      _____________________________________________________________________
     |      Input Parameters:
     |      * channel_name - valid name of supported channel.
     |       See GetAvailableChannels method.
     |      _____________________________________________________________________
     |      Output Returns:
     |      * none
     |      _____________________________________________________________________
     |      Exceptions:
     |      * OsApiGetChannelsException - cannot get supported channel list.
     |      * OsApiUnknownException - general exception.
     |      * OsApiChannelException - invalid input

More Information

For more information about Sun Connection, go to the Sun Connection information hub.

To get an inside perspective of Sun Connection, Sun Management Center software, Sun N1 Service Provisioning System, and Sun N1 System Manager, visit the Sun Connection blog. Contributors to this blog include members of the Sun Connection Field Enablement team. The goal of this blog is to share information with customers who either have already implemented or will implement these products in the future. The blog also provides important information about training and other key enablement activities.

Discuss and comment on this resource in the BigAdmin Wiki


Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License.


BigAdmin
  
 
 
 
 
Contact About Sun News & Events Employment Site Map Privacy Terms of Use Trademarks Copyright 1994-2008 Sun Microsystems, Inc.