Example #1
0
    def delete(self, request, obj_id):
        try:
            cache = CacheRule.objects.get(pk=obj_id)
            domain = Domain.objects.get(pk=cache.domain_id)
            domain_manager = middware.DomainManage()
            ret = domain_manager.find(domain.domain_id)
            domain_class = ret.getDomain()
            cacheBehaviors = domain_class.cacheBehaviors
            if cacheBehaviors is not None:
                for i in cacheBehaviors:
                    if cache.pathPattern == i.pathPattern:
                        cacheBehaviors.remove(i)
            domain_class = middware.domainApi.Domain(
                domainId=domain.domain_id, cacheBehaviors=cacheBehaviors)
            domain_manager.modify(domain_class)
            cache.delete()

        except Exception:
            obj = self.table.get_object_by_id(obj_id)
            name = self.table.get_object_display(obj)
            msg = _('Unable to delete domain %s') % name
            LOG.info(msg)
            messages.error(request, msg)
            exceptions.handle(request, msg)
            redirect = reverse(self.redirect_url)
            raise exceptions.Http302(redirect, message=msg)
Example #2
0
 def delete(self, request, obj_id):
     try:
         access = AccessControl.objects.get(pk=obj_id)
         domain = Domain.objects.get(pk=access.domain_id)
         domain_manager = middware.DomainManage()
         ret = domain_manager.find(domain.domain_id)
         domain_class = ret.getDomain()
         visitControlRules = domain_class.visitControlRules
         if visitControlRules is not None:
             for i in domain_class.visitControlRules:
                 if access.pathPattern == i.pathPattern:
                     visitControlRules.remove(i)
         domain_class = middware.domainApi.Domain(
             domainId=domain.domain_id,
             visitControlRules=domain_class.visitControlRules)
         domain_manager.modify(domain_class)
         access.delete()
     except Exception:
         obj = self.table.get_object_by_id(obj_id)
         name = self.table.get_object_display(obj)
         msg = _('Unable to delete domain %s') % name
         LOG.info(msg)
         messages.error(request, msg)
         exceptions.handle(request, msg)
         redirect = reverse(self.redirect_url)
         raise exceptions.Http302(redirect, message=msg)
 def handle(self, request, data):
     datasource_name = data['name']
     datasource_description = data.get('description')
     datasource_driver = data.pop('driver')
     config = {
         'username': data['username'],
         'password': data['password'],
         'tenant_name': data['tenant_name'],
         'auth_url': data['auth_url'],
         'poll_time': data['poll_time']
     }
     try:
         params = {
             'name': datasource_name,
             'driver': datasource_driver,
             'description': datasource_description,
             'config': config
         }
         datasource = congress.create_datasource(request, params)
         msg = _('Created Data Source "%s"') % datasource_name
         LOG.info(msg)
         messages.success(request, msg)
     except Exception as e:
         msg_args = {'datasource_name': datasource_name, 'error': str(e)}
         msg = _('Failed to create data source "%(datasource_name)s": '
                 '%(error)s') % msg_args
         LOG.error(msg)
         messages.error(self.request, msg)
         redirect = reverse(self.failure_url)
         raise exceptions.Http302(redirect)
     return datasource
Example #4
0
 def handle(self, request, data):
     redirect = reverse_lazy('horizon:project:instances:index')
     fip_id = data['fip']
     fips = [fip for fip in self.fips if fip.id == fip_id]
     if not fips:
         messages.error(request,
                        _("The specified floating IP no longer exists."))
         raise exceptions.Http302(redirect)
     fip = fips[0]
     try:
         if data['is_release']:
             api.neutron.tenant_floating_ip_release(request, fip_id)
             messages.success(
                 request,
                 _("Successfully disassociated and released "
                   "floating IP %s") % fip.ip)
         else:
             api.neutron.floating_ip_disassociate(request, fip_id)
             messages.success(
                 request,
                 _("Successfully disassociated floating IP %s") % fip.ip)
     except Exception:
         exceptions.handle(request,
                           _('Unable to disassociate floating IP %s') %
                           fip.ip,
                           redirect=redirect)
     return True
