Exemple #1
0
 def edit(self, host_address=None, *a, **kw):
     h = _h.get_host_by_address(host_address)
     if not h:
         raise HTTPNotFound
         
     _h.protect_obj(h)
     return dict(errors={}, original_host=h, host=h)
Exemple #2
0
    def post(self, *a, **kw):
        h = _h.get_host_by_address(kw.get('address', None))
        errors  = _h.get_validation_errors()
        if h:
            errors['address'] = "Host %s already exists!" % h.address

        h = Host()            
        group = _h.get_group_by_name(kw.get('group_name', None))
        
        h.address = unicode(kw['address'].strip())
        h.user = request.identity['user']
        h.group = group
        
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could " % h.address + \
                                     "not be identified via GeoIP. " + \
                                     "Please ensure the hostname resolves" 
                    
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)
        
        _h.protect_obj(h)
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
            
        flash(_("%s created successfully!" % kw['address']), 'info')
        redirect(url('/host/new'))