~ubuntu-branches/ubuntu/vivid/wsl/vivid

« back to all changes in this revision

Viewing changes to .pc/MYPATH.patch/wslinvoke

  • Committer: Package Import Robot
  • Author(s): Daniel Jared Dominguez
  • Date: 2012-11-05 16:44:54 UTC
  • Revision ID: package-import@ubuntu.com-20121105164454-sylr8c3bx36wa40e
Tags: 0.2.1-1
* Updated source
* wsl-functions changes
  - Added NOINIT option for wrapper scripts
  - use bash instead of sh in SendRequest (Jared Dominguez)
  - Added fMessageThenExit for a message and exit code
* wslecn: added getclass and getallclass commands

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# ###########################################################################
 
3
# Copyright (c) 2011, Dell Inc.
 
4
# All rights reserved.
 
5
#
 
6
# Redistribution and use in source and binary forms, with or without
 
7
# modification, are permitted provided that the following conditions
 
8
# are met:
 
9
#
 
10
#    * Redistributions of source code must retain the above copyright
 
11
#      notice, this list of conditions and the following disclaimer.
 
12
#    * Redistributions in binary form must reproduce the above copyright
 
13
#      notice, this list of conditions and the following disclaimer in the
 
14
#      documentation and/or other materials provided with the distribution.
 
15
#    * Neither the name of Dell Inc. nor the names of its contributors
 
16
#      may be used to endorse or promote products derived from this software
 
17
#      without specific prior written permission.
 
18
#
 
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
22
# ARE DISCLAIMED. IN NO EVENT SHALL DELL INC. BE LIABLE FOR ANY DIRECT,
 
23
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
24
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
25
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
26
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
27
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
28
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
29
# POSSIBILITY OF SUCH DAMAGE.
 
30
# ###########################################################################
 
31
# Authors: Chris A. Poblete
 
32
# Version: 1.0.0
 
33
# ###########################################################################
 
34
 
 
35
MYNAME=`basename $0`
 
36
WSENUMMAXELEM=512
 
37
 
 
38
# source function library
 
39
. /etc/wsl/wsl-functions
 
40
 
 
41
usage() {
 
42
  fUsageheader
 
43
  cat <<EOF
 
44
USAGE: $MYNAME CLASS METHOD [PARAM1=VAL1 PARAM2=VAL2 ...] [OPTIONS]
 
45
 
 
46
Sends SOAP message with WS-MAN INVOKE command. This script may accept only 
 
47
derived leaf classes unless you provide a CQL filter that can return a 
 
48
single instance. CLASS may be a class name or an absolute class URI.
 
49
CLASS should be the first input and Method the second input.
 
50
Enclose the value in double quotes when the value contains space.
 
51
 
 
52
[OPTIONS]
 
53
-filter "CQL"       - Apply CQL statement filter to enumeration
 
54
-inst FILENAME      - Contains class instance EPR 
 
55
-ns NAMESPACE       - Explicitly add the NAMESPACE selector
 
56
-raw FILENAME       - Use raw input for the method contained in the filename
 
57
 
 
58
If CLASS has more than one instance, use the -filter option to filter the 
 
59
enumeration to a single instance. Alternatively, use the -inst option to 
 
60
provide the instance EPR in a previous enumeration.
 
61
 
 
62
PARAM=FILE:FILENAME
 
63
If Value is of type EPR (endpoint reference), you can provide a file
 
64
that contains an instance EPR. An EPR contains EndpointReference
 
65
element. An example of this is:
 
66
  ManagedElement=FILE:compsys.xml
 
67
 
 
68
PARAM=RFILE:FILENAME
 
69
If Value could not be passed through command line perhaps due to special
 
70
characters of contain line breaks, you can provide it in a file with
 
71
RFILE prefix. An example of this is a certificate value:
 
72
  Certificate=RFILE:newad.cer
 
73
 
 
74
${CommonUsage1}
 
75
EOF
 
76
  $WSCOLORNORM
 
77
  exit 1
 
78
}
 
79
 
 
80
fCheckReqsOrUsage
 
81
 
 
82
[ $# -lt 2 ] && usage
 
83
while [ ! -z "$1" ]; do
 
84
  case "$1" in
 
85
    -h|-help|help ) usage
 
86
      ;;
 
87
    -i|-inst ) shift; InstanceFile="$1"
 
88
      ;;
 
89
    -f|-filter ) shift; CQL="$1"
 
90
      ;;
 
91
    -n|ns ) shift; WSNS="$1"
 
92
      ;;
 
93
    -r|-raw ) shift; RAW="$1"
 