Example #5
0
    def delete(self, request, obj_id):
        try:
            # 执行删除前状态检查,当状态为"unverified"或"failed"时直接删除数据库记录
            # 否则更新状态为"deleted",保证数据统计时有记录,然后调用网宿api,删除加速记录
            domain = Domain.objects.get(pk=obj_id)
            cdn = middware.DomainManage()
            if domain.status == "unverified" or domain.status == "failed" or domain.status == "addfailed" \
                    or domain.status == 'verified':
                domain.delete()
            elif domain.status == 'inProgress':
                msg = _("%s status is %s, can not do this action") % (
                    domain.domain_name, _(domain.status))
                messages.warning(request, msg)
            else:
                domain.status = 'deleted'
                domain.deleted_at = datetime.now()
                domain.save()
                cdn.delete(domainId=domain.domain_id)

        except Exception:
            name = self.table.get_object_display(obj_id)
            msg = _('Unable to delete domain %s') % name
            LOG.info(msg)
            messages.error(request, msg)
            exceptions.handle(request, msg)
            redirect = reverse(self.redirect_url)
            raise exceptions.Http302(redirect, message=msg)
 def handle(self, request, data):
     policy_name = data['name']
     policy_description = data.get('description')
     policy_kind = data.pop('kind')
     LOG.info('User %s creating policy "%s" of type %s in tenant %s',
              request.user.username, policy_name, policy_kind,
              request.user.tenant_name)
     try:
         params = {
             'name': policy_name,
             'description': policy_description,
             'kind': policy_kind,
         }
         policy = congress.policy_create(request, params)
         msg = _('Created policy "%s"') % policy_name
         LOG.info(msg)
         messages.success(request, msg)
     except Exception as e:
         msg_args = {'policy_name': policy_name, 'error': str(e)}
         msg = _('Failed to create policy "%(policy_name)s": '
                 '%(error)s') % msg_args
         LOG.error(msg)
         messages.error(self.request, msg)
         redirect = reverse(self.failure_url)
         raise exceptions.Http302(redirect)
     return policy
Example #7
0
 def delete(self, request, obj_id):
     try:
         # detach all interfaces before attempting to delete the router
         search_opts = {
             'device_owner': 'network:router_interface',
             'device_id': obj_id
         }
         ports = api.neutron.port_list(request, **search_opts)
         for port in ports:
             api.neutron.router_remove_interface(request,
                                                 obj_id,
                                                 port_id=port.id)
         api.neutron.router_delete(request, obj_id)
     except q_ext.NeutronClientException as e:
         msg = _('Unable to delete router "%s"') % e
         LOG.info(msg)
         messages.error(request, msg)
         redirect = reverse(self.redirect_url)
         raise exceptions.Http302(redirect, message=msg)
     except Exception:
         obj = self.table.get_object_by_id(obj_id)
         name = self.table.get_object_display(obj)
         msg = _('Unable to delete router "%s"') % name
         LOG.info(msg)
         exceptions.handle(request, msg)
Example #8
0
 def get_data(self):
     try:
         instance_id = self.kwargs['instance_id']
         instance = api.nova.server_get(self.request, instance_id)
         instance.volumes = api.nova.instance_volumes_list(
             self.request, instance_id)
         # Sort by device name
         instance.volumes.sort(key=lambda vol: vol.device)
         instance.full_flavor = api.nova.flavor_get(self.request,
                                                    instance.flavor["id"])
         instance.security_groups = api.network.server_security_groups(
             self.request, instance_id)
     except Exception:
         redirect = reverse(self.redirect_url)
         exceptions.handle(self.request,
                           _('Unable to retrieve details for '
                             'instance "%s".') % instance_id,
                           redirect=redirect)
         # Not all exception types handled above will result in a redirect.
         # Need to raise here just in case.
         raise exceptions.Http302(redirect)
     try:
         api.network.servers_update_addresses(self.request, [instance])
     except Exception:
         exceptions.handle(
             self.request,
             _('Unable to retrieve IP addresses from Neutron for instance '
               '"%s".') % instance_id,
             ignore=True)
     return instance
