示例#1
0
 def launch(self,
            type,
            status,
            command,
            cwd=None,
            callback=None,
            shell=False,
            replace=False,
            env=None,
            module="agent"):
     """ wrapper to run non blocking shell commands """
     thread = self.get_thread(type, module)
     # stop the current thread if replace is True
     if replace and thread:
         thread.stop()
         logger.debug("Stopping %s thread of module %s" % (type, module))
     if not thread or not thread.isAlive():
         # remove previoud thread
         if thread:
             self.threads.remove(thread)
         if not env:
             env = {}
         if not 'LC_ALL' in env:
             env['LC_ALL'] = TranslationManager().lang
         thread = ProcessThread(type, status, module, command, cwd,
                                callback, shell, env)
         self.threads.append(thread)
         logger.debug("Create %s thread for module %s" % (type, module))
         logger.debug("Command is: %s" % " ".join(command))
         thread.start()
     else:
         # let the thread finish
         pass
示例#2
0
    def __init__(self):
        if platform.machine() == 'x86_64':
            self.arch = 'x86_64'
        else:
            self.arch = 'i586'

        # Setup BDD access
        self.session = get_session(Config().db_file)

        self._token = False
        self._mode = None
        self.modules = {}
        self.sections_modules = {}
        self.sections = {}
        self.packages = []

        # Get machine-id
        with open('/etc/machine-id', 'r') as f:
            machine_id = f.read().strip()
        logger.info("Machine id is %s" % machine_id)
        self.set_option("machine-id", machine_id)
        # Translation manager
        TranslationManager().set_catalog('agent', os.path.join(os.path.dirname(__file__), '..'))
        # Load packages
        self.load_packages()
示例#3
0
    def request(self, url, params=None):
        """
        Used to query the ServicePlace API

        Handles token and language headers
        """
        if params:
            params = urllib.urlencode(params)
        request = urllib2.Request(url, params)
        if self._token:
            request.add_header('Authorization', 'Token ' + self._token)
        request.add_header('Accept-Language', TranslationManager().get_lang().split('_')[0] + ',en')
        try:
            response = urllib2.urlopen(request)
            if response.info().gettype() == "application/json":
                result = json.loads(response.read())
            else:
                result = response.read()
            code = response.getcode()
        except urllib2.HTTPError as e:
            code = e.code
            result = ""
            if code in (404, 500):
                raise xmlrpclib.Fault(code, _("Connection failed with the ServicePlace.", "agent"))
        except urllib2.URLError as e:
            logger.exception("URL error")
            raise xmlrpclib.Fault(777, str(e.reason))

        logger.debug("Return code %s" % code)
        return (result, code)
示例#4
0
 def run_script(self, script, args, cwd, module, callback):
     """ launch configuration script for module """
     env = {'TEXTDOMAIN': module,
            'TEXTDOMAINDIR': os.path.join(TranslationManager().get_catalog_path(module), 'locale')}
     if os.path.exists(os.path.join(cwd, script)):
         self.launch("config",
                     _("Running configuration"),
                     ["bash", script] + args, cwd=cwd,
                     module=module, env=env, callback=callback)
         return True
     else:
         return False
示例#5
0
 def run(self):
     """ run command """
     if self.params:
         self.params = urllib.urlencode(self.params)
     request = urllib2.Request(self.url, self.params)
     for header in self.headers:
         request.add_header(header[0], header[1])
     request.add_header('Accept-Language', TranslationManager().get_lang().split('_')[0] + ',en')
     try:
         response = urllib2.urlopen(request)
     except urllib2.HTTPError as e:
         logger.error("HTTP Error: %s (%s))" % (str(e.reason), self.url))
         self._code = e.code
     except urllib2.URLError as e:
         logger.error("URL Error: %s (%s))" % (str(e.reason), self.url))
         self._code = 500
     else:
         start = time.time()
         logger.debug("Start: %s" % str(start))
         self.chunk_read(response, report_hook=self.chunk_report)
         end = time.time()
         logger.debug("End: %s" % str(end))
         logger.debug("Last: %ss" % str(end - start))
示例#6
0
文件: __init__.py 项目: neoclust/mss
import re
from mss.agent.managers.translation import TranslationManager
from mss.agent.lib.utils import get_domain
import netifaces
from IPy import IP

_ = TranslationManager().translate


def get_config_info():
    return ("setup-samba4.sh", [
        "smb_mode", "smb_domain", 'admin', "smb_passwd", "net", "dns_ip",
        "smb_forwarder"
    ])


def valid_domain(string):
    """Validate domain input"""
    from socket import gethostname
    hostname = gethostname()

    if not re.match("^[A-Z0-9-]+(\\.[A-Z0-9-]+)*(\\.[A-Z]{2,})$", string,
                    re.IGNORECASE):
        return _(
            "Incorrect SAMBA domain name, use only alphanumeric characters and dots.",
            "mds_samba4")
    elif string.split('.')[0] == hostname:
        return _(
            "Incorrect SAMBA domain name, Must NOT start with short host name.",
            "mds_samba4")
    else:
示例#7
0
文件: module.py 项目: neoclust/mss
 def load_translations(self):
     TranslationManager().set_catalog(self.slug, self._path)
示例#8
0
 def get_lang(self):
     """ return current language """
     return TranslationManager().get_lang()
示例#9
0
 def set_lang(self, lang):
     """ change lang during execution """
     TranslationManager().set_lang(lang)
示例#10
0
文件: module.py 项目: neoclust/mss
 def set_lang(self, lang):
     """ change lang during execution """
     TranslationManager().locale_name = lang