public AntdStorageModule() { Get["/storage"] = x => { var disks = new Disks(); var model = new PageStorageModel { DisksList = disks.GetList() }; return(JsonConvert.SerializeObject(model)); }; Post["/storage/print"] = x => { string disk = Request.Form.Disk; var result = _bash.Execute($"parted /dev/{disk} print 2> /dev/null").SplitBash().Grep("'Partition Table: '").First(); return(Response.AsText(result.Replace("Partition Table: ", ""))); }; Post["/storage/mklabel"] = x => { string disk = Request.Form.Disk; string type = Request.Form.Type; string yn = Request.Form.Confirm; var result = _bash.Execute($"parted -a optimal /dev/{disk} mklabel {type} {yn}"); return(Response.AsText(result)); }; }
public AntdZfsModule() { Get["/zfs"] = x => { var zpool = new Zpool(); var zfsSnap = new ZfsSnap(); var zfs = new Zfs(); var disks = new Disks(); var model = new PageZfsModel { ZpoolList = zpool.List(), ZfsList = zfs.List(), ZfsSnap = zfsSnap.List(), ZpoolHistory = zpool.History(), DisksList = disks.GetList().Where(_ => _.Type == "disk" && string.IsNullOrEmpty(_.Mountpoint)) }; return(JsonConvert.SerializeObject(model)); }; //todo //Get["/zfs/cron"] = x => { // var list = _timerRepository.GetAll(); // return Response.AsJson(list); //}; Post["/zfs/snap"] = x => { string pool = Request.Form.Pool; string interval = Request.Form.Interval; if (string.IsNullOrEmpty(pool) || string.IsNullOrEmpty(interval)) { return(HttpStatusCode.InternalServerError); } _timers.Create(pool + "snap", interval, $"/sbin/zfs snap -r {pool}@${{TTDATE}}"); return(HttpStatusCode.OK); }; //Post["/zfs/snap/disable"] = x => { // string guid = Request.Form.Guid; // var tt = _timerRepository.GetByGuid(guid); // if(tt == null) // return HttpStatusCode.InternalServerError; // _timers.Disable(tt.Alias); // return HttpStatusCode.OK; //}; Post["/zpool/create"] = x => { string altroot = Request.Form.Altroot; string poolname = Request.Form.Name; string pooltype = Request.Form.Type; string disk = Request.Form.Disk; if (string.IsNullOrEmpty(altroot) || string.IsNullOrEmpty(poolname) || string.IsNullOrEmpty(pooltype) || string.IsNullOrEmpty(disk)) { return(HttpStatusCode.BadRequest); } ConsoleLogger.Log($"[zpool] create => altroot:{altroot} poolname:{poolname} pooltype:{pooltype} disk:{disk} "); _launcher.Launch("zpool-create", new Dictionary <string, string> { { "$pool_altroot", altroot }, { "$pool_name", poolname }, { "$pool_type", poolname }, { "$disk", disk } }); return(HttpStatusCode.OK); }; Post["/zfs/create"] = x => { string altroot = Request.Form.Altroot; string poolname = Request.Form.Name; string datasetname = Request.Form.Dataset; if (string.IsNullOrEmpty(altroot) || string.IsNullOrEmpty(poolname) || string.IsNullOrEmpty(datasetname)) { return(HttpStatusCode.BadRequest); } _launcher.Launch("zfs-create", new Dictionary <string, string> { { "$pool_altroot", altroot }, { "$pool_name", poolname }, { "$dataset_name", datasetname } }); return(HttpStatusCode.OK); }; }