Example #9
0
    def get_data(self):
        instance_id = self.kwargs['instance_id']

        try:
            instance = api.nova.server_get(self.request, instance_id)
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'instance "%s".') % instance_id,
                              redirect=redirect)
            # Not all exception types handled above will result in a redirect.
            # Need to raise here just in case.
            raise exceptions.Http302(redirect)

        choices = project_tables.STATUS_DISPLAY_CHOICES
        instance.status_label = (filters.get_display_label(
            choices, instance.status))

        futurist_utils.call_functions_parallel(
            (self._get_volumes, [instance]),
            (self._get_flavor, [instance]),
            (self._get_security_groups, [instance]),
            (self._update_addresses, [instance]),
        )

        return instance
Example #10
0
 def delete(self, request, obj_id):
     try:
         # detach all interfaces before attempting to delete the router
         search_opts = {'device_owner': 'network:router_interface',
                        'device_id': obj_id}
         ports = api.neutron.port_list(request, **search_opts)
         for port in ports:
             api.neutron.router_remove_interface(request, obj_id,
                                                 port_id=port.id)
         api.neutron.router_delete(request, obj_id)
     except q_ext.NeutronClientException as e:
         # TODO(amotoki): Revisit why Http302 needs to be raised.
         # We have this pattern ONLY HERE.
         # Can't we merge two except clauses?
         LOG.info('Unable to delete router %(id)s: %(exc)s',
                  {'id': obj_id, 'exc': e})
         obj = self.table.get_object_by_id(obj_id)
         name = self.table.get_object_display(obj)
         msg = _('Unable to delete router "%s"') % name
         messages.error(request, msg)
         redirect = reverse(self.redirect_url)
         raise exceptions.Http302(redirect, message=msg)
     except Exception as e:
         LOG.info('Unable to delete router %(id)s: %(exc)s',
                  {'id': obj_id, 'exc': e})
         obj = self.table.get_object_by_id(obj_id)
         name = self.table.get_object_display(obj)
         msg = _('Unable to delete router "%s"') % name
         exceptions.handle(request, msg)
Example #11
0
    def get_data(self):
        instance_id = self.kwargs['instance_id']

        try:
            instance = api.nova.server_get(self.request, instance_id)
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'instance "%s".') % instance_id,
                              redirect=redirect)
            # Not all exception types handled above will result in a redirect.
            # Need to raise here just in case.
            raise exceptions.Http302(redirect)

        status_label = [
            label for (value, label) in project_tables.STATUS_DISPLAY_CHOICES
            if value.lower() == (instance.status or '').lower()
        ]
        if status_label:
            instance.status_label = status_label[0]
        else:
            instance.status_label = instance.status

        try:
            instance.volumes = api.nova.instance_volumes_list(
                self.request, instance_id)
            # Sort by device name
            instance.volumes.sort(key=lambda vol: vol.device)
        except Exception:
            msg = _('Unable to retrieve volume list for instance '
                    '"%s".') % instance_id
            exceptions.handle(self.request, msg, ignore=True)

        try:
            instance.full_flavor = api.nova.flavor_get(self.request,
                                                       instance.flavor["id"])
        except Exception:
            msg = _('Unable to retrieve flavor information for instance '
                    '"%s".') % instance_id,
            exceptions.handle(self.request, msg, ignore=True)

        try:
            instance.security_groups = api.network.server_security_groups(
                self.request, instance_id)
        except Exception:
            msg = _('Unable to retrieve security groups for instance '
                    '"%s".') % instance_id
            exceptions.handle(self.request, msg, ignore=True)

        try:
            api.network.servers_update_addresses(self.request, [instance])
        except Exception:
            exceptions.handle(
                self.request,
                _('Unable to retrieve IP addresses from Neutron for instance '
                  '"%s".') % instance_id,
                ignore=True)

        return instance
    def handle(self, request, data):
        rule_name = data['rule_name']
        comment = data['comment']
        rule = data['rule']
        policy_name = data['policy_name']
        try:
            params = {
                'name': rule_name,
                'comment': comment,
                'rule': rule,
            }

            rule = congress.policy_rule_create(request,
                                               policy_name,
                                               body=params)
            msg = _("Rule created with id %s") % rule['id']
            LOG.info(msg)
            messages.success(request, msg)
            return rule
        except Exception as e:
            msg = _('Error creating rule : %s') % str(e)
            LOG.error(msg)
            messages.error(self.request, msg)
            redirect = reverse(self.failure_url, args=(policy_name, ))
            raise exceptions.Http302(redirect)
