Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/vlan/url-api-v3-vlan.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
url-api-v3-vlan/post
url-api-v3-vlan/put
url-api-v3-vlan/delete
url-api-v3-vlan/patch
37 changes: 37 additions & 0 deletions docs/vlan/url-api-v3-vlan/patch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PATCH
#####

.. _url-api-v3-vlan-patch-partially-update-list-vlans:

Partially updating list of Vlans in database
********************************************

URL::

/api/v3/vlan/

Request body:

.. code-block:: json

{
"vlans": [{
"id": [integer],
"active": [boolean]
},..]
}

Request Example:

.. code-block:: json

{
"vlans": [{
"id": 1,
"active": false
}]
}

In Vlan PATCH request, you only need to specify the fields you want to change. For now, only **active** field can be changed.

* **active** - If not specified, Vlan will be the same as before. If specified, it will be updated with the new value.
3 changes: 3 additions & 0 deletions networkapi/ambiente/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,9 @@ def get(self, cidr_id=None, env_id=None):
objects = EnvCIDR.objects.filter(id_env=env_id)
if not objects:
log.debug('There is no CIDR linked with the environment id=%s.' % env_id)
raise ObjectDoesNotExist
except ObjectDoesNotExist:
raise CIDRErrorV3('There is no CIDR linked with the environment id=%s.' % env_id)
except OperationalError as e:
self.log.error('Lock wait timeout exceeded.')
raise OperationalError(e, 'Lock wait timeout exceeded; try restarting transaction')
Expand Down
7 changes: 6 additions & 1 deletion networkapi/api_interface/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ def get_serializers(self):
'equipment__basic': {
'serializer': equipment_serializers.EquipmentV3Serializer,
'kwargs': {
'kind': 'basic'
'kind': 'details',
'fields': (
'id',
'name',
'model__details__brand',
)
},
'obj': 'equipamento',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,28 @@ def test_get_interface_by_search(self):

self.compare_status(200, response.status_code)
self.compare_json(expected_data, response.data["interfaces"])

def test_get_interface_list_with_equipment_model_brand(self):
"""Test list interfaces returning equipment model brand."""

search = urllib.urlencode({'extends_search': [],
'start_record': 0,
'custom_search': '',
'end_record': 10000,
'asorting_cols': ['id'],
'searchable_columns': ['id']})

url = '/api/v3/interface/?search=%s&include=equipment__basic' % search

response = self.client.get(url,
content_type='application/json',
HTTP_AUTHORIZATION=self.get_http_authorization('test'))

self.compare_status(200, response.status_code)

interface = response.data['interfaces'][0]
equipment = interface['equipment']

self.assertEqual(['id', 'model', 'name'], sorted(equipment.keys()))
self.assertEqual(['brand', 'id', 'name'], sorted(equipment['model'].keys()))
self.assertEqual(['id', 'name'], sorted(equipment['model']['brand'].keys()))
6 changes: 4 additions & 2 deletions networkapi/api_network/facade/v3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .networkv4 import get_networkipv4_by_search
from .networkv4 import undeploy_networkipv4
from .networkv4 import update_networkipv4
from .networkv4 import patch_networkipv4
from .networkv6 import create_networkipv6
from .networkv6 import delete_networkipv6
from .networkv6 import deploy_networkipv6
Expand All @@ -29,11 +30,12 @@
from .networkv6 import get_networkipv6_by_search
from .networkv6 import undeploy_networkipv6
from .networkv6 import update_networkipv6
from .networkv6 import patch_networkipv6

__all__ = (
'get_networkipv4_by_id', 'get_networkipv4_by_ids',
'get_networkipv4_by_search', 'create_networkipv4',
'update_networkipv4', 'delete_networkipv4', 'undeploy_networkipv4',
'update_networkipv4', 'patch_networkipv4', 'delete_networkipv4', 'undeploy_networkipv4',
'deploy_networkipv4', 'get_networkipv6_by_id', 'get_networkipv6_by_ids',
'get_networkipv6_by_search', 'create_networkipv6', 'update_networkipv6',
'get_networkipv6_by_search', 'create_networkipv6', 'update_networkipv6', 'patch_networkipv6',
'delete_networkipv6', 'undeploy_networkipv6', 'deploy_networkipv6')
26 changes: 26 additions & 0 deletions networkapi/api_network/facade/v3/networkv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ def update_networkipv4(networkv4, user, force=False):
return netv4_obj


def patch_networkipv4(networkv4, user, force=False):
"""Patches a NetworkIPv4."""

try:
netv4_obj = get_networkipv4_by_id(networkv4.get('id'))
netv4_obj.patch_v3(networkv4, force=force)

except ObjectDoesNotExistException, e:
raise ObjectDoesNotExistException(e.detail)

except ip_models.NetworkIPv4ErrorV3, e:
raise ValidationAPIException('NetworkIPv4 id=%s - %s' % (netv4_obj.id, str(e)))

except exceptions.InvalidInputException, e:
raise ValidationAPIException(e.detail)

except ValidationAPIException, e:
raise ValidationAPIException(e.detail)

except Exception, e:
raise NetworkAPIException(str(e))

else:
return netv4_obj


def delete_networkipv4(network_ids, user, force=False):
"""Deletes a list of NetworkIPv4."""

Expand Down
26 changes: 26 additions & 0 deletions networkapi/api_network/facade/v3/networkv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ def update_networkipv6(networkv6, user, force=False):
return netv6_obj


def patch_networkipv6(networkv6, user, force=False):
"""Patches a NetworkIPv6."""

try:
netv6_obj = get_networkipv6_by_id(networkv6.get('id'))
netv6_obj.patch_v3(networkv6, force=force)

except ObjectDoesNotExistException, e:
raise ObjectDoesNotExistException(e.detail)

except ip_models.NetworkIPv6ErrorV3, e:
raise ValidationAPIException('NetworkIPv6 id=%s - %s' % (netv6_obj.id, str(e)))

except exceptions.InvalidInputException, e:
raise ValidationAPIException(e.detail)

except ValidationAPIException, e:
raise ValidationAPIException(e.detail)

except Exception, e:
raise NetworkAPIException(str(e))

else:
return netv6_obj


def delete_networkipv6(network_ids, user, force=False):
"""Deletes a list of NetworkIPv6."""

Expand Down
28 changes: 28 additions & 0 deletions networkapi/api_network/specs/netv4_patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"title": "NetworkIPv4 Patch",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"networks"
],
"properties": {
"networks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"active": {
"type": "boolean"
}
},
"required": [
"id"
],
"additionalProperties": false
}
}
}
}
28 changes: 28 additions & 0 deletions networkapi/api_network/specs/netv6_patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"title": "NetworkIPv6 Patch",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"networks"
],
"properties": {
"networks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"active": {
"type": "boolean"
}
},
"required": [
"id"
],
"additionalProperties": false
}
}
}
}
18 changes: 18 additions & 0 deletions networkapi/api_network/views/v3/networkv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ def put(self, request, *args, **kwargs):

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('networkv4_patch')
@permission_classes_apiview((IsAuthenticated, permissions.WriteForce))
@commit_on_success
def patch(self, request, *args, **kwargs):
"""Patches list of networkv4."""

