/// <summary> /// Returns the identifier of a distributed network /// /// Note: The method assumes that there is only one distributed portgroup /// and datacenter with the specified names. /// </summary> /// <param name="serviceManager">Helper for instantiating vapi services</param> /// <param name="datacenterName">name of the datacenter</param> /// <param name="distPortgroupName">name of the distributed portgroup</param> /// <returns>identifier of the distributed network</returns> public static string GetDistributedNetworkBacking( StubFactory stubFactory, StubConfiguration sessionStubConfig, string datacenterName, string distPortgroupName) { HashSet<string> datacenters = new HashSet<string> { DatacenterHelper.GetDatacenter( stubFactory, sessionStubConfig, datacenterName) }; NetworkTypes.FilterSpec networkFilterSpec = new NetworkTypes.FilterSpec(); networkFilterSpec.SetNames( new HashSet<string> { distPortgroupName }); networkFilterSpec.SetDatacenters(datacenters); networkFilterSpec.SetTypes(new HashSet<NetworkTypes.Type> { NetworkTypes.Type.DISTRIBUTED_PORTGROUP }); Network networkService = stubFactory.CreateStub<Network>(sessionStubConfig); List<NetworkTypes.Summary> networkSummaries = networkService.List(networkFilterSpec); if (networkSummaries.Count > 1) { throw new Exception(String.Format("More than one distributed" + " portgroup with the specified name {0} exist", distPortgroupName)); } if (networkSummaries.Count <= 0) { throw new Exception(String.Format("Distributed portgroup " + "with name {0} not found !", distPortgroupName)); } return networkSummaries[0].GetNetwork(); }
/// <summary> /// Returns the identifier of a cluster. /// /// Note: The method assumes that there is only one cluster and /// datacenter with the specified names /// </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> /// <param name="clusterName">name of the cluster</param> /// <returns>identifier of the cluster</returns> public static String GetCluster( StubFactory stubFactory, StubConfiguration sessionStubConfig, string datacenterName, string clusterName) { HashSet <string> datacenters = new HashSet <string> { DatacenterHelper.GetDatacenter(stubFactory, sessionStubConfig, datacenterName) }; ClusterTypes.FilterSpec clusterFilterSpec = new ClusterTypes.FilterSpec(); HashSet <string> clusters = new HashSet <string> { clusterName }; clusterFilterSpec.SetNames(clusters); clusterFilterSpec.SetDatacenters(datacenters); Cluster clusterService = stubFactory.CreateStub <Cluster>( sessionStubConfig); List <ClusterTypes.Summary> clusterSummaries = clusterService.List(clusterFilterSpec); if (clusterSummaries.Count > 1) { throw new Exception(String.Format("More than one cluster with" + " the specified name {0} exist", clusterName)); } if (clusterSummaries.Count <= 0) { throw new Exception(String.Format("Cluster with name {0}" + " not found !", clusterName)); } return(clusterSummaries[0].GetCluster()); }
/// <summary> /// Returns the identifier of a folder. /// /// Note: The method assumes that there is only one folder and /// datacenter with the specified names. /// </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> /// <param name="folderName">name of the folder</param> /// <returns>identifier of a folder</returns> public static String GetFolder( StubFactory stubFactory, StubConfiguration sessionStubConfig, string datacenterName, string folderName) { HashSet <string> datacenters = new HashSet <string> { DatacenterHelper.GetDatacenter( stubFactory, sessionStubConfig, datacenterName) }; FolderTypes.FilterSpec folderFilterSpec = new FolderTypes.FilterSpec(); folderFilterSpec.SetNames(new HashSet <String> { folderName }); folderFilterSpec.SetDatacenters(datacenters); Folder folderService = stubFactory.CreateStub <Folder>( sessionStubConfig); List <FolderTypes.Summary> folderSummaries = folderService.List(folderFilterSpec); if (folderSummaries.Count > 1) { throw new Exception(String.Format("More than one folder" + " with the specified name {0} exist", folderName)); } if (folderSummaries.Count <= 0) { throw new Exception(String.Format("Folder with name {0}" + "not found !", folderName)); } return(folderSummaries[0].GetFolder()); }
/// <summary> /// Returns the identifier of a datastore. /// /// Note: The method assumes that there is only one datacenter and /// datastore with the specified names. /// </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> /// <param name="datastoreName">name of the datastore</param> /// <returns>identifier of a datastore</returns> public static String GetDatastore( StubFactory stubFactory, StubConfiguration sessionStubConfig, string datacenterName, string datastoreName) { HashSet <string> datacenters = new HashSet <string> { DatacenterHelper.GetDatacenter( stubFactory, sessionStubConfig, datacenterName) }; DatastoreTypes.FilterSpec dsFilterSpec = new DatastoreTypes.FilterSpec(); dsFilterSpec.SetNames(new HashSet <string> { datastoreName }); dsFilterSpec.SetDatacenters(datacenters); Datastore datastoreService = stubFactory.CreateStub <Datastore>(sessionStubConfig); List <DatastoreTypes.Summary> dsSummaries = datastoreService.List(dsFilterSpec); if (dsSummaries.Count > 1) { throw new Exception(String.Format("More than one datastore" + " with the specified name {0} exist", datastoreName)); } if (dsSummaries.Count <= 0) { throw new Exception(String.Format("Datastore with name {0}" + "not found !", datastoreName)); } return(dsSummaries[0].GetDatastore()); }