aboutsummaryrefslogtreecommitdiff
path: root/src/property/disk.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-06-03 12:54:58 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-06-03 13:18:22 -0700
commit73123bca4266051f6d6819670498ec6baa37699d (patch)
treeba461ddcc5f49c016bd4b17a896ca925a5248956 /src/property/disk.lisp
parentf5ca06034de2419af05cbe7a5e738ce0353f7c52 (diff)
downloadconsfigurator-73123bca4266051f6d6819670498ec6baa37699d.tar.gz
factor out and export DISK:PARSE-VOLUME-SIZE
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/disk.lisp')
-rw-r--r--src/property/disk.lisp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/property/disk.lisp b/src/property/disk.lisp
index 1b42504..c3db619 100644
--- a/src/property/disk.lisp
+++ b/src/property/disk.lisp
@@ -969,6 +969,20 @@ Currently only handling of LVM logical volumes is implemented."
;;;; Utilities
+(defun parse-volume-size (volume-size-specification)
+ (if (stringp volume-size-specification)
+ (multiple-value-bind (match groups)
+ (re:scan-to-strings #?/\A([0-9]+)([MGT])?\z/ volume-size-specification)
+ (unless match
+ (simple-program-error
+ "~A is not a valid volume size." volume-size-specification))
+ (* (parse-integer (elt groups 0))
+ (eswitch ((elt groups 1) :test #'string=)
+ ("M" 1)
+ ("G" 1024)
+ ("T" 1048576))))
+ volume-size-specification))
+
(defmacro volumes (&body volume-specifications)
"Return a list of instances of VOLUME, one for each element of
VOLUME-SPECIFICATIONS. Each of VOLUME-SPECIFICATIONS is an (unquoted) list of
@@ -1015,20 +1029,9 @@ Example usage:
(if contentsp (butlast (cdr spec)) (cdr spec)))
(contents (and contentsp (lastcar (cdr spec)))))
(when (loop for key on initargs by #'cddr
- thereis (and (eql (car key) :volume-size)
- (stringp (cadr key))))
- (let ((input (getf initargs :volume-size)))
- (multiple-value-bind (match groups)
- (re:scan-to-strings #?/\A([0-9]+)([MGT])?\z/ input)
- (unless match
- (simple-program-error
- "~A is not a valid volume size." input))
- (setf (getf initargs :volume-size)
- (* (parse-integer (elt groups 0))
- (eswitch ((elt groups 1) :test #'string=)
- ("M" 1)
- ("G" 1024)
- ("T" 1048576)))))))
+ thereis (and (eql (car key) :volume-size)))
+ (setf (getf initargs :volume-size)
+ `(parse-volume-size ,(getf initargs :volume-size))))
(when (and contents (not (listp contents)))
(simple-program-error "~A is not a list." contents))
`(make-instance