Example #1
0
 def _create_data_location(self):
     data_dir = sh.joinpths(self.get_option("app_dir"), self.cfg.getdefaulted("swift", "data_location", "data"))
     fs_image = sh.joinpths(data_dir, SWIFT_IMG)
     fs_dev = sh.joinpths(data_dir, DEVICE_PATH)
     loop_size = self.cfg.get("swift", "loopback_disk_size")
     if not loop_size:
         loop_size = DEF_LOOP_SIZE
     else:
         loop_size = utils.to_bytes(loop_size)
     sh.create_loopback_file(fname=fs_image, size=loop_size, fs_type=FS_TYPE)
     self.tracewriter.file_touched(fs_image)
     sh.mount_loopback_file(fs_image, fs_dev, FS_TYPE)
     sh.chown_r(fs_dev, sh.geteuid(), sh.getegid())
Example #2
0
def store_current_settings(settings):
    base_dir = sh.dirname(SETTINGS_FN)
    if not sh.isdir(base_dir):
        # Don't use sh here so that we always
        # read this (even if dry-run)    
        os.makedirs(base_dir)
    try:
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(settings)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown_r(base_dir, uid, gid)
    except Exception as e:
        pass
Example #3
0
 def configure(self):
     files = self._configure_files()
     if sh.isdir(self.cfg_dir):
         uid = None
         gid = None
         try:
             uid = sh.getuid(self.name)
             gid = sh.getgid(self.name)
         except (KeyError, AttributeError):
             LOG.warn("Unable to find uid & gid for user & group %s", self.name)
         if uid is not None and gid is not None:
             try:
                 sh.chown_r(self.cfg_dir, uid, gid)
             except Exception as e:
                 LOG.warn("Failed to change the ownership of %s to %s:%s due to: %s",
                          self.cfg_dir, uid, gid, e)
     return files
Example #4
0
def ensure_anvil_dir():
    if not sh.isdir(ANVIL_DIR):
        with sh.Rooted(True):
            os.makedirs(ANVIL_DIR)
            (uid, gid) = sh.get_suids()
            sh.chown_r(ANVIL_DIR, uid, gid)
Example #5
0
def ensure_anvil_dir():
    if not sh.isdir(ANVIL_DIR):
        with sh.Rooted(True):
            os.makedirs(ANVIL_DIR)
            (uid, gid) = sh.get_suids()
            sh.chown_r(ANVIL_DIR, uid, gid)