Example #13
0
    def get_object_by_id(self, lookup):
        """
        Returns the data object from the table's dataset which matches
        the ``lookup`` parameter specified. An error will be raised if
        the match is not a single data object.

        We will convert the object id and ``lookup`` to unicode before
        comparison.

        Uses :meth:`~horizon.tables.DataTable.get_object_id` internally.
        """
        if not isinstance(lookup, unicode):
            lookup = unicode(str(lookup), 'utf-8')
        matches = []
        for datum in self.data:
            obj_id = self.get_object_id(datum)
            if not isinstance(obj_id, unicode):
                obj_id = unicode(str(obj_id), 'utf-8')
            if obj_id == lookup:
                matches.append(datum)
        if len(matches) > 1:
            raise ValueError(
                "Multiple matches were returned for that id: %s." % matches)
        if not matches:
            raise exceptions.Http302(
                self.get_absolute_url(),
                _('No match returned for the id "%s".') % lookup)
        return matches[0]
Example #14
0
    def handle(self, request, data):
        index = "horizon:project:containers:index"
        orig_container = data['orig_container_name']
        orig_object = data['orig_object_name']
        new_container = data['new_container_name']
        new_object = data['new_object_name']
        path = data['path']
        if path and not path.endswith("/"):
            path = path + "/"
        new_path = "%s%s" % (path, new_object)

        # Now copy the object itself.
        try:
            api.swift.swift_copy_object(request, orig_container, orig_object,
                                        new_container, new_path)
            dest = "%s/%s" % (new_container, path)
            vals = {
                "dest": dest.rstrip("/"),
                "orig": orig_object.split("/")[-1],
                "new": new_object
            }
            messages.success(
                request,
                _('Copied "%(orig)s" to "%(dest)s" as "%(new)s".') % vals)
            return True
        except exceptions.HorizonException as exc:
            messages.error(request, exc)
            raise exceptions.Http302(
                reverse(index, args=[wrap_delimiter(orig_container)]))
        except Exception:
            redirect = reverse(index, args=[wrap_delimiter(orig_container)])
            exceptions.handle(request,
                              _("Unable to copy object."),
                              redirect=redirect)
