Name | Last modified | Size | Description | |
---|---|---|---|---|
Parent Directory | - | |||
Spectrum-CLI-1.016.tar.gz | 2003-12-16 09:56 | 19K | ||
ReadMe | 2000-01-21 16:57 | 1.0K | ||
EXAMPLES | 2000-01-21 15:11 | 858 | ||
old/ | 2014-05-25 12:02 | - | ||
use Spectrum::CLI;
see METHODS section below
Spectrum::CLI
is class which intends to provide a convenient way to invoke the various
CLI commands of Spectrum Enterprise Manager from within perl scripts.
In the author's estimation, the two primary benefits of
Spectrum::CLI
are:
Spectrum::CLI
intelligently parses of the output of CLI ``show'' commands. That is, it
will split apart the columnar values for you, and return them as an array
of hashes, each element representing one line of output.
map { $Model{$_->{MName}} = $_ } Spectrum::CLI->new->show_models;
This would subsequently enable one to refer to a model's handle like this:
my $handle = $Model{Universe}{MHandle};
In this way, scripts can be written which discover all SpecHex magic numbers, and are, therefore, more readable and potentially more portable/reusable amongst Spectrum installations.
$obj = Spectrum::CLI->new([VNM_Name,] [SPECROOT,] [ { [verbose => 1,] [Verbose => 1,] [CLISESSID => $sessid,] [CLIMNAMEWIDTH => $width,] [VNMSHRCPATH => $path,] [localhostname => $localname,] [timeout => $seconds,] } ]);
my $cli = new Spectrum::CLI;
This is the class' constructor - it returns a Spectrum::CLI
object upon success or undef on failure. Its arguments are optional, and
may occur in any order. In general, it can be called with no arguments
unless the SPECROOT environment variable is not set, or one wishes to
connect to a SpectroSERVER on another host (i.e. the script is not running
on the VNM host).
The optional constructor arguments are:
Spectrum::CLI
to use that value as the session id. Normally, in the absence of this
option, the perl script's process id is used. Use of this option is
discouraged unless the default value is somehow problematic.
Spectrum::CLI
to use that value as the model name width for CLI ``show'' commands.
Normally, in the absence of this option, the value 1024 is used. Use of
this option is discouraged unless the default value is somehow problematic.
Spectrum::CLI
to use that value as the full path to the configuration file for the CLI.
Normally, in the absence of this option, the value
``$SPECROOT/vnmsh/.vnmshrc'' is used. Use of this option is discouraged
unless the default value is somehow problematic.
Spectrum::CLI
to use that value as the IP address or resolvable hostname to determine
whether or not the local VnmShd is running. (If VnmShd is not running, the
constructor will attempt to launch it.) Normally, in the absence of this
option, the return value from Sys::Hostname::hostname is used. Use of this
option is discouraged unless the default value is somehow problematic.
(That should probably never happen as currently VnmShd seems to
bind(2)
and listen(2)
at the address associated
with the system's hostname.)
Spectrum::CLI
to use that value as the number of seconds to sleep before attempting to
connect to the VnmShd that it just launched. If the VnmShd is already
running (when the constructor is called) this timeout is not used. Perhaps
in the future this timeout will be use for other things as well. Normally,
in the absence of this option, the value of 5 seconds will be used. Use of
this option is discouraged unless the default value is somehow problematic.
# show_types: map { $Type{$_->{Name}} = $_ } $cli->show_types;
# show_attributes: map { $UserAttr{$_->{Name}} = $_ } $cli->show_attributes("mth=$Type{User}{Handle}");
# ...
These methods invoke the CLI ``show'' command. They return an array of hashes where the hash keys are the column headings from the first line of output of the corresponding CLI command, and the values are the corresponding value in that column for the given row.
@results = $obj->seek("attr=attribute_id,val=value", [lh=landscape_handle]);
This method invokes the CLI ``seek'' command. It returns values in a like the ``show'' methods.
# create_model: $cli->create_model("mth=$Type{User}{Handle}", "attr=$UserAttr{Model_Name}{Id},val=joe", "attr=$UserAttr{User_Full_Name}{Id},val='Joe User'");
ALL of the other CLI commands are available as methods. The return
value(s)
of these methods differs markedly from that of the
aforementioned show_* or seek methods. This is because these methods do not
normally produce columnar output, but instead produce messages which
sometimes include some useful piece of information. For instance, ``create
model'' produces a message upon success, which indicates the model handle
of the create model. The caller will nearly always want to obtain that
handle, which can be done by parsing the returned values. (See the results method for a hint at how to do this.)
In an array context these methods return an array in which the first element is the exit status (i.e. zero indication success) of the underlying CLI command. The subsequent elements of the returned array are the standard output and standard error (if any) lines produced by the underlying CLI command.
In a scalar context these methods return non-zero if the command succeeds, zero otherwise.
Regardless of the context in which they are invoked, these methods cause the objects internal status and results to be set. If it is more convenient, these values can be retrieved using the status and results methods rather than having to collect them as return values.
print $obj->dir;
this method returns the absolute path to the directory containing the vnmsh commands.
$obj->verbose(1); print $obj->verbose;
This method returns a boolean value indicating whether or not verbose behavior is currently turned on.
If a zero or non-zero argument is passed it will either clear or set this feature, respectively.
$obj->Verbose(1); print $obj->Verbose;
This method returns a boolean value indicating whether or not ``very verbose'' behavior is currently turned on.
If a zero or non-zero argument is passed it will either clear or set this feature, respectively.
@results = $obj->results;
This method returns an array containing the results (standard output and standard error) of the last vnmsh command that was executed.
The results method is extremely useful to determine things such as the model handle of the model that was created by a call to create_model. For instance:
if ($obj->create_model("mth=$T{User}{Handle}", "attr=$A{Model_Name}{Id},val=joe", "attr=$A{User_Full_Name}{Id},val='Joe User'")) { printf "created model: %s\n", model_handle($obj->results) }
sub model_handle { my $mh; grep { m/(0x[0-9A-Fa-f]+)$/ && ($mh = $&)} @_; return $mh }
if (0 != ($status = $obj->status)) { printf("the previous vnmsh command failed: %d\n", $status) }
This method returns the exit status of the last vnmsh command that was executed.
Theoretically, this has at least two advantages:
Copyright (C) 1999-2000 Dave Plonka. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
perl(1).