Python horizon.messages.success() Examples

The following are 30 code examples of horizon.messages.success(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module horizon.messages , or try the search function .
Example #1
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            send_data = {'name': data['name']}
            if data['description']:
                send_data['description'] = data['description']
            share_net_id = data.get('neutron_net_id', data.get('nova_net_id'))
            share_net_id = share_net_id.strip()
            if self.neutron_enabled and share_net_id:
                send_data['neutron_net_id'] = share_net_id
                subnet_key = 'subnet-choices-%s' % share_net_id
                if subnet_key in data:
                    send_data['neutron_subnet_id'] = data[subnet_key]
            elif not self.neutron_enabled and share_net_id:
                send_data['nova_net_id'] = data['nova_net_id']
            share_network = manila.share_network_create(request, **send_data)
            messages.success(request, _('Successfully created share'
                                        ' network: %s') % send_data['name'])
            return share_network
        except Exception:
            exceptions.handle(request, _('Unable to create share network.'))
            return False 
Example #2
Source File: forms.py    From avos with Apache License 2.0 6 votes vote down vote up
def handle(self, request, context):
        context['admin_state_up'] = (context['admin_state_up'] == 'True')
        try:
            data = {'member': {'pool_id': context['pool_id'],
                               'weight': context['weight'],
                               'admin_state_up': context['admin_state_up']}}
            member = api.lbaas.member_update(request,
                                             context['member_id'], **data)
            msg = _('Member %s was successfully updated.')\
                % context['member_id']
            LOG.debug(msg)
            messages.success(request, msg)
            return member
        except Exception:
            msg = _('Failed to update member %s') % context['member_id']
            LOG.info(msg)
            redirect = reverse(self.failure_url)
            exceptions.handle(request, msg, redirect=redirect) 
Example #3
Source File: forms.py    From trove-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        instance = data.get('instance_id')
        try:
            api.trove.user_update_attributes(
                request,
                instance,
                data['user_name'],
                host=data['user_host'],
                new_name=data['new_name'],
                new_password=data['new_password'],
                new_host=data['new_host'])

            messages.success(request,
                             _('Updated user "%s".') % data['user_name'])
        except Exception as e:
            redirect = reverse("horizon:project:databases:detail",
                               args=(instance,))
            exceptions.handle(request, _('Unable to update user. %s') % e,
                              redirect=redirect)
        return True 
Example #4
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        replica_id = self.initial['replica_id']
        try:
            replica = manila.share_replica_get(self.request, replica_id)
            manila.share_replica_reset_state(
                request, replica, data["replica_state"])
            message = _("Reseting replica ('%(id)s') state from '%(from)s' "
                        "to '%(to)s'.") % {
                            "id": replica_id,
                            "from": replica.replica_state,
                            "to": data["replica_state"]}
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:admin:shares:index")
            exceptions.handle(
                request,
                _("Unable to reset state of replica '%s'.") % replica_id,
                redirect=redirect) 
Example #5
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        replica_id = self.initial['replica_id']
        try:
            replica = manila.share_replica_get(self.request, replica_id)
            manila.share_replica_reset_status(
                request, replica, data["replica_status"])
            message = _("Reseting replica ('%(id)s') status from '%(from)s' "
                        "to '%(to)s'.") % {
                            "id": replica_id,
                            "from": replica.replica_state,
                            "to": data["replica_status"]}
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:admin:shares:index")
            exceptions.handle(
                request,
                _("Unable to reset status of replica '%s'.") % replica_id,
                redirect=redirect) 
Example #6
Source File: forms.py    From avos with Apache License 2.0 6 votes vote down vote up
def handle(self, request, context):
        context['admin_state_up'] = (context['admin_state_up'] == 'True')
        try:
            data = {'health_monitor': {
                    'delay': context['delay'],
                    'timeout': context['timeout'],
                    'max_retries': context['max_retries'],
                    'admin_state_up': context['admin_state_up']}}
            monitor = api.lbaas.pool_health_monitor_update(
                request, context['monitor_id'], **data)
            msg = _('Health monitor %s was successfully updated.')\
                % context['monitor_id']
            LOG.debug(msg)
            messages.success(request, msg)
            return monitor
        except Exception:
            msg = _('Failed to update health monitor %s')\
                % context['monitor_id']
            LOG.info(msg)
            redirect = reverse(self.failure_url)
            exceptions.handle(request, msg, redirect=redirect) 
Example #7
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        s_id = self.initial['share_group_snapshot_id']
        try:
            manila.share_group_snapshot_reset_state(
                request, s_id, data["status"])
            message = _(
                "Reseting share group snapshot ('%(id)s') status "
                "from '%(from)s' to '%(to)s'.") % {
                    "id": self.initial['share_group_snapshot_name'] or s_id,
                    "from": self.initial['share_group_snapshot_status'],
                    "to": data["status"]}
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:admin:share_group_snapshots:index")
            exceptions.handle(
                request,
                _("Unable to reset status of share group snapshot "
                  "'%s'.") % s_id,
                redirect=redirect)
        return False 
Example #8
Source File: forms.py    From tacker-horizon with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            toscal = yaml.load(data['tosca'], Loader=yaml.SafeLoader)
            vnfd_name = data['name']
            vnfd_description = data['description']
            tosca_arg = {'vnfd': {'name': vnfd_name,
                                  'description': vnfd_description,
                                  'attributes': {'vnfd': toscal}}}
            vnfd_instance = api.tacker.create_vnfd(request, tosca_arg)
            messages.success(request,
                             _('VNF Catalog entry %s has been created.') %
                             vnfd_instance['vnfd']['name'])
            return toscal
        except Exception as e:
            msg = _('Unable to create TOSCA. %s')
            msg %= e.message.split('Failed validating', 1)[0]
            exceptions.handle(request, message=msg)
            return False 
Example #9
Source File: forms.py    From trove-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            datastore = data['datastore'].split(',')[0]
            datastore_version = data['datastore'].split(',')[1]

            api.trove.configuration_create(request, data['name'], "{}",
                                           description=data['description'],
                                           datastore=datastore,
                                           datastore_version=datastore_version)

            messages.success(request, _('Created configuration group'))
        except Exception as e:
            redirect = reverse("horizon:project:database_configurations:index")
            exceptions.handle(request, _('Unable to create configuration '
                                         'group. %s') % e, redirect=redirect)
        return True 
Example #10
Source File: forms.py    From trove-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            (config_param_manager
                .get(request, self.initial["configuration_id"])
                .add_param(data["name"],
                           config_param_manager.adjust_type(
                               config_param_manager.find_parameter(
                                   data["name"], self.parameters).type,
                               data["value"])))
            messages.success(request, _('Successfully added parameter'))
        except Exception as e:
            redirect = reverse("horizon:project:database_configurations:index")
            exceptions.handle(request,
                              _('Unable to add new parameter: %s') % e,
                              redirect=redirect)
        return True 
Example #11
Source File: views.py    From don with Apache License 2.0 6 votes vote down vote up
def collect(request):
    macro = {'collect_status': 'Collection failed'}
    status = 0

    BASE_DIR = settings.ROOT_PATH
    # CUR_DIR = os.getcwd()
    os.chdir(BASE_DIR + '/don/ovs')
    cmd = 'sudo python collector.py'
    for line in run_command(cmd):
        if line.startswith('STATUS:') and line.find('Writing collected info') != -1:
            status = 1
            macro['collect_status'] = \
                "Collecton successful. Click visualize to display"
    # res = collector.main()
    os.chdir(BASE_DIR)
    if status:
        messages.success(request, macro['collect_status'])
    else:
        messages.error(request, macro['collect_status'])
    resp = HttpResponse(json.dumps(macro), content_type="application/json")
    return resp 
Example #12
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        share_name = _get_id_if_name_empty(data)
        try:
            result = manila.migration_get_progress(request,
                                                   self.initial['share_id'])
            progress = result[1]
            messages.success(
                request,
                _('Migration of share %(name)s is at %(progress)s percent.') %
                {'name': share_name, 'progress': progress['total_progress']})
            return True
        except Exception:
            exceptions.handle(request, _("Unable to obtain progress of "
                                         "migration of share %s at this "
                                         "moment.") % share_name)
        return False 
Example #13
Source File: forms.py    From monasca-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            kwargs = {}
            kwargs['notification_id'] = self.initial['id']
            kwargs['name'] = data['name']
            kwargs['type'] = data['type']
            kwargs['address'] = data['address']
            kwargs['period'] = int(data['period'])
            api.monitor.notification_update(
                request,
                **kwargs
            )
            messages.success(request,
                             _('Notification has been edited successfully.'))
        except Exception as e:
            exceptions.handle(request,
                              _('Unable to edit the notification: %s') % e)
            return False
        return True 
Example #14
Source File: forms.py    From monasca-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            alarm_actions = [notification.get('id')
                             for notification in data['notifications']]
            api.monitor.alarm_create(
                request,
                name=data['name'],
                expression=data['expression'],
                description=data['description'],
                severity=data['severity'],
                alarm_actions=alarm_actions,
                ok_actions=alarm_actions,
                undetermined_actions=alarm_actions,
            )
            messages.success(request,
                             _('Alarm has been created successfully.'))
        except Exception as e:
            exceptions.handle(request, _('Unable to create the alarm: %s') % e.message)
            return False
        return True 
Example #15
Source File: forms.py    From monasca-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            alarm_actions = []
            if data['notifications']:
                alarm_actions = [notification.get('id')
                                 for notification in data['notifications']]
            api.monitor.alarm_update(
                request,
                alarm_id=self.initial['id'],
                state=self.initial['state'],
                severity=data['severity'],
                name=data['name'],
                expression=data['expression'],
                description=data['description'],
                actions_enabled=data['actions_enabled'],
                alarm_actions=alarm_actions,
                ok_actions=alarm_actions,
                undetermined_actions=alarm_actions,
            )
            messages.success(request,
                             _('Alarm has been edited successfully.'))
        except Exception as e:
            exceptions.handle(request, _('Unable to edit the alarm: %s') % e)
            return False
        return True 
Example #16
Source File: forms.py    From monasca-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            alarm_def = api.monitor.alarmdef_get(request, self.initial['id'])
            api.monitor.alarmdef_update(
                request,
                alarm_id=self.initial['id'],
                severity=data['severity'],
                name=data['name'],
                expression=data['expression'],
                description=data['description'],
                match_by=alarm_def['match_by'],
                actions_enabled=data['actions_enabled'],
                alarm_actions=data['alarm_actions'],
                ok_actions=data['ok_actions'],
                undetermined_actions=data['undetermined_actions'],
            )
            messages.success(request,
                             _('Alarm definition has been updated.'))
        except Exception as e:
            exceptions.handle(request, _('%s') % e)
            return False
        return True 
Example #17
Source File: forms.py    From tacker-horizon with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            toscal = data['tosca']
            vnffgd_name = data['name']
            vnffgd_description = data['description']
            tosca_arg = {'vnffgd': {'name': vnffgd_name,
                                    'description': vnffgd_description,
                                    'template': {'vnffgd': toscal}}}
            vnffgd_instance = api.tacker.create_vnffgd(request, tosca_arg)
            messages.success(request,
                             _('VNFFG Catalog entry %s has been created.') %
                             vnffgd_instance['vnffgd']['name'])
            return toscal
        except Exception as e:
            msg = _('Unable to create TOSCA. %s')
            msg %= e.message.split('Failed validating', 1)[0]
            exceptions.handle(request, message=msg)
            return False 
Example #18
Source File: forms.py    From tacker-horizon with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            toscal = data['tosca']
            nsd_name = data['name']
            nsd_description = data['description']
            tosca_arg = {'nsd': {'name': nsd_name,
                                 'description': nsd_description,
                                 'attributes': {'nsd': toscal}}}
            nsd_instance = api.tacker.create_nsd(request, tosca_arg)
            messages.success(request,
                             _('NS Catalog entry %s has been created.') %
                             nsd_instance['nsd']['name'])
            return toscal
        except Exception as e:
            msg = _('Unable to create TOSCA. %s')
            msg %= e.message.split('Failed validating', 1)[0]
            exceptions.handle(request, message=msg)
            return False 
Example #19
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        snapshot_id = self.initial['snapshot_id']
        try:
            manila.share_snapshot_allow(
                request, snapshot_id,
                access_to=data['access_to'],
                access_type=data['access_type'])
            message = _('Creating snapshot rule for "%s"') % data['access_to']
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse(
                "horizon:project:share_snapshots:share_snapshot_manage_rules",
                args=[self.initial['snapshot_id']])
            exceptions.handle(
                request, _('Unable to add snapshot rule.'), redirect=redirect) 
Example #20
Source File: forms.py    From mistral-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            api.execution_update(
                request,
                data["execution_id"],
                "description",
                data["description"])
            msg = _('Successfully updated execution description.')
            messages.success(request, msg)

            return True

        except Exception as e:
            msg = _('Failed to update execution description: %s') % e
            redirect = reverse('horizon:mistral:executions:index')
            exceptions.handle(request, msg, redirect=redirect) 
Example #21
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        share_id = self.initial['share_id']
        is_public = data['is_public'] if self.enable_public_shares else False
        try:
            share = manila.share_get(self.request, share_id)
            manila.share_update(
                request, share, data['name'], data['description'],
                is_public=is_public)
            message = _('Updating share "%s"') % data['name']
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:shares:index")
            exceptions.handle(request,
                              _('Unable to update share.'),
                              redirect=redirect) 
Example #22
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        share_id = self.initial['share_id']
        try:
            manila.share_allow(
                request, share_id,
                access_to=data['access_to'],
                access_type=data['access_type'],
                access_level=data['access_level'])
            message = _('Creating rule for "%s"') % data['access_to']
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:shares:manage_rules",
                               args=[self.initial['share_id']])
            exceptions.handle(
                request, _('Unable to add rule.'), redirect=redirect) 
Example #23
Source File: forms.py    From mistral-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        data['input'] = convert_empty_string_to_none(data['input'])
        data['params'] = convert_empty_string_to_none(data['params'])
        data['schedule_pattern'] = convert_empty_string_to_none(
            data['schedule_pattern']
        )
        data['first_time'] = convert_empty_string_to_none(data['first_time'])
        data['schedule_count'] = convert_empty_string_to_none(
            data['schedule_count']
        )

        api.cron_trigger_create(
            request,
            data['name'],
            data['workflow_id'],
            data['input'],
            data['params'],
            data['schedule_pattern'],
            data['first_time'],
            data['schedule_count'],
        )
        msg = _('Successfully created Cron Trigger.')
        messages.success(request, msg)

        return True 
Example #24
Source File: forms.py    From manila-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        sec_service_id = self.initial['sec_service_id']
        try:
            manila.security_service_update(request, sec_service_id,
                                           name=data['name'],
                                           description=data['description'])

            message = _('Successfully updated security service '
                        '"%s"') % data['name']
            messages.success(request, message)
            return True
        except Exception:
            redirect = reverse("horizon:project:security_services:index")
            exceptions.handle(request,
                              _('Unable to update security service.'),
                              redirect=redirect) 
Example #25
Source File: forms.py    From mistral-dashboard with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            data['workflow_identifier'] = data.pop('workflow_name')
            data['workflow_input'] = {}
            for param in self.workflow_parameters:
                value = data.pop(param)
                if value == "":
                    value = None
                data['workflow_input'][param] = value
            ex = api.execution_create(request, **data)

            msg = _('Execution has been created with id "%s".') % ex.id
            messages.success(request, msg)

            return True
        except Exception as e:
            msg = _('Failed to execute workflow "%s".') % e
            redirect = reverse('horizon:mistral:workflows:index')
            exceptions.handle(request, msg, redirect=redirect) 
