Ejemplo n.º 1
0
Archivo: host.py Proyecto: jness/dmirr
 def new(self, *a, **kw):
     h = Host()
     group   = _h.get_group_by_name(kw.get('group_name', None))
     project = _h.get_project_by_name(kw.get('project_label', None))
     site    = _h.get_site_by_name(kw.get('site_label', None))
         
     _h.protect_obj(project)
     _h.protect_obj(site)
     
     h.user = request.identity['user']
     h.address = kw.get('address', 'host.example.com').strip()
     h.group = group
     transaction.doom()
     return dict(errors={}, host=h)
Ejemplo n.º 2
0
Archivo: host.py Proyecto: jness/dmirr
    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'))