def _get_data(self): if not hasattr(self, '_sg'): sg_id = filters.get_int_or_uuid(self.kwargs['security_group_id']) try: self._sg = api.network.security_group_get(self.request, sg_id) except Exception: redirect = reverse('horizon:hpcloud:access_and_security:index') exceptions.handle(self.request, _('Unable to retrieve security group.'), redirect=redirect) return self._sg
def get_object(self): if not hasattr(self, "_object"): sg_id = filters.get_int_or_uuid(self.kwargs['security_group_id']) try: self._object = api.network.security_group_get( self.request, sg_id) except Exception: msg = _('Unable to retrieve security group.') url = reverse('horizon:hpcloud:access_and_security:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def get_object(self): if not hasattr(self, "_object"): sg_id = filters.get_int_or_uuid(self.kwargs['security_group_id']) try: self._object = api.network.security_group_get(self.request, sg_id) except Exception: msg = _('Unable to retrieve security group.') url = reverse('horizon:hpcloud:access_and_security:index') exceptions.handle(self.request, msg, redirect=url) return self._object
def single(self, table, request, obj_id): try: fip = table.get_object_by_id(filters.get_int_or_uuid(obj_id)) api.network.floating_ip_disassociate(request, fip.id, fip.port_id) LOG.info('Disassociating Floating IP "%s".' % obj_id) messages.success( request, _('Successfully disassociated Floating IP: %s') % fip.ip) except Exception: exceptions.handle(request, _('Unable to disassociate floating IP.')) return shortcuts.redirect('horizon:hpcloud:access_and_security:index')
def single(self, table, request, obj_id): try: fip = table.get_object_by_id(filters.get_int_or_uuid(obj_id)) api.network.floating_ip_disassociate(request, fip.id, fip.port_id) LOG.info('Disassociating Floating IP "%s".' % obj_id) messages.success(request, _('Successfully disassociated Floating IP: %s') % fip.ip) except Exception: exceptions.handle(request, _('Unable to disassociate floating IP.')) return shortcuts.redirect('horizon:hpcloud:access_and_security:index')
def handle(self, request, data): try: rule = api.network.security_group_rule_create( request, filters.get_int_or_uuid(data['id']), data['direction'], data['ethertype'], data['ip_protocol'], data['from_port'], data['to_port'], data['cidr'], data['security_group']) messages.success(request, _('Successfully added rule: %s') % unicode(rule)) return rule except Exception: redirect = reverse( "horizon:hpcloud:access_and_security:" "security_groups:detail", args=[data['id']]) exceptions.handle(request, _('Unable to add rule to security group.'), redirect=redirect)
def get_form_kwargs(self): kwargs = super(AddRuleView, self).get_form_kwargs() try: groups = api.network.security_group_list(self.request) except Exception: groups = [] exceptions.handle(self.request, _("Unable to retrieve security groups.")) security_groups = [] for group in groups: if group.id == filters.get_int_or_uuid( self.kwargs['security_group_id']): security_groups.append( (group.id, _("%s (current)") % group.name)) else: security_groups.append((group.id, group.name)) kwargs['sg_list'] = security_groups return kwargs
def get_form_kwargs(self): kwargs = super(AddRuleView, self).get_form_kwargs() try: groups = api.network.security_group_list(self.request) except Exception: groups = [] exceptions.handle(self.request, _("Unable to retrieve security groups.")) security_groups = [] for group in groups: if group.id == filters.get_int_or_uuid( self.kwargs['security_group_id']): security_groups.append((group.id, _("%s (current)") % group.name)) else: security_groups.append((group.id, group.name)) kwargs['sg_list'] = security_groups return kwargs
def handle(self, request, data): try: rule = api.network.security_group_rule_create( request, filters.get_int_or_uuid(data['id']), data['direction'], data['ethertype'], data['ip_protocol'], data['from_port'], data['to_port'], data['cidr'], data['security_group']) messages.success(request, _('Successfully added rule: %s') % unicode(rule)) return rule except Exception: redirect = reverse("horizon:hpcloud:access_and_security:" "security_groups:detail", args=[data['id']]) exceptions.handle(request, _('Unable to add rule to security group.'), redirect=redirect)
def sanitize_id(self, obj_id): return filters.get_int_or_uuid(obj_id)