Contained Within
Find More DocumentationFeatured Support Resources | Download this book in PDF (730 KB)
Chapter 1 Using the Command-Line InterfaceThis chapter describes the command-line interface (CLI) for the Sun N1 Service Provisioning System software, which enables you to submit commands to the master server from another server. You can run the CLI from a shell prompt, a DOS prompt, or a script. You can also use the CLI as an alternative to the browser interface to access the master server. Before you can use the CLI, you must first install the Command-Line Interface Client on the local server. The CLI can be run in these two modes:
This chapter covers the following topics: CLI Command StructureThe cr_cli command has the following syntax:
Note that the common-arguments must be used in the position shown above , before the authentication arguments and other-arguments. The following table lists the common-arguments supported by all commands. Table 1–1 Using the common arguments
Note that most commands must use the authentication arguments: either -u and -p, or -s. To determine whether a command requires the authentication arguments, see the description of the command. Also, the authentication arguments do not have a fixed position on the command line, but they must appear after the -cmd, -h, -o, and -of arguments.
The cr_cli command returns 0 on success and 1 on failure. Example 1–1 Using the CLIThe following are some examples of the provisioning software's CLI:
Using NM: to Perform ID SubstitutionMost of the objects that you create are associated with ID numbers. An ID number is a unique identifier for an object in the repository, such as a user account or a component. While ID numbers are useful, they can be cumbersome to use. To use names rather than ID numbers, introduce the name of an object by using the NM: notation. For a complete list of the supported NM: mappings, see Appendix A, Input Types. For example, the following syntax is used to represent object IDs, such as hosts, user names, user group names, and host type names:
You can also use the NM: syntax to identify components and plans by name and optional version number:
The following are some sample uses of this notation:
If a version number is not specified, the provisioning software uses the latest version. CLI Input and OutputThe following sections describe how to use files as input to the CLI and how to use files to store output from the CLI commands. Redirecting Output to a FileTo redirect command output to a file, you can either use the -of argument or use a shell redirect. The argument to the -of argument is a full path to a file. For example, this command writes the output to a file called hostFile. Note that the -of argument must immediately follow the command specified by -cmd.
After the command is run, hostFile contains output in detail format, which is the default output format for the hdb.h.add command. Another example of redirecting output to a file involves using a stored session ID to authenticate commands. First, save the RPC-serialized representation of the session ID to a file called session. You can redirect this output to a file using either method.
Once you have stored your session ID in a file, you can use the file as input to another command. See Reading Input From a File. Reading Input From a FileTo pass data from a file to a command, identify the file by adding the prefix file: to the file name. For example, if you have stored a session ID in a file and want to use the file to authenticate the hdb.h.la command, use the file as input to the command.
If you did not store the session id to a file , you can pass a serialized version of the session object directly to another command by using the ser: prefix. In the example below, the serialized session object obtained by using udb.login command with the with the -o serialized argument, is available in sessionStr .
Reading CLI Arguments From a FileTo read a CLI argument from an input file, identify the input file by prefixing exp: to the file name. First, create a file that contains the information you want to pass to the CLI. Note that each argument must be listed on a separate line and must appear in the order required by the command. Then, have the command get the arguments from the file. For example, these files, file1.txt and file2.txt, can be used in conjunction with exp: to specify command arguments. file1.txt contains the following:
file2.txt contains the following:
To execute the command that is described by these files, type the following:
Output Formats of CLI CommandsYou can adjust the output format a CLI command. To specify the output format for a CLI command, the -o argument must immediately follow the command you specified by -cmd. For example, to specify the string output format for the hdb.h.la command, type the following:
These are the standard output formats that are available to all CLI commands:
If you do not specify an output format, the command uses its default output format. To see the default output format for a command, run the following:
Converting the Output FormatUse the reformat.util command to convert the output format of a command that has been written to a file. The reformat.util command reads data from the specified output file and reformats it by using the specified output format. For example, you created a host and stored the output from the hdb.h.add command in serialized format in a file named hostFile:
Use the util.reformat command to reformat the output to be the hdb.detail format.
The previous command results in the following output:
Running the Command-Line InterfaceTo execute one CLI command at a time, use the cr_cli tool. This tool invokes the CLI in single-line command mode. Single-line command mode accepts one command at a time as input. Each command submitted must be complete, you are not interactively prompted for the next input parameter. When operating in this mode, the Command Line Execution Client does not maintain a command history. cr_cli commands can be stored in a file and called from a shell script. This feature is useful for repetitive tasks such as running execution plans, comparisons, or populating hosts. The interactive command-line mode uses the Jython interpreter as its shell. When operating in this mode, the CLI offers you these advantages:
|
|||||||||||||||||||||||||||||||||||||||||||||||
./cr_cli -cmd subsystem.object.command -u user -p password |
From a server where the CLI Client and Jython are installed, start the CLI Jython Interpreter.
./cr_clij |
Include the following code at the beginning of your script.
from clui import * app=PyCLUI() app.execStr(CLI command) app.close() |
The assignment app=PyCLUI() calls the CLI. The App.close() call deletes the instance of this Jython class.
Only the execStr and execRaw calls are supported for SPS scripts with Jython. The returned objects from execRaw can only be used as parameters for other execRaw calls. If you attempt to use an object returned from an execRaw call as a parameter to an execStr call, the call fails. You can use the toString() method of the object to construct the string to feed to the execStr call.
To get general help about the CLI, type the following:
cr_cli -help |
To get help for a specific command, type the following:
cr_cli -cmd command -h |
The command descriptions use the following notation to indicate whether an argument is required or optional:
The argument is optional.
The argument is required.
The argument is usually optional, but might be required in some cases.
In such situations, the help indicates when the argument is required.
The following is the help information for the hdb.h.add command:
-u [O/R]: The user username for authentication: String -p [O/R]: The user password for authentication: String -s [O/R]: The session ID for authentication: SessionID -name: The host name: String -desc Optional: The host description: String -tID: The ID of the host type: HostTypeID -attr [O/R]: The host attributes; required if the host type requires them: Hashtable |
In this example, the only required arguments are -name, -tID, and the authentication arguments: either -u and -p, or -s. If the host type of the new host requires that host attributes be specified, the -attr argument is also required.
Note that help you get by using the -h does not use the Required notation to identify required arguments. Required arguments are shown without any notation.
To list all of the available commands, type the following:
cr_cli -cmd -l |
To list all of the commands that have the same command prefix, use the wildcard character * after the prefix. You might need to escape the * with a backslash (\) or by enclosing it in double quotes. For example, the following command lists all of the hdb commands:
cr_cli -cmd -l "hdb.*" |
The CLI commands are grouped in the following categories:
cat – Categories
cdb – Component database
cfg – Configuration generator
cmp – Comparison engine
fdb – Folder repository
hdb – Host repository
net – Network operations
pdb – Plan repository
pe – Plan execution
plg – Plug-in repository
rule – Rules for notifications
udb – User repository
util – Miscellaneous utilities