Below is a quick C# method for validating a XenServer API login, give the server name/IP address, username and password using the XenServer .Net SDK.
If you need the XenServer .NET SDK you can get it from the nuget.org package system within visual studio by searching for XenServer or by clicking on the direct link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool ValidateServerLogin(string Server, string Username, string Password) | |
{ | |
bool _returnValue = false; | |
//build the XenServer session object that will hold a validated/authenticated | |
//session to the specified xenserver | |
XenAPI.Session _session = new XenAPI.Session(Server, 80); | |
try | |
{ | |
//try to login to the specified xenserver with the | |
//supplied credentials | |
_session.login_with_password(Username, Password); | |
if (_session != null) | |
{ | |
//logout from the server, since this was only a auth test | |
_session.logout(); | |
//set the return value for the function | |
_returnValue = true; | |
} | |
} | |
catch (Exception e) | |
{ | |
//an authentication exception happened (which typically means | |
//that a wrong username/password was specified) | |
//set the return value of the function to be false | |
_returnValue = false; | |
} | |
//returning the auth status for the function | |
return _returnValue; | |
} |