94
      ;;
 
95
    * ) echo "$1" | grep '=' >/dev/null 2>&1
 
96
      if [ $? -ne 0 ]; then
 
97
        [ -z "${CLASS}" ] && export CLASS="$1" && shift && continue
 
98
        [ -z "${METHOD}" ] && export METHOD="$1" && shift && continue
 
99
      else
 
100
        Name=$(echo "$1" | cut -d '=' -f1 )
 
101
        Value=$(echo "$1" | cut -d '=' -f2- )
 
102
        echo "${Value}" | grep "^FILE:" >/dev/null 2>&1
 
103
        if [ $? -eq 0 ]; then
 
104
          filename=$(echo "${Value}" | cut -d ':' -f2- )
 
105
          echo "using ${filename} to extract EPR XML for parameter ${Name}"
 
106
          fExtractEPRXML ${filename}
 
107
          Value="${EPRXML}"
 
108
        else
 
109
          echo "${Value}" | grep "^RFILE:" >/dev/null 2>&1
 
110
          if [ $? -eq 0 ]; then
 
111
            filename=$(echo "${Value}" | cut -d ':' -f2- )
 
112
            echo "using ${filename} to extract EPR XML for parameter ${Name}"
 
113
            Value=$(cat ${filename})
 
114
          fi
 
115
        fi
 
116
        PARAMLIST="${PARAMLIST}<p:${Name}>${Value}</p:${Name}>"
 
117
      fi
 
118
      ;;
 
119
  esac
 
120
  shift
 
121
done
 
122
 
 
123
[ ! -z "${PARAMLIST}" ] && [ ${OUTLEVEL} -ge 3 ] && echo -en "## ${PARAMLIST}\n\n"
 
124
 
 
125
# initializations
 
126
fGetTarget
 
127
fSetWGET
 
128
fNormalizeClass
 
129
 
 
130
[ ! -z "${CQL}" ] && CQLQUERY="<wsman:Filter Dialect='http://schemas.dmtf.org/wbem/cql/1/dsp0202.pdf'>${CQL}</wsman:Filter>"
 
131
 
 
132
if [ ! -z "${WSNS}" ]; then
 
133
REQSELECTORS=`cat <<EOF
 
134
  <wsman:SelectorSet>
 
135
    <wsman:Selector Name="__cimnamespace">${WSNS}</wsman:Selector>
 
136
  </wsman:SelectorSet>
 
137
EOF`
 
138
fi
 
139
 
 
140
dopullX() {
 
141
  fGetUUID
 
142
  fReqRspNext
 
143
  cat <<EOF >${REQUESTFILE}
 
144
${WSENVELOPEHEADER}
 
145
  <s:Header>
 
146
    <wsa:Action s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull</wsa:Action>
 
147
    ${WSCOMMONHEADER}
 
148
    <wsman:ResourceURI s:mustUnderstand="true">${CLASS}</wsman:ResourceURI>
 
149
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
150
    <wsa:ReplyTo>
 
151
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
152
    </wsa:ReplyTo>
 
153
  </s:Header>
 
154
  <s:Body>
 
155
    <wsen:Pull>
 
156
      <wsen:EnumerationContext>${CONTEXT}</wsen:EnumerationContext>
 
157
      ${WSPULLMAXELEMSTR}
 
158
    </wsen:Pull>
 
159
  </s:Body>
 
160
</s:Envelope>
 
161
EOF
 
162
  fNormalizeXML ${REQUESTFILE}
 
163
  fDumpRequestFile
 
164
  fSendRequest
 
165
  fNormalizeXML ${RESPONSEFILE}
 
166
  unset CONTEXT ; fGetFlatValueOfSingle ${RESPONSEFILE} N "EnumerationContext" ; export CONTEXT=${PVALUE}
 
167
  grep 'PullResponse' ${RESPONSEFILE} 2>&1 >/dev/null
 
168
  export STAT=$?
 
169
}
 
