|
| 1 | +# (C) Copyright [2020] Hewlett Packard Enterprise Development LP |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +# copy of this software and associated documentation files (the "Software"), |
| 5 | +# to deal in the Software without restriction, including without limitation |
| 6 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 | +# and/or sell copies of the Software, and to permit persons to whom the |
| 8 | +# Software is furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included |
| 11 | +# in all copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 | +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 | +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 | +# OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + |
| 21 | +"""Module for working with datatap.""" |
| 22 | + |
| 23 | +from .base_resource import AbstractResource, AbstractResourceController |
| 24 | + |
| 25 | + |
| 26 | +class Datatap(AbstractResource): |
| 27 | + """Datatap Image item.""" |
| 28 | + |
| 29 | + # All of the fields of Catalog objects as returned by the HPE Container |
| 30 | + # Platform API. |
| 31 | + # TODO: Verify this with the specification |
| 32 | + all_fields = ( |
| 33 | + "id", |
| 34 | + "name", |
| 35 | + "description", |
| 36 | + "type", |
| 37 | + "status", |
| 38 | + ) |
| 39 | + |
| 40 | + default_display_fields = [ |
| 41 | + "id", |
| 42 | + "name", |
| 43 | + "description", |
| 44 | + "type", |
| 45 | + "status", |
| 46 | + ] |
| 47 | + |
| 48 | + # These fields are displayed by default, e.g. in tabulate() |
| 49 | + # TODO: Verify this with the specification |
| 50 | + # TODO: Pick a smaller subset, again based on the API response |
| 51 | + default_display_fields = all_fields |
| 52 | + |
| 53 | + @property |
| 54 | + def name(self): |
| 55 | + """@Field: from json['_embedded']['label']['name'].""" |
| 56 | + try: |
| 57 | + return self.json["_embedded"]["label"]["name"] |
| 58 | + except KeyError: |
| 59 | + return "" |
| 60 | + |
| 61 | + @property |
| 62 | + def description(self): |
| 63 | + """@Field: from json['_embedded']['label']['description'].""" |
| 64 | + try: |
| 65 | + return self.json["_embedded"]["label"]["description"] |
| 66 | + except KeyError: |
| 67 | + return "" |
| 68 | + |
| 69 | + @property |
| 70 | + def type(self): |
| 71 | + """@Field: from json['_embedded']['endpoint']['type'].""" |
| 72 | + try: |
| 73 | + return self.json["_embedded"]["endpoint"]["type"] |
| 74 | + except KeyError: |
| 75 | + return "" |
| 76 | + |
| 77 | + @property |
| 78 | + def self_href(self): |
| 79 | + """@Field: from json['_links']['self']['href'].""" |
| 80 | + try: |
| 81 | + return self.json["_links"]["self"]["href"] |
| 82 | + except KeyError: |
| 83 | + return "" |
| 84 | + |
| 85 | + @property |
| 86 | + def status(self): |
| 87 | + """@Field: from json['_embedded']['status'].""" |
| 88 | + try: |
| 89 | + return self.json["_embedded"]["status"] |
| 90 | + except KeyError: |
| 91 | + return "" |
| 92 | + |
| 93 | + |
| 94 | +class DatatapController(AbstractResourceController): |
| 95 | + """Class that users will interact with to work with datataps. |
| 96 | +
|
| 97 | + An instance of this class is available in the |
| 98 | + `client.ContainerPlatformClient` with the attribute name |
| 99 | + :py:attr:`datatap <.client.ContainerPlatformClient.catalog>`. The methods |
| 100 | + of this class can be invoked using `client.datatap.method()`. See the |
| 101 | + example below: |
| 102 | +
|
| 103 | + Examples |
| 104 | + -------- |
| 105 | + >>> client = ContainerPlatformClient(...).create_session() |
| 106 | + >>> client.datatap.list() |
| 107 | + """ |
| 108 | + |
| 109 | + base_resource_path = "/api/v1/dataconn" |
| 110 | + |
| 111 | + resource_list_path = "data_connectors" |
| 112 | + |
| 113 | + resource_class = Datatap |
| 114 | + |
| 115 | + def create_hdfs_with_kerberos( |
| 116 | + self, |
| 117 | + name, |
| 118 | + description, |
| 119 | + path_from_endpoint, |
| 120 | + kdc_data_host, |
| 121 | + kdc_data_port, |
| 122 | + realm, |
| 123 | + client_principal, |
| 124 | + browse_only, |
| 125 | + host, |
| 126 | + keytab, |
| 127 | + service_id, |
| 128 | + backup_host, |
| 129 | + endpoint_type, |
| 130 | + endpoint_port, |
| 131 | + read_only, |
| 132 | + ): |
| 133 | + """TODO. |
| 134 | +
|
| 135 | + Parameters |
| 136 | + ---------- |
| 137 | + name : [type] |
| 138 | + [description] |
| 139 | + description : [type] |
| 140 | + [description] |
| 141 | + path_from_endpoint : [type] |
| 142 | + [description] |
| 143 | + kdc_data_host : [type] |
| 144 | + [description] |
| 145 | + kdc_data_port : [type] |
| 146 | + [description] |
| 147 | + realm : [type] |
| 148 | + [description] |
| 149 | + client_principal : [type] |
| 150 | + [description] |
| 151 | + browse_only : [type] |
| 152 | + [description] |
| 153 | + host : [type] |
| 154 | + [description] |
| 155 | + keytab : [type] |
| 156 | + [description] |
| 157 | + service_id : [type] |
| 158 | + [description] |
| 159 | + backup_host : [type] |
| 160 | + [description] |
| 161 | + endpoint_type : [type] |
| 162 | + [description] |
| 163 | + endpoint_port : [type] |
| 164 | + [description] |
| 165 | + read_only : [type] |
| 166 | + [description] |
| 167 | + """ |
| 168 | + _data = { |
| 169 | + "bdfs_root": {"path_from_endpoint": path_from_endpoint}, |
| 170 | + "endpoint": { |
| 171 | + "kdc_data": [{"host": kdc_data_host, "port": kdc_data_port}], |
| 172 | + "realm": realm, |
| 173 | + "client_principal": client_principal, |
| 174 | + "browse_only": browse_only, |
| 175 | + "host": host, |
| 176 | + "keytab": keytab, |
| 177 | + "service_id": service_id, |
| 178 | + "backup_host": backup_host, |
| 179 | + "type": endpoint_type, |
| 180 | + "port": endpoint_port, |
| 181 | + }, |
| 182 | + "flags": {"read_only": read_only}, |
| 183 | + "label": {"name": name, "description": description}, |
| 184 | + } |
| 185 | + |
| 186 | + self.client._request( |
| 187 | + url=DatatapController.base_resource_path, |
| 188 | + http_method="post", |
| 189 | + description="datatap/create", |
| 190 | + data=_data, |
| 191 | + ) |
0 commit comments