1 module glustercli.volume; 2 3 import glustercli.volume_parser; 4 import glustercli.utils; 5 6 struct VolumeCreateOptions 7 { 8 int replicaCount; 9 int arbiterCount; 10 int disperseCount; 11 int disperseRedundancyCount; 12 int disperseDataCount; 13 string transport; 14 bool force; 15 } 16 17 void volumeCreate(string volname, string[] bricks, VolumeCreateOptions opts) 18 { 19 import std.format; 20 21 auto cmd = ["volume", "create", volname]; 22 if (opts.replicaCount > 0) 23 cmd ~= ["replica", format!"%d"(opts.replicaCount)]; 24 25 if (opts.arbiterCount > 0) 26 cmd ~= ["arbiter", format!"%d"(opts.arbiterCount)]; 27 28 if (opts.disperseCount > 0) 29 cmd ~= ["disperse", format!"%d"(opts.disperseCount)]; 30 31 if (opts.disperseDataCount > 0) 32 cmd ~= ["disperse-data", format!"%d"(opts.disperseDataCount)]; 33 34 if (opts.disperseRedundancyCount > 0) 35 cmd ~= ["redundancy", format!"%d"(opts.disperseRedundancyCount)]; 36 37 if (opts.transport != "tcp" && opts.transport != "") 38 cmd ~= ["transport", opts.transport]; 39 40 cmd ~= bricks; 41 42 if (opts.force) 43 cmd ~= ["force"]; 44 45 executeGlusterCmd(cmd); 46 } 47 48 void volumeStart(string volname, bool force=false) 49 { 50 auto cmd = ["volume", "start", volname]; 51 if (force) 52 cmd ~= ["force"]; 53 54 executeGlusterCmd(cmd); 55 } 56 57 void volumeStop(string volname, bool force=false) 58 { 59 auto cmd = ["volume", "stop", volname]; 60 if (force) 61 cmd ~= ["force"]; 62 63 executeGlusterCmd(cmd); 64 } 65 66 void volumeRestart(string volname) 67 { 68 volumeStop(volname, true); 69 volumeStart(volname, true); 70 } 71 72 void volumeDelete(string volname) 73 { 74 executeGlusterCmd(["volume", "delete", volname]); 75 } 76 77 // void getVolumeOption(string volname, string optname) 78 // { 79 // TODO: parse volume option 80 // auto cmd = ["volume", "get", volname, optname]; 81 // } 82 83 void volumeSetOption(string volname, string[string] opts) 84 { 85 auto cmd = ["volume", "set", volname]; 86 foreach(keyval; opts.byKeyValue()) 87 cmd ~= [keyval.key, keyval.value]; 88 89 executeGlusterCmd(cmd); 90 } 91 92 void volumeResetOption(string volname, string opt, bool force) 93 { 94 auto cmd = ["reset", volname]; 95 96 if (opt != "") 97 cmd ~= opt; 98 99 if (force) 100 cmd ~= "force"; 101 102 executeGlusterCmd(cmd); 103 } 104 105 void volumeResetOption(string volname, string opt) 106 { 107 volumeResetOption(volname, opt, false); 108 } 109 110 void volumeResetOption(string volname, bool force) 111 { 112 volumeResetOption(volname, "", force); 113 } 114 115 void volumeResetOption(string volname) 116 { 117 volumeResetOption(volname, "", false); 118 } 119 120 string[] volumeList() 121 { 122 return executeGlusterCmd(["volume", "list"]); 123 } 124 125 Volume[] volumeInfo(string volname) 126 { 127 auto cmd = ["volume", "info"]; 128 if (volname != "") 129 cmd ~= volname; 130 131 auto outlines = executeGlusterCmdXml(cmd); 132 Volume[] volumes; 133 parseVolumesFromVolinfo(outlines, volumes); 134 return volumes; 135 } 136 137 Volume[] volumeStatus(string volname) 138 { 139 auto cmd = [ 140 "volume", "status", 141 volname == "" ? "all" : volname, 142 "detail" 143 ]; 144 145 auto outlines = executeGlusterCmdXml(cmd); 146 147 auto volumes = volumeInfo(volname); 148 parseVolumesFromStatus(outlines, volumes); 149 return volumes; 150 } 151 152 Volume[] volumeInfo() 153 { 154 return volumeInfo(""); 155 } 156 157 Volume[] volumeStatus() 158 { 159 return volumeStatus(""); 160 }