forked from RedHatQE/wrapanapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.py
77 lines (58 loc) · 1.92 KB
/
stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
wrapanapi.entities.stack
Orchestration stacks
"""
from abc import ABCMeta, abstractmethod
from wrapanapi.entities.base import Entity, EntityMixin
from wrapanapi.exceptions import MultipleItemsError, NotFoundError
class Stack(Entity, metaclass=ABCMeta):
"""
Defines methods/properties pertaining to stacks
"""
@abstractmethod
def get_details(self):
"""
Return a dict with detailed info about this object
There's no specific prescription for how this dict should be formatted--
it will vary based on entity and provider type. It is recommended
that the values contain simple python data types instead of
complex classes so the data can be parsed easily.
Returns: dict
"""
class StackMixin(EntityMixin, metaclass=ABCMeta):
"""
Defines methods for systems that support stacks
"""
@abstractmethod
def list_stacks(self, **kwargs):
"""
Return a list of Stack entities.
Returns: list of Stack objects
"""
@abstractmethod
def find_stacks(self, name, **kwargs):
"""
Find a stacks based on 'name' or other kwargs
Returns an empty list if no matches found
Returns: implementation of wrapanapi.stack.Stack
"""
@abstractmethod
def get_stack(self, name, **kwargs):
"""
Get stack based on name or other kwargs
Returns: Stack object
Raises:
MultipleItemsError if multiple matches found
NotFoundError if unable to find stack
"""
def does_stack_exist(self, name):
"""
Checks if a stack with 'name' exists on the system
If multiple stacks with the same name exists, this still returns 'True'
"""
try:
return bool(self.get_stack(name))
except MultipleItemsError:
return True
except NotFoundError:
return False