Example #26
Source File: forms.py    From django-leonardo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def handle(self, request, data):

        try:
            user = User.objects.create_user(**data)
            messages.success(
                request,
                _("User account {} was successfuly created.".format(user)))

        except Exception as e:
            raise e
        else:
            data.pop('email')
            return LoginForm().handle(request, data)

        messages.error(request, _("Create Account failed."))
        return False 
Example #27
Source File: forms.py    From monasca-ui with Apache License 2.0 6 votes vote down vote up
def handle(self, request, data):
        try:
            api.monitor.notification_create(
                request,
                name=data['name'],
                type=data['type'],
                address=data['address'],
                period=int(data['period']))
            messages.success(request,
                             _('Notification method has been created '
                               'successfully.'))
        except Exception as e:
            exceptions.handle(request,
                              _('Unable to create the notification '
                                'method: %s') % e)
            return False
        return True 
Example #28
Source File: forms.py    From manila-ui with Apache License 2.0 5 votes vote down vote up
def handle(self, request, data):
        share_name = _get_id_if_name_empty(data)
        try:
            manila.migration_cancel(request, self.initial['share_id'])
            messages.success(
                request,
                _('Successfully sent the request to cancel migration of '
                  ' share: %s.') % share_name)
            return True
        except Exception:
            exceptions.handle(request, _("Unable to cancel migration of share"
                                         " %s at this moment.") % share_name)
        return False 