Example #15
0
    def get_data(self):
        instance_id = self.kwargs['instance_id']

        try:
            instance = api.nova.server_get(self.request, instance_id)
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'instance "%s".') % instance_id,
                              redirect=redirect)
            # Not all exception types handled above will result in a redirect.
            # Need to raise here just in case.
            raise exceptions.Http302(redirect)

        choices = project_tables.STATUS_DISPLAY_CHOICES
        instance.status_label = (
            filters.get_display_label(choices, instance.status))

        try:
            instance.volumes = api.nova.instance_volumes_list(self.request,
                                                              instance_id)
            # Sort by device name
            instance.volumes.sort(key=lambda vol: vol.device)
        except Exception:
            msg = _('Unable to retrieve volume list for instance '
                    '"%(name)s" (%(id)s).') % {'name': instance.name,
                                               'id': instance_id}
            exceptions.handle(self.request, msg, ignore=True)

        try:
            instance.full_flavor = api.nova.flavor_get(
                self.request, instance.flavor["id"])
        except Exception:
            msg = _('Unable to retrieve flavor information for instance '
                    '"%(name)s" (%(id)s).') % {'name': instance.name,
                                               'id': instance_id}
            exceptions.handle(self.request, msg, ignore=True)

        try:
            instance.security_groups = api.network.server_security_groups(
                self.request, instance_id)
        except Exception:
            msg = _('Unable to retrieve security groups for instance '
                    '"%(name)s" (%(id)s).') % {'name': instance.name,
                                               'id': instance_id}
            exceptions.handle(self.request, msg, ignore=True)

        try:
            api.network.servers_update_addresses(self.request, [instance])
        except Exception:
            msg = _('Unable to retrieve IP addresses from Neutron for '
                    'instance "%(name)s" (%(id)s).') % {'name': instance.name,
                                                        'id': instance_id}
            exceptions.handle(self.request, msg, ignore=True)

        return instance
Example #16
0
    def get_context_data(self, request):
        host = client_proxy.get_host(self.request, self.tab_group.kwargs['host_id'])
        if not host:
            raise exceptions.Http302(reverse('horizon:giraffe_dashboard'
                                             ':hosts:index'))

        host_meters = client_proxy.get_host_meters( \
                                   self.request, \
                                   self.tab_group.kwargs['host_id'])

        return {'host': host, 'meters': host_meters}
Example #17
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        policy_name = kwargs['policy_name']
        try:
            policy = congress.policy_get(self.request, policy_name)
        except Exception as e:
            msg_args = {'policy_name': policy_name, 'error': str(e)}
            msg = _('Unable to get policy "%(policy_name)s": '
                    '%(error)s') % msg_args
            LOG.error(msg)
            messages.error(self.request, msg)
            redirect = reverse('horizon:admin:policies:index')
            raise exceptions.Http302(redirect)
        context['policy'] = policy

        # Alphabetize and convert list of data source tables and columns into
        # JSON formatted string consumable by JavaScript. Do this here instead
        # of in the Create Rule form so that the tables and columns lists
        # appear in the HTML document before the JavaScript that uses them.
        all_tables = ds_utils.get_datasource_tables(self.request)
        sorted_datasources = dictsort(all_tables, 'datasource')
        tables = []
        for ds in sorted_datasources:
            datasource_tables = ds['tables']
            datasource_tables.sort()
            for table in ds['tables']:
                tables.append(
                    '%s%s%s' %
                    (ds['datasource'], congress.TABLE_SEPARATOR, table))
        context['tables'] = json.dumps(tables)

        datasource_columns = ds_utils.get_datasource_columns(self.request)
        sorted_datasources = dictsort(datasource_columns, 'datasource')
        columns = []
        for ds in sorted_datasources:
            sorted_tables = dictsort(ds['tables'], 'table')
            for tbl in sorted_tables:
                # Ignore service-derived tables, which are already included.
                if congress.TABLE_SEPARATOR in tbl['table']:
                    continue
                table_columns = tbl['columns']
                if table_columns:
                    table_columns.sort()
                else:
                    # Placeholder name for column when the table has none.
                    table_columns = ['_']

                for column in table_columns:
                    columns.append('%s%s%s %s' %
                                   (ds['datasource'], congress.TABLE_SEPARATOR,
                                    tbl['table'], column))
        context['columns'] = json.dumps(columns)
        return context
