Example #1
0
 def update(self, request, *args, **kwargs):
     instance = self.queryset.filter(id=kwargs['pk'])[0]
     old_name = instance.name
     new_name = request.data['name']
     if old_name != new_name:
         kwargs = instance.to_dict()
         kwargs['deploy_type'] = 'upstreams'
         kwargs['instance'] = instance.apigateway
         kwargs['category_id'] = instance.id
         ngx = Nginx(**kwargs)
         old_filename = '%s.conf' % old_name
         new_filename = '%s.conf' % new_name
         assert not ngx.build_file(filename=new_filename) == False, (
             'Upstream create %s file error' % new_name)
         assert not ngx.rename(old_filename, new_filename) == False, (
             'Upstream %s rename to %s file error' %
             (old_filename, new_filename))
         return super().update(request, *args, **kwargs)
     else:
         return super().update(request, *args, **kwargs)
Example #2
0
 def update(self, request, *args, **kwargs):
     instance = self.queryset.filter(id=kwargs['pk'])[0]
     old_name = re.split("[ |,]", instance.domain)[0]
     new_name = re.split("[ |,]", request.data['domain'])[0]
     if old_name != new_name:
         kwargs = instance.to_dict()
         kwargs['deploy_type'] = 'vhosts.d'
         kwargs['instance'] = instance.apigateway
         kwargs['category_id'] = instance.id
         ngx = Nginx(**kwargs)
         old_filename = '%s.conf' % old_name
         new_filename = '%s.conf' % new_name
         assert not ngx.build_file(filename=new_filename) == False, (
             'Vhost create %s file error' % new_name)
         if ngx.rename(old_filename, new_filename):
             return super().update(request, *args, **kwargs)
         else:
             assert not ngx.undo_rename(
                 old_filename,
                 new_filename) == False, ('Vhost rename undo error')
     else:
         return super().update(request, *args, **kwargs)