Webservice setup and overview: Difference between revisions

From MyLVS
Jump to navigation Jump to search
 
Line 227: Line 227:


'''Same but using the IP Address parameter'''
'''Same but using the IP Address parameter'''
'WD:
'300: WeightDown in progress, please stand by
'301: TurnOff in progress, please stand by
'Status=>200<= =>200: Host is waiting for a update (updatepending) - on 192.168.88.60
'OR WD pending:
'302: Another maintenance service is already running, please come back later -> 192.168.88.60
'WU:
'Status=>200<= =>200: Host has been set to go online, please check the status later - 192.168.88.60
'Trying to manipulate sequence
'500: REQUESTWEIGHTDOWN (Updatepending) is already set on 192.168.88.60
'500: updatepending is not set on 192.168.88.60
'Status Manual Turn Off
'500: Host is entirely disabled (192.168.88.60/hh-ibe01)
'Status Manual WeightDown
'500: Service has weightdown set set (Link:hh-ibe01:7000/INV-ID:689)
'https://www.example-code.com/vbscript/http_soapPost11.asp
'https://www.example-code.com/vb6/xml_UpdateAttrAt.asp
'https://www.example-code.com/vbscript/http_soapPost11.asp
'https://www.example-code.com/vbscript/xml_newChild2.asp


  Dim fso, outFile, strLVSCmd, strLVSHost,strLVSPort,strLVSClientIP
  Dim fso, outFile, strLVSCmd, strLVSHost,strLVSPort,strLVSClientIP

Latest revision as of 15:55, 21 February 2019

Samples

Sample request from a Linux client using perl

  • Note: The below samples are included within the installation archive in /var/www/mylvs/templates/client_scripts
  • Require Debian package: apt-get install libsoap-lite-perl

Sample script (test.pl)

#!/usr/bin/perl -w
use SOAP::Lite; # + qw/ trace /;
my $soap = SOAP::Lite
  -> uri('urn:lvs')
  -> proxy('http://ws.mylvs.foo/cgi-bin/lvs.cgi');
my $result = $soap->WHATISMYIP ();
unless ($result->fault) {
 print $result->result();
} else {
  print join ', ',
    $result->faultcode,
    $result->faultstring;
}

Sample script output (test.pl)

root@myLVS-LinuxClient:/usr/local/dev/mylvs# perl test.pl
200 192.168.2.222






Sample request from a Windows client using perl

To install the ActiveState Perl Module use:

C:\Users\Administrator\Documents\lvs> ppm install Soap-Lite

Sample script (test.pl):

#!/usr/bin/perl -w
use SOAP::Lite; # + qw/ trace /;
my $soap = SOAP::Lite
 -> uri('urn:lvs')
 -> proxy('http://ws.mylvs.foo/cgi-bin/lvs.cgi');
my $result = $soap->WHATISMYIP ();
unless ($result->fault) {
 print $result->result();
} else {
  print join ', ',
  $result->faultcode,
  $result->faultstring;
}

Sample script output (test.pl):

C:\Users\Administrator\Documents\lvs>perl test.pl
200 192.168.2.221






Sample request from a Windows client using cscript with MSXML

Set xmlReq = CreateObject("MSXML2.DOMDocument.6.0")
request="<SOAP-ENV:Envelope xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' " 
request = request & "xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' "
request = request & "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "
request = request & "xmlns:xsd='http://www.w3.org/1999/XMLSchema' "
request = request & "SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"
request = request & "<SOAP-ENV:Body><mylvs:WHATISMYIP xmlns:mylvs='urn:lvs'/>"
'request = request & "<c-gensym3 xsi:type='xsd:string'>192.168.xx.yy</c-gensym3>" 'alternative param
request = request & "</SOAP-ENV:Body></SOAP-ENV:Envelope>"
xmlReq.loadXML  request 'load our request
Set xmlRes = CreateObject("MSXML2.XMLHTTP.6.0")  
xmlRes.open "POST", "http://ws.mylvs.foo/cgi-bin/lvs.cgi"
xmlRes.send (xmlReq)
while xmlRes.readyState <> 4
wend
Set objDispatch =  xmlRes.responseXML
set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.Load objDispatch
WScript.Echo xmlDoc.selectSingleNode("//WHATISMYIPResponse").text

Sample script output (test.vbs):

C:\Users\Administrator\Documents\lvs>cscript test.vbs //Nologo
200 192.168.2.221




Sample request from a Windows client using cscript with SoapLite

Soaplite is a smart way to handle our request. It still runs as 32bit application on Server2012
but it requires the 32bit part of cscript.

Soaplite must be registered with the 32bit part of regsvr:

C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\regsvr32.exe Lite.dll

Sample script (test-lite.vbs):

strSoapProxy="http://ws.mylvs.foo/cgi-bin/lvs.cgi"
strSoapURI = "urn:lvs"
set wso = CreateObject("SOAP.Lite").new("proxy", strSoapProxy, "uri",strSoapURI )
'wscript.echo  wso.WHATISMYIP(strBLA).result 'Sample for an alternative parameter
wscript.echo  wso.WHATISMYIP().result

Sample script output (test-lite.vbs):

