def undeploy_neighbor_v6(neighbor_id): neighbor = NeighborV6.objects.get(id=neighbor_id) if not neighbor.created: raise exceptions.NeighborV6IsUndeployed(neighbor) locks_list = lock_resources_used_by_neighbor_v6(neighbor) try: get_created_neighbors_v4_shares_same_eqpt_and_peer(neighbor) get_created_neighbors_v6_shares_same_eqpt_and_peer(neighbor) eqpt = get_v6_equipment(neighbor) plugin = PluginFactory.factory(eqpt) plugin.bgp().undeploy_neighbor(neighbor) neighbor.deploy() except Exception as e: raise api_rest_exceptions.NetworkAPIException(str(e)) finally: destroy_lock(locks_list)
def deploy_neighbor_v4(neighbor_id): neighbor = NeighborV4.objects.get(id=neighbor_id) if neighbor.created: raise NeighborV4IsDeployed(neighbor) locks_list = lock_resources_used_by_neighbor_v4(neighbor) try: depl_v4 = get_created_neighbors_v4_shares_same_eqpt_and_peer(neighbor) depl_v6 = get_created_neighbors_v6_shares_same_eqpt_and_peer(neighbor) eqpt = get_v4_equipment(neighbor) plugin = PluginFactory.factory(eqpt) plugin.bgp().deploy_neighbor(neighbor) neighbor.deploy() except Exception as e: raise NetworkAPIException(str(e)) finally: destroy_lock(locks_list)
def delete(self, request, *args, **kwargs): """Deletes list of interfaces.""" obj_ids = kwargs.get('obj_ids').split(';') locks_list = create_lock(obj_ids, LOCK_INTERFACE) for obj in obj_ids: try: facade.delete_interface(obj) finally: destroy_lock(locks_list) return Response({}, status=status.HTTP_200_OK)
def delete(self, request, *args, **kwargs): """Remove link between interfaces.""" interface_a = kwargs.get('interface_a') interface_b = kwargs.get('interface_b') locks_list = create_lock([interface_a], LOCK_INTERFACE) try: facade.remove_link([interface_a, interface_b]) finally: destroy_lock(locks_list) return Response({}, status=status.HTTP_200_OK)
def put(self, request, *args, **kwargs): """Updates list of interfaces.""" response = list() data = request.DATA json_validate(SPECS.get('interface_put')).validate(data) locks_list = create_lock(data['interfaces'], LOCK_INTERFACE) for interface in data['interfaces']: try: interface = facade.update_interface(interface) response.append({'id': interface.id}) finally: destroy_lock(locks_list) return Response(response, status=status.HTTP_200_OK)
def delete(self, request, *args, **kwargs): """ Remove the relationship between an interface and environments. :param kwargs: obj_ids :return: 200 OK """ obj_ids = kwargs.get('obj_ids').split(';') locks_list = create_lock(obj_ids, LOCK_INTERFACE) for obj in obj_ids: try: facade.delete_interface_environments(obj) finally: destroy_lock(locks_list) return Response({}, status=status.HTTP_200_OK)
data = request.DATA json_validate(SPECS.get('vlan_put')).validate(data) locks_list = create_lock(data['vlans'], LOCK_VLAN) response = list() try: for vlan in data['vlans']: vl = facade.update_vlan(vlan, request.user) response.append({'id': vl.id}) except Exception, exception: log.error(exception) raise api_exceptions.NetworkAPIException(exception) finally: destroy_lock(locks_list) return CustomResponse(response, status=status.HTTP_200_OK, request=request) @permission_classes_apiview((IsAuthenticated, Write)) @permission_obj_apiview([delete_obj_permission]) @commit_on_success def delete(self, request, *args, **kwargs): """ Deletes list of vlans """ obj_ids = kwargs['obj_ids'].split(';') locks_list = create_lock(obj_ids, LOCK_VLAN)
for equipment in equipments: equipment_obj = get_equipment_by_id(equipment.get('id')) equipment_obj.update_v4(equipment) response.append({'id': equipment_obj.id}) except ObjectDoesNotExistException, e: raise ObjectDoesNotExistException(e.detail) except EquipamentoError, e: raise ValidationAPIException(e.message) except EquipmentInvalidValueException, e: raise ValidationAPIException(str(e)) except ValidationAPIException, e: raise ValidationAPIException(str(e)) except Exception, e: raise NetworkAPIException(str(e)) finally: destroy_lock(locks_list) return response def create_equipment(equipments, user): """Create equipment""" response = list() try: for equipment in equipments: equipment_obj = Equipamento() equipment_obj.create_v4(equipment) response.append({'id': equipment_obj.id}) except EquipamentoError, e: