Class: Pvectl::Services::EditVolume
- Inherits:
-
Object
- Object
- Pvectl::Services::EditVolume
- Defined in:
- lib/pvectl/services/edit_volume.rb
Overview
Orchestrates the interactive volume property editing flow.
Fetches the disk config string from VM/CT config, parses it into editable YAML (key-value pairs), opens editor, and applies changes. Size changes delegate to ResizeVolume; config changes rebuild the disk config string.
Instance Method Summary collapse
-
#execute(id:, disk:, node:) ⇒ Models::VolumeOperationResult?
Executes the interactive volume edit flow.
-
#initialize(repository:, resource_type:, editor_session: nil, options: {}) ⇒ EditVolume
constructor
A new instance of EditVolume.
Constructor Details
#initialize(repository:, resource_type:, editor_session: nil, options: {}) ⇒ EditVolume
Returns a new instance of EditVolume.
26 27 28 29 30 31 |
# File 'lib/pvectl/services/edit_volume.rb', line 26 def initialize(repository:, resource_type:, editor_session: nil, options: {}) @repository = repository @resource_type = resource_type @editor_session = editor_session @options = end |
Instance Method Details
#execute(id:, disk:, node:) ⇒ Models::VolumeOperationResult?
Executes the interactive volume edit flow.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pvectl/services/edit_volume.rb', line 39 def execute(id:, disk:, node:) config = @repository.fetch_config(node, id) disk_value = config[disk.to_sym] unless disk_value return build_result(id, disk, node, success: false, error: "Volume '#{disk}' not found in config for resource #{id}") end editable = parse_disk_config(disk_value) yaml_content = build_yaml_content(editable, disk, id, node) session = @editor_session || EditorSession.new edited = session.edit(yaml_content) return nil unless edited edited_config = parse_edited_yaml(edited) changes = compute_diff(editable, edited_config) return nil if no_changes?(changes) if @options[:dry_run] return build_result(id, disk, node, success: true, resource: { diff: changes }) end apply_changes(id, disk, node, disk_value, changes) build_result(id, disk, node, success: true) rescue ResizeVolume::VolumeNotFoundError, ResizeVolume::SizeTooSmallError, ArgumentError => e build_result(id, disk, node, success: false, error: e.) rescue StandardError => e build_result(id, disk, node, success: false, error: e.) end |