Example #18
0
 def get_data(self):
     plan_id = self.kwargs['plan_id']
     try:
         plan = api.plan_get(self.request, plan_id)
     except Exception:
         redirect = reverse(self.redirect_url)
         exceptions.handle(self.request,
                           _("Unable to retrieve details for "
                             "plan %s.") % plan_id,
                           redirect=redirect)
         raise exceptions.Http302(redirect)
     return plan
Example #19
0
    def get_context_data(self, request):
        submitted = self.request.GET.get('meter', None) is not None

        host = client_proxy.get_host(self.request, self.tab_group.kwargs['host_id'])
        if not host:
            raise exceptions.Http302(reverse('horizon:giraffe_dashboard'
                                             ':hosts:index'))

        # @[fbahr] - TODO: make /hosts/hid/meters return only host meters?!
        meters = [meter \
                  for meter in client_proxy.get_host_meters( \
                                       self.request, \
                                       self.tab_group.kwargs['host_id']) \
                  if meter.name.startswith('host')]

        today = time.today()
        month = self.request.GET.get('month', today.month)
        day = self.request.GET.get('day', 0)
        year = self.request.GET.get('year', today.year)

        meter_id = self.request.GET.get('meter', meters[0].id if meters else None)
        meter = next(m for m in meters if int(m.id) == int(meter_id)) \
                    if meter_id \
                    else None

        form = forms.DateMeterForm(initial={'month': month,
                                            'year': year,
                                            'day': 0,
                                            'meter': meter_id},
                                   meters=meters)

        context = {'submitted': submitted}
        if submitted and meter_id:
            avgs = client_proxy.get_host_meter_records_avg(request=self.request,
                                                           host_id=host.id,
                                                           meter_id=meter_id,
                                                           year=year,
                                                           month=month,
                                                           day=int(day))

            ticks = 25 \
                    if   day \
                    else (calendar.monthrange(*map(int, (year, month)))[1] + 1)

            context['graph'] = {'y_data': avgs, 'x_data': range(1, ticks)}

        context['form'] = form
        context['meters'] = meters
        context['host'] = host
        context['meter'] = meter

        return context
Example #20
0
 def get_domain(self):
     domain_id = self.kwargs['domain_id']
     try:
         return api.designate.domain_get(self.request, domain_id)
     except Exception:
         redirect = reverse('horizon:project:dns_domains:records',
                            args=(self.kwargs['domain_id'], ))
         exceptions.handle(self.request,
                           ('Unable to retrieve domain record.'),
                           redirect=redirect)
         # NotAuthorized errors won't be redirected automatically. Need
         # to force the issue
         raise exceptions.Http302(redirect)
Example #21
0
 def delete(self, request, obj_id):
     try:
         api.swift.swift_delete_container(request, obj_id)
     except exceptions.Conflict:
         messages.error(
             request,
             _("The container cannot be deleted since "
               "it's not empty."))
         raise exceptions.Http302(self.success_url)
     except Exception:
         exceptions.handle(request,
                           _('Unable to delete container.'),
                           redirect=self.success_url)
Example #22
0
    def get_data(self):
        vim_id = self.kwargs['vim_id']

        try:
            vim = tacker_api.tacker.get_vim(self.request, vim_id)
            return vim
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'VIM "%s".') % vim_id,
                              redirect=redirect)
            raise exceptions.Http302(redirect)
