Best Python code snippet using localstack_python
stack.py
Source:stack.py
1from datetime import datetime2from boto.resultset import ResultSet3class Stack:4 def __init__(self, connection=None):5 self.connection = connection6 self.creation_time = None7 self.description = None8 self.disable_rollback = None9 self.notification_arns = []10 self.outputs = []11 self.parameters = []12 self.capabilities = []13 self.stack_id = None14 self.stack_status = None15 self.stack_name = None16 self.stack_name_reason = None17 self.timeout_in_minutes = None18 def startElement(self, name, attrs, connection):19 if name == "Parameters":20 self.parameters = ResultSet([('member', Parameter)])21 return self.parameters22 elif name == "Outputs":23 self.outputs = ResultSet([('member', Output)])24 return self.outputs25 elif name == "Capabilities":26 self.capabilities = ResultSet([('member', Capability)])27 return self.capabilities28 else:29 return None30 def endElement(self, name, value, connection):31 if name == 'CreationTime':32 self.creation_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')33 elif name == "Description":34 self.description = value35 elif name == "DisableRollback":36 self.disable_rollback = bool(value)37 elif name == "NotificationARNs":38 self.notification_arns = value39 elif name == 'StackId':40 self.stack_id = value41 elif name == 'StackName':42 self.stack_name = value43 elif name == 'StackStatus':44 self.stack_status = value45 elif name == "StackStatusReason":46 self.stack_status_reason = value47 elif name == "TimeoutInMinutes":48 self.timeout_in_minutes = int(value)49 elif name == "member":50 pass51 else:52 setattr(self, name, value)53 def delete(self):54 return self.connection.delete_stack(stack_name_or_id=self.stack_id)55 def describe_events(self, next_token=None):56 return self.connection.describe_stack_events(57 stack_name_or_id=self.stack_id,58 next_token=next_token59 )60 def describe_resource(self, logical_resource_id):61 return self.connection.describe_stack_resource(62 stack_name_or_id=self.stack_id,63 logical_resource_id=logical_resource_id64 )65 def describe_resources(self, logical_resource_id=None,66 physical_resource_id=None):67 return self.connection.describe_stack_resources(68 stack_name_or_id=self.stack_id,69 logical_resource_id=logical_resource_id,70 physical_resource_id=physical_resource_id71 )72 def list_resources(self, next_token=None):73 return self.connection.list_stack_resources(74 stack_name_or_id=self.stack_id,75 next_token=next_token76 )77 def update(self):78 rs = self.connection.describe_stacks(self.stack_id)79 if len(rs) == 1 and rs[0].stack_id == self.stack_id:80 self.__dict__.update(rs[0].__dict__)81 else:82 raise ValueError("%s is not a valid Stack ID or Name" %83 self.stack_id)84 def get_template(self):85 return self.connection.get_template(stack_name_or_id=self.stack_id)86class StackSummary:87 def __init__(self, connection=None):88 self.connection = connection89 self.stack_id = None90 self.stack_status = None91 self.stack_name = None92 self.creation_time = None93 self.deletion_time = None94 self.template_description = None95 def startElement(self, name, attrs, connection):96 return None97 def endElement(self, name, value, connection):98 if name == 'StackId':99 self.stack_id = value100 elif name == 'StackStatus':101 self.stack_status = value102 elif name == 'StackName':103 self.stack_name = value104 elif name == 'CreationTime':105 self.creation_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')106 elif name == "DeletionTime":107 self.deletion_time = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')108 elif name == 'TemplateDescription':109 self.template_description = value110 elif name == "member":111 pass112 else:113 setattr(self, name, value)114class Parameter:115 def __init__(self, connection=None):116 self.connection = None117 self.key = None118 self.value = None119 def startElement(self, name, attrs, connection):120 return None121 def endElement(self, name, value, connection):122 if name == "ParameterKey":123 self.key = value124 elif name == "ParameterValue":125 self.value = value126 else:127 setattr(self, name, value)128 def __repr__(self):129 return "Parameter:\"%s\"=\"%s\"" % (self.key, self.value)130class Output:131 def __init__(self, connection=None):132 self.connection = connection133 self.description = None134 self.key = None135 self.value = None136 def startElement(self, name, attrs, connection):137 return None138 def endElement(self, name, value, connection):139 if name == "Description":140 self.description = value141 elif name == "OutputKey":142 self.key = value143 elif name == "OutputValue":144 self.value = value145 else:146 setattr(self, name, value)147 def __repr__(self):148 return "Output:\"%s\"=\"%s\"" % (self.key, self.value)149class Capability:150 def __init__(self, connection=None):151 self.connection = None152 self.value = None153 def startElement(self, name, attrs, connection):154 return None155 def endElement(self, name, value, connection):156 self.value = value157 def __repr__(self):158 return "Capability:\"%s\"" % (self.value)159class StackResource:160 def __init__(self, connection=None):161 self.connection = connection162 self.description = None163 self.logical_resource_id = None164 self.physical_resource_id = None165 self.resource_status = None166 self.resource_status_reason = None167 self.resource_type = None168 self.stack_id = None169 self.stack_name = None170 self.timestamp = None171 def startElement(self, name, attrs, connection):172 return None173 def endElement(self, name, value, connection):174 if name == "Description":175 self.description = value176 elif name == "LogicalResourceId":177 self.logical_resource_id = value178 elif name == "PhysicalResourceId":179 self.physical_resource_id = value180 elif name == "ResourceStatus":181 self.resource_status = value182 elif name == "ResourceStatusReason":183 self.resource_status_reason = value184 elif name == "ResourceType":185 self.resource_type = value186 elif name == "StackId":187 self.stack_id = value188 elif name == "StackName":189 self.stack_name = value190 elif name == "Timestamp":191 self.timestamp = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')192 else:193 setattr(self, name, value)194 def __repr__(self):195 return "StackResource:%s (%s)" % (self.logical_resource_id,196 self.resource_type)197class StackResourceSummary:198 def __init__(self, connection=None):199 self.connection = connection200 self.last_updated_timestamp = None201 self.logical_resource_id = None202 self.physical_resource_id = None203 self.resource_status = None204 self.resource_status_reason = None205 self.resource_type = None206 def startElement(self, name, attrs, connection):207 return None208 def endElement(self, name, value, connection):209 if name == "LastUpdatedTimestamp":210 self.last_updated_timestampe = datetime.strptime(value,211 '%Y-%m-%dT%H:%M:%SZ')212 elif name == "LogicalResourceId":213 self.logical_resource_id = value214 elif name == "PhysicalResourceId":215 self.physical_resource_id = value216 elif name == "ResourceStatus":217 self.resource_status = value218 elif name == "ResourceStatusReason":219 self.resource_status_reason = value220 elif name == "ResourceType":221 self.resource_type = value222 else:223 setattr(self, name, value)224 def __repr__(self):225 return "StackResourceSummary:%s (%s)" % (self.logical_resource_id,226 self.resource_type)227class StackEvent:228 valid_states = ("CREATE_IN_PROGRESS", "CREATE_FAILED", "CREATE_COMPLETE",229 "DELETE_IN_PROGRESS", "DELETE_FAILED", "DELETE_COMPLETE")230 def __init__(self, connection=None):231 self.connection = connection232 self.event_id = None233 self.logical_resource_id = None234 self.physical_resource_id = None235 self.resource_properties = None236 self.resource_status = None237 self.resource_status_reason = None238 self.resource_type = None239 self.stack_id = None240 self.stack_name = None241 self.timestamp = None242 def startElement(self, name, attrs, connection):243 return None244 def endElement(self, name, value, connection):245 if name == "EventId":246 self.event_id = value247 elif name == "LogicalResourceId":248 self.logical_resource_id = value249 elif name == "PhysicalResourceId":250 self.physical_resource_id = value251 elif name == "ResourceProperties":252 self.resource_properties = value253 elif name == "ResourceStatus":254 self.resource_status = value255 elif name == "ResourceStatusReason":256 self.resource_status_reason = value257 elif name == "ResourceType":258 self.resource_type = value259 elif name == "StackId":260 self.stack_id = value261 elif name == "StackName":262 self.stack_name = value263 elif name == "Timestamp":264 self.timestamp = datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')265 else:266 setattr(self, name, value)267 def __repr__(self):268 return "StackEvent %s %s %s" % (self.resource_type,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!