コード例 #1
0
        public AssetGlusterModule()
        {
            Get["/gluster"] = x => {
                var model = new PageGlusterModel {
                    Gluster = GlusterConfiguration.Get()
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/gluster/set"] = x => {
                GlusterConfiguration.Set();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/restart"] = x => {
                GlusterConfiguration.Launch();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/stop"] = x => {
                GlusterConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/enable"] = x => {
                GlusterConfiguration.Enable();
                GlusterConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/disable"] = x => {
                GlusterConfiguration.Disable();
                GlusterConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/save"] = x => {
                string config = Request.Form.Config;
                var    model  = JsonConvert.DeserializeObject <GlusterConfigurationModel>(config);
                GlusterConfiguration.Save(model);
                return(HttpStatusCode.OK);
            };
        }
コード例 #2
0
ファイル: AntdGlusterModule.cs プロジェクト: pk8est/Antd
        public AntdGlusterModule()
        {
            Get["/gluster"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                var glusterIsActive      = glusterConfiguration.IsActive();
                var model = new PageGlusterModel {
                    GlusterIsActive = glusterIsActive,
                    Nodes           = glusterConfiguration.Get()?.Nodes,
                    Volumes         = glusterConfiguration.Get()?.Volumes
                };
                return(JsonConvert.SerializeObject(model));
            };

            Post["/gluster/set"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Set();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/restart"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/stop"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/enable"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Enable();
                glusterConfiguration.Start();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/disable"] = x => {
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Disable();
                glusterConfiguration.Stop();
                return(HttpStatusCode.OK);
            };

            Post["/gluster/options"] = x => {
                string nodes                = Request.Form.GlusterNode;
                var    nodelist             = nodes.Split(new[] { "," }, StringSplitOptions.None).ToList();
                string volumeNames          = Request.Form.GlusterVolumeName;
                string volumeBrick          = Request.Form.GlusterVolumeBrick;
                string volumeMountPoint     = Request.Form.GlusterVolumeMountPoint;
                var    volumeNamesList      = volumeNames.Split(new[] { "," }, StringSplitOptions.None);
                var    volumeBrickList      = volumeBrick.Split(new[] { "," }, StringSplitOptions.None);
                var    volumeMountPointList = volumeMountPoint.Split(new[] { "," }, StringSplitOptions.None);
                var    volumelist           = new List <GlusterVolume>();
                for (var i = 0; i < 20; i++)
                {
                    if (volumeNamesList.Length < i - 1 ||
                        volumeBrickList.Length < i - 1 ||
                        volumeMountPointList.Length < i - 1)
                    {
                        continue;
                    }
                    try {
                        var vol = new GlusterVolume {
                            Name       = volumeNamesList[i],
                            Brick      = volumeBrickList[i],
                            MountPoint = volumeMountPointList[i],
                        };
                        volumelist.Add(vol);
                    }
                    catch (Exception) {
                        continue;
                    }
                }
                var config = new GlusterConfigurationModel {
                    Nodes   = nodelist.ToArray(),
                    Volumes = volumelist.ToArray()
                };
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.Save(config);
                return(HttpStatusCode.OK);
            };

            Post["/gluster/node"] = x => {
                string node = Request.Form.Node;
                if (string.IsNullOrWhiteSpace(node))
                {
                    return(HttpStatusCode.BadRequest);
                }
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.AddNode(node);
                return(HttpStatusCode.OK);
            };

            Post["/gluster/node/del"] = x => {
                string node = Request.Form.Node;
                if (string.IsNullOrWhiteSpace(node))
                {
                    return(HttpStatusCode.BadRequest);
                }
                var glusterConfiguration = new GlusterConfiguration();
                glusterConfiguration.RemoveNode(node);
                return(HttpStatusCode.OK);
            };
        }