|
| 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 | + "label_name", |
| 34 | + "label_description", |
| 35 | + "self_href", |
| 36 | + # "state", |
| 37 | + # "state_info", |
| 38 | + ) |
| 39 | + |
| 40 | + default_display_fields = [ |
| 41 | + "label_name", |
| 42 | + "label_description", |
| 43 | + "self_href", |
| 44 | + ] |
| 45 | + |
| 46 | + # These fields are displayed by default, e.g. in tabulate() |
| 47 | + # TODO: Verify this with the specification |
| 48 | + # TODO: Pick a smaller subset, again based on the API response |
| 49 | + default_display_fields = all_fields |
| 50 | + |
| 51 | + @property |
| 52 | + def label_name(self): |
| 53 | + """@Field: from json['label']['name'].""" |
| 54 | + try: |
| 55 | + return self.json["label"]["name"] |
| 56 | + except KeyError: |
| 57 | + return "" |
| 58 | + |
| 59 | + @property |
| 60 | + def label_description(self): |
| 61 | + """@Field: from json['label']['description'].""" |
| 62 | + try: |
| 63 | + return self.json["label"]["description"] |
| 64 | + except KeyError: |
| 65 | + return "" |
| 66 | + |
| 67 | + @property |
| 68 | + def self_href(self): |
| 69 | + """@Field: from json['_links']['self']['href'].""" |
| 70 | + try: |
| 71 | + return self.json["_links"]["self"]["href"] |
| 72 | + except KeyError: |
| 73 | + return "" |
| 74 | + |
| 75 | + # @property |
| 76 | + # def state(self): |
| 77 | + # """@Field: from json['state']""" |
| 78 | + # try: |
| 79 | + # return self.json["state"] |
| 80 | + # except KeyError: |
| 81 | + # return "" |
| 82 | + |
| 83 | + # @property |
| 84 | + # def state_info(self): |
| 85 | + # """@Field: from json['state_info']""" |
| 86 | + # try: |
| 87 | + # return self.json["state_info"] |
| 88 | + # except KeyError: |
| 89 | + # return "" |
| 90 | + |
| 91 | + |
| 92 | +class DatatapController(AbstractResourceController): |
| 93 | + """Class that users will interact with to work with datataps. |
| 94 | +
|
| 95 | + An instance of this class is available in the |
| 96 | + `client.ContainerPlatformClient` with the attribute name |
| 97 | + :py:attr:`datatap <.client.ContainerPlatformClient.catalog>`. The methods |
| 98 | + of this class can be invoked using `client.datatap.method()`. See the |
| 99 | + example below: |
| 100 | +
|
| 101 | + Examples |
| 102 | + -------- |
| 103 | + >>> client = ContainerPlatformClient(...).create_session() |
| 104 | + >>> client.datatap.list() |
| 105 | + """ |
| 106 | + |
| 107 | + base_resource_path = "/api/v1/dataconn" |
| 108 | + |
| 109 | + resource_list_path = "data_connectors" |
| 110 | + |
| 111 | + resource_class = Datatap |
0 commit comments