C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\cscript.exe test-lite.vbs //nologo
200 192.168.2.221






Webservice functions

Note: Additional steps were required to setup webservices, see more details here:


  • The LVS-WFE Webservice offers the following functions:


Function Optional Paramter Description Return
REQUESTWEIGHTDOWN String (a ip address like 192.168.1.1) Request to set the host offline String (Code(d{3}) Description
REQUESTWEIGHTUP String (a ip address like 192.168.1.1) Request to set the host online String (Code(d{3}) Description
REQUESTWEIGHTSTATUS String (a ip address like 192.168.1.1) Request the current status String (Code(d{3}) Description
REQUESTGROUPINFORMATION String (a ip address like 192.168.1.1) Request the current group configuration String (Code(d{3}) Description
WHATISMYIP - - -


Return Codes

  • The LVS-WFE Webservice returns the following codes:
  • Log Categories
    • 2nn = Success
    • 3nn = Logical Errors
    • 4nn = Functional Errors
    • 5nn = Access or Request Errors


Code Description Return
200 Request accepted (function defined message) True
300 WeigthDown in process False
301 TurnOff in process False
302 Another maintenance service is already running False
304 Host has already maintenance running, please come back later False
305 Host has already ip renew set, please come back later False
306 Host has already ip renewed a few minutes ago, please come back later False
307 Host not found in inventory False
407 IP renew is not set (debugging only) False
408 Function not supported (debugging only) False
500 Access denied or Request Refused False
501 Access denied - update failed, contact IT-Admin False



Alternative example using Chilkat

'https://www.example-code.com/vbscript/http_soapPost11.asp
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)
set http = CreateObject("Chilkat_9_5_0.Http")
success = http.UnlockComponent("any code to test")
If (success <> 1) Then
   outFile.WriteLine(crypt.LastErrorText)
   outFile.WriteLine("unlock failed.")
   WScript.Quit
End If
set soapXml = CreateObject("Chilkat_9_5_0.Xml")
soapXml.Tag = "soap:Envelope"
success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/")
success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
success = soapXml.UpdateAttrAt("Body|REQUESTWEIGHTSTATUS",1,"xmlns","urn:lvs")
outFile.WriteLine(soapXml.GetXml())
set req = CreateObject("Chilkat_9_5_0.HttpRequest")
req.HttpVerb = "POST"
req.SendCharset = 0
req.AddHeader "Content-Type","text/xml; charset=utf-8"
req.AddHeader "SOAPAction","urn:lvs#REQUESTWEIGHTSTATUS"
req.Path = "/cgi-bin/lvs.cgi"
success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8")
'http.SessionLogFilename = "httpSessionLog.txt"
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.SynchronousRequest("ws.hhlvs.intern",80,0,req)
If (http.LastMethodSuccess = 0) Then
 outFile.WriteLine(http.LastErrorText)
Else
 set xmlResponse = CreateObject("Chilkat_9_5_0.Xml")
 success = xmlResponse.LoadXml(resp.BodyStr)
 outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing"))
End If
outFile.Close


Same but using the IP Address parameter

Dim fso, outFile, strLVSCmd, strLVSHost,strLVSPort,strLVSClientIP
strLVSCmd="REQUESTWEIGHTSTATUS"
strLVSHost="ws.domain.com"
strLVSPort=80
strLVSClientIP="192.168.x.y"
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)
set http = CreateObject("Chilkat_9_5_0.Http")
success = http.UnlockComponent("...code...")
If (success <> 1) Then
   outFile.WriteLine(crypt.LastErrorText)
   outFile.WriteLine("unlock failed.")
   WScript.Quit
End If
set soapXml = CreateObject("Chilkat_9_5_0.Xml")
soapXml.Tag = "soap:Envelope"
success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/")
success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/")
success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd ,1,"xmlns","urn:lvs")
success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd & "|c-gensym3",1,"xsi:type","xsd:string") 
soapXml.UpdateChildContent "soap:Body|" & strLVSCmd & "|c-gensym3",strLVSClientIP
'wscript.echo soapXml.GetXml()
set req = CreateObject("Chilkat_9_5_0.HttpRequest")
req.HttpVerb = "POST"
req.SendCharset = 0
req.AddHeader "Content-Type","text/xml; charset=utf-8"
req.AddHeader "SOAPAction","urn:lvs#" & strLVSCmd
req.Path = "/cgi-bin/lvs.cgi"
success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8")
'http.SessionLogFilename = "httpSessionLog.txt"
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.SynchronousRequest(strLVSHost,strLVSPort,0,req)
If (http.LastMethodSuccess = 0) Then
 outFile.WriteLine(http.LastErrorText)
Else
 set xmlResponse = CreateObject("Chilkat_9_5_0.Xml")
 success = xmlResponse.LoadXml(resp.BodyStr)
 outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing"))
 wscript.echo "Status=>" & cint(mid(xmlResponse.AccumulateTagContent("s-gensym3","nothing"),1,3)) & "<= =>" & xmlResponse.AccumulateTagContent("s-gensym3","nothing")
End If
outFile.Close



  • Note: The webservice requires mylvsmon to run