|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Collections.ObjectModel; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Net; |
5 | 6 | using System.Threading.Tasks; |
@@ -689,6 +690,172 @@ public virtual IEnumerable<Tenant> ListTenants(CloudIdentity identity) |
689 | 690 | return response.Data.Tenants; |
690 | 691 | } |
691 | 692 |
|
| 693 | + /// <summary> |
| 694 | + /// Lists the endpoints in a tenant's service catalog. |
| 695 | + /// </summary> |
| 696 | + /// <remarks> |
| 697 | + /// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para> |
| 698 | + /// </remarks> |
| 699 | + /// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param> |
| 700 | + /// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param> |
| 701 | + /// <returns>A collection of <see cref="ExtendedEndpoint"/> objects containing endpoint details.</returns> |
| 702 | + /// <exception cref="ArgumentNullException">If <paramref name="tenantId"/> is <see langword="null"/>.</exception> |
| 703 | + /// <exception cref="ArgumentException">If <paramref name="tenantId"/> is empty.</exception> |
| 704 | + /// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception> |
| 705 | + /// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception> |
| 706 | + /// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception> |
| 707 | + /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso> |
| 708 | + /// <preliminary/> |
| 709 | + public virtual ReadOnlyCollection<ExtendedEndpoint> ListServiceCatalogEndpoints(string tenantId, CloudIdentity identity) |
| 710 | + { |
| 711 | + if (tenantId == null) |
| 712 | + throw new ArgumentNullException("tenantId"); |
| 713 | + if (string.IsNullOrEmpty(tenantId)) |
| 714 | + throw new ArgumentException("tenantId cannot be empty"); |
| 715 | + |
| 716 | + CheckIdentity(identity); |
| 717 | + |
| 718 | + var response = ExecuteRESTRequest<ListEndpointsResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints", tenantId)), HttpMethod.GET); |
| 719 | + |
| 720 | + if (response == null || response.Data == null || response.Data.Endpoints == null) |
| 721 | + return null; |
| 722 | + |
| 723 | + return new ReadOnlyCollection<ExtendedEndpoint>(response.Data.Endpoints); |
| 724 | + } |
| 725 | + |
| 726 | + /// <summary> |
| 727 | + /// Gets an endpoint by ID from the service catalog for a tenant. |
| 728 | + /// </summary> |
| 729 | + /// <remarks> |
| 730 | + /// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para> |
| 731 | + /// </remarks> |
| 732 | + /// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param> |
| 733 | + /// <param name="endpointId">The endpoint ID. This is obtained from <see cref="ExtendedEndpoint.Id"/></param> |
| 734 | + /// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param> |
| 735 | + /// <returns>An <see cref="ExtendedEndpoint"/> object containing the endpoint details.</returns> |
| 736 | + /// <exception cref="ArgumentNullException"> |
| 737 | + /// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para> |
| 738 | + /// <para>-or-</para> |
| 739 | + /// <para>If <paramref name="endpointId"/> is <see langword="null"/>.</para> |
| 740 | + /// </exception> |
| 741 | + /// <exception cref="ArgumentException"> |
| 742 | + /// <para>If <paramref name="tenantId"/> is empty.</para> |
| 743 | + /// <para>-or-</para> |
| 744 | + /// <para>If <paramref name="endpointId"/> is empty.</para> |
| 745 | + /// </exception> |
| 746 | + /// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception> |
| 747 | + /// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception> |
| 748 | + /// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception> |
| 749 | + /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso> |
| 750 | + /// <preliminary/> |
| 751 | + public virtual ExtendedEndpoint GetServiceCatalogEndpoint(string tenantId, string endpointId, CloudIdentity identity) |
| 752 | + { |
| 753 | + if (tenantId == null) |
| 754 | + throw new ArgumentNullException("tenantId"); |
| 755 | + if (endpointId == null) |
| 756 | + throw new ArgumentNullException("endpointId"); |
| 757 | + if (string.IsNullOrEmpty(tenantId)) |
| 758 | + throw new ArgumentException("tenantId cannot be empty"); |
| 759 | + if (string.IsNullOrEmpty(endpointId)) |
| 760 | + throw new ArgumentException("endpointId cannot be empty"); |
| 761 | + |
| 762 | + CheckIdentity(identity); |
| 763 | + |
| 764 | + var response = ExecuteRESTRequest<GetEndpointResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints/{1}", tenantId, endpointId)), HttpMethod.GET); |
| 765 | + |
| 766 | + if (response == null || response.Data == null) |
| 767 | + return null; |
| 768 | + |
| 769 | + return response.Data.Endpoint; |
| 770 | + } |
| 771 | + |
| 772 | + /// <summary> |
| 773 | + /// Adds an endpoint to the service catalog for a tenant. |
| 774 | + /// </summary> |
| 775 | + /// <remarks> |
| 776 | + /// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para> |
| 777 | + /// </remarks> |
| 778 | + /// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param> |
| 779 | + /// <param name="endpointTemplateId">The endpoint template ID.</param> |
| 780 | + /// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param> |
| 781 | + /// <returns>An <see cref="ExtendedEndpoint"/> object containing the endpoint details.</returns> |
| 782 | + /// <exception cref="ArgumentNullException"> |
| 783 | + /// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para> |
| 784 | + /// <para>-or-</para> |
| 785 | + /// <para>If <paramref name="endpointTemplateId"/> is <see langword="null"/>.</para> |
| 786 | + /// </exception> |
| 787 | + /// <exception cref="ArgumentException">If <paramref name="tenantId"/> is empty.</exception> |
| 788 | + /// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception> |
| 789 | + /// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception> |
| 790 | + /// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception> |
| 791 | + /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso> |
| 792 | + /// <preliminary/> |
| 793 | + public virtual ExtendedEndpoint AddServiceCatalogEndpoint(string tenantId, EndpointTemplateId endpointTemplateId, CloudIdentity identity) |
| 794 | + { |
| 795 | + if (tenantId == null) |
| 796 | + throw new ArgumentNullException("tenantId"); |
| 797 | + if (endpointTemplateId == null) |
| 798 | + throw new ArgumentNullException("endpointTemplateId"); |
| 799 | + if (string.IsNullOrEmpty(tenantId)) |
| 800 | + throw new ArgumentException("tenantId cannot be empty"); |
| 801 | + |
| 802 | + CheckIdentity(identity); |
| 803 | + |
| 804 | + var request = new AddServiceCatalogEndpointRequest(endpointTemplateId); |
| 805 | + var response = ExecuteRESTRequest<GetEndpointResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints", tenantId)), HttpMethod.POST, request); |
| 806 | + |
| 807 | + if (response == null || response.Data == null) |
| 808 | + return null; |
| 809 | + |
| 810 | + return response.Data.Endpoint; |
| 811 | + } |
| 812 | + |
| 813 | + /// <summary> |
| 814 | + /// Removes an endpoint from the service catalog for a tenant. |
| 815 | + /// </summary> |
| 816 | + /// <remarks> |
| 817 | + /// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para> |
| 818 | + /// </remarks> |
| 819 | + /// <param name="tenantId">The tenant Id. This is obtained from <see cref="Tenant.Id"/></param> |
| 820 | + /// <param name="endpointId">The endpoint Id. This is obtained from <see cref="ExtendedEndpoint.Id"/></param> |
| 821 | + /// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param> |
| 822 | + /// <returns><see langword="true"/> if the endpoint was successfully deleted; otherwise, <see langword="false"/>.</returns> |
| 823 | + /// <exception cref="ArgumentNullException"> |
| 824 | + /// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para> |
| 825 | + /// <para>-or-</para> |
| 826 | + /// <para>If <paramref name="endpointId"/> is <see langword="null"/>.</para> |
| 827 | + /// </exception> |
| 828 | + /// <exception cref="ArgumentException"> |
| 829 | + /// <para>If <paramref name="tenantId"/> is empty.</para> |
| 830 | + /// <para>-or-</para> |
| 831 | + /// <para>If <paramref name="endpointId"/> is empty.</para> |
| 832 | + /// </exception> |
| 833 | + /// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception> |
| 834 | + /// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception> |
| 835 | + /// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception> |
| 836 | + /// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso> |
| 837 | + /// <preliminary/> |
| 838 | + public virtual bool DeleteServiceCatalogEndpoint(string tenantId, string endpointId, CloudIdentity identity) |
| 839 | + { |
| 840 | + if (tenantId == null) |
| 841 | + throw new ArgumentNullException("tenantId"); |
| 842 | + if (endpointId == null) |
| 843 | + throw new ArgumentNullException("endpointId"); |
| 844 | + if (string.IsNullOrEmpty(tenantId)) |
| 845 | + throw new ArgumentException("tenantId cannot be empty"); |
| 846 | + if (string.IsNullOrEmpty(endpointId)) |
| 847 | + throw new ArgumentException("endpointId cannot be empty"); |
| 848 | + |
| 849 | + CheckIdentity(identity); |
| 850 | + |
| 851 | + var response = ExecuteRESTRequest(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints/{1}", tenantId, endpointId)), HttpMethod.DELETE); |
| 852 | + |
| 853 | + if (response == null && response.StatusCode != HttpStatusCode.NoContent) |
| 854 | + return false; |
| 855 | + |
| 856 | + return true; |
| 857 | + } |
| 858 | + |
692 | 859 | #endregion |
693 | 860 |
|
694 | 861 | #region Token and Authentication |
|
0 commit comments