N1 Service Provisioning System 4.1 Reference Guide

Working with the CLI

Authentication by Username and Password or Session ID

All but a few of the commands in the command line interface require authentication by username and password or by session ID.


cr_cli -cmd [command] -u [user] -p [password]

Note –

You do not need a username and password to get help on any of the commands or to list all available commands.


For increased security, place the password in a file and pass the file to the command. You can then use the filesystem to restrict access to the file containing the password. Use the following method to securely enter commands that require authentication. For more information on this technique, see Passing Arguments to the CLI from a File.

Create a file with the password, and pass the file to the command.


cr_cli -cmd [command] -u [user] -p exp:[passwordfile] 

Listing the Commands

To list all the commands available, type:


cr_cli -cmd -l

To list all the commands with a command prefix, use the wildcard character * after the prefix. For example, the command below lists all the hdb commands:


cr_cli -cmd -l hdb.*

Getting Help with the CLI

To access the general help for the CLI, enter the command:


cr_cli -help

To see the help for a specific command, enter the command:


cr_cli –cmd <commandname> –h 

CLI Syntax

CLI syntax includes:

The following is an example of the general CLI syntax:

Table 4–1 Syntax of a CLI Command.

cr_cli 

-cmd hdb.h.lo 

-ID 

NM:barolo7 

-u user -p password 

Invokes the single command-line interface. 

Name of the command you want to invoke. 

An argument for the command 

Value to be specified with an argument requiring a value. 

User name and password, for authentication. Alternatively, you can specify a session ID. 

Selecting the Output Format of a CLI Command

Because you may want to use the output resulting from CLI commands in various ways, you can adjust the format a CLI command uses to return information. There are two types of CLI output formats:

Standard Output Formats

The CLI supports the following output formats:

Table 4–2 CLI Format Options

Format Option 

Result 

string 

Produces brief output. Use this option for postprocessing 

serialized 

Produces XML serialized text output. Use this option when you want to pass information to another script. 

sink 

Discards output. On UNIX systems, directs output to /dev/null. 

detail 

Formats the output as a table. Includes detailed information. 

If you do not specify an output format, the command uses its default format for the output.

To discover the default output format for a given command, refer to the help information for that command by running the command with -h:


cr_cli –cmd <commandname> –h 

The default output format will be in asterisks at the bottom of the help.

Command-Specific Output Formats

You can also use the -h argument to discover command-specific output formats that are available for a command.Table 4–3 lists command-specific output formats

Table 4–3 Command Output Formats for CLI Command Families

Command Format 

Description 

cdb.detail 

Detailed text output of components 

cmp.detail 

Detailed text output of comparisons 

hdb.detail 

Detailed text output of host data 

net.detail 

Detailed text output of network data 

net.summary 

Summarized output of network data 

pdb.detail 

Detailed text output of plans 

pe.detail 

Detailed output from the running of plans 

rule.detail 

Detailed text output of notification rules 

udb.deep 

Very detailed text output describing users and user groups 

udb.detail 

Detailed text output describing users and user groups 

udb.summary 

Summarized text output describing users and user groups 

Specifying the Output Format

To specify the output format for a CLI command, use the -o argument and list it as the first argument to the command. For example, to select the string output format for the hdb.h.la command, you would run the command:


cr_cli -cmd hdb.h.la -o string -u [user] -p [password]

Note –

The output format you specify must appear after the command itself, but before any other arguments, as shown in this example.


Passing Output Data to a File

To pass the data resulting from a command to an external file, you can use the -of option. Use -of to provide a fully-specified file name into which the N1 Service Provisioning System software can put the data from the command you execute.

For example, to pass the data from creating a host named myhost to a file called hostFile, type:


cr_cli -cmd hdb.h.add -of hostFile -u [user]
-p [password] -name myhost -tID NM:roxhost 

The file hostFile will contain the host information in detail format (the default formatter for the hdb.h.add command).


Note –

The -of option must occur right after the command name, before any other arguments.


Passing Data to an Individual CLI Argument

To pass data to the CLI from an external file, you can use the file: option. For instance, you may want to store the session ID of the session you have just started and then use it to authenticate commands.

To save the session ID to a file called session, type:


cr_cli -cmd udb.login -u [user] -p [password] > session 

Then, to pass the session ID to another command, type:


cr_cli -cmd hdb.h.la -s file:session

Converting the Output Format

To convert the output format of a command that you have passed to a file, you can use the reformat.util command.

The util.reformat command reads in data from the output file you specify and reformats it using the output format you choose.

For example, if you have created a host and stored the output from the hdb.h.add command in serialized format in a file named hostFile:


cr_cli -cmd hdb.h.add -o serialized -u [user] 
-p [password] -name myhost -tID NM:roxhost > hostFile

you can give util.reformat the output of the previous command and tell it to use the detail format by passing it hostFile using the file: option as described in Passing Data to an Individual CLI Argument:


cr_cli -cmd util.reformat -u [user] -p [password] 
-o hdb.detail -self file:hostFile

which will return:


ID: 010010000204-1027365659275-00170-1199101891
Name: myhost
Description: 
Virtual: false
Hidden: false
Type ID: 010010001024-0000000000000-00001-0000000004
Attributes:
<Table is empty>
Applications:
<Table is empty>

Passing Arguments to the CLI from a File

To pass an argument to the CLI from an input file, you can use the Expand option. To do this, you create a file into which you enter the information you want to pass to the CLI. Each argument and its value must be listed on a separate line. Arguments must be listed in the order in which the command requires them. To pass these arguments to the command, call the command and make the exp: argument the first argument.

For example, here are two files (file1.txt and file2.txt) that can be used in conjunction with the exp: option:

file1.txt:


hdb.h.la
-u
[user]
exp: file2.txt

file2.txt:


-p
[password]

To execute them, type:


cr_cli -cmd exp:file1.txt

The first file will call the second file and execute the command.

Descriptions and Multi-word Names

To specify a description or any other qualifier that includes a space, you must enclose the string in quotes, such as:


“This is a multi-word description.”

You can also escape every space with a backslash (\) if you prefer.

ID Substitution Using NM:

Most of the objects that you create have ID numbers associated with them. This ID number is a unique identifier for an entity, such as a user account or a component, in the repository.

ID numbers are useful because they are unique, but they can be cumbersome to enter as the argument to a command. To use names rather than ID numbers, you can use the tag NM: to introduce the name of an object on a command line..

Table 4–6 provides a complete listing of all supported NM: mappings.

To use the object name rather than the full ID number, use the following syntax to represent an object ID in any CLI command:


NM:<host|user|user group name|host type name|etc.>

with no spaces.

You can also use the NM: syntax to identify components and plans. You may optionally specify a version number in addition to the name itself:


plan = NM:<plan name>[:<version>]

For example:


NM:simplePlan
NM:simplePlan:1.0

If you do not specify a version number, the N1 Service Provisioning System software uses the latest version of the component or plan.

Showing and Hiding Objects

Because the objects you store in the repository are deeply interconnected, it is not possible to delete objects. You can choose to hide objects that you are not currently using to keep your work space uncluttered.


Note –

Hiding an object does not make it inactive or unusable. For example, if a resource is referenced by a component and the resource is hidden, the next build of the component will still reference the resource. The resource is not deactivated or removed; it is simply hidden from view.


You can specify whether or not to show or hide the following objects.