Skip to content
Snippets Groups Projects
Commit 23448e02 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Add netmask field in network json representation

parent 6bb8e3e7
No related branches found
No related tags found
No related merge requests found
...@@ -402,6 +402,10 @@ class Network(CreatedMixin, db.Model): ...@@ -402,6 +402,10 @@ class Network(CreatedMixin, db.Model):
def network_ip(self): def network_ip(self):
return ipaddress.ip_network(self.address) return ipaddress.ip_network(self.address)
@property
def netmask(self):
return self.network_ip.netmask
@property @property
def first(self): def first(self):
return ipaddress.ip_address(self.first_ip) return ipaddress.ip_address(self.first_ip)
...@@ -490,6 +494,7 @@ class Network(CreatedMixin, db.Model): ...@@ -490,6 +494,7 @@ class Network(CreatedMixin, db.Model):
'vlan_name': self.vlan_name, 'vlan_name': self.vlan_name,
'vlan_id': self.vlan_id, 'vlan_id': self.vlan_id,
'address': self.address, 'address': self.address,
'netmask': str(self.netmask),
'first_ip': self.first_ip, 'first_ip': self.first_ip,
'last_ip': self.last_ip, 'last_ip': self.last_ip,
'description': self.description, 'description': self.description,
......
...@@ -463,15 +463,16 @@ def test_create_network(client, admin_token, network_scope_factory): ...@@ -463,15 +463,16 @@ def test_create_network(client, admin_token, network_scope_factory):
'scope': scope.name} 'scope': scope.name}
response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token) response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token)
assert response.status_code == 201 assert response.status_code == 201
assert {'id', 'vlan_name', 'vlan_id', 'address', 'first_ip', assert {'id', 'vlan_name', 'vlan_id', 'address', 'netmask',
'last_ip', 'description', 'admin_only', 'scope', 'first_ip', 'last_ip', 'description', 'admin_only',
'domain', 'interfaces', 'created_at', 'updated_at', 'scope', 'domain', 'interfaces', 'created_at',
'user'} == set(response.json.keys()) 'updated_at', 'user'} == set(response.json.keys())
assert response.json['vlan_name'] == 'network1' assert response.json['vlan_name'] == 'network1'
assert response.json['vlan_id'] == 1600 assert response.json['vlan_id'] == 1600
assert response.json['address'] == '172.16.1.0/24' assert response.json['address'] == '172.16.1.0/24'
assert response.json['first_ip'] == '172.16.1.10' assert response.json['first_ip'] == '172.16.1.10'
assert response.json['last_ip'] == '172.16.1.250' 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 # Check that address and name shall be unique
response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token) response = post(client, f'{API_URL}/network/networks', data=data, token=admin_token)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment