~ubuntu-branches/debian/sid/wsl/sid

« back to all changes in this revision

Viewing changes to wslput

  • Committer: Package Import Robot
  • Author(s): Daniel Jared Dominguez
  • Date: 2012-11-05 16:44:54 UTC
  • Revision ID: package-import@ubuntu.com-20121105164454-c19vauy6n0u2op58
Tags: upstream-0.2.1
ImportĀ upstreamĀ versionĀ 0.2.1

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 PROP1=VAL1 [PROP2=VAL2 ...] [OPTIONS]
 
45
 
 
46
Sends SOAP message with WS-MAN PUT 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 at least one property-value pair.
 
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
-fragment           - Perform a fragment put, applies to only one property
 
55
-ns NAMESPACE       - Explicitly add the NAMESPACE selector
 
56
 
 
57
For array properties, specify prop=value for each index.
 
58
 
 
59
${CommonUsage1}
 
60
EOF
 
61
  $WSCOLORNORM
 
62
  exit 1
 
63
}
 
64
 
 
65
fCheckReqsOrUsage
 
66
 
 
67
[ $# -lt 2 ] && usage
 
68
NameList=()
 
69
ValueList=()
 
70
CLASS=$1; shift
 
71
index=0
 
72
while [ ! -z "$1" ]; do
 
73
  case "$1" in
 
74
    -h|-help|help ) usage
 
75
      ;;
 
76
    -f|-filter ) shift; CQL="$1"
 
77
      ;;
 
78
    -F|-fragment ) FRAGMENT=1
 
79
      ;;
 
80
    -n|-ns ) shift; WSNS="$1"
 
81
      ;;
 
82
    * ) NameList[$index]=$(echo "$1" | cut -d '=' -f1 )
 
83
      ValueList[$index]=$(echo "$1" | cut -d '=' -f2- )
 
84
      index=$((index + 1))
 
85
      ;;
 
86
  esac
 
87
  shift
 
88
done
 
89
 
 
90
# initializations
 
91
fGetTarget
 
92
fSetWGET
 
93
fNormalizeClass
 
94
 
 
95
[ ! -z "${CQL}" ] && CQLQUERY="<wsman:Filter Dialect='http://schemas.dmtf.org/wbem/cql/1/dsp0202.pdf'>${CQL}</wsman:Filter>"
 
96
 
 
97
if [ ! -z "${WSNS}" ]; then
 
98
REQSELECTORS=`cat <<EOF
 
99
  <wsman:SelectorSet>
 
100
    <wsman:Selector Name="__cimnamespace">${WSNS}</wsman:Selector>
 
101
  </wsman:SelectorSet>
 
102
EOF`
 
103
fi
 
104
 
 
105
dopullX() {
 
106
  fGetUUID
 
107
  fReqRspNext
 
108
  cat <<EOF >${REQUESTFILE}
 
109
${WSENVELOPEHEADER}
 
110
  <s:Header>
 
111
    <wsa:Action s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull</wsa:Action>
 
112
    ${WSCOMMONHEADER}
 
113
    <wsman:ResourceURI s:mustUnderstand="true">${CLASS}</wsman:ResourceURI>
 
114
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
115
    <wsa:ReplyTo>
 
116
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
117
    </wsa:ReplyTo>
 
118
  </s:Header>
 
119
  <s:Body>
 
120
    <wsen:Pull>
 
121
      <wsen:EnumerationContext>${CONTEXT}</wsen:EnumerationContext>
 
122
      ${WSPULLMAXELEMSTR}
 
123
    </wsen:Pull>
 
124
  </s:Body>
 
125
</s:Envelope>
 
126
EOF
 
127
  fNormalizeXML ${REQUESTFILE}
 
128
  fDumpRequestFile
 
129
  fSendRequest
 
130
  fNormalizeXML ${RESPONSEFILE}
 
131
  unset CONTEXT ; fGetFlatValueOfSingle ${RESPONSEFILE} N "EnumerationContext" ; export CONTEXT=${PVALUE}
 
132
  grep 'PullResponse' ${RESPONSEFILE} 2>&1 >/dev/null
 
133
  export STAT=$?
 
134
}
 
135
 
 
136
doenumerateX() {
 
137
  fGetUUID
 
138
  fReqRspNext
 
139
  cat <<EOF >${REQUESTFILE}
 
140
${WSENVELOPEHEADER}
 
141
  <s:Header>
 
142
    <wsa:Action s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</wsa:Action>
 
143
    ${WSCOMMONHEADER}
 
144
    <wsman:ResourceURI s:mustUnderstand="true">${CLASS}</wsman:ResourceURI>
 
145
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
146
    <wsa:ReplyTo>
 
147
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
148
    </wsa:ReplyTo>
 
149
    ${REQSELECTORS}
 
150
  </s:Header>
 
151
  <s:Body>
 
152
    <wsen:Enumerate>
 
153
      ${WSENUMOPTIMIZEDSTR}
 
154
      ${WSENUMMAXELEMSTR}
 
155
      ${EPR}
 
156
      ${CQLQUERY}
 
157
    </wsen:Enumerate>
 
158
  </s:Body>
 
159
</s:Envelope>
 
160
EOF
 
161
  fNormalizeXML ${REQUESTFILE}
 
162
  fDumpRequestFile
 
163
  fSendRequest
 
164
  fNormalizeXML ${RESPONSEFILE}
 
165
  unset CONTEXT ; fGetFlatValueOfSingle ${RESPONSEFILE} N "EnumerationContext" ; export CONTEXT=${PVALUE}
 
166
  grep 'EnumerateResponse' ${RESPONSEFILE} 2>&1 >/dev/null
 
167
  export STAT=$?
 
168
}
 
