Beispiel #1
0
    def create_ramdisk(self, mountpoint, size):
        # ensure serverdir exists
        if not os.path.exists(mountpoint):
            os.makedirs(mountpoint)

        # see if it's already mounted
        if mountutil.is_mounted(mountpoint) == True:
            log(2, "%s was already mounted, unmounting")
            mountutil.unmount(mountpoint)

        # create the ramdisk and mount it at SERVERDIR
        mount_cmd = ["mount", "-t", "tmpfs", "-o", \
                "size=" + str(size) + "M", "tmpfs", mountpoint]

        popenutil.quick_popen(mount_cmd)
Beispiel #2
0
    def mount_bmp(self, username, server):
        #_name, server_mount_point):
        log(6, "mount_bmp")
        bind_mount_point = os.path.join(self.home_source, \
                username, self.BMP_DIR, server.server_name)

        if mountutil.is_mounted(bind_mount_point) == True:
            log(3, "BMP already mounted: %s" % bind_mount_point)
            return

        cmd = ["mount", "-o", "bind", server.mount_point, \
              bind_mount_point]

        popenutil.quick_popen(cmd)

        server.add_bind_mount(username, bind_mount_point)
Beispiel #3
0
    def mount(self, server, uid=0, gid=0):
        """Mount the SSHFSServer in _server_ to
           _server.mount_point_"""

        # TODO: if we can control the read/write from the Fuse module
        # Then we don't need this code
        # TODO: remove when we're confident we dont need this, put it
        # back if we do
        # gid = str(grp.getgrnam("x_%s" % sid)[2])

        # TODO: the purpose of this is to accept the initial host key
        # instead we should ajaxify the user interface and ask the
        # user whether the host key is correct
        do_strict_key_check = "no"
        for host in paramiko.util.load_host_keys(
                xsftp.common.constants.KNOWN_HOSTS_FILE).keys():
            components = host.split(':')
            host_name = components[0].replace("[","").replace("]","")
            if len(components) == 1:
                port = 22
            elif len(components) == 2:
                port = int(components[1])

            if server.address == host_name and server.port == port:
                log(4, "Found match for '%s:%s' in known_hosts," + 
                        " performing strict key check" % (address, port))
                do_strict_key_check = "yes"

        # All the parameters passed to -o
        params = {}
        # static params
        params["port"] = server.port
        params["compression"] = "yes"
        params["cache"] = "no"
        params["default_permissions"] = None
        params["umask"] = "002"
        params["nonempty"] = None
        params["reconnect"] = None
        params["allow_other"] = None
        params["ServerAliveInterval"] = 3
        # variable params
        params["uid"] = uid
        params["gid"] = gid
        params["UserKnownHostsFile"] = xsftp.common.constants.KNOWN_HOSTS_FILE
        params["IdentityFile"] = xsftp.webui.constants.KEY_FILE_LOCATION
        # TODO implement a pexpect wrapper around sshfs that takes into account
        # the below param "password" for interactive autentication
        params["password"] = None 
        params["StrictHostKeyChecking"] = do_strict_key_check


        # join the params into a string
        # converting it to an array is more efficient than just
        # catting the strings
        options = []
        for key, value in params.items():
            if value == None:
                options.append(key)
            else:
                options.append("%s=%s" % (key, str(value)))

        options_str = ",".join(options)

        uri = "%s@%s:%s" % (server.username, server.hostname, \
                server.remote_path)
        cmd = ["sshfs", "-o", options_str, uri, server.mount_point]

        popenutil.quick_popen(cmd)
        log(1, "Server Link '%s' successfully established." %
                server.server_name)
Beispiel #4
0
    def unmount(self, server):
        """The default unmounter suits most server types"""
        cmd = ["umount", "-l", "-f", server.mount_point]

        popenutil.quick_popen(cmd)
Beispiel #5
0
    def unmount_bmp(self, bind_mount_point):
        cmd = ["umount", "-l", "-f", bind_mount_point]

        popenutil.quick_popen(cmd)