66
77
88class StackMixin (HttpMixin ):
9+ VALID_LOG_TYPES = {
10+ "provisioning" : ['log' , 'err' ],
11+ "global-orchestration" : ['log' , 'err' ],
12+ "orchestration" : ['log' , 'err' ],
13+ "launch" : ['log' ],
14+ }
915
1016 @endpoint ("stacks/" )
1117 def create_stack (self , stack_data ):
1218 """Launch a stack as described by stack_data"""
1319 return self ._post (endpoint , data = json .dumps (stack_data ), jsonify = True )
1420
15-
1621 @endpoint ("stacks/" )
1722 def list_stacks (self ):
1823 """Return a list of all stacks"""
1924 return self ._get (endpoint , jsonify = True )['results' ]
2025
21-
2226 @endpoint ("stacks/{stack_id}/" )
2327 def get_stack (self , stack_id ):
2428 """Get stack info"""
2529 return self ._get (endpoint , jsonify = True )
2630
27-
2831 @endpoint ("stacks/" )
2932 def search_stacks (self , * kwargs ):
3033 """Search for stacks that match the given criteria"""
3134 return self ._get (endpoint , params = kwargs , jsonify = True )['results' ]
3235
33-
3436 @endpoint ("stacks/{stack_id}/" )
3537 def delete_stack (self , stack_id ):
3638 """Destructively delete a stack forever."""
3739 return self ._delete (endpoint , jsonify = True )
3840
39-
4041 @endpoint ("stacks/{stack_id}/action/" )
41- def get_valid_stack_actions (self ):
42+ def get_valid_stack_actions (self , stack_id ):
4243 return self ._get (endpoint , jsonify = True )['available_actions' ]
4344
44-
4545 @endpoint ("stacks/{stack_id}/action/" )
4646 def do_stack_action (self , stack_id , action ):
4747 """Execute an action on a stack"""
48- valid_actions = self .get_valid_actions (stack_id )
48+ valid_actions = self .get_valid_stack_actions (stack_id )
4949
5050 if action not in valid_actions :
5151 raise StackException ("Invalid action, must be one of %s" %
@@ -55,7 +55,6 @@ def do_stack_action(self, stack_id, action):
5555
5656 return self ._post (endpoint , data = json .dumps (data ), jsonify = True )
5757
58-
5958 @endpoint ("stacks/{stack_id}/history/" )
6059 def get_stack_history (self , stack_id ):
6160 """Get stack info"""
@@ -65,7 +64,6 @@ def get_stack_history(self, stack_id):
6564 else :
6665 return result
6766
68-
6967 @deprecated
7068 @accepted_versions ("<0.7" )
7169 def get_stack_id (self , title ):
@@ -78,13 +76,11 @@ def get_stack_id(self, title):
7876
7977 raise StackException ("Stack %s not found" % title )
8078
81-
8279 @endpoint ("stacks/{stack_id}/hosts/" )
8380 def get_stack_hosts (self , stack_id ):
8481 """Get a list of all stack hosts"""
8582 return self ._get (endpoint , jsonify = True )['results' ]
8683
87-
8884 @endpoint ("stacks/{stack_id}/hosts/" )
8985 def describe_hosts (self , stack_id , key = "fqdn" , ec2 = False ):
9086 """Retrieve a list of info about a stack. Defaults to the id for each
@@ -102,10 +98,57 @@ def describe_hosts(self, stack_id, key="fqdn", ec2=False):
10298 else :
10399 host_details = host .get (EC2 ).get (key )
104100
105- if host_details :
101+ if host_details is not None :
106102 stack_details .append (host_details )
107103
108104 if stack_details :
109105 return stack_details
110106
111107 raise StackException ("Key %s for stack %s not available" % (key , stack_id ))
108+
109+ @endpoint ("stacks/{stack_id}/logs/{log_type}.{level}.{date}" )
110+ def get_logs (self , stack_id , log_type , level = 'log' , date = 'latest' , tail = None ):
111+ """Get logs for a stack"""
112+
113+ if log_type and log_type not in self .VALID_LOG_TYPES :
114+ raise StackException ("Invalid log type, must be one of %s" %
115+ ", " .join (self .VALID_LOG_TYPES .keys ()))
116+
117+ if level not in self .VALID_LOG_TYPES [log_type ]:
118+ raise StackException ("Invalid log level, must be one of %s" %
119+ ", " .join (self .VALID_LOG_TYPES [log_type ]))
120+
121+ return self ._get (endpoint , params = {'tail' : tail }).text
122+
123+ @endpoint ("stacks/{stack_id}/security_groups/" )
124+ def list_access_rules (self , stack_id ):
125+ """Get Access rules for a stack"""
126+
127+ return self ._get (endpoint , jsonify = True )['results' ]
128+
129+ @deprecated
130+ @accepted_versions ("<0.7" )
131+ def get_access_rule_id (self , stack_id , title ):
132+ """Find an access rule id"""
133+
134+ rules = self .list_access_rules (stack_id )
135+
136+ try :
137+ for group in rules :
138+ if group .get ("blueprint_host_definition" ).get ("title" ) == title :
139+ return group .get ("id" )
140+ except TypeError , e :
141+ pass
142+
143+ raise StackException ("Access Rule %s not found" % title )
144+
145+ @endpoint ("security_groups/{group_id}/rules/" )
146+ def list_rules_for_group (self , group_id ):
147+ return self ._get (endpoint , jsonify = True )
148+
149+ @endpoint ("security_groups/{group_id}/rules/" )
150+ def edit_access_rule (self , group_id , data = None ):
151+ """Add an access rule to a group"""
152+
153+ return self ._put (endpoint , jsonify = True , data = json .dumps (data ))
154+
0 commit comments