Пример #1
0
  def action_create(self):
    path = self.resource.path
    
    if sudo.path_isdir(path):
      raise Fail("Applying %s failed, directory with name %s exists" % (self.resource, path))
    
    dirname = os.path.dirname(path)
    if not sudo.path_isdir(dirname):
      raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
    
    write = False
    content = self._get_content()
    if not sudo.path_exists(path):
      write = True
      reason = "it doesn't exist"
    elif self.resource.replace:
      if content is not None:
        old_content = sudo.read_file(path, encoding=self.resource.encoding)
        if content != old_content:
          write = True
          reason = "contents don't match"
          if self.resource.backup:
            self.resource.env.backup_file(path)

    if write:
      Logger.info("Writing %s because %s" % (self.resource, reason))
      sudo.create_file(path, content, encoding=self.resource.encoding)

    _ensure_metadata(self.resource.path, self.resource.owner,
                        self.resource.group, mode=self.resource.mode, cd_access=self.resource.cd_access)
Пример #2
0
  def get_content(self):
    if self.download_path and not os.path.exists(self.download_path):
      raise Fail("Directory {0} doesn't exist, please provide valid download path".format(self.download_path))
    
    if urlparse.urlparse(self.url).path:
      filename = os.path.basename(urlparse.urlparse(self.url).path)
    else:
      filename = 'index.html.{0}'.format(time.time())
      
    filepath = os.path.join(self.download_path, filename)
    
    if not self.cache or not os.path.exists(filepath):
      Logger.info("Downloading the file from {0}".format(self.url))
      
      if self.ignore_proxy:
        opener = urllib2.build_opener(urllib2.ProxyHandler({}))
      else:
        opener = urllib2.build_opener()
      
      req = urllib2.Request(self.url)
      
      try:
        web_file = opener.open(req)
      except urllib2.HTTPError as ex:
        raise Fail("Failed to download file from {0} due to HTTP error: {1}".format(self.url, str(ex)))
      
      content = web_file.read()
      
      if self.cache:
        sudo.create_file(filepath, content)
    else:
      Logger.info("Not downloading the file from {0}, because {1} already exists".format(self.url, filepath))
      content = sudo.read_file(filepath)

    return content
Пример #3
0
  def action_create(self):
    path = self.resource.path
    
    if sudo.path_isdir(path):
      raise Fail("Applying %s failed, directory with name %s exists" % (self.resource, path))
    
    dirname = os.path.dirname(path)
    if not sudo.path_isdir(dirname):
      raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
    
    write = False
    content = self._get_content()
    if not sudo.path_exists(path):
      write = True
      reason = "it doesn't exist"
    elif self.resource.replace:
      if content is not None:
        old_content = sudo.read_file(path, encoding=self.resource.encoding)
        if content != old_content:
          write = True
          reason = "contents don't match"
          if self.resource.backup:
            self.resource.env.backup_file(path)

    if write:
      Logger.info("Writing %s because %s" % (self.resource, reason))
      sudo.create_file(path, content, encoding=self.resource.encoding)

    _ensure_metadata(self.resource.path, self.resource.owner,
                        self.resource.group, mode=self.resource.mode, cd_access=self.resource.cd_access)
Пример #4
0
 def _configure_pg_hba_ambaridb_users(conf_file, database_username):
   conf_file_content_in = sudo.read_file(conf_file)
   conf_file_content_out = conf_file_content_in
   conf_file_content_out += "\n"
   conf_file_content_out += "local  all  " + database_username + ",mapred md5"
   conf_file_content_out += "\n"
   conf_file_content_out += "host  all   " + database_username + ",mapred 0.0.0.0/0  md5"
   conf_file_content_out += "\n"
   conf_file_content_out += "host  all   " + database_username + ",mapred ::/0 md5"
   conf_file_content_out += "\n"
   sudo.create_file(conf_file, conf_file_content_out)
   retcode, out, err = run_os_command(PGConfig.PG_HBA_RELOAD_CMD)
   if not retcode == 0:
     raise FatalException(retcode, err)
Пример #5
0
 def _configure_postgresql_conf():
   listenAddress = "listen_addresses = '*'        #"
   postgresql_conf_file_in = sudo.read_file(PGConfig.POSTGRESQL_CONF_FILE)
   postgresql_conf_file_out = re.sub('#+listen_addresses.*?(#|$)', listenAddress, postgresql_conf_file_in)
   sudo.create_file(PGConfig.POSTGRESQL_CONF_FILE, postgresql_conf_file_out)
   sudo.chmod(PGConfig.POSTGRESQL_CONF_FILE, 0644)
Пример #6
0
 def _configure_pg_hba_postgres_user():
   postgresString = "all   postgres"
   pg_hba_conf_file_content_in = sudo.read_file(PGConfig.PG_HBA_CONF_FILE)
   pg_hba_conf_file_content_out = re.sub('all\s*all', postgresString, pg_hba_conf_file_content_in)
   sudo.create_file(PGConfig.PG_HBA_CONF_FILE, pg_hba_conf_file_content_out)
   sudo.chmod(PGConfig.PG_HBA_CONF_FILE, 0644)