"Fossies" - the Fresh Open Source Software Archive

Member "horizon-16.0.0/openstack_dashboard/dashboards/project/networks/forms.py" (16 Oct 2019, 2980 Bytes) of package /linux/misc/openstack/horizon-16.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "forms.py": 15.1.0_vs_16.0.0.

    1 # Copyright 2012 United States Government as represented by the
    2 # Administrator of the National Aeronautics and Space Administration.
    3 # All Rights Reserved.
    4 #
    5 # Copyright 2012 NEC Corporation
    6 #
    7 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    8 #    not use this file except in compliance with the License. You may obtain
    9 #    a copy of the License at
   10 #
   11 #         http://www.apache.org/licenses/LICENSE-2.0
   12 #
   13 #    Unless required by applicable law or agreed to in writing, software
   14 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   15 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   16 #    License for the specific language governing permissions and limitations
   17 #    under the License.
   18 
   19 import logging
   20 
   21 from django.urls import reverse
   22 from django.utils.translation import ugettext_lazy as _
   23 
   24 from horizon import exceptions
   25 from horizon import forms
   26 from horizon import messages
   27 
   28 from openstack_dashboard import api
   29 from openstack_dashboard import policy
   30 
   31 
   32 LOG = logging.getLogger(__name__)
   33 
   34 
   35 class UpdateNetwork(forms.SelfHandlingForm):
   36     name = forms.CharField(label=_("Name"), required=False)
   37     admin_state = forms.BooleanField(
   38         label=_("Enable Admin State"),
   39         required=False,
   40         help_text=_("If checked, the network will be enabled."))
   41     shared = forms.BooleanField(label=_("Shared"), required=False)
   42     failure_url = 'horizon:project:networks:index'
   43 
   44     def __init__(self, request, *args, **kwargs):
   45         super(UpdateNetwork, self).__init__(request, *args, **kwargs)
   46 
   47         if not policy.check((("network", "update_network:shared"),), request):
   48             self.fields['shared'].widget = forms.HiddenInput()
   49 
   50     def handle(self, request, data):
   51         try:
   52             params = {'admin_state_up': data['admin_state'],
   53                       'name': data['name']}
   54             # Make sure we are not sending shared data when the user
   55             # doesn't have admin rights because even if the user doesn't
   56             # change it neutron sends back a 403 error
   57             if policy.check((("network", "update_network:shared"),), request):
   58                 params['shared'] = data['shared']
   59             network = api.neutron.network_update(request,
   60                                                  self.initial['network_id'],
   61                                                  **params)
   62             msg = (_('Network %s was successfully updated.') %
   63                    network.name_or_id)
   64             messages.success(request, msg)
   65             return network
   66         except Exception as e:
   67             LOG.info('Failed to update network %(id)s: %(exc)s',
   68                      {'id': self.initial['network_id'], 'exc': e})
   69             name_or_id = data['name'] or self.initial['network_id']
   70             msg = _('Failed to update network %s') % name_or_id
   71             redirect = reverse(self.failure_url)
   72             exceptions.handle(request, msg, redirect=redirect)