Exemple #1
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     network = self._get_data()
     context["network"] = network
     table = project_tables.NetworksTable(self.request)
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(network)
     choices = project_tables.STATUS_DISPLAY_CHOICES
     network.status_label = filters.get_display_label(choices, network.status)
     choices = project_tables.DISPLAY_CHOICES
     network.admin_state_label = filters.get_display_label(choices, network.admin_state)
     return context
Exemple #2
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     network = self._get_data()
     context["network"] = network
     table = project_tables.NetworksTable(self.request)
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(network)
     choices = project_tables.STATUS_DISPLAY_CHOICES
     network.status_label = (
         filters.get_display_label(choices, network.status))
     choices = project_tables.DISPLAY_CHOICES
     network.admin_state_label = (
         filters.get_display_label(choices, network.admin_state))
     return context
Exemple #3
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        router = self._get_data()
        table = rtables.RoutersTable(self.request)

        context["router"] = router
        context["url"] = self.failure_url
        context["actions"] = table.render_row_actions(router)
        context["dvr_supported"] = api.neutron.get_feature_permission(self.request, "dvr", "get")
        context["ha_supported"] = api.neutron.get_feature_permission(self.request, "l3-ha", "get")
        choices = rtables.STATUS_DISPLAY_CHOICES
        router.status_label = filters.get_display_label(choices, router.status)
        choices = rtables.ADMIN_STATE_DISPLAY_CHOICES
        router.admin_state_label = filters.get_display_label(choices, router.admin_state)
        return context
Exemple #4
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
Exemple #5
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
Exemple #6
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
Exemple #7
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
Exemple #8
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        router = self._get_data()
        table = rtables.RoutersTable(self.request)

        context["router"] = router
        context["url"] = self.failure_url
        context["actions"] = table.render_row_actions(router)
        context['dvr_supported'] = api.neutron.get_feature_permission(
            self.request, "dvr", "get")
        context['ha_supported'] = api.neutron.get_feature_permission(
            self.request, "l3-ha", "get")
        choices = rtables.STATUS_DISPLAY_CHOICES
        router.status_label = filters.get_display_label(choices, router.status)
        choices = rtables.ADMIN_STATE_DISPLAY_CHOICES
        router.admin_state_label = (filters.get_display_label(
            choices, router.admin_state))
        return context
Exemple #9
0
    def get_row_data(self):

        choices = project_tables.STATUS_DISPLAY_CHOICES
        for inst in self.context['usage'].get_instances():
            state_label = (filters.get_display_label(choices, inst['state']))
            yield (inst['name'], inst['vcpus'], inst['memory_mb'],
                   inst['local_gb'], floatformat(inst['hours'],
                                                 2), inst['uptime'],
                   capfirst(state_label))
Exemple #10
0
    def _get_data(self):
        network = {}
        network_id = None
        try:
            network_id = self.tab_group.kwargs['network_id']
            network = api.neutron.network_get(self.request, network_id)
            network.set_id_as_name_if_empty(length=0)

            choices = project_tables.STATUS_DISPLAY_CHOICES
            network.status_label = (filters.get_display_label(
                choices, network.status))
            choices = project_tables.DISPLAY_CHOICES
            network.admin_state_label = (filters.get_display_label(
                choices, network.admin_state))
        except Exception:
            msg = _('Unable to retrieve details for network "%s".') \
                % (network_id)
            exceptions.handle(self.request, msg)
        return network
Exemple #11
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     volume, snapshots = self.get_data()
     table = volume_tables.VolumesTable(self.request)
     context["volume"] = volume
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(volume)
     choices = volume_tables.VolumesTableBase.STATUS_DISPLAY_CHOICES
     volume.status_label = filters.get_display_label(choices, volume.status)
     return context
Exemple #12
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     image = self.get_data()
     table = project_tables.ImagesTable(self.request)
     context["image"] = image
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(image)
     choices = project_tables.ImagesTable.STATUS_DISPLAY_CHOICES
     image.status_label = filters.get_display_label(choices, image.status)
     return context
Exemple #13
0
    def _get_data(self):
        network = {}
        network_id = None
        try:
            network_id = self.tab_group.kwargs['network_id']
            network = api.neutron.network_get(self.request, network_id)
            network.set_id_as_name_if_empty(length=0)

            choices = project_tables.STATUS_DISPLAY_CHOICES
            network.status_label = (
                filters.get_display_label(choices, network.status))
            choices = project_tables.DISPLAY_CHOICES
            network.admin_state_label = (
                filters.get_display_label(choices, network.admin_state))
        except Exception:
            msg = _('Unable to retrieve details for network "%s".') \
                % (network_id)
            exceptions.handle(self.request, msg)
        return network
Exemple #14
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     volume = self.get_data()
     table = project_tables.VolumesTable(self.request)
     context["volume"] = volume
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(volume)
     choices = project_tables.VolumesTableBase.STATUS_DISPLAY_CHOICES
     volume.status_label = filters.get_display_label(choices, volume.status)
     return context
Exemple #15
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     image = self.get_data()
     table = project_tables.ImagesTable(self.request)
     context["image"] = image
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(image)
     choices = project_tables.ImagesTable.STATUS_DISPLAY_CHOICES
     image.status_label = filters.get_display_label(choices, image.status)
     return context
Exemple #16
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        network = self._get_data()
        # Needs to exclude agents table if dhcp-agent-scheduler extension
        # is not supported.
        try:
            dhcp_agent_support = api.neutron.is_extension_supported(self.request, "dhcp_agent_scheduler")
            context["dhcp_agent_support"] = dhcp_agent_support
        except Exception:
            context["dhcp_agent_support"] = False

        table = networks_tables.NetworksTable(self.request)
        context["network"] = network
        context["url"] = self.get_redirect_url()
        context["actions"] = table.render_row_actions(network)
        choices = networks_tables.project_tables.STATUS_DISPLAY_CHOICES
        network.status_label = filters.get_display_label(choices, network.status)
        choices = networks_tables.DISPLAY_CHOICES
        network.admin_state_label = filters.get_display_label(choices, network.admin_state)
        return context
Exemple #17
0
 def get_context_data(self, **kwargs):
     context = super(DetailView, self).get_context_data(**kwargs)
     replication = self.get_data()
     table = rep_tables.VolumeReplicationsTable(self.request)
     context["replication"] = replication
     context["url"] = self.get_redirect_url()
     context["actions"] = table.render_row_actions(replication)
     choices = rep_tables.VolumeReplicationsTable.STATUS_DISPLAY_CHOICES
     replication.status_label = filters.get_display_label(
         choices, replication.status)
     return context
Exemple #18
0
    def get_row_data(self):

        choices = project_tables.STATUS_DISPLAY_CHOICES
        for inst in self.context['usage'].get_instances():
            state_label = (
                filters.get_display_label(choices, inst['state']))
            yield (inst['name'],
                   inst['vcpus'],
                   inst['memory_mb'],
                   inst['local_gb'],
                   floatformat(inst['hours'], 2),
                   inst['uptime'],
                   capfirst(state_label))
Exemple #19
0
    def get_context_data(self, **kwargs):
        context = super(DetailView, self).get_context_data(**kwargs)
        network = self._get_data()
        # Needs to exclude agents table if dhcp-agent-scheduler extension
        # is not supported.
        try:
            dhcp_agent_support = api.neutron.is_extension_supported(
                self.request, 'dhcp_agent_scheduler')
            context['dhcp_agent_support'] = dhcp_agent_support
        except Exception:
            context['dhcp_agent_support'] = False

        table = networks_tables.NetworksTable(self.request)
        context["network"] = network
        context["url"] = self.get_redirect_url()
        context["actions"] = table.render_row_actions(network)
        choices = networks_tables.project_tables.STATUS_DISPLAY_CHOICES
        network.status_label = (filters.get_display_label(
            choices, network.status))
        choices = networks_tables.DISPLAY_CHOICES
        network.admin_state_label = (filters.get_display_label(
            choices, network.admin_state))
        return context
Exemple #20
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))

        def _task_get_volumes():
            try:
                instance.volumes = api.nova.instance_volumes_list(
                    self.request, instance_id)
                # Sort by device name
                # WRS: if instance takes an error on launch, volume may not
                #      have "device" attribute
                try:
                    instance.volumes.sort(key=lambda vol: vol.device)
                except AttributeError:
                    pass
            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)

        def _task_get_flavor():
            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)

        def _task_get_security_groups():
            try:
                instance.security_groups = api.neutron.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)

        def _task_update_addresses():
            instance.uptime = get_uptime(instance)
            # There is a space in the attribute name and the result is a list
            # that we want to strip the square brackets from so it looks good.
            vcpus_min_cur_max = getattr(instance, 'wrs-res:vcpus',
                                        [" ", " ", " "])
            instance.vcpus_min_cur_max = '/'.join(map(str, vcpus_min_cur_max))
            instance.vcpus = vcpus_min_cur_max[1]

            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)

        with futurist.ThreadPoolExecutor(max_workers=4) as e:
            e.submit(fn=_task_get_volumes)
            e.submit(fn=_task_get_flavor)
            e.submit(fn=_task_get_security_groups)
            e.submit(fn=_task_update_addresses)

        if (hasattr(instance, "addresses") and hasattr(instance, "nics")):
            instance.addresses = project_utils.sort_addresses_by_nic(instance)
        else:
            instance.addresses = []

        return instance