Example #23
0
 def delete(self, request, obj_id):
     LOG.info('User %s deleting policy "%s" in tenant %s',
              request.user.username, obj_id, request.user.tenant_name)
     try:
         congress.policy_delete(request, obj_id)
         LOG.info('Deleted policy "%s"', obj_id)
     except Exception as e:
         msg_args = {'policy_id': obj_id, 'error': str(e)}
         msg = _('Failed to delete policy "%(policy_id)s": '
                 '%(error)s') % msg_args
         LOG.error(msg)
         messages.error(request, msg)
         redirect = reverse(self.redirect_url)
         raise exceptions.Http302(redirect)
 def _delete_network(self, request, network):
     """Delete the created network when subnet creation failed."""
     try:
         api.neutron.network_delete(request, network.id)
         msg = _('Delete the created network "%s" '
                 'due to subnet creation failure.') % network.name
         LOG.debug(msg)
         redirect = self.get_failure_url()
         messages.info(request, msg)
         raise exceptions.Http302(redirect)
     except Exception:
         msg = _('Failed to delete network "%s"') % network.name
         LOG.info(msg)
         redirect = self.get_failure_url()
         exceptions.handle(request, msg, redirect=redirect)
Example #25
0
 def delete(self, request, obj_id):
     obj = self.table.get_object_by_id(obj_id)
     name = self.table.get_object_display(obj)
     try:
         api.neutron.router_delete(request, obj_id)
     except q_ext.NeutronClientException as e:
         msg = _('Unable to delete router "%s"') % e
         LOG.info(msg)
         messages.error(request, msg)
         redirect = reverse(self.redirect_url)
         raise exceptions.Http302(redirect, message=msg)
     except Exception:
         msg = _('Unable to delete router "%s"') % name
         LOG.info(msg)
         exceptions.handle(request, msg)
Example #26
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        policy_name = kwargs['policy_name']
        try:
            policy = congress.policy_get(self.request, policy_name)
        except Exception as e:
            msg_args = {'policy_name': policy_name, 'error': e.message}
            msg = _('Unable to get policy "%(policy_name)s": '
                    '%(error)s') % msg_args
            messages.error(self.request, msg)
            redirect = reverse('horizon:admin:policies:index')
            raise exceptions.Http302(redirect)

        context['policy'] = policy
        return context
Example #27
0
    def __init__(self, request, *args, **kwargs):
        super(RestoreBackupForm, self).__init__(request, *args, **kwargs)

        try:
            volumes = api.cinder.volume_list(request)
        except Exception:
            msg = _('Unable to lookup volume or backup information.')
            redirect = reverse('horizon:admin:volumes:index')
            exceptions.handle(request, msg, redirect=redirect)
            raise exceptions.Http302(redirect)

        volumes.sort(key=operator.attrgetter('name', 'created_at'))
        choices = [('', _('Create a New Volume'))]
        choices.extend((volume.id, volume.name) for volume in volumes)
        self.fields['volume_id'].choices = choices
Example #28
0
    def get_context_data(self, request):
        project = client_proxy.get_projects(
            self.request, self.tab_group.kwargs['project_id'])
        if not project:
            raise exceptions.Http302(
                reverse('horizon:giraffe_dashboard'
                        ':projects:index'))


#        project_meters = client_proxy.get_host_meters( \
#                                      self.request, \
#                                      self.tab_group.kwargs['project_id'])
#
#        return {'project': project, 'meters': project_meters}

        return {}
Example #29
0
    def get_data(self):
        ns_id = self.kwargs['ns_id']

        try:
            ns = tacker_api.tacker.get_ns(self.request, ns_id)
            return ns
        except ValueError as e:
            msg = _('Cannot decode json : %s') % e
            LOG.error(msg)
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'NS "%s".') % ns_id,
                              redirect=redirect)
            raise exceptions.Http302(redirect)
Example #30
0
    def get_data(self):
        vnffgd_id = self.kwargs['vnffgd_id']

        try:
            template = None
            vnffgd = tacker_api.tacker.get_vnffgd(self.request, vnffgd_id)
            template = vnffgd['vnffgd']['template'].get('vnffgd', None)
            vnffgd['template'] = template
        except Exception:
            redirect = reverse(self.redirect_url)
            exceptions.handle(self.request,
                              _('Unable to retrieve details for '
                                'VNFFGD "%s".') % vnffgd_id,
                              redirect=redirect)
            raise exceptions.Http302(redirect)
        return vnffgd