How to use _delete_rule method in localstack

Best Python code snippet using localstack_python

zstack_test_security_group.py

Source:zstack_test_security_group.py Github

copy

Full Screen

...123 for rule_uuid in target_rule_uuids:124 rule = test_lib.lib_get_sg_rule_by_uuid(rule_uuid)125 if rule.protocol == inventory.TCP:126 if rule.type == inventory.INGRESS:127 self._delete_rule(rule, self.tcp_ingress_rule)128 else:129 self._delete_rule(rule, self.tcp_egress_rule)130 elif rule.protocol == inventory.UDP:131 if rule.type == inventory.INGRESS:132 self._delete_rule(rule, self.udp_ingress_rule)133 else:134 self._delete_rule(rule, self.udp_egress_rule)135 elif rule.protocol == inventory.ICMP:136 if rule.type == inventory.INGRESS:137 self._delete_rule(rule, self.icmp_ingress_rule)138 else:139 self._delete_rule(rule, self.icmp_egress_rule)140 net_ops.remove_rules_from_security_group(target_rule_uuids)141 def delete_rule(self, target_rule_objs):142 target_rule_uuids = test_lib.lib_get_sg_rule_uuid_by_rule_obj(self.security_group.uuid, target_rule_objs)143 self.delete_rule_by_uuids(target_rule_uuids)144 def _delete_rule(self, target_rule, rule_dict):145 if not rule_dict.has_key(target_rule.allowedCidr):146 return147 for rule in rule_dict[target_rule.allowedCidr]:148 if rule.uuid == target_rule.uuid:149 rule_dict[target_rule.allowedCidr].remove(rule)150 break151 if not rule_dict[target_rule.allowedCidr]:152 rule_dict.pop(target_rule.allowedCidr)153 def _add_nic(self, l3_uuid, nic_uuid):154 if self.nic_dict.has_key(l3_uuid):155 if not nic_uuid in self.nic_dict[l3_uuid]:156 self.nic_dict[l3_uuid].append(nic_uuid)157 else:158 self.nic_dict[l3_uuid] = [nic_uuid]...

Full Screen

Full Screen

linux_firewall.py

Source:linux_firewall.py Github

copy

Full Screen

...42 L.debug("Creating iptables rule {}".format(rule_args))43 if self._rule_exists(rule_args):44 L.debug("iptables rule {} already exists".format(rule_args))45 self._connector_helper.check_command(["iptables", "-w", "-A"] + rule_args, root=True)46 def _delete_rule(self, rule_args):47 L.debug("Deleting iptables rule {}".format(rule_args))48 if not self._rule_exists(rule_args):49 L.debug("iptables rule {} doesn't exist".format(rule_args))50 return51 self._connector_helper.check_command(["iptables", "-w", "-D"] + rule_args, root=True)52 def _jump_rule_args(self, chain):53 return [chain, "-j", self._testing_chain_name]54 def _delete_testing_chain(self):55 # Flush all rules in our chain56 self._connector_helper.check_command(57 ["iptables", "-w", "-F", self._testing_chain_name], root=True)58 # Remove all references (jumps) to our chain59 L.debug("Cleaning up iptables testing chain")60 for source_chain in ["INPUT", "OUTPUT"]:61 self._delete_rule(self._jump_rule_args(source_chain))62 self._delete_chain(self._testing_chain_name)63 def _create_testing_chain(self):64 self._create_chain(self._testing_chain_name)65 for source_chain in ["INPUT", "OUTPUT"]:66 self._create_rule(self._jump_rule_args(source_chain))67 def block_ip(self, ip):68 rules = self._block_ip_args_rules(ip)69 for rule in rules:70 self._create_rule(rule)71 def unblock_ip(self, ip):72 rules = self._block_ip_args_rules(ip)73 for rule in rules:74 self._delete_rule(rule)75# I wanted to use iptc (https://github.com/ldx/python-iptables) but it was buggy so gave up.76 # def _delete_testing_chain(self):77 # for source_chain in ["INPUT", "OUTPUT"]:78 # jump_rule = iptc.Rule()79 # jump_rule.create_target(self._testing_chain_name)80 # chain = iptc.Chain(iptc.Table(iptc.Table.FILTER), source_chain)81 # chain.delete_rule(jump_rule)82 # chain = iptc.Chain(iptc.Table(iptc.Table.FILTER), self._testing_chain_name)83 # chain.flush()84 # chain.delete()85 # def _create_testing_chain(self):86 # try:87 # iptc.Table(iptc.Table.FILTER).create_chain(self._testing_chain_name)88 # except iptc.ip4tc.IPTCError as ex:...

Full Screen

Full Screen

firewall_rule_delete.py

Source:firewall_rule_delete.py Github

copy

Full Screen

...15 def run(self):16 LOG.debug('Firewall Delete Rule running')17 if not self.status:18 # set rule19 return self._delete_rule()20 def _delete_rule(self):21 address = '%s:%s' % (self.host, self.port)22 res = {'host': self.host,23 'port': self.port,24 'status': None}25 rule_no = {}26 rule_no['rule_id'] = self.rule_id27 status = fw_proxy.delete_firewall_rule(address, rule_no, self.dpid)28 res['status'] = status...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful