How to use horizon - 10 common examples

To help you get started, we’ve selected a few horizon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / horizon / openstack_dashboard / dashboards / project / instances / tabs.py View on Github external
def get_context_data(self, request):
        instance = self.tab_group.kwargs['instance']
        console_type = settings.CONSOLE_TYPE
        console_url = None
        try:
            console_type, console_url = console.get_console(
                request, console_type, instance)
            # For serial console, the url is different from VNC, etc.
            # because it does not include params for title and token
            if console_type == "SERIAL":
                console_url = reverse('horizon:project:instances:serial',
                                      args=[instance.id])
        except exceptions.NotAvailable:
            exceptions.handle(request, ignore=True, force_log=True)

        return {'console_url': console_url, 'instance_id': instance.id,
                'console_type': console_type}
github openstack / horizon / horizon / dashboards / syspanel / projects / forms.py View on Github external
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from horizon import api
from horizon import forms
from horizon.dashboards.syspanel.users.forms import CreateUserForm


class CreateUser(CreateUserForm):
    role_id = forms.ChoiceField(widget=forms.HiddenInput())
    tenant_id = forms.CharField(widget=forms.HiddenInput())

    def __init__(self, request, *args, **kwargs):
        super(CreateUser, self).__init__(request, *args, **kwargs)
        tenant_id = self.request.path.split("/")[-1]
        self.fields['tenant_id'].initial = tenant_id
github openstack / horizon / openstack_dashboard / dashboards / admin / metadata_defs / forms.py View on Github external
def handle(self, request, data):
        try:
            namespace = glance.metadefs_namespace_create(request,
                                                         data['namespace'])
            messages.success(request,
                             _('Namespace %s has been created.') %
                             namespace['namespace'])
            return namespace
        except Exception as e:
            msg = _('Unable to create new namespace. %s')
            msg %= e.message.split('Failed validating', 1)[0]
            exceptions.handle(request, message=msg)
            return False


class ManageResourceTypesForm(forms.SelfHandlingForm):
    def handle(self, request, context):
        namespace_name = self.initial['id']
        current_names = self.get_names(self.initial['resource_types'])
        try:
            updated_types = json.loads(self.data['resource_types'])
            selected_types = [updated_type for updated_type in updated_types
                              if updated_type.pop('selected', False)]
            for current_name in current_names:
                glance.metadefs_namespace_remove_resource_type(
                    self.request, namespace_name, current_name)
            for selected_type in selected_types:
                selected_type.pop('$$hashKey', None)
                selected_type.pop('created_at', None)
                selected_type.pop('updated_at', None)
                glance.metadefs_namespace_add_resource_type(
                    self.request, namespace_name, selected_type)
github openstack / sahara-dashboard / sahara_dashboard / content / data_processing / tabs.py View on Github external
if filter_field is None and filter_field_session is not None:
            filter_field = filter_field_session
        setattr(table.base_actions["filter"], "filter_string", filter_string)
        setattr(table.base_actions["filter"], "filter_field", filter_field)
        filter_info = {
            'action': filter_action,
            'value_param': param_name,
            'value': filter_string,
            'field_param': filter_field_param,
            'field': filter_field,
            'changed': changed
        }
        return filter_info


class PaginationFriendlyTabGroup(tabs.TabGroup):
    def load_tab_data(self):
        """Preload all data that for the tabs that will be displayed."""
        request_without_marker = u.delete_pagination_params_from_request(
            self.request, save_limit=True)
        for tab in self._tabs.values():
            current_tab_id = tab.slug

            tab_request = self.request.GET.get('tab')
            request_tab_id = None

            if tab_request:
                request_tab_id = tab_request.split(base.SEPARATOR)[1]
            if request_tab_id and current_tab_id != request_tab_id:
                try:
                    tab.request = request_without_marker
                    tab._data = tab.get_context_data(request_without_marker)
github openstack / horizon / openstack_dashboard / contrib / trove / content / database_clusters / forms.py View on Github external
def datastores(self, request):
        try:
            return trove_api.trove.datastore_list(request)
        except Exception:
            LOG.exception("Exception while obtaining datastores list")
            self._datastores = []
            redirect = reverse('horizon:project:database_clusters:index')
            exceptions.handle(request,
                              _('Unable to obtain datastores.'),
                              redirect=redirect)
github openstack / horizon / horizon / dashboards / project / networks / views.py View on Github external
def _get_object(self, *args, **kwargs):
        if not hasattr(self, "_object"):
            network_id = self.kwargs['network_id']
            try:
                self._object = api.quantum.network_get(self.request,
                                                       network_id)
            except:
                redirect = self.success_url
                msg = _('Unable to retrieve network details.')
                exceptions.handle(self.request, msg, redirect=redirect)
        return self._object
github openstack / python-muranoclient / tabula / tabula / windc / views.py View on Github external
def get_data(self):
        try:
            dc_id = self.kwargs['data_center_id']
            self.datacenter_id = dc_id
            datacenter = api.datacenters_get(self.request, dc_id)
            self.dc_name = datacenter.name
            services = api.services_list(self.request, dc_id)
        except:
            services = []
            exceptions.handle(self.request,
                              _('Unable to retrieve list of services for '
                                'data center "%s".') % self.dc_name)
        return services
github openstack / manila-ui / manila_ui / dashboards / admin / share_group_snapshots / views.py View on Github external
def get_object(self):
        if not hasattr(self, "_object"):
            s_id = self.kwargs["share_group_snapshot_id"]
            try:
                self._object = manila.share_group_snapshot_get(
                    self.request, s_id)
            except Exception:
                msg = _("Unable to retrieve share group snapshot '%s'.") % s_id
                url = reverse('horizon:admin:share_group_snapshots:index')
                exceptions.handle(self.request, msg, redirect=url)
        return self._object
github openstack / horizon / openstack_dashboard / dashboards / project / instances / workflows / create_instance.py View on Github external
base.is_service_enabled(self.request, 'volume')
            flavors = json.dumps([f._info for f in
                                  instance_utils.flavor_list(self.request)])
            extra['flavors'] = flavors
            images = image_utils.get_available_images(
                self.request, self.initial['project_id'], self._images_cache)
            if images is not None:
                attrs = [{'id': i.id,
                          'min_disk': getattr(i, 'min_disk', 0),
                          'min_ram': getattr(i, 'min_ram', 0),
                          'size': functions.bytes_to_gigabytes(i.size)}
                         for i in images]
                extra['images'] = json.dumps(attrs)

        except Exception:
            exceptions.handle(self.request,
                              _("Unable to retrieve quota information."))
        return super(SetInstanceDetailsAction, self).get_help_text(extra)
github cmusatyalab / elijah-openstack / dashboard / images / views.py View on Github external
def get_object(self):
        if not hasattr(self, "_object"):
            try:
                self._object = api.glance.image_get(self.request,
                                                    self.kwargs['image_id'])
            except:
                msg = _('Unable to retrieve image.')
                url = reverse('horizon:project:images_and_snapshots:index')
                exceptions.handle(self.request, msg, redirect=url)
        return self._object