VMware VC-SRM4-A Developer's Guide - Page 20
SrmLoginLocale, SrmLoginSites, Example 3-3.
View all VMware VC-SRM4-A manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 20 highlights
Site Recovery Manager API Developer's Guide SrmLoginLocale This method logs in to the SRM server. The Connect public method requires the URL of an SRM server and authentication credentials. The SrmLoginLocale method takes the _srcRef managed object reference from SrmServiceInstance, and fails if the user name and password combination is invalid, or if the user is already logged in. In these examples, a locale string could be provided instead of the null parameter. Example 3-3. C# code for SRM login protected SrmService _service; protected SrmServiceInstanceContent _sic; protected ManagedObjectReference _svcRef; ... public void Connect(string url, string username, string password) { _service = new SrmService(); _service.Url = url; _service.Timeout = 600000; _service.CookieContainer = new System.Net.CookieContainer(); _sic = _service.RetrieveContent(_svcRef); _service.SrmLoginLocale(_svcRef, username, password, null); ... } The Java code is similar to the C# code but uses a service locator. Example 3-4. Java code for SRM login private static SrmPortType srmPort; private static SrmServiceInstanceContent serviceContent; private static boolean isConnected = false; ... srmPort = srmService.getSrmPort(); Map ctxt = ((BindingProvider) srmPort).getRequestContext(); ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); serviceContent = srmPort.retrieveContent(SVC_INST_REF); srmPort.srmLoginLocale(SVC_INST_REF, userName, password, null); isConnected = true; Subsequent SRM methods are called as a subclass of _service, for example _service.ListPlans() in C# or srmport.listPlans() in Java. SrmLoginSites The SrmLoginSites API is very similar to SrmLoginLocale, except it takes an additional user name and password combination for the remote (usually recovery) site. The SrmServiceInstance _this is obtained from the local (usually protected) site. Example 3-5. C# and Java for double SRM login /// C# _service.SrmLoginSites(_svcRef, username, password, remoteuser, remotepass, locale); // Java _service.srmLoginSites(_svcRef, username, password, remoteuser, remotepass, locale); Parameters are as follows _svcRef - managed object reference to SrmServiceInstance username - user name authorized for access to the local vCenter Server password - password for that user on the local vCenter Server remoteuser - user name authorized for access to the remote vCenter Server 20 VMware, Inc.