/// <summary> /// Returns the identifier of the datacenter. /// /// Note: The method assumes that there is only one datacenter with the /// specified name /// </summary> /// <param name="stubFactory">Stub factory for api endpoint</param> /// <param name="sessionStubConfig">stub configuration for the current /// session /// </param> /// <param name="datacenterName">name of the datacenter</param> /// <returns>identifier of a datacenter</returns> public static String GetDatacenter( StubFactory stubFactory, StubConfiguration sessionStubConfig, string datacenterName) { Datacenter datacenterService = stubFactory.CreateStub <Datacenter>(sessionStubConfig); HashSet <String> datacenterNames = new HashSet <String> { datacenterName }; DatacenterTypes.FilterSpec dcFilterSpec = new DatacenterTypes.FilterSpec(); dcFilterSpec.SetNames(datacenterNames); List <DatacenterTypes.Summary> dcSummaries = datacenterService.List(dcFilterSpec); if (dcSummaries.Count > 1) { throw new Exception(String.Format("More than one datacenter" + " with the specified name {0} exist", datacenterName)); } if (dcSummaries.Count <= 0) { throw new Exception(String.Format("Datacenter with name {0}" + " not found !", datacenterName)); } return(dcSummaries[0].GetDatacenter()); }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "external Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the lookup service on the " + "Platform Services Controller node."); LookupServiceHelper lookupServiceHelper = new LookupServiceHelper( LookupServiceUrl); Console.WriteLine("\nStep 2: Discover the Single Sign-On service " + "URL from lookup service."); String ssoUrl = lookupServiceHelper.FindSsoUrl(); Console.WriteLine("\nStep 3: Connect to the Single Sign-On URL and" + " retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 4. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 5: Perform certain tasks using the vAPI " + "services."); Datacenter datacenterService = vapiAuthHelper.StubFactory.CreateStub <Datacenter>( sessionStubConfig); List <DatacenterTypes.Summary> dcList = datacenterService.List(new DatacenterTypes.FilterSpec()); Console.WriteLine("\nList of datacenters on the vcenter server:"); foreach (DatacenterTypes.Summary dcSummary in dcList) { Console.WriteLine(dcSummary); } vapiAuthHelper.Logout(); }
public override void Run() { System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; Console.WriteLine("\n\n#### Example: Login to vCenter server with " + "embedded Platform Services Controller"); VapiAuthenticationHelper vapiAuthHelper = new VapiAuthenticationHelper(); /* * Since the platform services controller is embedded, the sso * server is the same as the vcenter server. */ String ssoUrl = "https://" + Server + SSO_PATH; SetupSslTrustForServer(); Console.WriteLine("\nStep 1: Connect to the Single Sign-On URL " + "and retrieve the SAML bearer token."); SamlToken samlBearerToken = SsoHelper.GetSamlBearerToken(ssoUrl, UserName, Password); Console.WriteLine("\nStep 2. Login to vAPI services using the " + "SAML bearer token."); StubConfiguration sessionStubConfig = vapiAuthHelper.LoginBySamlBearerToken(Server, samlBearerToken); Console.WriteLine("\nStep 3: Perform certain tasks using the vAPI " + "services."); Datacenter datacenterService = vapiAuthHelper.StubFactory.CreateStub <Datacenter>( sessionStubConfig); List <DatacenterTypes.Summary> dcList = datacenterService.List(new DatacenterTypes.FilterSpec()); Console.WriteLine("\nList of datacenters on the vcenter server:"); foreach (DatacenterTypes.Summary dcSummary in dcList) { Console.WriteLine(dcSummary); } vapiAuthHelper.Logout(); }