Ejemplo n.º 1
0
 def rebinding_domain(self, instance):
     # Binding in nginx
     from tool.domain import binding_domain_in_nginx
     ret, reason = binding_domain_in_nginx(
         self.db2, instance.id, domain = self.get_domain(instance) )
     if not ret:
         logging.warning(_('binding domain error: %s') % reason)
Ejemplo n.º 2
0
    def binding_domain(self, instance):

        # Updated instance subdomain value
        sub, top= self.get_domain2( instance )
        if sub and top:
            instance.subdomain = sub
            self.db2.commit()
        else:
            return None

        full_domain = self.get_domain( instance )
        # Binding in nginx
        from tool.domain import binding_domain_in_nginx
        ret, reason = binding_domain_in_nginx(
            self.db2, instance.id, domain = full_domain )
        if not ret:
            return None

        if not instance.config:
            instance.init_config()

        config = json.loads(instance.config)
            
        if 'domain' in config.keys():
            domain = config['domain']
        else:
            domain = {}

        domain['name'] = full_domain
        domain['ip'] = instance.access_ip
        config['domain'] = domain

        instance.config = json.dumps( config )
        instance.updated = datetime.utcnow()
        self.db2.commit()
Ejemplo n.º 3
0
    def binding_domain(self, instance):

        # Updated instance subdomain value
        sub, top= self.get_domain2( instance )
        if sub and top:
            instance.subdomain = sub
            self.db2.commit()
        else:
            return None

        full_domain = self.get_domain( instance )
        # Binding in nginx
        from tool.domain import binding_domain_in_nginx
        ret, reason = binding_domain_in_nginx(
            self.db2, instance.id, domain = full_domain )
        if not ret:
            return None

        if not instance.config:
            instance.init_config()

        config = json.loads(instance.config)
            
        if 'domain' in config.keys():
            domain = config['domain']
        else:
            domain = {}

        domain['name'] = full_domain
        domain['ip'] = instance.access_ip
        config['domain'] = domain

        instance.config = json.dumps( config )
        instance.updated = datetime.utcnow()
        self.db2.commit()
Ejemplo n.º 4
0
 def rebinding_domain(self, instance):
     # Binding in nginx
     from tool.domain import binding_domain_in_nginx
     ret, reason = binding_domain_in_nginx(
         self.db2, instance.id, domain = self.get_domain(instance) )
     if not ret:
         logging.warning(_('binding domain error: %s') % reason)
     # TODO: update config about domain
     self.binding_domain(instance)
Ejemplo n.º 5
0
    def rebinding_domain(self, instance):
        # Binding in nginx
        from tool.domain import binding_domain_in_nginx

        ret, reason = binding_domain_in_nginx(self.db2, instance.id, domain=self.get_domain(instance))
        if not ret:
            logging.warning(_("binding domain error: %s") % reason)
        # TODO: update config about domain
        self.binding_domain(instance)
