def updateMount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AliyunNasResponse() linux.is_valid_nfs_url(cmd.newUrl) if not naslinux.is_mounted(cmd.mountPath, cmd.newUrl): # umount old one if naslinux.is_mounted(cmd.mountPath, cmd.url): linux.umount(cmd.mountPath) # mount new linux.mount(cmd.newUrl, cmd.mountPath, cmd.options) self.mount_path[cmd.uuid] = cmd.mountPath logger.debug('updated the mount path[%s] mounting point from %s to %s' % ( cmd.mountPath, cmd.url, cmd.newUrl)) self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def ismount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = IsMountResponse() linux.is_valid_nfs_url(cmd.url) if naslinux.is_mounted(cmd.mountPath, cmd.url): rsp.ismounted = True return jsonobject.dumps(rsp)
def umount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AliyunNasResponse() if naslinux.is_mounted(path=cmd.mountPath): ret = linux.umount(cmd.mountPath) if not ret: logger.warn(http.path_msg(self.UNMOUNT_PATH, 'unmount %s failed' % cmd.mountPath)) logger.debug(http.path_msg(self.UNMOUNT_PATH, 'umounted %s' % cmd.mountPath)) return jsonobject.dumps(rsp)
def mountdata(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AliyunNasResponse() naslinux.createCommonPath(cmd.mountPath, cmd.basePath) if not naslinux.is_mounted(cmd.dataPath, cmd.url): linux.mount(cmd.url, cmd.dataPath, cmd.options) logger.debug(http.path_msg(self.MOUNT_DATA_PATH, 'mounted %s on %s' % (cmd.url, cmd.dataPath))) rsp.mounted = True self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def mount(self, req): cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = AliyunNasResponse() linux.is_valid_nfs_url(cmd.url) if not naslinux.is_mounted(cmd.mountPath, cmd.url): linux.mount(cmd.url, cmd.mountPath, cmd.options) logger.debug(http.path_msg(self.MOUNT_PATH, 'mounted %s on %s' % (cmd.url, cmd.mountPath))) rsp.mounted = True self.mount_path[cmd.uuid] = cmd.mountPath self._set_capacity_to_response(cmd.uuid, rsp) return jsonobject.dumps(rsp)
def init(self, req): ''' cmd.url --> domain:/ps-[uuid] cmd.mountPath --> /opt/ps cmd.common --> /opt/ps/commons cmd.data --> /opt/ps/datas cmd.dirs --> [] ''' cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = InitResponse() linux.is_valid_nfs_url(cmd.url) ''' example: 1. mount url: /opt/ps 2. mkdir /opt/ps/ps-[uuid] 3. mkdir /opt/ps/ps-[uuid]/commons/xxx.. (such as heartbeat, cache, ..) at last we get url:/ps-[uuid] for hosts mount ''' domain = cmd.url.split(':')[0] + ":/" psDir = cmd.url.split(':')[1].lstrip('/') basedir = os.path.join(cmd.mountPath, psDir) ''' check if mounted {cmd.mountPath} ''' if linux.is_mounted(path=cmd.mountPath) and not naslinux.is_mounted( cmd.mountPath, cmd.url): raise Exception('mountPath[%s] already mount to another url' % cmd.mountPath) linux.mount(domain, cmd.mountPath, cmd.options) shell.call('mkdir -p %s' % basedir) for dir in cmd.dirs: shell.call('mkdir -p %s' % os.path.join(basedir, dir)) linux.umount(cmd.mountPath) common_dir = os.path.join(cmd.mountPath, cmd.common) data_dir = os.path.join(cmd.mountPath, cmd.data) shell.call('mkdir -p %s' % common_dir) shell.call('mkdir -p %s' % data_dir) linux.mount(cmd.url, common_dir, cmd.options) rsp.mounted = True self.mount_path[cmd.uuid] = common_dir self._set_capacity_to_response(cmd.uuid, rsp) self.uuid = cmd.uuid return jsonobject.dumps(rsp)
def init(self, req): ''' cmd.url --> domain:/ps-[uuid] cmd.mountPath --> /opt/ps cmd.common --> /opt/ps/commons cmd.data --> /opt/ps/datas cmd.dirs --> [] ''' cmd = jsonobject.loads(req[http.REQUEST_BODY]) rsp = InitResponse() linux.is_valid_nfs_url(cmd.url) ''' example: 1. mount url: /opt/ps 2. mkdir /opt/ps/ps-[uuid] 3. mkdir /opt/ps/ps-[uuid]/commons/xxx.. (such as heartbeat, cache, ..) at last we get url:/ps-[uuid] for hosts mount ''' domain = cmd.url.split(':')[0] + ":/" psDir = cmd.url.split(':')[1].lstrip('/') basedir = os.path.join(cmd.mountPath, psDir) ''' check if mounted {cmd.mountPath} ''' if linux.is_mounted(path=cmd.mountPath) and not naslinux.is_mounted(cmd.mountPath, cmd.url): raise Exception('mountPath[%s] already mount to another url' % cmd.mountPath) linux.mount(domain, cmd.mountPath, cmd.options) shell.call('mkdir -p %s' % basedir) for dir in cmd.dirs: shell.call('mkdir -p %s' % os.path.join(basedir, dir)) linux.umount(cmd.mountPath) common_dir = os.path.join(cmd.mountPath, cmd.common) data_dir = os.path.join(cmd.mountPath, cmd.data) shell.call('mkdir -p %s' % common_dir) shell.call('mkdir -p %s' % data_dir) linux.mount(cmd.url, common_dir, cmd.options) rsp.mounted = True self.mount_path[cmd.uuid] = common_dir self._set_capacity_to_response(cmd.uuid, rsp) self.uuid = cmd.uuid return jsonobject.dumps(rsp)