Example #29
Source File: forms.py    From manila-ui with Apache License 2.0 5 votes vote down vote up
def handle(self, request, data):
        try:
            set_dict, unset_list = utils.parse_str_meta(data['group_specs'])
            if unset_list:
                msg = _("Expected only pairs of key=value.")
                raise ValidationError(message=msg)

            is_public = (
                self.enable_public_share_group_type_creation and
                data["is_public"])
            share_group_type = manila.share_group_type_create(
                request, data["name"], share_types=data['share_types'],
                is_public=is_public)
            if set_dict:
                manila.share_group_type_set_specs(
                    request, share_group_type.id, set_dict)

            msg = _("Successfully created share group type: "
                    "%s") % share_group_type.name
            messages.success(request, msg)
            return True
        except ValidationError as e:
            # handle error without losing dialog
            self.api_error(e.messages[0])
            return False
        except Exception:
            exceptions.handle(request, _('Unable to create share group type.'))
            return False 
Example #30
Source File: forms.py    From tacker-horizon with Apache License 2.0 5 votes vote down vote up
def handle(self, request, data):
        try:
            vnf_name = data['vnf_name']
            description = data['description']
            vnfd_id = data.get('vnfd_id')
            vnfd_template = data.get('vnfd_template')
            vim_id = data['vim_id']
            region_name = data['region_name']
            param_val = data['param_values']
            config_val = data['config_values']

            if (vnfd_id == '') and (vnfd_template is None):
                raise ValidationError(_("Both VNFD id and template cannot be "
                                        "empty. Please specify one of them"))

            if (vnfd_id != '') and (vnfd_template is not None):
                raise ValidationError(_("Both VNFD id and template cannot be "
                                        "specified. Please specify any one"))

            vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name':  vnf_name,
                               'description': description,
                               'vim_id': vim_id,
                               'vnfd_template': vnfd_template}}
            if region_name:
                vnf_arg.setdefault('placement_attr', {})[
                    region_name] = region_name
            vnf_attr = vnf_arg['vnf'].setdefault('attributes', {})
            if param_val:
                vnf_attr['param_values'] = param_val
            if config_val:
                vnf_attr['config'] = config_val

            api.tacker.create_vnf(request, vnf_arg)
            messages.success(request,
                             _('VNF %s create operation initiated.') %
                             vnf_name)
            return True
        except Exception as e:
            exceptions.handle(request,
                              _('Failed to create VNF: %s') %
                              e.message)