def do_create(self, arg): """Create an ACL rule (time enforcement is optional). """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: <source IP> <destination IP> " "<transport protocol> <source port> <destination " "port> <policy domain> <action> <start time as " "HH:MM (24 hour)> (optional) <duration (seconds)> (" "optional)") return if len(args) == 7: rule = self._rule_to_json(args) self._post_acl_rule(rule) elif len(args) == 9: try: datetime.strptime(args[7], "%H:%M") except ValueError: print("Start does not match accepted format: HH:MM " "(24 hour)") return try: i = int(args[8]) if not self._MIN_TIME <= i <= self._MAX_TIME: raise ValueError except ValueError: print("Enforcement duration should be a whole number " "greater than 0 and less than 65,536.") return rule = self._rule_to_json(args) self._post_acl_rule(rule) else: print("Incorrect number of arguments: {0} " "provided.".format(len(args))) return
def do_remove(self, arg): """Remove a policy domain. """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: <policy name>") return if len(args) != 1: print("Incorrect number of arguments: {0} " "provided.".format(len(arg))) return policy = self._policy_to_json(args) self._delete_policy(policy) return
def do_show(self, arg): """Fetch the ACL or time queue and display it to the user. """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: acl OR queue") return if "acl" in args[0]: acl = self._fetch_acl() if acl is None: return self._print_table_acls(acl) elif "queue" in args[0]: time_queue = self._fetch_time_queue() if time_queue is None: return self._print_table_time_queue(time_queue) else: print("Argument neither: acl NOR queue")
def do_show(self, arg): """Fetch the list of policies or switches and display it to the user. """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: policy OR switch") return if "policy" in args[0]: policies = self._fetch_policies() if policies is None: return self._print_table_policies(policies) elif "switch" in args[0]: switches = self._fetch_switches() if switches is None: return self._print_table_switches(switches) else: print("Argument neither: policy NOR switch")
def do_remove(self, arg): """Remove an ACL rule. """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: <rule ID>") return if len(args) != 1: print("Incorrect number of arguments: {0} " "provided.".format(len(arg))) return try: i = int(args[0]) if i < 0: raise ValueError except ValueError: print("Argument error: rule ID should be a whole number " "greater than -1.") return rule_id = self._rule_id_to_json(args) self._delete_acl_rule(rule_id)
def do_assign(self, arg): """Assign a policy domain to a switch. """ args = cli_util.parse(arg) if len(args) < 1: print("Argument expected: <policy name> <switch ID>") return if len(args) != 2: print("Incorrect number of arguments: {0} " "provided.".format(len(arg))) return try: i = int(args[1]) if i < 0: raise ValueError except ValueError: print("Argument error: switch ID should be a positive " "whole number.") return policy = self._policy_assign_to_json(args) self._put_policy_assign(policy) return