diff options
author | stark, steven <steven.stark@att.com> | 2020-09-17 13:04:35 -0700 |
---|---|---|
committer | stark, steven <steven.stark@att.com> | 2020-09-17 13:04:35 -0700 |
commit | 35375724d9657de99adb8e530e1be21305555a40 (patch) | |
tree | 28806a1a1317426546ffdb9755d6f632ce088605 /onap-client/onap_client/resource.py | |
parent | 591c548e569423dad8d106d4d2cd26bc5ce24b19 (diff) |
[VVP] Updating onap-client
Removing dependency on distutils
moving etc/ to package resource
Adding support for volume creation and delete
Removing module level imports
Adding delete capability to spec-engine
Adding kwarg to pass Client instance to functions
Issue-ID: VVP-469
Signed-off-by: stark, steven <steven.stark@att.com>
Change-Id: Ie00065f54411c8ff40ea20c35fe919ce15f65e6a
Diffstat (limited to 'onap-client/onap_client/resource.py')
-rw-r--r-- | onap-client/onap_client/resource.py | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/onap-client/onap_client/resource.py b/onap-client/onap_client/resource.py index cd7c677..abe7bf0 100644 --- a/onap-client/onap_client/resource.py +++ b/onap-client/onap_client/resource.py @@ -35,7 +35,12 @@ # # ============LICENSE_END============================================ from abc import ABC -from onap_client.exceptions import InvalidSpecException, ResourceAlreadyExistsException, ResourceCreationFailure +from onap_client.exceptions import ( + InvalidSpecException, + ResourceAlreadyExistsException, + ResourceCreationFailure, + ResourceDeleteFailure +) from onap_client.client.clients import get_client as Client @@ -43,9 +48,14 @@ class Resource(ABC): resource_name = "abstract" spec = {} - def __init__(self, **kwargs): + def __init__(self, oc=None, **kwargs): self.attributes = {} - self.oc = Client() + + if not oc: + self.oc = Client() + else: + self.oc = oc + self.input_spec = self.validate(kwargs, spec=self.spec) def __getattr__(self, attr): @@ -56,9 +66,15 @@ class Resource(ABC): self.resolve_attributes(attributes) self._post_create() + def delete(self): + self._delete(self.input_spec) + def _create(self, input): pass + def _delete(self, input): + pass + def _post_create(self): pass @@ -72,8 +88,8 @@ class Resource(ABC): return None @classmethod - def create_from_spec(cls, spec, submit=True): - instance = cls(**spec) + def create_from_spec(cls, spec, submit=True, oc=None): + instance = cls(**spec, oc=oc) try: instance.create() @@ -89,6 +105,19 @@ class Resource(ABC): return instance + @classmethod + def delete_from_spec(cls, spec, oc=None): + instance = cls(**spec, oc=oc) + + try: + instance.delete() + except Exception as e: + raise ResourceDeleteFailure( + "Failed to delete resource {}: {}".format(instance.resource_name, str(e)) + ) + + return instance + def resolve_attributes(self, attributes): for key, val in attributes.items(): self.attributes[key] = val |