diff --git a/app/models.py b/app/models.py index 4478aa16a31ba6dab6eb32c1aff8cb92b105af95..53e008fe4190c3bd827baa8f97c37d6b76355f07 100644 --- a/app/models.py +++ b/app/models.py @@ -402,6 +402,10 @@ class Network(CreatedMixin, db.Model): def network_ip(self): return ipaddress.ip_network(self.address) + @property + def netmask(self): + return self.network_ip.netmask + @property def first(self): return ipaddress.ip_address(self.first_ip) @@ -490,6 +494,7 @@ class Network(CreatedMixin, db.Model): 'vlan_name': self.vlan_name, 'vlan_id': self.vlan_id, 'address': self.address, + 'netmask': str(self.netmask), 'first_ip': self.first_ip, 'last_ip': self.last_ip, 'description': self.description, diff --git a/tests/functional/test_api.py b/tests/functional/test_api.py index e81cd86e7cd5d4200c0be6d3ab985294245d39a9..6954f28cec1f65b682bee7cc3802e2d6bd0be6d1 100644 --- a/tests/functional/test_api.py +++ b/tests/functional/test_api.py @@ -463,15 +463,16 @@ def test_create_network(client, admin_token, network_scope_factory): 'scope': scope.name} response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token) assert response.status_code == 201 - assert {'id', 'vlan_name', 'vlan_id', 'address', 'first_ip', - 'last_ip', 'description', 'admin_only', 'scope', - 'domain', 'interfaces', 'created_at', 'updated_at', - 'user'} == set(response.json.keys()) + assert {'id', 'vlan_name', 'vlan_id', 'address', 'netmask', + 'first_ip', 'last_ip', 'description', 'admin_only', + 'scope', 'domain', 'interfaces', 'created_at', + 'updated_at', 'user'} == set(response.json.keys()) assert response.json['vlan_name'] == 'network1' assert response.json['vlan_id'] == 1600 assert response.json['address'] == '172.16.1.0/24' assert response.json['first_ip'] == '172.16.1.10' assert response.json['last_ip'] == '172.16.1.250' + assert response.json['netmask'] == '255.255.255.0' # Check that address and name shall be unique response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token)