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.
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
}
}
}
}
19 changes: 19 additions & 0 deletions networkapi/api_vlan/views/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ def put(self, request, *args, **kwargs):

return Response(response, status=status.HTTP_202_ACCEPTED)

@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('')
@permission_classes_apiview((IsAuthenticated, permissions.Write))
Expand Down
4 changes: 4 additions & 0 deletions networkapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ def local_files(path):
PROJECT_ROOT_PATH,
'api_vlan/specs/vlan_post.json'
),
'vlan_patch': os.path.join(
PROJECT_ROOT_PATH,
'api_vlan/specs/vlan_patch.json'
),
'vlan_put': os.path.join(
PROJECT_ROOT_PATH,
'api_vlan/specs/vlan_put.json'
Expand Down
28 changes: 28 additions & 0 deletions networkapi/vlan/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,34 @@ def update_v3(self, vlan, user):

return self

def patch_v3(self, vlan, user):
"""Patch vlan."""

try:
self.ativada = vlan.get('active', self.ativada)

except Exception, e:
raise VlanErrorV3(e)

else:
# Prepare locks for vlan
locks_name = [LOCK_VLAN % self.id]
locks_list = create_lock_with_blocking(locks_name)

try:
# validate name and number
#self.validate_v3()
self.save()

except Exception, e:
raise VlanErrorV3(e)

finally:
# Destroy locks
destroy_lock(locks_list)

return self

def delete_v3(self):
ogp_models = get_app('api_ogp', 'models')
ipcantberemovedfromvip = get_model('ip', 'IpCantBeRemovedFromVip')
Expand Down
Loading