169
 
 
170
doenumerate() {
 
171
  doenumerateX
 
172
  [ ${OUTLEVEL} -ge 3 ] && ( $WSCOLORRSP; [ ${STAT} -ne 0 ] && $WSCOLORERR ; cat ${RESPONSEFILE} ; $WSCOLORNORM )
 
173
  while [ ! -z "${CONTEXT}" ]; do
 
174
    dopullX
 
175
    [ ${OUTLEVEL} -ge 3 ] && ( $WSCOLORRSP; [ ${STAT} -ne 0 ] && $WSCOLORERR ; cat ${RESPONSEFILE} ; $WSCOLORNORM )
 
176
    echo "(${CONTEXT})"
 
177
  done
 
178
}
 
179
 
 
180
doput() {
 
181
  fGetUUID
 
182
  fReqRspNext
 
183
cat <<EOF >${REQUESTFILE}
 
184
${WSENVELOPEHEADER}
 
185
  <s:Header>
 
186
    <wsa:Action s:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/09/transfer/Put</wsa:Action>
 
187
    ${WSCOMMONHEADER}
 
188
    <wsman:ResourceURI s:mustUnderstand="true">${RURI}</wsman:ResourceURI>
 
189
    <wsa:MessageID s:mustUnderstand="true">${UUID}</wsa:MessageID>
 
190
    ${FRAGMENTXFER}
 
191
    <wsa:ReplyTo>
 
192
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>
 
193
    </wsa:ReplyTo>
 
194
    ${EPRSELECTORSTR}
 
195
  </s:Header>
 
196
  <s:Body>
 
197
    ${PUTPAYLOAD}
 
198
  </s:Body>
 
199
</s:Envelope>
 
200
EOF
 
201
  fNormalizeXML ${REQUESTFILE}
 
202
  fDumpRequestFile
 
203
  fSendRequest
 
204
  fNormalizeXML ${RESPONSEFILE}
 
205
  grep "_OUTPUT" ${RESPONSEFILE} 2>&1 >/dev/null
 
206
  export STAT=$?
 
207
}
 
208
 
 
209
[ ${OUTLEVEL} -ge 3 ] && echo "NOTE: Enumerate operation may take time to reply."
 
210
 
 
211
EPR="<wsman:EnumerationMode>EnumerateObjectAndEPR</wsman:EnumerationMode>"
 
212
WSENUMMAXELEM=256
 
213
WSENUMOPTIMIZE=1
 
214
fInitEnum
 
215
 
 
216
doenumerate
 
217
FileObjEpr="${RESPONSEFILE}"
 
218
 
 
219
if [ ${STAT} -eq 0 ]; then
 
220
  fGetEPRSELECTOR ${FileObjEpr}
 
221
  if [ -z "${RCLASS}" ]; then
 
222
    echo "Failed to extract ResourceURI from the response, verify class name and filter if any."
 
223
    exit 1
 
224
  fi
 
225
  if [ ! -z "${FRAGMENT}" ]; then
 
226
    FRAGMENTXFER="<wsman:FragmentTransfer s:mustUnderstand=\"true\">${NameList[0]}</wsman:FragmentTransfer>"
 
227
    PUTPAYLOAD="<wsman:XmlFragment>"
 
228
    for (( index = 0; index < ${#NameList[@]}; index++ )); do
 
229
      Name=${NameList[$index]}
 
230
      Value=${ValueList[$index]}
 
231
      PUTPAYLOAD="${PUTPAYLOAD}<${Name}>${Value}</${Name}>"
 
232
    done
 
233
    PUTPAYLOAD="${PUTPAYLOAD}</wsman:XmlFragment>"
 
234
  else
 
235
    FileInstanceonly="${OUTPREFIX}/tmpinstanceonly.xml"
 
236
    fGetInstanceToFile ${FileObjEpr} ${RCLASS} ${FileInstanceonly}
 
237
    PUTPAYLOAD="<${NSPREFIX}:${RCLASS} xmlns:${NSPREFIX}=\"${RURI}\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
 
238
    index=0
 
239
    while read -e line ; do
 
240
      if [ $index -lt ${#NameList[@]} ]; then
 
241
        Name=${NameList[$index]}
 
242
        if [ ` echo "${line}" | grep ":${Name}" ` ]; then
 
243
          Value=${ValueList[$index]}
 
244
          PUTPAYLOAD="${PUTPAYLOAD}<${NSPREFIX}:${Name}>${Value}</${NSPREFIX}:${Name}>"
 
245
          index=$((index + 1))
 
246
          continue
 
247
        fi
 
248
      fi
 
249
      PUTPAYLOAD="${PUTPAYLOAD}${line}"
 
250
    done < "${FileInstanceonly}"
 
251
    PUTPAYLOAD="${PUTPAYLOAD}</${NSPREFIX}:${RCLASS}>"
 
252
  fi
 
253
 
 
254
  [ ${OUTLEVEL} -ge 3 ] && echo "NOTE: Invoke operation may take time to reply."
 
255
  doput
 
256
fi
 
257
 
 
258
fDisplayResponse ${RESPONSEFILE}
 
259
 
 
260
/bin/cp ${RESPONSEFILE} ${RETURNFILE}
 
261
[ ${OUTLEVEL} -ge 3 ] && echo "Output is saved to ${RETURNFILE}"
 
262
exit ${STAT} 
 
263
 
 
264
# ###########################################################################
 
265
# End of Code
 
266
# ###########################################################################