diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-31 13:05:47 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-31 13:05:47 -0500 |
commit | 0d626d668ba6c14022ca88611aff2365cbe4f30c (patch) | |
tree | f3312bbf41165733b8edc111618bf82b38cd3cec /hscript/disk.cc | |
parent | bd078146c3b2ab4fb8011e67d9d5c9016bb9d09b (diff) | |
download | horizon-0d626d668ba6c14022ca88611aff2365cbe4f30c.tar.gz horizon-0d626d668ba6c14022ca88611aff2365cbe4f30c.tar.bz2 horizon-0d626d668ba6c14022ca88611aff2365cbe4f30c.tar.xz horizon-0d626d668ba6c14022ca88611aff2365cbe4f30c.zip |
hscript: Implement lvm_lv, add tests
Diffstat (limited to 'hscript/disk.cc')
-rw-r--r-- | hscript/disk.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc index a8c70db..a54b36d 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -550,6 +550,62 @@ bool LVMGroup::execute(ScriptOptions) const { } +Key *LVMVolume::parseFromData(const std::string &data, int lineno, int *errors, + int *) { + std::string vg, name, size_str; + std::string::size_type name_start, size_start; + SizeType size_type; + uint64_t size; + + long spaces = std::count(data.cbegin(), data.cend(), ' '); + if(spaces != 2) { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "lvm_lv: expected 3 elements, got: " + + std::to_string(spaces), + "syntax is: lvm_lv [vg] [name] [size]"); + return nullptr; + } + + name_start = data.find_first_of(' '); + vg = data.substr(0, name_start); + size_start = data.find_first_of(' ', name_start + 1); + name = data.substr(name_start + 1, size_start - name_start - 1); + size_str = data.substr(size_start + 1); + + if(!is_valid_lvm_name(vg)) { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "lvm_lv: invalid volume group name"); + return nullptr; + } + + if(!is_valid_lvm_lv_name(name)) { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "lvm_lv: invalid volume name"); + return nullptr; + } + + if(!parse_size_string(size_str, &size, &size_type)) { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "lvm_lv: invalid size", size_str); + return nullptr; + } + + return new LVMVolume(lineno, vg, name, size_type, size); +} + +bool LVMVolume::validate(ScriptOptions) const { + return true; +} + +bool LVMVolume::execute(ScriptOptions) const { + return false; +} + + Key *Mount::parseFromData(const std::string &data, int lineno, int *errors, int *warnings) { std::string dev, where, opt; |