data = request.DATA

json_validate(SPECS.get('networkv4_patch')).validate(data)

response = list()
for networkv4 in data['networks']:
vl = facade.patch_networkipv4(networkv4, request.user, force=True)
response.append({'id': vl.id, 'active': vl.active})

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('')
@permission_classes_apiview((IsAuthenticated, permissions.WriteForce))
Expand Down
18 changes: 18 additions & 0 deletions networkapi/api_network/views/v3/networkv6.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ def put(self, request, *args, **kwargs):

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('networkv6_patch')
@permission_classes_apiview((IsAuthenticated, permissions.WriteForce))
@commit_on_success
def patch(self, request, *args, **kwargs):
"""Patches list of networkv6."""

data = request.DATA

json_validate(SPECS.get('networkv6_patch')).validate(data)

response = list()
for networkv6 in data['networks']:
vl = facade.patch_networkipv6(networkv6, request.user, force=True)
response.append({'id': vl.id, 'active': vl.active})

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('')
@permission_classes_apiview((IsAuthenticated, permissions.WriteForce))
Expand Down
16 changes: 16 additions & 0 deletions networkapi/api_vlan/facade/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def update_vlan(vlan, user):
return vlan_obj


def patch_vlan(vlan, user):
"""Patch vlan."""

try:
vlan_obj = get_vlan_by_id(vlan.get('id'))
vlan_obj.patch_v3(vlan, user)
except ObjectDoesNotExistException, e:
raise ObjectDoesNotExistException(str(e))
except (VlanError, VlanErrorV3, ValidationAPIException), e:
raise ValidationAPIException(str(e))
except (Exception, NetworkAPIException), e:
raise NetworkAPIException(str(e))
else:
return vlan_obj


def create_vlan(vlan, user):
"""Create vlan."""

Expand Down
28 changes: 28 additions & 0 deletions networkapi/api_vlan/specs/vlan_patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"title": "Vlan Patch",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"vlans"
],
"properties": {
"vlans": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"active": {
"type": "boolean"
}
},
"required": [
"id"
],
"additionalProperties": false
}
}
}
}
4 changes: 2 additions & 2 deletions networkapi/api_vlan/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
########################
# Vlan V3
########################
url(r'^v3/vlan/async/((?P<obj_ids>[;\w]+)/)?$',
url(r'^v3/vlan/async(?:/(?P<obj_ids>[;\w]+))?/?$',
views.VlanAsyncView.as_view()),
url(r'^v3/vlan/((?P<obj_ids>[;\w]+)/)?$', views.VlanDBView.as_view()),
url(r'^v3/vlan(?:/(?P<obj_ids>[;\w]+))?/?$', views.VlanDBView.as_view()),
)
21 changes: 20 additions & 1 deletion networkapi/api_vlan/views/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ def put(self, request, *args, **kwargs):
response.append({'id': vl.id})

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('vlan_patch')
@permission_classes_apiview((IsAuthenticated, permissions.Write))
@permission_obj_apiview([permissions.write_obj_permission])
@commit_on_success
def patch(self, request, *args, **kwargs):
"""Patches list of vlans."""

data = request.DATA

json_validate(SPECS.get('vlan_patch')).validate(data)

response = list()
for vlan in data['vlans']:
vl = facade.patch_vlan(vlan, request.user)
response.append({'id': vl.id, 'active': vl.ativada})

return Response(response, status=status.HTTP_200_OK)

@logs_method_apiview
@raise_json_validate('')
Expand Down Expand Up @@ -171,7 +190,7 @@ def put(self, request, *args, **kwargs):
response.append(task)

return Response(response, status=status.HTTP_202_ACCEPTED)

@logs_method_apiview
@raise_json_validate('')
@permission_classes_apiview((IsAuthenticated, permissions.Write))
Expand Down
Loading
Loading