170
 
 
171
doenumerateX() {
 
172
  fGetUUID
 
173
  fReqRspNext
 
174
  cat <<EOF >${REQUESTFILE}
 
175
${WSENVELOPEHEADER}
 
176
  <s:Header>
 
177
    <wsa:Action s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</wsa:Action>
 
178
    ${WSCOMMONHEADER}
 
179
    <wsman:ResourceURI s:mustUnderstand="true">${CLASS}</wsman:ResourceURI>
 
180
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
181
    <wsa:ReplyTo>
 
182
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
183
    </wsa:ReplyTo>
 
184
    ${REQSELECTORS}
 
185
  </s:Header>
 
186
  <s:Body>
 
187
    <wsen:Enumerate>
 
188
      ${WSENUMOPTIMIZEDSTR}
 
189
      ${WSENUMMAXELEMSTR}
 
190
      ${EPR}
 
191
      ${CQLQUERY}
 
192
    </wsen:Enumerate>
 
193
  </s:Body>
 
194
</s:Envelope>
 
195
EOF
 
196
  fNormalizeXML ${REQUESTFILE}
 
197
  fDumpRequestFile
 
198
  fSendRequest
 
199
  fNormalizeXML ${RESPONSEFILE}
 
200
  unset CONTEXT ; fGetFlatValueOfSingle ${RESPONSEFILE} N "EnumerationContext" ; export CONTEXT=${PVALUE}
 
201
  grep 'EnumerateResponse' ${RESPONSEFILE} 2>&1 >/dev/null
 
202
  export STAT=$?
 
203
}
 
204
 
 
205
doenumerate() {
 
206
  doenumerateX
 
207
  [ ${OUTLEVEL} -ge 3 ] && ( $WSCOLORRSP; [ ${STAT} -ne 0 ] && $WSCOLORERR ; cat ${RESPONSEFILE} ; $WSCOLORNORM )
 
208
  while [ ! -z "${CONTEXT}" ]; do
 
209
    dopullX
 
210
    [ ${OUTLEVEL} -ge 3 ] && ( $WSCOLORRSP; [ ${STAT} -ne 0 ] && $WSCOLORERR ; cat ${RESPONSEFILE} ; $WSCOLORNORM )
 
211
    echo "(${CONTEXT})"
 
212
  done
 
213
}
 
214
 
 
215
doinvoke() {
 
216
  fGetUUID
 
217
  fReqRspNext
 
218
 
 
219
  if [ ! -z "${RAW}" ]; then
 
220
    PARAMBODY=`cat ${RAW}`
 
221
  else
 
222
    PARAMBODY=`cat <<EOF
 
223
      <p:${METHOD}_INPUT xmlns:p="${RURI}">
 
224
        ${PARAMLIST}
 
225
     </p:${METHOD}_INPUT>
 
226
EOF`
 
227
  fi
 
228
 
 
229
cat <<EOF >${REQUESTFILE}
 
230
${WSENVELOPEHEADER}
 
231
  <s:Header>
 
232
    <wsa:Action s:mustUnderstand="true">${RURI}/${METHOD}</wsa:Action>
 
233
    ${WSCOMMONHEADER}
 
234
    <wsman:ResourceURI s:mustUnderstand="true">${RURI}</wsman:ResourceURI>
 
235
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
236
    <wsa:ReplyTo>
 
237
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
238
    </wsa:ReplyTo>
 
239
    ${EPRSELECTORSTR}
 
240
  </s:Header>
 
241
  <s:Body>
 
242
    ${PARAMBODY}
 
243
  </s:Body>
 
244
</s:Envelope>
 
245
EOF
 
246
  fNormalizeXML ${REQUESTFILE}
 
247
  fDumpRequestFile
 
248
  fSendRequest
 
249
  fNormalizeXML ${RESPONSEFILE}
 
250
  grep "_OUTPUT" ${RESPONSEFILE} 2>&1 >/dev/null
 
251
  export STAT=$?
 
252
}
 
253
 
 
254
if [ ! -z "${InstanceFile}" ]; then
 
255
  fGetEPRSELECTOR ${InstanceFile}
 
256
else
 
257
  [ ${OUTLEVEL} -ge 3 ] && echo "NOTE: Enumerate operation may take time to reply."
 
258
  EPR="<wsman:EnumerationMode>EnumerateEPR</wsman:EnumerationMode>"
 
259
  doenumerate
 
260
  fGetEPRSELECTOR ${RESPONSEFILE}
 
261
fi
 
262
 
 
263
if [ ! -z "${EPRSELECTORSTR}" ]; then
 
264
  [ ${OUTLEVEL} -ge 3 ] && echo "NOTE: Invoke operation may take time to reply."
 
265
  doinvoke 
 
266
fi
 
267
 
 
268
fDisplayResponse ${RESPONSEFILE}
 
269
 
 
270
/bin/cp ${RESPONSEFILE} ${RETURNFILE}
 
271
[ ${OUTLEVEL} -ge 3 ] && echo "Output is saved to ${RETURNFILE}"
 
272
exit ${STAT} 
 
273
 
 
274
# ###########################################################################
 
275
# End of Code
 
276
# ###########################################################################