HP StorageWorks P2000 HP StorageWorks P2000 G3 MSA System CLI Reference Guide - Page 15

Using the XML API, XML API elements - configuration

Page 15 highlights

The above shows a Perl script for logging in. cLogin is called at the start of the script to log a user into the CLI. The script uses the command-line parameters specified as the IP address, username, and password. After the user has been logged in, other commands can be sent to the CLI. For scripting support, change the CLI output mode from the default, console, which produces human-readable output, to api or api-embed, which produce XML output. In the following command, the first argument enables API mode to allow easier parsing. The second argument disables the paging mode that pauses for each full screen of command output. $telnet->cmd("set cli-parameters api pager disabled"); The following code segment shows how to get the entire configuration information from the CLI and print the output. The output can easily be redirected to a file for archiving. @sV = $telnet->cmd("show configuration"); for ($i=0; $i

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262

HP StorageWorks P2000 G3 MSA System CLI Reference Guide
15
The above shows a Perl script for logging in.
cLogin
is called at the start of the script to log a user into the
CLI. The script uses the command-line parameters specified as the IP address, username, and password.
After the user has been logged in, other commands can be sent to the CLI.
For scripting support, change the CLI output mode from the default,
console
, which produces
human-readable output, to
api
or
api-embed
, which produce XML output.
In the following command, the first argument enables API mode to allow easier parsing. The second
argument disables the paging mode that pauses for each full screen of command output.
$telnet->cmd("set cli-parameters api pager disabled");
The following code segment shows how to get the entire configuration information from the CLI and print
the output. The output can easily be redirected to a file for archiving.
@sV = $telnet->cmd("show configuration");
for ($i=0; $i<scalar(@sV); $i++)
{
print (“@sV[ $i ]”);
}
The next section provides more information about using the XML API.
Using the XML API
You can use an XML parser, such as
XML::Parser
in Perl, to process the XML output and store this
information as objects. The XML parser should use the Document Type Definition (DTD) version that
corresponds to the firmware level to ensure that the XML is validated. By obtaining the latest DTD for
validation, the parser will be forward compatible.
The output of each CLI command is composed of valid XML data until the CLI prompt (typically
#
) is
encountered. The output contains a valid XML header followed by the XML elements described in the
following table.
Table 3
XML API elements
Element
Description and attributes
RESPONSE
The
RESPONSE
element is the top-level element, which contains all data output for the CLI command
that was issued. The response includes:
A number of
OBJECT
elements, which varies by command.
A status object that provides a message and return code. A return code of 0 indicates that the
command succeeded. Any other return code is an error code.
There is only one
RESPONSE
element per issued command.
OBJECT
In general, an
OBJECT
element describes a storage-system component such as a disk or a volume. An
object has these attributes:
basetype
. This attribute allows output in brief mode to be correlated with metadata to reduce
the overhead of each command, as described in
XML API optimization
. This is also a good field to
use to detect the type of the object (e.g., a disk, a volume, etc.).
name
. The name of the object.
oid
. The unique identifier for the object in the scope of the response.
The
OBJECT
element can contain
PROPERTY
elements.