def rules(self):
        list_of_rules = []
        for main_row in self.dict_rules:
            if 'rules' in main_row:
                for rule_row in main_row['rules']:
                    if 'grants' in rule_row:
                        for grant_row in rule_row['grants']:
                            if 'group_id' in grant_row:
                                group_id = grant_row['group_id']
                                if 'name' in grant_row:
                                    row_name = grant_row['name']
                                else:
                                    row_name = None
                                fr = FirewallRule(
                                    main_row['id'],
                                    main_row['name'],
                                    main_row['description'],
                                    rules_direction=rule_row['direction'],
                                    rules_ip_protocol=rule_row['ip_protocol'],
                                    rules_from_port=rule_row['from_port'],
                                    rules_to_port=rule_row['to_port'],
                                    rules_grants_group_id=group_id,
                                    rules_grants_name=row_name,
                                    rules_description=grant_row['description'])
                                list_of_rules.append(fr)
                            elif 'cidr_ip' in grant_row:
                                fr = FirewallRule(
                                    main_row['id'],
                                    main_row['name'],
                                    main_row['description'],
                                    rules_direction=rule_row['direction'],
                                    rules_ip_protocol=rule_row['ip_protocol'],
                                    rules_from_port=rule_row['from_port'],
                                    rules_to_port=rule_row['to_port'],
                                    rules_grants_cidr_ip=grant_row['cidr_ip'],
                                    rules_description=grant_row['description'])
                                list_of_rules.append(fr)
                            else:
                                raise ValueError("Unsupported grant:",
                                                 grant_row)
                    else:
                        fr = FirewallRule(
                            main_row['id'],
                            main_row['name'],
                            main_row['description'],
                            rules_direction=rule_row['direction'],
                            rules_ip_protocol=rule_row['ip_protocol'],
                            rules_from_port=rule_row['from_port'],
                            rules_to_port=rule_row['to_port'])
                        list_of_rules.append(fr)
            else:
                fr = FirewallRule(main_row['id'],
                                  main_row['name'],
                                  main_row['description'])
                list_of_rules.append(fr)
        sorted_list = sorted(list_of_rules,
                             key=lambda fr: (str(fr.id),
                                             str(fr.name),
                                             str(fr.description),
                                             str(fr.rules_direction),
                                             str(fr.rules_ip_protocol),
                                             str(fr.rules_from_port),
                                             str(fr.rules_to_port),
                                             str(fr.rules_grants_group_id),
                                             str(fr.rules_grants_name),
                                             str(fr.rules_grants_cidr_ip)))
        return sorted_list