Ejemplo n.º 6
0
    def post(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst: return

        d = { 'title': _('Configure Domain'),
              'instance': inst, 'ERROR': [] }

        oldsub, d['topdomain'] = self.get_domain2( inst )

        subdomain = self.get_argument('subdomain', None)
        if not subdomain:
            d['ERROR'].append( _('Domain is not configured!') )

        if subdomain != oldsub:
            d['subdomain'] = subdomain
            if subdomain.isalpha():
                exist_domain = self.db2.query(Instance.id).filter_by(
                    subdomain = subdomain ).first()
                if exist_domain:
                    d['ERROR'].append( _('Domain name is taken!') )
                if len(subdomain) > 16:
                    d['ERROR'].append( _("Domain name is too long.") )
            else:
                d['ERROR'].append( _('Please use alpha characters in domain name!') )

        if d['ERROR']:
            return self.render('instance/domain_edit.html', **d)

        # Updated instance subdomain value
        inst.subdomain = subdomain
        self.db2.commit()

        # Binding in nginx
        from tool.domain import binding_domain_in_nginx
        ret, reason = binding_domain_in_nginx(
            self.db2, inst.id, domain = self.get_domain(inst) )
        if not ret:
            d['ERROR'] = _('binding domain error: %s') % reason

        if not inst.config:
            inst.init_config()

        config = json.loads(inst.config)
            
        if 'domain' in config.keys():
            domain = config['domain']
        else:
            domain = {}

        domain['name'] = self.get_domain( inst )
        domain['ip'] = inst.access_ip
        config['domain'] = domain

        inst.config = json.dumps( config )

        inst.updated = datetime.utcnow()
        if inst.is_running:
            inst.ischanged = True
        self.db2.commit()

        url = self.reverse_url('instance:view', inst.id)
        url += '?view=domain'
        return self.redirect(url)
Ejemplo n.º 7
0
    def post_domain(self, I):

        d = self.d
        d['ERROR'] = []

        sub, d['topdomain'] = get_default_domain(self.db2, I.id)

        if d['topdomain']:
            oldsub = I.subdomain if I.subdomain else sub

        subdomain = self.get_argument('subdomain', None)
        if not subdomain:
            d['ERROR'].append( self.trans(_('Domain is not configured!')) )

        if subdomain != oldsub:
            d['subdomain'] = subdomain
            if subdomain.isalpha():
                exist_domain = self.db2.query(Instance.id).filter_by(
                    subdomain = subdomain ).first()
                if exist_domain:
                    d['ERROR'].append( self.trans(_('Domain name is taken!')) )
                if len(subdomain) > 16:
                    d['ERROR'].append( self.trans(_("Domain name is too long.")) )
            else:
                d['ERROR'].append( self.trans(_('Please use alpha characters in domain name!')) )

        if d['ERROR']:
            return self.render('myun/instance/edit_domain.html', **d)

        # Updated instance subdomain value
        I.subdomain = subdomain
        self.db2.commit()

        fulldomain = '.'.join([subdomain, d['topdomain']])

        # Binding in nginx
        from tool.domain import binding_domain_in_nginx
        ret, reason = binding_domain_in_nginx(
            self.db2, I.id, domain = fulldomain )
        if not ret:
            d['ERROR'].append(_('binding domain error: %s') % reason )

        if not I.config:
            I.init_config()

        config = json.loads(I.config)
            
        if 'domain' in config.keys():
            domain = config['domain']
        else:
            domain = {}

        domain['name'] = fulldomain
        domain['ip'] = I.access_ip
        config['domain'] = domain

        I.config = json.dumps( config )

        I.updated = datetime.now()
        if I.is_running:
            I.ischanged = True
        self.db2.commit()

        if d['ERROR']:
            self.render('myun/instance/edit_domain.html', **d)
        else:
            url = self.reverse_url('myun:instance:view', I.id)
            url += '?tab=domain'
            self.redirect( url )
Ejemplo n.º 8
0
    def post(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst: return

        d = { 'title': _('Configure Domain'),
              'instance': inst, 'ERROR': [] }

        oldsub, d['topdomain'] = self.get_domain2( inst )

        subdomain = self.get_argument('subdomain', None)
        if not subdomain:
            d['ERROR'].append( _('Domain is not configured!') )

        if subdomain != oldsub:
            d['subdomain'] = subdomain
            if subdomain.isalpha():
                exist_domain = self.db2.query(Instance.id).filter_by(
                    subdomain = subdomain ).first()
                if exist_domain:
                    d['ERROR'].append( _('Domain name is taken!') )
                if len(subdomain) > 16:
                    d['ERROR'].append( _("Domain name is too long.") )
            else:
                d['ERROR'].append( _('Please use alpha characters in domain name!') )

        if d['ERROR']:
            return self.render('instance/domain_edit.html', **d)

        # Updated instance subdomain value
        inst.subdomain = subdomain
        self.db2.commit()

        # Binding in nginx
        from tool.domain import binding_domain_in_nginx
        ret, reason = binding_domain_in_nginx(
            self.db2, inst.id, domain = self.get_domain(inst) )
        if not ret:
            d['ERROR'] = _('binding domain error: %s') % reason

        if not inst.config:
            inst.init_config()

        config = json.loads(inst.config)
            
        if 'domain' in config.keys():
            domain = config['domain']
        else:
            domain = {}

        domain['name'] = self.get_domain( inst )
        domain['ip'] = inst.access_ip
        config['domain'] = domain

        inst.config = json.dumps( config )

        inst.updated = datetime.utcnow()
        if inst.is_running:
            inst.ischanged = True
        self.db2.commit()

        url = self.reverse_url('instance:view', inst.id)
        url += '?view=domain'
        return self.redirect(url)
Ejemplo n.º 9
0
    def post(self, id):

        inst = self.get_instance(id, isowner=True)
        if not inst:
            return

        d = {"title": _("Configure Domain"), "instance": inst, "ERROR": []}

        oldsub, d["topdomain"] = self.get_domain2(inst)

        subdomain = self.get_argument("subdomain", None)
        if not subdomain:
            d["ERROR"].append(_("Domain is not configured!"))

        if subdomain != oldsub:
            d["subdomain"] = subdomain
            if subdomain.isalpha():
                exist_domain = self.db2.query(Instance.id).filter_by(subdomain=subdomain).first()
                if exist_domain:
                    d["ERROR"].append(_("Domain name is taken!"))
                if len(subdomain) > 16:
                    d["ERROR"].append(_("Domain name is too long."))
            else:
                d["ERROR"].append(_("Please use alpha characters in domain name!"))

        if d["ERROR"]:
            return self.render("instance/domain_edit.html", **d)

        # Updated instance subdomain value
        inst.subdomain = subdomain
        self.db2.commit()

        # Binding in nginx
        from tool.domain import binding_domain_in_nginx

        ret, reason = binding_domain_in_nginx(self.db2, inst.id, domain=self.get_domain(inst))
        if not ret:
            d["ERROR"] = _("binding domain error: %s") % reason

        if not inst.config:
            inst.init_config()

        config = json.loads(inst.config)

        if "domain" in config.keys():
            domain = config["domain"]
        else:
            domain = {}

        domain["name"] = self.get_domain(inst)
        domain["ip"] = inst.access_ip
        config["domain"] = domain

        inst.config = json.dumps(config)

        inst.updated = datetime.utcnow()
        if inst.is_running:
            inst.ischanged = True
        self.db2.commit()

        url = self.reverse_url("instance:view", inst.id)
        url += "?view=domain"
        return self.redirect(url)